init
Browse files- experiments/model_predict_ner.py +15 -16
experiments/model_predict_ner.py
CHANGED
@@ -34,21 +34,21 @@ def preprocess(model_name, text):
|
|
34 |
class NER:
|
35 |
|
36 |
id_to_label = {
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
}
|
53 |
|
54 |
def __init__(self, model_name: str):
|
@@ -95,7 +95,6 @@ class NER:
|
|
95 |
k: torch.tensor(encoded_input[k]).to(self.device) for k in input_keys if k in encoded_input
|
96 |
})
|
97 |
prob = torch.softmax(output['logits'], dim=-1)
|
98 |
-
print(prob.shape)
|
99 |
pred = torch.max(prob, dim=-1)[1].cpu().detach().int().tolist()
|
100 |
preds += [[self.id_to_label[_p] for _p in p] for p in pred]
|
101 |
return [{"prediction": p, "label": i} for p, i in zip(preds, labels)]
|
|
|
34 |
class NER:
|
35 |
|
36 |
id_to_label = {
|
37 |
+
0: 'B-corporation',
|
38 |
+
1: 'B-creative_work',
|
39 |
+
2: 'B-event',
|
40 |
+
3: 'B-group',
|
41 |
+
4: 'B-location',
|
42 |
+
5: 'B-person',
|
43 |
+
6: 'B-product',
|
44 |
+
7: 'I-corporation',
|
45 |
+
8: 'I-creative_work',
|
46 |
+
9: 'I-event',
|
47 |
+
10: 'I-group',
|
48 |
+
11: 'I-location',
|
49 |
+
12: 'I-person',
|
50 |
+
13: 'I-product',
|
51 |
+
14: 'O'
|
52 |
}
|
53 |
|
54 |
def __init__(self, model_name: str):
|
|
|
95 |
k: torch.tensor(encoded_input[k]).to(self.device) for k in input_keys if k in encoded_input
|
96 |
})
|
97 |
prob = torch.softmax(output['logits'], dim=-1)
|
|
|
98 |
pred = torch.max(prob, dim=-1)[1].cpu().detach().int().tolist()
|
99 |
preds += [[self.id_to_label[_p] for _p in p] for p in pred]
|
100 |
return [{"prediction": p, "label": i} for p, i in zip(preds, labels)]
|