Update README.md
Browse files
README.md
CHANGED
@@ -22,7 +22,7 @@ To use it on a sentence :
|
|
22 |
````python
|
23 |
import torch
|
24 |
|
25 |
-
sentence = "
|
26 |
|
27 |
encoded_inputs = tokenizer([sentence], padding='longest')
|
28 |
input_ids = torch.tensor(encoded_inputs['input_ids'])
|
@@ -35,3 +35,15 @@ predicted_token = tokenizer.decode(masked_token)
|
|
35 |
|
36 |
print(predicted_token)
|
37 |
````
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
````python
|
23 |
import torch
|
24 |
|
25 |
+
sentence = "Let's have a [MASK]."
|
26 |
|
27 |
encoded_inputs = tokenizer([sentence], padding='longest')
|
28 |
input_ids = torch.tensor(encoded_inputs['input_ids'])
|
|
|
35 |
|
36 |
print(predicted_token)
|
37 |
````
|
38 |
+
|
39 |
+
Or we can also predict the n most relevant predictions :
|
40 |
+
|
41 |
+
````python
|
42 |
+
top_n = 5
|
43 |
+
|
44 |
+
vocab_size = model.config.vocab_size
|
45 |
+
logits = output['logits'][0][mask_index].tolist()
|
46 |
+
top_tokens = sorted(list(range(vocab_size)), key=lambda i:logits[i], reverse=True)[:top_n]
|
47 |
+
|
48 |
+
tokenizer.decode(top_tokens)
|
49 |
+
````
|