Text Classification
Transformers
Safetensors
Bengali
English
xlm-roberta
safeage
safety-classification
bangla
banglish
text-embeddings-inference
Instructions to use mehedi4/SafeAge-XLM-R-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mehedi4/SafeAge-XLM-R-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="mehedi4/SafeAge-XLM-R-Base")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("mehedi4/SafeAge-XLM-R-Base") model = AutoModelForSequenceClassification.from_pretrained("mehedi4/SafeAge-XLM-R-Base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Release original SafeAge-trained xlmr baseline checkpoint
Browse filesOriginal evaluated weights matched to archived training-run SHA256 records; includes tokenizer, frozen validation threshold, loading example, attribution, and provenance. No retraining or new evaluation.
- .gitattributes +1 -0
- LICENSE +22 -0
- LICENSE.base-model.mit +21 -0
- README.md +114 -0
- SHA256SUMS +21 -0
- base_model_reference.json +17 -0
- config.json +39 -0
- decision_threshold.json +10 -0
- evaluation/test_by_language_variant.csv +5 -0
- evaluation/test_metrics.json +48 -0
- inference.py +86 -0
- model.safetensors +3 -0
- provenance/environment.json +17 -0
- provenance/model_reload_check.json +5 -0
- provenance/original_checkpoint_sha256.json +9 -0
- provenance/release_verification.json +83 -0
- provenance/training_configuration.json +19 -0
- provenance/upstream_license_source.json +6 -0
- provenance/upstream_model_card.md +200 -0
- provenance/weight_update_check.json +5 -0
- requirements.txt +6 -0
- tokenizer.json +3 -0
- tokenizer_config.json +14 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Facebook, Inc. and its affiliates.
|
| 4 |
+
Copyright (c) 2026 SafeAge authors (fine-tuning and original release materials).
|
| 5 |
+
|
| 6 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
in the Software without restriction, including without limitation the rights
|
| 9 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
furnished to do so, subject to the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 22 |
+
SOFTWARE.
|
LICENSE.base-model.mit
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Facebook, Inc. and its affiliates.
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- bn
|
| 4 |
+
- en
|
| 5 |
+
license: mit
|
| 6 |
+
library_name: transformers
|
| 7 |
+
pipeline_tag: text-classification
|
| 8 |
+
base_model: FacebookAI/xlm-roberta-base
|
| 9 |
+
base_model_relation: finetune
|
| 10 |
+
tags:
|
| 11 |
+
- safeage
|
| 12 |
+
- safety-classification
|
| 13 |
+
- bangla
|
| 14 |
+
- banglish
|
| 15 |
+
- xlm-roberta
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# SafeAge XLM-R Base
|
| 19 |
+
|
| 20 |
+
This is the **original fully fine-tuned XLM-R base comparison model** evaluated in the SafeAge study. The SafeAge authors fine-tuned [FacebookAI/xlm-roberta-base](https://huggingface.co/FacebookAI/xlm-roberta-base) and its binary classification head on the SafeAge training partition. The pretrained architecture and representations are credited to [Conneau et al.](https://arxiv.org/abs/1911.02116) and the XLM-R team. This is a trained baseline, distinct from **SafeAge Guard**, the study's Qwen3-1.7B LoRA reference adaptation.
|
| 21 |
+
|
| 22 |
+
The repository contains the complete original classifier weights, tokenizer, validation-selected decision threshold, loading example, evaluation metadata, and provenance. **No base-model download or LoRA merge is required.** The original tensors and tokenizer/configuration files are unchanged.
|
| 23 |
+
|
| 24 |
+
## Decisions and intended use
|
| 25 |
+
|
| 26 |
+
The model classifies a complete request and its supplied visible context under SafeAge's contextual **allow/block** policy. It was trained on Bangla, Bangla-English mixed text, romanized Bangla (Banglish), and an aligned English reference form.
|
| 27 |
+
|
| 28 |
+
The original saved labels are `0 = benign` (allow) and `1 = attack` (block). The block class includes harmful facilitation and unauthorized actions as well as prompt injection. Compute the two-class softmax and **block when the class-1 probability is greater than or equal to 0.99**. This threshold was selected using validation only and frozen before test evaluation. The generic classification pipeline's argmax or default 0.5 rule does not reproduce this operating point.
|
| 29 |
+
|
| 30 |
+
Provide the raw request text and the context needed to decide whether the requested action is permitted. Do not apply a chat template. Labels do not measure age suitability, generated-response safety, or complete agent security. Untrusted text asserting permission does not itself establish authorization.
|
| 31 |
+
|
| 32 |
+
## Loading and inference
|
| 33 |
+
|
| 34 |
+
Install `requirements.txt` and download `inference.py` from this repository:
|
| 35 |
+
|
| 36 |
+
```bash
|
| 37 |
+
pip install -r requirements.txt
|
| 38 |
+
python inference.py --text "Explain how to protect my own account from phishing."
|
| 39 |
+
python inference.py --text-file request.txt
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Programmatic usage, with `inference.py` in your working directory:
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
from inference import load_classifier, classify_texts
|
| 46 |
+
|
| 47 |
+
classifier = load_classifier("mehedi4/SafeAge-XLM-R-Base")
|
| 48 |
+
print(classify_texts(["Explain how to protect my own account from phishing."], classifier))
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
An exact release commit can be passed as `revision` or `--revision`. The complete model can also be loaded with `AutoModelForSequenceClassification.from_pretrained`; apply the saved **0.99** threshold rather than taking the maximum class.
|
| 52 |
+
|
| 53 |
+
The saved tensors are FP32. The original run used Transformers 5.5.4, PyTorch 2.11.0, and FP16 mixed precision on CUDA. The example keeps FP32 weights and uses FP16 autocast on CUDA by default, matching that mixed-precision setting; CPU inference uses FP32. `--precision fp32` explicitly selects full precision. Precision, hardware, library versions, batching, and attention kernels may cause small numerical differences, so alternative execution settings do not promise bitwise equality with the archived probabilities.
|
| 54 |
+
|
| 55 |
+
Inputs use a **512-token** maximum, right padding, and padding to a multiple of 8. The loader explicitly uses right truncation, the library default used by the original worker, which did not set a truncation-side override. The classifier architecture uses the first-token XLM-R classification head. The loader preserves the saved architecture and the library's attention selection used by the original loading code. Long inputs are truncated; important context beyond the limit may be lost.
|
| 56 |
+
|
| 57 |
+
## Training and data
|
| 58 |
+
|
| 59 |
+
[SafeAge](https://doi.org/10.5281/zenodo.23622437) contains 24,508 labeled requests from 6,127 aligned four-form cases. The fixed partitions contain 22,096 training, 1,208 validation, and 1,204 test requests, with related cases grouped within partitions. Validation and test contain author-reviewed constructed cases from synthetic scenario expansions. They are not independently collected user traffic.
|
| 60 |
+
|
| 61 |
+
The two authors annotated disjoint assigned subsets and repeatedly reviewed their own examples. The same procedure applied to validation and test. No independent double-annotation set was used, so inter-annotator agreement was not estimated.
|
| 62 |
+
|
| 63 |
+
| Setting | Value |
|
| 64 |
+
|---|---|
|
| 65 |
+
| Pretrained base | `FacebookAI/xlm-roberta-base` |
|
| 66 |
+
| Exact pretrained revision | `e73636d4f797dec63c3081bb6ed5c7b0bb3f2089` |
|
| 67 |
+
| Training method | Full fine-tuning, including a binary classification head |
|
| 68 |
+
| Parameters | 278,045,186 |
|
| 69 |
+
| Saved tensor dtype / training precision | FP32 / FP16 mixed |
|
| 70 |
+
| Optimizer / learning rate | AdamW / 0.00002 |
|
| 71 |
+
| Weight decay / warmup | 0.01 / 10% |
|
| 72 |
+
| Effective batch size | 32 |
|
| 73 |
+
| Completed epochs / selected epoch | 5 / 5 |
|
| 74 |
+
| Training seed | 42 |
|
| 75 |
+
| Maximum input length | 512 tokens |
|
| 76 |
+
| Checkpoint selection | Highest validation macro F1 at threshold 0.5 |
|
| 77 |
+
| Decision threshold selection | Validation macro F1 on a 0.01-spaced grid; ties closest to 0.5, then lower threshold |
|
| 78 |
+
|
| 79 |
+
## Held-out evaluation
|
| 80 |
+
|
| 81 |
+
At the frozen threshold **0.99**, the original checkpoint achieved the following on **1,204 SafeAge test requests** (301 cases; 199 connected groups):
|
| 82 |
+
|
| 83 |
+
| Metric | Result |
|
| 84 |
+
|---|---:|
|
| 85 |
+
| Accuracy | 91.03% |
|
| 86 |
+
| Macro F1 | 90.14% |
|
| 87 |
+
| Block precision | 93.15% |
|
| 88 |
+
| Block recall | 81.92% |
|
| 89 |
+
| Benign false positive rate | 3.57% |
|
| 90 |
+
| Brier score | 0.08267 |
|
| 91 |
+
|
| 92 |
+
Confusion counts: **729 true negatives, 27 false positives, 81 false negatives, and 367 true positives**. `evaluation/test_metrics.json` contains the original run's results at thresholds 0.5 and 0.99; `evaluation/test_by_language_variant.csv` records language slices. These are archived measurements, not a new inference run during release. The paper's confidence intervals use connected-group resampling and do not estimate training-seed variation.
|
| 93 |
+
|
| 94 |
+
## Verification and limitations
|
| 95 |
+
|
| 96 |
+
All **seven original checkpoint files** were checked against the archived run's SHA256 manifest. Five inference-required original files are released byte-for-byte; `trainer_state.json` and `training_args.bin` are training-only artifacts and are not required for inference.
|
| 97 |
+
|
| 98 |
+
The complete `model.safetensors` SHA256 is:
|
| 99 |
+
|
| 100 |
+
```text
|
| 101 |
+
050b292486894af1e841a0d4a9f6a3992f5bb3413a4ddeb59806d6a458dce442
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
The file contains 201 FP32 tensors, including the trained classifier's dense and output projection weights and biases. The archived eight-validation-row reload check passed with a maximum positive-probability difference of `4.27e-08`, as recorded in `provenance/model_reload_check.json`. Release preparation checks artifact identity and structure; it does not add a fresh model evaluation.
|
| 105 |
+
|
| 106 |
+
Results use a single seed on an author-curated benchmark with synthetic held-out scenarios and no measured independent annotation agreement. Template regularities, translation style, and truncation may affect performance. The model has not established universal safety performance or deployment reliability. Its validation-selected threshold does not guarantee the same error rates on other data.
|
| 107 |
+
|
| 108 |
+
## License and attribution
|
| 109 |
+
|
| 110 |
+
The pinned [upstream XLM-R model card](https://huggingface.co/FacebookAI/xlm-roberta-base/blob/e73636d4f797dec63c3081bb6ed5c7b0bb3f2089/README.md) declares **MIT**. The original fairseq MIT copyright notice is included as `LICENSE.base-model.mit`; the source URL and revision are recorded in `provenance/upstream_license_source.json`. The SafeAge fine-tuned release and accompanying original materials use MIT, consistent with the authors' SafeAge Guard release, while preserving upstream attribution. The SafeAge dataset has separate release terms; this model license does not relicense the dataset.
|
| 111 |
+
|
| 112 |
+
Dataset and adaptation authors: **Md. Rehanul Bary and Mehedi Hasan Emon**. Associated manuscript: *SafeAge: Context-Sensitive Safety Classification for Bangla LLMs and Agentic Systems across Four Language Forms*. No conference acceptance or publication is claimed here.
|
| 113 |
+
|
| 114 |
+
Historical experiment identifiers in provenance retain their original version strings for traceability. The dataset's display name is **SafeAge**.
|
SHA256SUMS
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fb5a8d4e1db3b510fdec89f13a0bd7b04e2340dd3fa090e19618b33f0b8eacd1 LICENSE
|
| 2 |
+
52412d7bc7ce4157ea628bbaacb8829e0a9cb3c58f57f99176126bc8cf2bfc85 LICENSE.base-model.mit
|
| 3 |
+
155fef939c4b3457a7674a19c8c78a10a15731e159b074b1f3b45fd5b30ca8d3 README.md
|
| 4 |
+
886e8ca7cd4f2275bd9ef27ef300947720772e890cb5759b4102f6cd5f97c709 base_model_reference.json
|
| 5 |
+
9438e0e2e31d4e3d23c2dc7c03d828c2fe935ece253961bfc8a1d83dbba59aea config.json
|
| 6 |
+
5e205df03ac49585e4f32fd21bf2947ecd11470bd380ab2af21dca8c08638f93 decision_threshold.json
|
| 7 |
+
5ad15a1e7c8bfd423f2b9aed05a4439dfffb6f1eb564a8f769f49896fe6f2b4b evaluation/test_by_language_variant.csv
|
| 8 |
+
f1c4650dc4c37a88c61b18dc3a6217737133ca80f98103de57898ff43497cc8c evaluation/test_metrics.json
|
| 9 |
+
53325b09949b6cc71e6ffba4d22fc942e3c57f1c68670004367c06545e31a543 inference.py
|
| 10 |
+
050b292486894af1e841a0d4a9f6a3992f5bb3413a4ddeb59806d6a458dce442 model.safetensors
|
| 11 |
+
9ba46d0d822b7a3b52f37a6e598285f78f493e3a898473a2481c02683c5e37b1 provenance/environment.json
|
| 12 |
+
4a0b373298c9cb9b3cbb49a2bc96378cb4ea8aabf7e7afbffa459a1e15426d28 provenance/model_reload_check.json
|
| 13 |
+
17d1b70eb1aa582d07372c1993db738bf0a52fd1a04bc6d791553a29ec90ef73 provenance/original_checkpoint_sha256.json
|
| 14 |
+
840bacdd195a9c6c825fabf9cafa8efd032a7e8073ca181d4c7546a2102cdd08 provenance/release_verification.json
|
| 15 |
+
b378ed2a1680acf4f113e81df1094b4ec9ee76625402b5c3b9e77e6f58b59525 provenance/training_configuration.json
|
| 16 |
+
bc126adec626ce03e965030c2638d3e3358565614e0189268f81cd2023d0bc5f provenance/upstream_license_source.json
|
| 17 |
+
bec9f2cd81f7396a64ee474145117d81139906443a21480cbe4993c97cb499aa provenance/upstream_model_card.md
|
| 18 |
+
006e42d58819f1bc1f876431ac60579ce182f586a17b0be69b60d1bdeaf1cb46 provenance/weight_update_check.json
|
| 19 |
+
c7e44a25ec692b836b4336d66c185fa9c0456109dd64b88cd50ccf8954e592c4 requirements.txt
|
| 20 |
+
acbd420e2269cdc1ef45332d3d5c418be4aef6b8cb5a0b7ccae0893485307153 tokenizer.json
|
| 21 |
+
159697d23b04b1e7a607e737f5d331e2d356e8484080d723a9495dafc58caab1 tokenizer_config.json
|
base_model_reference.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_source": "FacebookAI/xlm-roberta-base",
|
| 3 |
+
"model_revision": "e73636d4f797dec63c3081bb6ed5c7b0bb3f2089",
|
| 4 |
+
"training_method": "full_finetune",
|
| 5 |
+
"requires_base_model_download": false,
|
| 6 |
+
"num_labels": 2,
|
| 7 |
+
"id2label": {
|
| 8 |
+
"0": "benign",
|
| 9 |
+
"1": "attack"
|
| 10 |
+
},
|
| 11 |
+
"max_length": 512,
|
| 12 |
+
"pad_token_id": 1,
|
| 13 |
+
"saved_dtype": "float32",
|
| 14 |
+
"original_training_precision": "float16_mixed",
|
| 15 |
+
"padding_side": "right",
|
| 16 |
+
"truncation_side": "right"
|
| 17 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"XLMRobertaForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "float32",
|
| 10 |
+
"eos_token_id": 2,
|
| 11 |
+
"hidden_act": "gelu",
|
| 12 |
+
"hidden_dropout_prob": 0.1,
|
| 13 |
+
"hidden_size": 768,
|
| 14 |
+
"id2label": {
|
| 15 |
+
"0": "benign",
|
| 16 |
+
"1": "attack"
|
| 17 |
+
},
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"intermediate_size": 3072,
|
| 20 |
+
"is_decoder": false,
|
| 21 |
+
"label2id": {
|
| 22 |
+
"attack": 1,
|
| 23 |
+
"benign": 0
|
| 24 |
+
},
|
| 25 |
+
"layer_norm_eps": 1e-05,
|
| 26 |
+
"max_position_embeddings": 514,
|
| 27 |
+
"model_type": "xlm-roberta",
|
| 28 |
+
"num_attention_heads": 12,
|
| 29 |
+
"num_hidden_layers": 12,
|
| 30 |
+
"output_past": true,
|
| 31 |
+
"pad_token_id": 1,
|
| 32 |
+
"position_embedding_type": "absolute",
|
| 33 |
+
"problem_type": "single_label_classification",
|
| 34 |
+
"tie_word_embeddings": true,
|
| 35 |
+
"transformers_version": "5.5.4",
|
| 36 |
+
"type_vocab_size": 1,
|
| 37 |
+
"use_cache": false,
|
| 38 |
+
"vocab_size": 250002
|
| 39 |
+
}
|
decision_threshold.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"threshold": 0.99,
|
| 3 |
+
"selected_using": "validation_macro_f1",
|
| 4 |
+
"tie_break": "closest to 0.5, then lower threshold",
|
| 5 |
+
"source_split": "valid",
|
| 6 |
+
"positive_class": "attack",
|
| 7 |
+
"positive_class_id": 1,
|
| 8 |
+
"comparison": "probability_attack >= threshold",
|
| 9 |
+
"smoke_run": false
|
| 10 |
+
}
|
evaluation/test_by_language_variant.csv
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
language_variant,independent_groups,rows,benign_rows,attack_rows,threshold,accuracy,balanced_accuracy,macro_f1,attack_precision,attack_recall,attack_f1,benign_specificity,benign_false_positive_rate,attack_false_negative_rate,roc_auc,average_precision,brier_score,log_loss,tn,fp,fn,tp
|
| 2 |
+
banglish,199,301,189,112,0.99,0.8903654485049833,0.8708664021164021,0.87960145937625,0.898989898989899,0.7946428571428571,0.8436018957345972,0.9470899470899471,0.05291005291005291,0.20535714285714285,0.9588766061980348,0.942103455794577,0.11305866331354969,0.7794276160798205,179,10,23,89
|
| 3 |
+
bn,199,301,189,112,0.99,0.9169435215946844,0.9011243386243386,0.9091808778980653,0.9306930693069307,0.8392857142857143,0.8826291079812206,0.9629629629629629,0.037037037037037035,0.16071428571428573,0.9689862055933484,0.9603811310910885,0.07639742406036554,0.5753729884552156,182,7,18,94
|
| 4 |
+
bn_en,199,301,189,112,0.99,0.9169435215946844,0.8993055555555556,0.9087889843759469,0.9393939393939394,0.8303571428571429,0.8815165876777251,0.9682539682539683,0.031746031746031744,0.16964285714285715,0.9724584278155707,0.9630867201418858,0.07518063140097832,0.5491630271223695,183,6,19,93
|
| 5 |
+
en,199,301,189,112,0.99,0.9169435215946844,0.8956679894179894,0.9079679569497952,0.9578947368421052,0.8125,0.8792270531400966,0.9788359788359788,0.021164021164021163,0.1875,0.9772770219198792,0.9698465793237102,0.06604231339754098,0.47274693667632417,185,4,21,91
|
evaluation/test_metrics.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"default_0_5": {
|
| 3 |
+
"rows": 1204,
|
| 4 |
+
"benign_rows": 756,
|
| 5 |
+
"attack_rows": 448,
|
| 6 |
+
"threshold": 0.5,
|
| 7 |
+
"accuracy": 0.9127906976744186,
|
| 8 |
+
"balanced_accuracy": 0.9000909391534392,
|
| 9 |
+
"macro_f1": 0.9053775802797357,
|
| 10 |
+
"attack_precision": 0.9093078758949881,
|
| 11 |
+
"attack_recall": 0.8504464285714286,
|
| 12 |
+
"attack_f1": 0.8788927335640139,
|
| 13 |
+
"benign_specificity": 0.9497354497354498,
|
| 14 |
+
"benign_false_positive_rate": 0.05026455026455026,
|
| 15 |
+
"attack_false_negative_rate": 0.14955357142857142,
|
| 16 |
+
"roc_auc": 0.970037320483749,
|
| 17 |
+
"average_precision": 0.9595743795979578,
|
| 18 |
+
"brier_score": 0.08266975804310862,
|
| 19 |
+
"log_loss": 0.5941776420834323,
|
| 20 |
+
"tn": 718,
|
| 21 |
+
"fp": 38,
|
| 22 |
+
"fn": 67,
|
| 23 |
+
"tp": 381
|
| 24 |
+
},
|
| 25 |
+
"validation_selected": {
|
| 26 |
+
"rows": 1204,
|
| 27 |
+
"benign_rows": 756,
|
| 28 |
+
"attack_rows": 448,
|
| 29 |
+
"threshold": 0.99,
|
| 30 |
+
"accuracy": 0.9102990033222591,
|
| 31 |
+
"balanced_accuracy": 0.8917410714285714,
|
| 32 |
+
"macro_f1": 0.9013842247522319,
|
| 33 |
+
"attack_precision": 0.9314720812182741,
|
| 34 |
+
"attack_recall": 0.8191964285714286,
|
| 35 |
+
"attack_f1": 0.8717339667458432,
|
| 36 |
+
"benign_specificity": 0.9642857142857143,
|
| 37 |
+
"benign_false_positive_rate": 0.03571428571428571,
|
| 38 |
+
"attack_false_negative_rate": 0.18080357142857142,
|
| 39 |
+
"roc_auc": 0.970037320483749,
|
| 40 |
+
"average_precision": 0.9595743795979578,
|
| 41 |
+
"brier_score": 0.08266975804310862,
|
| 42 |
+
"log_loss": 0.5941776420834323,
|
| 43 |
+
"tn": 729,
|
| 44 |
+
"fp": 27,
|
| 45 |
+
"fn": 81,
|
| 46 |
+
"tp": 367
|
| 47 |
+
}
|
| 48 |
+
}
|
inference.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Load the original fully fine-tuned SafeAge XLM-R binary baseline."""
|
| 2 |
+
import argparse
|
| 3 |
+
import contextlib
|
| 4 |
+
import json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
DEFAULT_REPO = "mehedi4/SafeAge-XLM-R-Base"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def load_classifier(source=DEFAULT_REPO, revision=None, device=None, precision="auto"):
|
| 11 |
+
import torch
|
| 12 |
+
from huggingface_hub import snapshot_download
|
| 13 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 14 |
+
|
| 15 |
+
folder = Path(source)
|
| 16 |
+
if not folder.is_dir():
|
| 17 |
+
folder = Path(snapshot_download(
|
| 18 |
+
repo_id=source, revision=revision,
|
| 19 |
+
allow_patterns=["config.json", "model.safetensors", "decision_threshold.json",
|
| 20 |
+
"tokenizer.json", "tokenizer_config.json", "base_model_reference.json"],
|
| 21 |
+
))
|
| 22 |
+
reference = json.loads((folder / "base_model_reference.json").read_text())
|
| 23 |
+
decision = json.loads((folder / "decision_threshold.json").read_text())
|
| 24 |
+
tokenizer = AutoTokenizer.from_pretrained(folder, use_fast=True, local_files_only=True)
|
| 25 |
+
tokenizer.model_max_length = reference["max_length"]
|
| 26 |
+
tokenizer.padding_side = "right"
|
| 27 |
+
tokenizer.truncation_side = "right"
|
| 28 |
+
if tokenizer.pad_token_id != reference["pad_token_id"]:
|
| 29 |
+
raise ValueError("Padding token differs from the original evaluated tokenizer")
|
| 30 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 31 |
+
folder, local_files_only=True, use_safetensors=True, dtype=torch.float32,
|
| 32 |
+
).eval()
|
| 33 |
+
if model.config.model_type != "xlm-roberta" or model.config.num_labels != 2:
|
| 34 |
+
raise ValueError("Expected the original binary XLM-R classifier")
|
| 35 |
+
model.requires_grad_(False)
|
| 36 |
+
device = torch.device(device or ("cuda" if torch.cuda.is_available() else "cpu"))
|
| 37 |
+
if precision not in {"auto", "fp32", "fp16_mixed"}:
|
| 38 |
+
raise ValueError("Precision must be auto, fp32, or fp16_mixed")
|
| 39 |
+
mixed = device.type == "cuda" if precision == "auto" else precision == "fp16_mixed"
|
| 40 |
+
if mixed and device.type != "cuda":
|
| 41 |
+
raise ValueError("FP16 mixed inference requires a CUDA device; use fp32 on CPU")
|
| 42 |
+
model.to(device)
|
| 43 |
+
return model, tokenizer, reference, decision, mixed
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def classify_texts(texts, classifier):
|
| 47 |
+
"""Classify complete raw requests with context; no chat template is applied."""
|
| 48 |
+
import torch
|
| 49 |
+
if isinstance(texts, str):
|
| 50 |
+
texts = [texts]
|
| 51 |
+
if not texts or any(not isinstance(text, str) for text in texts):
|
| 52 |
+
raise ValueError("Supply one or more strings")
|
| 53 |
+
model, tokenizer, reference, decision, mixed = classifier
|
| 54 |
+
encoded = tokenizer(
|
| 55 |
+
texts, truncation=True, max_length=reference["max_length"], padding=True,
|
| 56 |
+
pad_to_multiple_of=8, return_token_type_ids=False, return_tensors="pt",
|
| 57 |
+
)
|
| 58 |
+
device = next(model.parameters()).device
|
| 59 |
+
encoded = {key: value.to(device) for key, value in encoded.items()}
|
| 60 |
+
amp = torch.autocast(device_type="cuda", dtype=torch.float16) if mixed else contextlib.nullcontext()
|
| 61 |
+
with torch.inference_mode(), amp:
|
| 62 |
+
logits = model(**encoded).logits
|
| 63 |
+
# The archived worker computes softmax after converting logits to float64.
|
| 64 |
+
values = torch.softmax(logits.double(), dim=-1)[:, decision["positive_class_id"]].cpu().tolist()
|
| 65 |
+
threshold = float(decision["threshold"])
|
| 66 |
+
return [{"decision": "block" if p >= threshold else "allow",
|
| 67 |
+
"block_probability": p, "threshold": threshold} for p in values]
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def main():
|
| 71 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 72 |
+
group = parser.add_mutually_exclusive_group(required=True)
|
| 73 |
+
group.add_argument("--text", help="Complete raw request and its visible context")
|
| 74 |
+
group.add_argument("--text-file", type=Path, help="UTF-8 file containing one complete request")
|
| 75 |
+
parser.add_argument("--source", default=DEFAULT_REPO, help="Hub repository or local folder")
|
| 76 |
+
parser.add_argument("--revision", help="Optional exact release commit")
|
| 77 |
+
parser.add_argument("--device", help="cpu, cuda, or cuda:0; default selects CUDA if available")
|
| 78 |
+
parser.add_argument("--precision", choices=["auto", "fp32", "fp16_mixed"], default="auto")
|
| 79 |
+
args = parser.parse_args()
|
| 80 |
+
text = args.text if args.text is not None else args.text_file.read_text(encoding="utf-8")
|
| 81 |
+
classifier = load_classifier(args.source, args.revision, args.device, args.precision)
|
| 82 |
+
print(json.dumps(classify_texts(text, classifier)[0], ensure_ascii=False, indent=2))
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
if __name__ == "__main__":
|
| 86 |
+
main()
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:050b292486894af1e841a0d4a9f6a3992f5bb3413a4ddeb59806d6a458dce442
|
| 3 |
+
size 1112204984
|
provenance/environment.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"versions": {
|
| 3 |
+
"torch": "2.11.0+cu128",
|
| 4 |
+
"transformers": "5.5.4",
|
| 5 |
+
"accelerate": "1.13.0",
|
| 6 |
+
"numpy": "2.1.3",
|
| 7 |
+
"pandas": "2.3.3",
|
| 8 |
+
"scikit-learn": "1.6.1",
|
| 9 |
+
"tokenizers": "0.22.2",
|
| 10 |
+
"huggingface-hub": "1.29.0"
|
| 11 |
+
},
|
| 12 |
+
"cuda_version": "12.8",
|
| 13 |
+
"world_size": 2,
|
| 14 |
+
"effective_batch_size": 32,
|
| 15 |
+
"model_revision": "e73636d4f797dec63c3081bb6ed5c7b0bb3f2089",
|
| 16 |
+
"model_path": "/kaggle/working/hf_cache/models--FacebookAI--xlm-roberta-base/snapshots/e73636d4f797dec63c3081bb6ed5c7b0bb3f2089"
|
| 17 |
+
}
|
provenance/model_reload_check.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"status": "PASS",
|
| 3 |
+
"validation_rows": 8,
|
| 4 |
+
"maximum_probability_difference": 4.270144715601276e-08
|
| 5 |
+
}
|
provenance/original_checkpoint_sha256.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"config.json": "9438e0e2e31d4e3d23c2dc7c03d828c2fe935ece253961bfc8a1d83dbba59aea",
|
| 3 |
+
"decision_threshold.json": "5e205df03ac49585e4f32fd21bf2947ecd11470bd380ab2af21dca8c08638f93",
|
| 4 |
+
"model.safetensors": "050b292486894af1e841a0d4a9f6a3992f5bb3413a4ddeb59806d6a458dce442",
|
| 5 |
+
"tokenizer.json": "acbd420e2269cdc1ef45332d3d5c418be4aef6b8cb5a0b7ccae0893485307153",
|
| 6 |
+
"tokenizer_config.json": "159697d23b04b1e7a607e737f5d331e2d356e8484080d723a9495dafc58caab1",
|
| 7 |
+
"trainer_state.json": "9234ad8b94308a82c0a487c5265167d8f5afea7cde4174e006fb68a2475cf431",
|
| 8 |
+
"training_args.bin": "dcc4257d8b83dec675a33e0ee1af4429f34c4f1bc5a015012563a466d0c5eb20"
|
| 9 |
+
}
|
provenance/release_verification.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"repository": "mehedi4/SafeAge-XLM-R-Base",
|
| 3 |
+
"original_checkpoint_directory": "xlmr/safeage_v3_xlmr_base_full_seed42_20261024_144752_7006aa/best_model",
|
| 4 |
+
"all_original_checkpoint_files_verified": true,
|
| 5 |
+
"original_file_count": 7,
|
| 6 |
+
"original_checkpoint_sha256": {
|
| 7 |
+
"config.json": "9438e0e2e31d4e3d23c2dc7c03d828c2fe935ece253961bfc8a1d83dbba59aea",
|
| 8 |
+
"decision_threshold.json": "5e205df03ac49585e4f32fd21bf2947ecd11470bd380ab2af21dca8c08638f93",
|
| 9 |
+
"model.safetensors": "050b292486894af1e841a0d4a9f6a3992f5bb3413a4ddeb59806d6a458dce442",
|
| 10 |
+
"tokenizer.json": "acbd420e2269cdc1ef45332d3d5c418be4aef6b8cb5a0b7ccae0893485307153",
|
| 11 |
+
"tokenizer_config.json": "159697d23b04b1e7a607e737f5d331e2d356e8484080d723a9495dafc58caab1",
|
| 12 |
+
"trainer_state.json": "9234ad8b94308a82c0a487c5265167d8f5afea7cde4174e006fb68a2475cf431",
|
| 13 |
+
"training_args.bin": "dcc4257d8b83dec675a33e0ee1af4429f34c4f1bc5a015012563a466d0c5eb20"
|
| 14 |
+
},
|
| 15 |
+
"published_original_files": [
|
| 16 |
+
"config.json",
|
| 17 |
+
"decision_threshold.json",
|
| 18 |
+
"model.safetensors",
|
| 19 |
+
"tokenizer.json",
|
| 20 |
+
"tokenizer_config.json"
|
| 21 |
+
],
|
| 22 |
+
"excluded_training_only_files": [
|
| 23 |
+
"trainer_state.json",
|
| 24 |
+
"training_args.bin"
|
| 25 |
+
],
|
| 26 |
+
"all_published_checkpoint_files_unchanged": true,
|
| 27 |
+
"model_tensor_count": 201,
|
| 28 |
+
"model_parameter_count": 278045186,
|
| 29 |
+
"classifier_tensors": {
|
| 30 |
+
"classifier.dense.bias": {
|
| 31 |
+
"dtype": "F32",
|
| 32 |
+
"shape": [
|
| 33 |
+
768
|
| 34 |
+
],
|
| 35 |
+
"data_offsets": [
|
| 36 |
+
0,
|
| 37 |
+
3072
|
| 38 |
+
]
|
| 39 |
+
},
|
| 40 |
+
"classifier.dense.weight": {
|
| 41 |
+
"dtype": "F32",
|
| 42 |
+
"shape": [
|
| 43 |
+
768,
|
| 44 |
+
768
|
| 45 |
+
],
|
| 46 |
+
"data_offsets": [
|
| 47 |
+
3072,
|
| 48 |
+
2362368
|
| 49 |
+
]
|
| 50 |
+
},
|
| 51 |
+
"classifier.out_proj.bias": {
|
| 52 |
+
"dtype": "F32",
|
| 53 |
+
"shape": [
|
| 54 |
+
2
|
| 55 |
+
],
|
| 56 |
+
"data_offsets": [
|
| 57 |
+
2362368,
|
| 58 |
+
2362376
|
| 59 |
+
]
|
| 60 |
+
},
|
| 61 |
+
"classifier.out_proj.weight": {
|
| 62 |
+
"dtype": "F32",
|
| 63 |
+
"shape": [
|
| 64 |
+
2,
|
| 65 |
+
768
|
| 66 |
+
],
|
| 67 |
+
"data_offsets": [
|
| 68 |
+
2362376,
|
| 69 |
+
2368520
|
| 70 |
+
]
|
| 71 |
+
}
|
| 72 |
+
},
|
| 73 |
+
"base_model_revision": "e73636d4f797dec63c3081bb6ed5c7b0bb3f2089",
|
| 74 |
+
"threshold": 0.99,
|
| 75 |
+
"inference_script_syntax_valid": true,
|
| 76 |
+
"release_new_inference_performed": false,
|
| 77 |
+
"original_model_reload_check": {
|
| 78 |
+
"status": "PASS",
|
| 79 |
+
"validation_rows": 8,
|
| 80 |
+
"maximum_probability_difference": 4.270144715601276e-08
|
| 81 |
+
},
|
| 82 |
+
"license_selection_source": "Pinned upstream XLM-R card declares MIT; upstream fairseq copyright preserved; MIT for SafeAge modifications follows the authors' existing SafeAge Guard release."
|
| 83 |
+
}
|
provenance/training_configuration.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"seed": 42,
|
| 3 |
+
"model_source": "FacebookAI/xlm-roberta-base",
|
| 4 |
+
"model_revision": "e73636d4f797dec63c3081bb6ed5c7b0bb3f2089",
|
| 5 |
+
"max_length": 512,
|
| 6 |
+
"expected_world_size": 2,
|
| 7 |
+
"per_device_train_batch_size": 4,
|
| 8 |
+
"gradient_accumulation_steps": 4,
|
| 9 |
+
"epochs": 5,
|
| 10 |
+
"learning_rate": 2e-05,
|
| 11 |
+
"weight_decay": 0.01,
|
| 12 |
+
"warmup_fraction": 0.1,
|
| 13 |
+
"optimizer": "adamw_torch",
|
| 14 |
+
"fp16": true,
|
| 15 |
+
"bf16": false,
|
| 16 |
+
"precision": "float16_mixed",
|
| 17 |
+
"training_method": "full_finetune",
|
| 18 |
+
"resolved_model_revision": "e73636d4f797dec63c3081bb6ed5c7b0bb3f2089"
|
| 19 |
+
}
|
provenance/upstream_license_source.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"license": "MIT",
|
| 3 |
+
"pinned_huggingface_card": "https://huggingface.co/FacebookAI/xlm-roberta-base/blob/e73636d4f797dec63c3081bb6ed5c7b0bb3f2089/README.md",
|
| 4 |
+
"license_file_source": "https://raw.githubusercontent.com/facebookresearch/fairseq/3d262bb25690e4eb2e7d3c1309b1e9c406ca4b99/LICENSE",
|
| 5 |
+
"upstream_fairseq_revision": "3d262bb25690e4eb2e7d3c1309b1e9c406ca4b99"
|
| 6 |
+
}
|
provenance/upstream_model_card.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- exbert
|
| 4 |
+
language:
|
| 5 |
+
- multilingual
|
| 6 |
+
- af
|
| 7 |
+
- am
|
| 8 |
+
- ar
|
| 9 |
+
- as
|
| 10 |
+
- az
|
| 11 |
+
- be
|
| 12 |
+
- bg
|
| 13 |
+
- bn
|
| 14 |
+
- br
|
| 15 |
+
- bs
|
| 16 |
+
- ca
|
| 17 |
+
- cs
|
| 18 |
+
- cy
|
| 19 |
+
- da
|
| 20 |
+
- de
|
| 21 |
+
- el
|
| 22 |
+
- en
|
| 23 |
+
- eo
|
| 24 |
+
- es
|
| 25 |
+
- et
|
| 26 |
+
- eu
|
| 27 |
+
- fa
|
| 28 |
+
- fi
|
| 29 |
+
- fr
|
| 30 |
+
- fy
|
| 31 |
+
- ga
|
| 32 |
+
- gd
|
| 33 |
+
- gl
|
| 34 |
+
- gu
|
| 35 |
+
- ha
|
| 36 |
+
- he
|
| 37 |
+
- hi
|
| 38 |
+
- hr
|
| 39 |
+
- hu
|
| 40 |
+
- hy
|
| 41 |
+
- id
|
| 42 |
+
- is
|
| 43 |
+
- it
|
| 44 |
+
- ja
|
| 45 |
+
- jv
|
| 46 |
+
- ka
|
| 47 |
+
- kk
|
| 48 |
+
- km
|
| 49 |
+
- kn
|
| 50 |
+
- ko
|
| 51 |
+
- ku
|
| 52 |
+
- ky
|
| 53 |
+
- la
|
| 54 |
+
- lo
|
| 55 |
+
- lt
|
| 56 |
+
- lv
|
| 57 |
+
- mg
|
| 58 |
+
- mk
|
| 59 |
+
- ml
|
| 60 |
+
- mn
|
| 61 |
+
- mr
|
| 62 |
+
- ms
|
| 63 |
+
- my
|
| 64 |
+
- ne
|
| 65 |
+
- nl
|
| 66 |
+
- no
|
| 67 |
+
- om
|
| 68 |
+
- or
|
| 69 |
+
- pa
|
| 70 |
+
- pl
|
| 71 |
+
- ps
|
| 72 |
+
- pt
|
| 73 |
+
- ro
|
| 74 |
+
- ru
|
| 75 |
+
- sa
|
| 76 |
+
- sd
|
| 77 |
+
- si
|
| 78 |
+
- sk
|
| 79 |
+
- sl
|
| 80 |
+
- so
|
| 81 |
+
- sq
|
| 82 |
+
- sr
|
| 83 |
+
- su
|
| 84 |
+
- sv
|
| 85 |
+
- sw
|
| 86 |
+
- ta
|
| 87 |
+
- te
|
| 88 |
+
- th
|
| 89 |
+
- tl
|
| 90 |
+
- tr
|
| 91 |
+
- ug
|
| 92 |
+
- uk
|
| 93 |
+
- ur
|
| 94 |
+
- uz
|
| 95 |
+
- vi
|
| 96 |
+
- xh
|
| 97 |
+
- yi
|
| 98 |
+
- zh
|
| 99 |
+
license: mit
|
| 100 |
+
---
|
| 101 |
+
|
| 102 |
+
# XLM-RoBERTa (base-sized model)
|
| 103 |
+
|
| 104 |
+
XLM-RoBERTa model pre-trained on 2.5TB of filtered CommonCrawl data containing 100 languages. It was introduced in the paper [Unsupervised Cross-lingual Representation Learning at Scale](https://arxiv.org/abs/1911.02116) by Conneau et al. and first released in [this repository](https://github.com/pytorch/fairseq/tree/master/examples/xlmr).
|
| 105 |
+
|
| 106 |
+
Disclaimer: The team releasing XLM-RoBERTa did not write a model card for this model so this model card has been written by the Hugging Face team.
|
| 107 |
+
|
| 108 |
+
## Model description
|
| 109 |
+
|
| 110 |
+
XLM-RoBERTa is a multilingual version of RoBERTa. It is pre-trained on 2.5TB of filtered CommonCrawl data containing 100 languages.
|
| 111 |
+
|
| 112 |
+
RoBERTa is a transformers model pretrained on a large corpus in a self-supervised fashion. This means it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of publicly available data) with an automatic process to generate inputs and labels from those texts.
|
| 113 |
+
|
| 114 |
+
More precisely, it was pretrained with the Masked language modeling (MLM) objective. Taking a sentence, the model randomly masks 15% of the words in the input then run the entire masked sentence through the model and has to predict the masked words. This is different from traditional recurrent neural networks (RNNs) that usually see the words one after the other, or from autoregressive models like GPT which internally mask the future tokens. It allows the model to learn a bidirectional representation of the sentence.
|
| 115 |
+
|
| 116 |
+
This way, the model learns an inner representation of 100 languages that can then be used to extract features useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a standard classifier using the features produced by the XLM-RoBERTa model as inputs.
|
| 117 |
+
|
| 118 |
+
## Intended uses & limitations
|
| 119 |
+
|
| 120 |
+
You can use the raw model for masked language modeling, but it's mostly intended to be fine-tuned on a downstream task. See the [model hub](https://huggingface.co/models?search=xlm-roberta) to look for fine-tuned versions on a task that interests you.
|
| 121 |
+
|
| 122 |
+
Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked) to make decisions, such as sequence classification, token classification or question answering. For tasks such as text generation, you should look at models like GPT2.
|
| 123 |
+
|
| 124 |
+
## Usage
|
| 125 |
+
|
| 126 |
+
You can use this model directly with a pipeline for masked language modeling:
|
| 127 |
+
|
| 128 |
+
```python
|
| 129 |
+
>>> from transformers import pipeline
|
| 130 |
+
>>> unmasker = pipeline('fill-mask', model='xlm-roberta-base')
|
| 131 |
+
>>> unmasker("Hello I'm a <mask> model.")
|
| 132 |
+
|
| 133 |
+
[{'score': 0.10563907772302628,
|
| 134 |
+
'sequence': "Hello I'm a fashion model.",
|
| 135 |
+
'token': 54543,
|
| 136 |
+
'token_str': 'fashion'},
|
| 137 |
+
{'score': 0.08015287667512894,
|
| 138 |
+
'sequence': "Hello I'm a new model.",
|
| 139 |
+
'token': 3525,
|
| 140 |
+
'token_str': 'new'},
|
| 141 |
+
{'score': 0.033413201570510864,
|
| 142 |
+
'sequence': "Hello I'm a model model.",
|
| 143 |
+
'token': 3299,
|
| 144 |
+
'token_str': 'model'},
|
| 145 |
+
{'score': 0.030217764899134636,
|
| 146 |
+
'sequence': "Hello I'm a French model.",
|
| 147 |
+
'token': 92265,
|
| 148 |
+
'token_str': 'French'},
|
| 149 |
+
{'score': 0.026436051353812218,
|
| 150 |
+
'sequence': "Hello I'm a sexy model.",
|
| 151 |
+
'token': 17473,
|
| 152 |
+
'token_str': 'sexy'}]
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
Here is how to use this model to get the features of a given text in PyTorch:
|
| 156 |
+
|
| 157 |
+
```python
|
| 158 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
| 159 |
+
|
| 160 |
+
tokenizer = AutoTokenizer.from_pretrained('xlm-roberta-base')
|
| 161 |
+
model = AutoModelForMaskedLM.from_pretrained("xlm-roberta-base")
|
| 162 |
+
|
| 163 |
+
# prepare input
|
| 164 |
+
text = "Replace me by any text you'd like."
|
| 165 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
| 166 |
+
|
| 167 |
+
# forward pass
|
| 168 |
+
output = model(**encoded_input)
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
### BibTeX entry and citation info
|
| 172 |
+
|
| 173 |
+
```bibtex
|
| 174 |
+
@article{DBLP:journals/corr/abs-1911-02116,
|
| 175 |
+
author = {Alexis Conneau and
|
| 176 |
+
Kartikay Khandelwal and
|
| 177 |
+
Naman Goyal and
|
| 178 |
+
Vishrav Chaudhary and
|
| 179 |
+
Guillaume Wenzek and
|
| 180 |
+
Francisco Guzm{\'{a}}n and
|
| 181 |
+
Edouard Grave and
|
| 182 |
+
Myle Ott and
|
| 183 |
+
Luke Zettlemoyer and
|
| 184 |
+
Veselin Stoyanov},
|
| 185 |
+
title = {Unsupervised Cross-lingual Representation Learning at Scale},
|
| 186 |
+
journal = {CoRR},
|
| 187 |
+
volume = {abs/1911.02116},
|
| 188 |
+
year = {2019},
|
| 189 |
+
url = {http://arxiv.org/abs/1911.02116},
|
| 190 |
+
eprinttype = {arXiv},
|
| 191 |
+
eprint = {1911.02116},
|
| 192 |
+
timestamp = {Mon, 11 Nov 2019 18:38:09 +0100},
|
| 193 |
+
biburl = {https://dblp.org/rec/journals/corr/abs-1911-02116.bib},
|
| 194 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
| 195 |
+
}
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
<a href="https://huggingface.co/exbert/?model=xlm-roberta-base">
|
| 199 |
+
<img width="300px" src="https://cdn-media.huggingface.co/exbert/button.png">
|
| 200 |
+
</a>
|
provenance/weight_update_check.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"changed": true,
|
| 3 |
+
"initial_classifier_head_sha256": "8525992b7c0f62ea5e7d4d9ba33a20aa71acf73016426ef8315c03aa6386e112",
|
| 4 |
+
"selected_classifier_head_sha256": "79dc02c2255263b0d4b98924ab1a23831c33d92c4505deda2b88e3f6b5027f1d"
|
| 5 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==2.11.0
|
| 2 |
+
transformers==5.5.4
|
| 3 |
+
accelerate==1.13.0
|
| 4 |
+
tokenizers==0.22.2
|
| 5 |
+
huggingface_hub==1.29.0
|
| 6 |
+
safetensors>=0.4.3
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:acbd420e2269cdc1ef45332d3d5c418be4aef6b8cb5a0b7ccae0893485307153
|
| 3 |
+
size 17098086
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"cls_token": "<s>",
|
| 6 |
+
"eos_token": "</s>",
|
| 7 |
+
"is_local": true,
|
| 8 |
+
"mask_token": "<mask>",
|
| 9 |
+
"model_max_length": 512,
|
| 10 |
+
"pad_token": "<pad>",
|
| 11 |
+
"sep_token": "</s>",
|
| 12 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 13 |
+
"unk_token": "<unk>"
|
| 14 |
+
}
|