nimishgarg commited on
Commit
c8f775e
·
verified ·
1 Parent(s): 65d3963

Upload 8 files

Browse files
Files changed (8) hide show
  1. README.md +123 -0
  2. config.json +48 -0
  3. merges.txt +0 -0
  4. model.safetensors +3 -0
  5. special_tokens_map.json +15 -0
  6. tokenizer.json +0 -0
  7. tokenizer_config.json +58 -0
  8. vocab.json +0 -0
README.md ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # RoBERTa-Base Model for Named Entity Recognition (NER) on CoNLL-2003 Dataset
2
+
3
+ This repository hosts a fine-tuned version of the RoBERTa model for Named Entity Recognition (NER) using the CoNLL-2003 dataset. The model is capable of identifying and classifying named entities such as people, organizations, locations, etc.
4
+
5
+ ## Model Details
6
+
7
+ - **Model Architecture:** RoBERTa Base
8
+ - **Task:** Named Entity Recognition
9
+ - **Dataset:** CoNLL-2003 (Hugging Face Datasets)
10
+ - **Quantization:** Float16
11
+ - **Fine-tuning Framework:** Hugging Face Transformers
12
+
13
+ ---
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install datasets transformers seqeval torch --quiet
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Loading the Model
24
+
25
+
26
+ ```python
27
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
28
+ import torch
29
+
30
+ # Load tokenizer and model
31
+ model = "roberta-base"
32
+ tokenizer = AutoTokenizer.from_pretrained(model)
33
+ model = AutoModelForSequenceClassification.from_pretrained(model)
34
+ # Define test sentences
35
+ sentences = [
36
+ "Barack Obama was born in Hawaii.",
37
+ "Elon Musk founded SpaceX and Tesla.",
38
+ "Apple is headquartered in Cupertino, California."
39
+ ]
40
+
41
+ for sentence in sentences:
42
+ tokens = tokenizer(sentence, return_tensors="pt", truncation=True, is_split_into_words=False).to(device)
43
+ with torch.no_grad():
44
+ outputs = model(**tokens)
45
+ logits = outputs.logits
46
+ predictions = torch.argmax(logits, dim=2)
47
+ predicted_labels = predictions[0].cpu().numpy()
48
+ tokens_decoded = tokenizer.convert_ids_to_tokens(tokens["input_ids"][0])
49
+ print(f"Sentence: {sentence}")
50
+ for token, label_id in zip(tokens_decoded, predicted_labels):
51
+ label = label_list[label_id]
52
+ if token.startswith("Ġ") or not token.startswith("▁"):
53
+ token = token.replace("Ġ", "")
54
+ if label != "O":
55
+ print(f"{token}: {label}")
56
+ print("\n" + "-"*50 + "\n")
57
+ ```
58
+
59
+
60
+ ## Performance Metrics
61
+
62
+ - **Accuracy:** 0.9921
63
+ - **Precision:** 0.9466
64
+ - **Recall:** 0.9589
65
+ - **F1 Score:** 0.9527
66
+
67
+ ---
68
+
69
+ ## Fine-Tuning Details
70
+
71
+ ### Dataset
72
+
73
+ The dataset used is the CoNLL-2003 dataset, which contains labeled tokens for Named Entity Recognition (NER).
74
+ Entities are categorized into classes such as PER (person), ORG (organization), LOC (location), and MISC (miscellaneous).
75
+ It includes four columns: the word, part-of-speech tag, syntactic chunk tag, and NER tag.
76
+
77
+ The dataset is automatically loaded using the Hugging Face datasets library and is split into train, validation, and test sets.
78
+
79
+
80
+ ### Training
81
+
82
+ - **Epochs:** 3
83
+ - **Batch size:** 16 (train) / 16 (eval)
84
+ - **Learning rate:** 2e-5
85
+ - **Evaluation strategy:** `epoch`
86
+ - **FP16 Training:** Enabled
87
+ - **Trainer:** Hugging Face `Trainer` API
88
+
89
+ ---
90
+
91
+ ## Quantization
92
+
93
+ Post-training quantization was applied using `model.to(dtype=torch.float16)` to reduce model size and speed up inference.
94
+
95
+ ---
96
+
97
+ ## Repository Structure
98
+
99
+ ```bash
100
+ .
101
+ ├── quantized-model/ # Directory containing trained model artifacts
102
+ │ ├── config.json
103
+ │ ├── merges.txt
104
+ │ ├── model.safetensors # (May appear as 'model' in UI)
105
+ │ ├── special_tokens_map.json
106
+ │ ├── tokenizer.json
107
+ │ ├── tokenizer_config.json
108
+ │ └── vocab.json
109
+ ├── README.md
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Limitations
115
+
116
+ - The model is trained only on CoNLL-2003 and may not generalize to unseen NER tasks.
117
+ - Token misalignment may occur for complex or ambiguous phrases.
118
+
119
+
120
+ ## Contributing
121
+
122
+ Feel free to open issues or submit pull requests to improve the model, training process, or documentation.
123
+
config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "LABEL_0",
14
+ "1": "LABEL_1",
15
+ "2": "LABEL_2",
16
+ "3": "LABEL_3",
17
+ "4": "LABEL_4",
18
+ "5": "LABEL_5",
19
+ "6": "LABEL_6",
20
+ "7": "LABEL_7",
21
+ "8": "LABEL_8"
22
+ },
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 3072,
25
+ "label2id": {
26
+ "LABEL_0": 0,
27
+ "LABEL_1": 1,
28
+ "LABEL_2": 2,
29
+ "LABEL_3": 3,
30
+ "LABEL_4": 4,
31
+ "LABEL_5": 5,
32
+ "LABEL_6": 6,
33
+ "LABEL_7": 7,
34
+ "LABEL_8": 8
35
+ },
36
+ "layer_norm_eps": 1e-05,
37
+ "max_position_embeddings": 514,
38
+ "model_type": "roberta",
39
+ "num_attention_heads": 12,
40
+ "num_hidden_layers": 12,
41
+ "pad_token_id": 1,
42
+ "position_embedding_type": "absolute",
43
+ "torch_dtype": "float16",
44
+ "transformers_version": "4.51.1",
45
+ "type_vocab_size": 1,
46
+ "use_cache": true,
47
+ "vocab_size": 50265
48
+ }
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:490ea47e40c26ba0cd15162c39a18f2a06f2030837bbcb40b1aab60966ca19c3
3
+ size 248147794
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "model_max_length": 512,
53
+ "pad_token": "<pad>",
54
+ "sep_token": "</s>",
55
+ "tokenizer_class": "RobertaTokenizer",
56
+ "trim_offsets": true,
57
+ "unk_token": "<unk>"
58
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff