Views
No views yet
dbmdz/bert-base-turkish-cased.yeniguno/turkish_agriculture_corpus1import torch
2from transformers import AutoModelForMaskedLM, AutoTokenizer
3
4model_checkpoint = "yeniguno/bert-turkish-agriculture-mlm"
5
6model = AutoModelForMaskedLM.from_pretrained(model_checkpoint)
7tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
8
9text = "Sabah kahvaltıda babam, köyde bu hafta [MASK] hazırlığının başlayacağını söyledi."
10
11inputs = tokenizer(text, return_tensors="pt")
12token_logits = model(**inputs).logits
13
14mask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]
15mask_token_logits = token_logits[0, mask_token_index, :]
16
17# Pick the [MASK] candidates with the highest logits
18top_5_tokens = torch.topk(mask_token_logits, 5, dim=1).indices[0].tolist()
19
20for token in top_5_tokens:
21 print(f"'>>> {text.replace(tokenizer.mask_token, tokenizer.decode([token]))}'")