Views
No views yet
1import torch
2from transformers import AutoModelForTokenClassification, AutoTokenizer
3
4model_id = "paragdakle/greek-ner-numeric-greekbert"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForTokenClassification.from_pretrained(model_id).eval()
7
8text = "Στις 08.11.2019, η ΟΠΑΠ INVESTMENT LTD ήρθε σε συμφωνία..."
9enc = tokenizer(text, return_offsets_mapping=True, return_tensors="pt")
10offsets = enc.pop("offset_mapping")[0]
11with torch.no_grad():
12 logits = model(**enc).logits
13tags = [model.config.id2label[i] for i in logits.argmax(-1)[0].tolist()]
14# pair `tags` with `offsets` to recover character-span entities (see the
15# submission's ner_utils.encoder_predict for the full decode)