Views
No views yet
google-bert/bert-base-uncased, designed to perform Named Entity Recognition on a text sentence imput.google-bert/bert-base-uncased1from transformers import AutoTokenizer, AutoModelForTokenClassification
2from transformers import pipeline
3
4tokenizer = AutoTokenizer.from_pretrained("sartajbhuvaji/bert-named-entity-recognition")
5model = AutoModelForTokenClassification.from_pretrained("sartajbhuvaji/bert-named-entity-recognition")
6
7nlp = pipeline("ner", model=model, tokenizer=tokenizer)
8example = "My name is Wolfgang and I live in Berlin"
9
10ner_results = nlp(example)
11print(ner_results)
121[
2 {
3 "end": 19,
4 "entity": "B-PER",
5 "index": 4,
6 "score": 0.99633455,
7 "start": 11,
8 "word": "wolfgang"
9 },
10 {
11 "end": 40,
12 "entity": "B-LOC",
13 "index": 9,
14 "score": 0.9987465,
15 "start": 34,
16 "word": "berlin"
17 }
18]| Abbreviation | Description |
|---|---|
| O | Outside of a named entity |
| B-MISC | Beginning of a miscellaneous entity right after another miscellaneous entity |
| I-MISC | Miscellaneous entity |
| B-PER | Beginning of a person's name right after another person's name |
| I-PER | Person's name |
| B-ORG | Beginning of an organization right after another organization |
| I-ORG | Organization |
| B-LOC | Beginning of a location right after another location |
| I-LOC | Location |

| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| LOC | 0.91 | 0.93 | 0.92 | 1668 |
| MISC | 0.76 | 0.81 | 0.78 | 702 |
| ORG | 0.87 | 0.88 | 0.88 | 1661 |
| PER | 0.98 | 0.97 | 0.97 | 1617 |
| Micro Avg | 0.90 | 0.91 | 0.91 | 5648 |
| Macro Avg | 0.88 | 0.90 | 0.89 | 5648 |
| Weighted Avg | 0.90 | 0.91 | 0.91 | 5648 |