Update README.md
Browse files
README.md
CHANGED
|
@@ -67,41 +67,28 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
| 67 |
|
| 68 |
# Define the custom label mapping
|
| 69 |
custom_label_mapping = {
|
| 70 |
-
0: 'O',
|
| 71 |
-
1: 'B-PER',
|
| 72 |
-
2: 'I-PER',
|
| 73 |
-
3: 'B-ORG',
|
| 74 |
-
4: 'I-ORG',
|
| 75 |
-
5: 'B-LOC',
|
| 76 |
-
6: 'I-LOC',
|
| 77 |
}
|
| 78 |
|
| 79 |
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
|
| 80 |
|
| 81 |
-
#
|
| 82 |
-
text = "
|
| 83 |
|
| 84 |
raw_results = ner_pipeline(text)
|
| 85 |
|
| 86 |
-
results_with_labels = []
|
| 87 |
for entity in raw_results:
|
| 88 |
label_index = int(entity['entity'].split('_')[1])
|
| 89 |
|
| 90 |
entity_label = custom_label_mapping.get(label_index, "UNKNOWN")
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
"entity": entity_label, # Use the mapped label
|
| 94 |
-
"word": entity["word"],
|
| 95 |
-
"start": entity["start"],
|
| 96 |
-
"end": entity["end"],
|
| 97 |
-
"score": entity["score"],
|
| 98 |
-
}
|
| 99 |
-
results_with_labels.append(entity_with_label)
|
| 100 |
-
|
| 101 |
-
# Print the final results
|
| 102 |
-
print("NER Results Labels:")
|
| 103 |
-
for result in results_with_labels:
|
| 104 |
-
print(result)
|
| 105 |
```
|
| 106 |
|
| 107 |
## Training procedure
|
|
|
|
| 67 |
|
| 68 |
# Define the custom label mapping
|
| 69 |
custom_label_mapping = {
|
| 70 |
+
0: 'O',
|
| 71 |
+
1: 'B-PER',
|
| 72 |
+
2: 'I-PER',
|
| 73 |
+
3: 'B-ORG',
|
| 74 |
+
4: 'I-ORG',
|
| 75 |
+
5: 'B-LOC',
|
| 76 |
+
6: 'I-LOC',
|
| 77 |
}
|
| 78 |
|
| 79 |
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
|
| 80 |
|
| 81 |
+
# Sample Spanish text
|
| 82 |
+
text = "Elon Musk vive en Estados Unidos y es dueño de Space X, Tesla y Starlink"
|
| 83 |
|
| 84 |
raw_results = ner_pipeline(text)
|
| 85 |
|
|
|
|
| 86 |
for entity in raw_results:
|
| 87 |
label_index = int(entity['entity'].split('_')[1])
|
| 88 |
|
| 89 |
entity_label = custom_label_mapping.get(label_index, "UNKNOWN")
|
| 90 |
+
print(f"Word: {entity['word']}, Label: {entity_label}")
|
| 91 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
```
|
| 93 |
|
| 94 |
## Training procedure
|