Muhammad Farrukh Mehmood
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -1,93 +1,104 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
-
|
14 |
-
|
15 |
-
-
|
16 |
-
|
17 |
-
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Model Card: BERT for Named Entity Recognition (NER)
|
2 |
+
|
3 |
+
## Model Overview
|
4 |
+
|
5 |
+
This model, **sbert-conll-ner**, is a fine-tuned version of `bert-base-uncased` trained for the task of Named Entity Recognition (NER) using the CoNLL-2003 dataset. It is designed to identify and classify entities in text, such as **person names (PER)**, **organizations (ORG)**, **locations (LOC)**, and **miscellaneous (MISC)** entities.
|
6 |
+
|
7 |
+
### Model Architecture
|
8 |
+
- **Base Model**: BERT (Bidirectional Encoder Representations from Transformers) with the `bert-base-uncased` architecture.
|
9 |
+
- **Task**: Token Classification (NER).
|
10 |
+
|
11 |
+
## Training Dataset
|
12 |
+
|
13 |
+
- **Dataset**: CoNLL-2003, a standard dataset for NER tasks containing sentences annotated with named entity spans.
|
14 |
+
- **Classes**:
|
15 |
+
- `PER` (Person)
|
16 |
+
- `ORG` (Organization)
|
17 |
+
- `LOC` (Location)
|
18 |
+
- `MISC` (Miscellaneous)
|
19 |
+
- `O` (Outside of any entity span)
|
20 |
+
|
21 |
+
## Performance Metrics
|
22 |
+
|
23 |
+
The model demonstrates strong performance metrics on the CoNLL-2003 evaluation set:
|
24 |
+
|
25 |
+
| Metric | Value |
|
26 |
+
|-------------|------------|
|
27 |
+
| **Loss** | 0.0649 |
|
28 |
+
| **Precision** | 93.59% |
|
29 |
+
| **Recall** | 95.07% |
|
30 |
+
| **F1 Score** | 94.32% |
|
31 |
+
| **Accuracy** | 98.79% |
|
32 |
+
|
33 |
+
These metrics indicate the model's high accuracy and robustness in identifying and classifying entities.
|
34 |
+
|
35 |
+
## Training Details
|
36 |
+
|
37 |
+
- **Optimizer**: AdamW (Adam with weight decay)
|
38 |
+
- **Learning Rate**: 2e-5
|
39 |
+
- **Batch Size**: 8
|
40 |
+
- **Number of Epochs**: 3
|
41 |
+
- **Scheduler**: Linear scheduler with warm-up steps
|
42 |
+
- **Loss Function**: Cross-entropy loss with ignored index (`-100`) for padding tokens
|
43 |
+
|
44 |
+
## Model Input/Output
|
45 |
+
|
46 |
+
- **Input Format**: Tokenized text with special tokens `[CLS]` and `[SEP]`.
|
47 |
+
- **Output Format**: Token-level predictions with corresponding labels from the NER tag set (`B-PER`, `I-PER`, etc.).
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
## How to Use the Model
|
52 |
+
|
53 |
+
### Installation
|
54 |
+
```bash
|
55 |
+
pip install transformers
|
56 |
+
```
|
57 |
+
|
58 |
+
### Loading the Model
|
59 |
+
```python
|
60 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
61 |
+
|
62 |
+
tokenizer = AutoTokenizer.from_pretrained("sfarrukh/modernbert-conll-ner")
|
63 |
+
model = AutoModelForTokenClassification.from_pretrained("sfarrukh/modernbert-conll-ner")
|
64 |
+
```
|
65 |
+
|
66 |
+
### Running Inference
|
67 |
+
```python
|
68 |
+
from transformers import pipeline
|
69 |
+
|
70 |
+
nlp = pipeline("token-classification", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
|
71 |
+
text = "John lives in New York City."
|
72 |
+
result = nlp(text)
|
73 |
+
print(result)
|
74 |
+
```
|
75 |
+
|
76 |
+
```json
|
77 |
+
[{'entity_group': 'PER',
|
78 |
+
'score': 0.99912304,
|
79 |
+
'word': 'john',
|
80 |
+
'start': 0,
|
81 |
+
'end': 4},
|
82 |
+
{'entity_group': 'LOC',
|
83 |
+
'score': 0.9993351,
|
84 |
+
'word': 'new york city',
|
85 |
+
'start': 14,
|
86 |
+
'end': 27}]
|
87 |
+
```
|
88 |
+
|
89 |
+
## Limitations
|
90 |
+
|
91 |
+
1. **Domain-Specific Adaptability**: Performance might drop on domain-specific texts (e.g., legal or medical) not covered by the CoNLL-2003 dataset.
|
92 |
+
2. **Ambiguity**: Ambiguous entities or overlapping spans are not explicitly handled.
|
93 |
+
## Recommendations
|
94 |
+
|
95 |
+
- For domain-specific tasks, consider fine-tuning this model further on a relevant dataset.
|
96 |
+
- Use a pre-processing pipeline to handle long texts by splitting them into smaller segments.
|
97 |
+
|
98 |
+
## Acknowledgements
|
99 |
+
|
100 |
+
- **Transformers Library**: Hugging Face
|
101 |
+
- **Dataset**: CoNLL-2003
|
102 |
+
- **Base Model**: `bert-base-uncased` by Google
|
103 |
+
|
104 |
+
|