Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
How to use
|
| 2 |
+
```
|
| 3 |
+
label_names = [
|
| 4 |
+
'O',
|
| 5 |
+
'B-P', 'I-P', 'B-T', 'I-T', 'B-A', 'I-A', 'B-C', 'I-C',
|
| 6 |
+
'B-ah', 'I-ah', 'B-at', 'I-at', 'B-az', 'I-az',
|
| 7 |
+
'B-g_', 'I-g_', 'B-gc', 'I-gc', 'B-gh', 'I-gh',
|
| 8 |
+
'B-gl', 'I-gl', 'B-gq', 'I-gq', 'B-gr', 'I-gr',
|
| 9 |
+
'B-gs', 'I-gs', 'B-gt', 'I-gt', 'B-gu', 'I-gu',
|
| 10 |
+
'B-i_', 'I-i_', 'B-ia', 'I-ia', 'B-ic', 'I-ic',
|
| 11 |
+
'B-if', 'I-if', 'B-io', 'I-io', 'B-me', 'I-me',
|
| 12 |
+
'B-mi', 'I-mi', 'B-mn', 'I-mn', 'B-ms', 'I-ms',
|
| 13 |
+
'B-n_', 'I-n_', 'B-na', 'I-na', 'B-nb', 'I-nb',
|
| 14 |
+
'B-nc', 'I-nc', 'B-ni', 'I-ni', 'B-no', 'I-no',
|
| 15 |
+
'B-ns', 'I-ns', 'B-o_', 'I-o_', 'B-oa', 'I-oa',
|
| 16 |
+
'B-oe', 'I-oe', 'B-om', 'I-om', 'B-op', 'I-op',
|
| 17 |
+
'B-or', 'I-or', 'B-p_', 'I-p_', 'B-pc', 'I-pc',
|
| 18 |
+
'B-pd', 'I-pd', 'B-pf', 'I-pf', 'B-pm', 'I-pm',
|
| 19 |
+
'B-pp', 'I-pp', 'B-ps', 'I-ps', 'B-td', 'I-td',
|
| 20 |
+
'B-tf', 'I-tf', 'B-th', 'I-th', 'B-tm', 'I-tm', 'B-ty', 'I-ty']
|
| 21 |
+
model = AutoModelForTokenClassification.from_pretrained(stulcrad/CNEC2_0_nested_robeczech-base)
|
| 22 |
+
device = get_device()
|
| 23 |
+
model.to(device)
|
| 24 |
+
tokenizer = AutoTokenizer.from_pretrained(stulcrad/CNEC2_0_nested_robeczech-base, add_prefix_space=True)
|
| 25 |
+
text = "Bydlim v Usti nad Labem"
|
| 26 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 27 |
+
|
| 28 |
+
with torch.no_grad():
|
| 29 |
+
outputs = model(**inputs).logits
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
flat_outputs = outputs.squeeze()
|
| 33 |
+
pred = flat_outputs.heaviside(torch.tensor([0.0], device=device)).int().tolist()
|
| 34 |
+
tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"].squeeze())
|
| 35 |
+
|
| 36 |
+
for token, p, flat_o in zip(tokens, pred, flat_outputs):
|
| 37 |
+
outs = [label_names[i] for i in range(len(label_names)) if p[i] == 1 and label_names[i] != 'O']
|
| 38 |
+
if outs:
|
| 39 |
+
print(f"{token:<10} {outs}")
|
| 40 |
+
```
|