Update README.md
Browse files
README.md
CHANGED
@@ -10,22 +10,28 @@ PS : the tokenizer is the same as the one of the model bert-base-uncased.
|
|
10 |
To load the model \& tokenizer :
|
11 |
|
12 |
````python
|
13 |
-
from transformers import
|
14 |
|
15 |
model_name = "eli4s/Bert-L12-h384-A6"
|
16 |
-
model =
|
17 |
-
tokenizer =
|
18 |
````
|
19 |
|
20 |
To use it on a sentence :
|
21 |
|
22 |
````python
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
input_ids = torch.tensor(encoded_inputs['input_ids'])
|
25 |
attention_mask = torch.tensor(encoded_inputs['attention_mask'])
|
26 |
output = model(input_ids, attention_mask=attention_mask)
|
27 |
|
28 |
mask_index = input_ids.tolist()[0].index(103)
|
29 |
masked_token = output['logits'][0][mask_index].argmax(axis=-1)
|
30 |
-
tokenizer.decode(masked_token)
|
|
|
|
|
31 |
````
|
|
|
10 |
To load the model \& tokenizer :
|
11 |
|
12 |
````python
|
13 |
+
from transformers import BertForMaskedLM, BertTokenizer
|
14 |
|
15 |
model_name = "eli4s/Bert-L12-h384-A6"
|
16 |
+
model = BertForMaskedLM.from_pretrained(model_name)
|
17 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
18 |
````
|
19 |
|
20 |
To use it on a sentence :
|
21 |
|
22 |
````python
|
23 |
+
import torch
|
24 |
+
|
25 |
+
sentence = "The goal of life is [MASK]."
|
26 |
+
|
27 |
+
encoded_inputs = tokenizer([sentence], padding='longest')
|
28 |
input_ids = torch.tensor(encoded_inputs['input_ids'])
|
29 |
attention_mask = torch.tensor(encoded_inputs['attention_mask'])
|
30 |
output = model(input_ids, attention_mask=attention_mask)
|
31 |
|
32 |
mask_index = input_ids.tolist()[0].index(103)
|
33 |
masked_token = output['logits'][0][mask_index].argmax(axis=-1)
|
34 |
+
predicted_token = tokenizer.decode(masked_token)
|
35 |
+
|
36 |
+
print(predicted_token)
|
37 |
````
|