Update snippet slightly
Browse files
README.md
CHANGED
@@ -60,20 +60,20 @@ Using `AutoModelForMaskedLM`:
|
|
60 |
```python
|
61 |
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
62 |
|
63 |
-
|
64 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
65 |
-
model = AutoModelForMaskedLM.from_pretrained(
|
66 |
|
67 |
text = "The capital of France is [MASK]."
|
68 |
inputs = tokenizer(text, return_tensors="pt")
|
69 |
outputs = model(**inputs)
|
70 |
|
71 |
# To get predictions for the mask:
|
72 |
-
|
73 |
-
|
74 |
-
predicted_token_id = logits[0, masked_index].argmax(axis=-1)
|
75 |
predicted_token = tokenizer.decode(predicted_token_id)
|
76 |
print("Predicted token:", predicted_token)
|
|
|
77 |
```
|
78 |
|
79 |
Using a pipeline:
|
|
|
60 |
```python
|
61 |
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
62 |
|
63 |
+
model_id = "answerdotai/ModernBERT-base"
|
64 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
65 |
+
model = AutoModelForMaskedLM.from_pretrained(model_id)
|
66 |
|
67 |
text = "The capital of France is [MASK]."
|
68 |
inputs = tokenizer(text, return_tensors="pt")
|
69 |
outputs = model(**inputs)
|
70 |
|
71 |
# To get predictions for the mask:
|
72 |
+
masked_index = inputs["input_ids"][0].tolist().index(tokenizer.mask_token_id)
|
73 |
+
predicted_token_id = outputs.logits[0, masked_index].argmax(axis=-1)
|
|
|
74 |
predicted_token = tokenizer.decode(predicted_token_id)
|
75 |
print("Predicted token:", predicted_token)
|
76 |
+
# Predicted token: Paris
|
77 |
```
|
78 |
|
79 |
Using a pipeline:
|