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

Predict a masked word #361

@ebilal

Description

@ebilal

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')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions