Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Predict a masked word #361

Open
ebilal opened this issue Oct 3, 2023 · 0 comments
Open

Predict a masked word #361

ebilal opened this issue Oct 3, 2023 · 0 comments

Comments

@ebilal
Copy link

ebilal commented Oct 3, 2023

How can I predict a masked word? The code below doesnt work, maybe because of XLMTokenizer

reloaded = torch.load('dumped/xlm_en/lavlwh2d6j/best-valid_en_mlm_ppl.pth')

model_params = AttrDict(reloaded['params'])

dico = Dictionary(reloaded['dico_id2word'], reloaded['dico_word2id'], reloaded['dico_counts'])

encoder = TransformerModel(model_params, dico, is_encoder=True, with_output=True).cuda().eval()

encoder.load_state_dict(reloaded['model'])

tokenizer = XLMTokenizer.from_pretrained('xlm-mlm-en-2048')

text = "The capital of France is <mask>."

tokens = tokenizer(text, return_tensors='pt')

with torch.no_grad():

    predictions, _= encoder(**tokens, mode='predict')

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant