Views
No views yet
1from transformers import AutoModelForMaskedLM, AutoTokenizer
2
3tokenizer = AutoTokenizer.from_pretrained('dicta-il/dictabert-tiny')
4model = AutoModelForMaskedLM.from_pretrained('dicta-il/dictabert-tiny')
5
6model.eval()
7
8sentence = 'בשנת 1948 השלים אפרים קישון את [MASK] בפיסול מתכת ובתולדות האמנות והחל לפרסם מאמרים הומוריסטיים'
9
10output = model(tokenizer.encode(sentence, return_tensors='pt'))
11# the [MASK] is the 7th token (including [CLS])
12import torch
13top_2 = torch.topk(output.logits[0, 7, :], 2)[1]
14print('\n'.join(tokenizer.convert_ids_to_tokens(top_2))) # should print עבודתו / התמחותו
15DictaBERT: A State-of-the-Art BERT Suite for Modern Hebrew1@misc{shmidman2023dictabert,
2 title={DictaBERT: A State-of-the-Art BERT Suite for Modern Hebrew},
3 author={Shaltiel Shmidman and Avi Shmidman and Moshe Koppel},
4 year={2023},
5 eprint={2308.16687},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}