Spaces:
Running
Running
Commit
·
e028bfd
1
Parent(s):
3d34dc2
Final Updates
Browse files
app.py
CHANGED
|
@@ -121,6 +121,19 @@ def predict_ner(sentence: str, model, id2label: dict, device="cpu"):
|
|
| 121 |
|
| 122 |
return word_labels
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
sentence = "ذهب احمد الى السوق"
|
| 126 |
# id2label = {i: s for i, s in enumerate(label_vocab.itos)}
|
|
|
|
| 121 |
|
| 122 |
return word_labels
|
| 123 |
|
| 124 |
+
def find_label_vocab(vocabs):
|
| 125 |
+
for i, v in enumerate(vocabs):
|
| 126 |
+
if hasattr(v, "itos"):
|
| 127 |
+
itos = v.itos
|
| 128 |
+
if isinstance(itos, (list, tuple)) and any(x in itos for x in ["O", "B-PER", "I-PER"]):
|
| 129 |
+
return i, v
|
| 130 |
+
return None, None
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
idx, label_vocab = find_label_vocab(label_vocab)
|
| 134 |
+
print("label vocab index:", idx)
|
| 135 |
+
id2label = {i: s for i, s in enumerate(label_vocab.itos)}
|
| 136 |
+
|
| 137 |
|
| 138 |
sentence = "ذهب احمد الى السوق"
|
| 139 |
# id2label = {i: s for i, s in enumerate(label_vocab.itos)}
|