-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xlm-mlm-17-1280 model masked word prediction #1842
Comments
Would it be possible to use XML-R #1769 ? Its model has a simple description ( |
Hi |
There are also multilingual, pretrained models for BERT, which we could try. Usually the quality decreases in large, multilingual models with very different languages. |
I get the following warning and error when trying modelpath = "bert-base-multilingual-cased": |
'hungry' is in the list, but as two tokens since the multilingual model has a different vocabulary. Therefore, we have to tokenize the target word. Check this out:
|
I tried the code but it's giving word pieces suggestions, not whole word. And the suggestions are poor. Thank you so much for your effort but this is not useful for me unless somehow I could get whole word suggestions. Also, I am still seeking for an implementation of xlm model to get prediction, of anyone could help, that would be great |
Don't the pieces build complete words in the end? |
Hi, you can predict a masked word with XLM as you would do with any other MLM-based model. Here's an example using the checkpoint from transformers import XLMTokenizer, XLMWithLMHeadModel
import torch
# load tokenizer
tokenizer = XLMTokenizer.from_pretrained("xlm-mlm-17-1280")
# encode sentence with a masked token in the middle
sentence = torch.tensor([tokenizer.encode("This was the first time Nicolas ever saw a " + tokenizer.mask_token + ". It was huge.")])
# Identify the masked token position
masked_index = torch.where(sentence == tokenizer.mask_token_id)[1].tolist()[0]
# Load model
model = XLMWithLMHeadModel.from_pretrained("xlm-mlm-17-1280")
# Get the five top answers
result = model(sentence)
result = result[0][:, masked_index].topk(5).indices
result = result.tolist()[0]
print(tokenizer.decode(result))
# monster dragon snake wolf tiger |
Thank you so much guys for the replies, they been very helpfull. |
Hi
I would like some help with how to use pretrained xlm-mlm-17-1280 model to get predictions for masked word prediction. I have followed http://mayhewsw.github.io/2019/01/16/can-bert-generate-text/ for BERT mask prediction and it is working. Could you help me with how to use xlm-mlm-17-1280 model for word prediction. I need to get prediction for Turkish Language which is one of the languages in 17 languages
The text was updated successfully, but these errors were encountered: