shibing624
commited on
Commit
•
90c27a7
1
Parent(s):
3cfe78a
Update README.md
Browse files
README.md
CHANGED
@@ -65,10 +65,10 @@ from seqeval.metrics.sequence_labeling import get_entities
|
|
65 |
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
66 |
|
67 |
# Load model from HuggingFace Hub
|
68 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
69 |
-
model = AutoModelForTokenClassification.from_pretrained("
|
70 |
label_list = ["E-ORG", "E-LOC", "S-MISC", "I-MISC", "S-PER", "E-PER", "B-MISC", "O", "S-LOC",
|
71 |
-
|
72 |
|
73 |
sentence = "AL-AIN, United Arab Emirates 1996-12-06"
|
74 |
|
@@ -79,15 +79,15 @@ def get_entity(sentence):
|
|
79 |
with torch.no_grad():
|
80 |
outputs = model(inputs).logits
|
81 |
predictions = torch.argmax(outputs, dim=2)
|
82 |
-
|
83 |
print(sentence)
|
84 |
-
print(
|
85 |
|
86 |
-
pred_labels = [i[1] for i in
|
87 |
entities = []
|
88 |
line_entities = get_entities(pred_labels)
|
89 |
for i in line_entities:
|
90 |
-
word =
|
91 |
entity_type = i[0]
|
92 |
entities.append((word, entity_type))
|
93 |
|
|
|
65 |
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
66 |
|
67 |
# Load model from HuggingFace Hub
|
68 |
+
tokenizer = AutoTokenizer.from_pretrained("../bert4ner-base-uncased")
|
69 |
+
model = AutoModelForTokenClassification.from_pretrained("../bert4ner-base-uncased")
|
70 |
label_list = ["E-ORG", "E-LOC", "S-MISC", "I-MISC", "S-PER", "E-PER", "B-MISC", "O", "S-LOC",
|
71 |
+
"E-MISC", "B-ORG", "S-ORG", "I-ORG", "B-LOC", "I-LOC", "B-PER", "I-PER"]
|
72 |
|
73 |
sentence = "AL-AIN, United Arab Emirates 1996-12-06"
|
74 |
|
|
|
79 |
with torch.no_grad():
|
80 |
outputs = model(inputs).logits
|
81 |
predictions = torch.argmax(outputs, dim=2)
|
82 |
+
word_tags = [(token, label_list[prediction]) for token, prediction in zip(tokens, predictions[0].numpy()[1:-1])]
|
83 |
print(sentence)
|
84 |
+
print(word_tags)
|
85 |
|
86 |
+
pred_labels = [i[1] for i in word_tags]
|
87 |
entities = []
|
88 |
line_entities = get_entities(pred_labels)
|
89 |
for i in line_entities:
|
90 |
+
word = tokens[i[1]: i[2] + 1]
|
91 |
entity_type = i[0]
|
92 |
entities.append((word, entity_type))
|
93 |
|