tomaarsen HF staff commited on
Commit
c480c3f
1 Parent(s): fec8a7d

Update snippet slightly

Browse files
Files changed (1) hide show
  1. README.md +6 -6
README.md CHANGED
@@ -60,20 +60,20 @@ Using `AutoModelForMaskedLM`:
60
  ```python
61
  from transformers import AutoTokenizer, AutoModelForMaskedLM
62
 
63
- checkpoint = "answerdotai/ModernBERT-base"
64
- tokenizer = AutoTokenizer.from_pretrained(checkpoint)
65
- model = AutoModelForMaskedLM.from_pretrained(checkpoint)
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
- logits = outputs.logits
73
- masked_index = (inputs["input_ids"] == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0]
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: