Upload 9 files
Browse files- README.md +109 -0
- config.json +44 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- special_tokens_map.json +51 -0
- tokenizer.json +0 -0
- tokenizer_config.json +62 -0
- training_args.bin +3 -0
- vocab.json +0 -0
README.md
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# RoBERTa-Base Quantized Model for Named Entity Recognition (NER)
|
2 |
+
|
3 |
+
This repository contains a quantized version of the RoBERTa model fine-tuned for Named Entity Recognition (NER) on the WikiANN (English) dataset. The model is particularly suitable for **tagging named entities in news articles**, such as persons, organizations, and locations. It has been optimized for efficient deployment using quantization techniques.
|
4 |
+
|
5 |
+
|
6 |
+
## Model Details
|
7 |
+
|
8 |
+
- **Model Architecture:** RoBERTa Base
|
9 |
+
- **Task:** Named Entity Recognition
|
10 |
+
- **Dataset:** WikiANN (English)
|
11 |
+
- **Use Case:** Tagging news articles with named entities
|
12 |
+
- **Quantization:** Float16
|
13 |
+
- **Fine-tuning Framework:** Hugging Face Transformers
|
14 |
+
|
15 |
+
## Usage
|
16 |
+
|
17 |
+
### Installation
|
18 |
+
|
19 |
+
```sh
|
20 |
+
pip install transformers torch
|
21 |
+
```
|
22 |
+
|
23 |
+
|
24 |
+
### Loading the Model
|
25 |
+
|
26 |
+
```python
|
27 |
+
|
28 |
+
from transformers import RobertaTokenizerFast, RobertaForSequenceClassification, Trainer, TrainingArguments
|
29 |
+
import torch
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
# Load tokenizer
|
34 |
+
|
35 |
+
tokenizer = RobertaTokenizerFast.from_pretrained("roberta-base")
|
36 |
+
|
37 |
+
# Create NER pipeline
|
38 |
+
ner_pipeline = pipeline(
|
39 |
+
"ner",
|
40 |
+
model=model,
|
41 |
+
tokenizer=tokenizer,
|
42 |
+
aggregation_strategy="simple"
|
43 |
+
)
|
44 |
+
|
45 |
+
# Sample news headline
|
46 |
+
text = "Apple Inc. is planning to open a new campus in London by the end of 2025."
|
47 |
+
|
48 |
+
# Inference
|
49 |
+
entities = ner_pipeline(text)
|
50 |
+
|
51 |
+
# Display results
|
52 |
+
for ent in entities:
|
53 |
+
print(f"{ent['word']}: {ent['entity_group']} ({ent['score']:.2f})")
|
54 |
+
|
55 |
+
```
|
56 |
+
|
57 |
+
## Performance Metrics
|
58 |
+
|
59 |
+
- **Accuracy:** 0.923422
|
60 |
+
- **Precision:** 0.923052
|
61 |
+
- **Recall:** 0.923422
|
62 |
+
- **F1:** 0.923150
|
63 |
+
|
64 |
+
|
65 |
+
## Fine-Tuning Details
|
66 |
+
|
67 |
+
### Dataset
|
68 |
+
|
69 |
+
The dataset is taken from Hugging Face WikiANN (English).
|
70 |
+
|
71 |
+
### Training
|
72 |
+
|
73 |
+
- Number of epochs: 5
|
74 |
+
|
75 |
+
- Batch size: 16
|
76 |
+
|
77 |
+
- Evaluation strategy: epoch
|
78 |
+
|
79 |
+
- Learning rate: 3e-5
|
80 |
+
|
81 |
+
### Quantization
|
82 |
+
|
83 |
+
Post-training quantization was applied using PyTorch's built-in quantization framework to reduce the model size and improve inference efficiency.
|
84 |
+
|
85 |
+
## Repository Structure
|
86 |
+
|
87 |
+
```
|
88 |
+
|
89 |
+
.
|
90 |
+
├── config.json
|
91 |
+
├── tokenizer_config.json
|
92 |
+
├── sepcial_tokens_map.json
|
93 |
+
├── tokenizer.json
|
94 |
+
├── model.safetensors # Fine Tuned Model
|
95 |
+
├── README.md # Model documentation
|
96 |
+
|
97 |
+
```
|
98 |
+
|
99 |
+
## Limitations
|
100 |
+
|
101 |
+
- The model may not generalize well to domains outside the fine-tuning dataset.
|
102 |
+
|
103 |
+
- Quantization may result in minor accuracy degradation compared to full-precision models.
|
104 |
+
|
105 |
+
## Contributing
|
106 |
+
|
107 |
+
Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
|
108 |
+
|
109 |
+
|
config.json
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"RobertaForTokenClassification"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"bos_token_id": 0,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"eos_token_id": 2,
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.1,
|
11 |
+
"hidden_size": 768,
|
12 |
+
"id2label": {
|
13 |
+
"0": "O",
|
14 |
+
"1": "B-PER",
|
15 |
+
"2": "I-PER",
|
16 |
+
"3": "B-ORG",
|
17 |
+
"4": "I-ORG",
|
18 |
+
"5": "B-LOC",
|
19 |
+
"6": "I-LOC"
|
20 |
+
},
|
21 |
+
"initializer_range": 0.02,
|
22 |
+
"intermediate_size": 3072,
|
23 |
+
"label2id": {
|
24 |
+
"B-LOC": 5,
|
25 |
+
"B-ORG": 3,
|
26 |
+
"B-PER": 1,
|
27 |
+
"I-LOC": 6,
|
28 |
+
"I-ORG": 4,
|
29 |
+
"I-PER": 2,
|
30 |
+
"O": 0
|
31 |
+
},
|
32 |
+
"layer_norm_eps": 1e-05,
|
33 |
+
"max_position_embeddings": 514,
|
34 |
+
"model_type": "roberta",
|
35 |
+
"num_attention_heads": 12,
|
36 |
+
"num_hidden_layers": 12,
|
37 |
+
"pad_token_id": 1,
|
38 |
+
"position_embedding_type": "absolute",
|
39 |
+
"torch_dtype": "float16",
|
40 |
+
"transformers_version": "4.51.1",
|
41 |
+
"type_vocab_size": 1,
|
42 |
+
"use_cache": true,
|
43 |
+
"vocab_size": 50265
|
44 |
+
}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:db5e9cfb52d845e0f66a72a18c1a0efeae654aa7f13c7f96505c67e072e02e6f
|
3 |
+
size 248144718
|
special_tokens_map.json
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": true,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"cls_token": {
|
10 |
+
"content": "<s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": true,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"eos_token": {
|
17 |
+
"content": "</s>",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": true,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
},
|
23 |
+
"mask_token": {
|
24 |
+
"content": "<mask>",
|
25 |
+
"lstrip": true,
|
26 |
+
"normalized": false,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": false
|
29 |
+
},
|
30 |
+
"pad_token": {
|
31 |
+
"content": "<pad>",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": true,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false
|
36 |
+
},
|
37 |
+
"sep_token": {
|
38 |
+
"content": "</s>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": true,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false
|
43 |
+
},
|
44 |
+
"unk_token": {
|
45 |
+
"content": "<unk>",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": true,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false
|
50 |
+
}
|
51 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": true,
|
3 |
+
"added_tokens_decoder": {
|
4 |
+
"0": {
|
5 |
+
"content": "<s>",
|
6 |
+
"lstrip": false,
|
7 |
+
"normalized": true,
|
8 |
+
"rstrip": false,
|
9 |
+
"single_word": false,
|
10 |
+
"special": true
|
11 |
+
},
|
12 |
+
"1": {
|
13 |
+
"content": "<pad>",
|
14 |
+
"lstrip": false,
|
15 |
+
"normalized": true,
|
16 |
+
"rstrip": false,
|
17 |
+
"single_word": false,
|
18 |
+
"special": true
|
19 |
+
},
|
20 |
+
"2": {
|
21 |
+
"content": "</s>",
|
22 |
+
"lstrip": false,
|
23 |
+
"normalized": true,
|
24 |
+
"rstrip": false,
|
25 |
+
"single_word": false,
|
26 |
+
"special": true
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"content": "<unk>",
|
30 |
+
"lstrip": false,
|
31 |
+
"normalized": true,
|
32 |
+
"rstrip": false,
|
33 |
+
"single_word": false,
|
34 |
+
"special": true
|
35 |
+
},
|
36 |
+
"50264": {
|
37 |
+
"content": "<mask>",
|
38 |
+
"lstrip": true,
|
39 |
+
"normalized": false,
|
40 |
+
"rstrip": false,
|
41 |
+
"single_word": false,
|
42 |
+
"special": true
|
43 |
+
}
|
44 |
+
},
|
45 |
+
"bos_token": "<s>",
|
46 |
+
"clean_up_tokenization_spaces": false,
|
47 |
+
"cls_token": "<s>",
|
48 |
+
"eos_token": "</s>",
|
49 |
+
"errors": "replace",
|
50 |
+
"extra_special_tokens": {},
|
51 |
+
"mask_token": "<mask>",
|
52 |
+
"max_length": 512,
|
53 |
+
"model_max_length": 512,
|
54 |
+
"pad_token": "<pad>",
|
55 |
+
"sep_token": "</s>",
|
56 |
+
"stride": 0,
|
57 |
+
"tokenizer_class": "RobertaTokenizer",
|
58 |
+
"trim_offsets": true,
|
59 |
+
"truncation_side": "right",
|
60 |
+
"truncation_strategy": "longest_first",
|
61 |
+
"unk_token": "<unk>"
|
62 |
+
}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:48332ab964fedff29c76d05ee53d1996b9b3fbd342c84a6e69dfa676f563312c
|
3 |
+
size 5240
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|