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