Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### How to use
|
| 2 |
+
Here is how to use this model in PyTorch:
|
| 3 |
+
```python
|
| 4 |
+
from transformers import PerceiverTokenizer, PerceiverForMaskedLM
|
| 5 |
+
tokenizer = PerceiverTokenizer.from_pretrained("deepmind/language-perceiver")
|
| 6 |
+
model = PerceiverForMaskedLM.from_pretrained("deepmind/language-perceiver")
|
| 7 |
+
text = "This is an incomplete sentence where some words are missing."
|
| 8 |
+
# prepare input
|
| 9 |
+
encoding = tokenizer(text, padding="max_length", return_tensors="pt")
|
| 10 |
+
# mask " missing.". Note that the model performs much better if the masked span starts with a space.
|
| 11 |
+
encoding.input_ids[0, 52:61] = tokenizer.mask_token_id
|
| 12 |
+
inputs, input_mask = encoding.input_ids.to(device), encoding.attention_mask.to(device)
|
| 13 |
+
# forward pass
|
| 14 |
+
outputs = model(inputs=inputs, attention_mask=input_mask)
|
| 15 |
+
logits = outputs.logits
|
| 16 |
+
masked_tokens_predictions = logits[0, 51:61].argmax(dim=-1)
|
| 17 |
+
print(tokenizer.decode(masked_tokens_predictions))
|
| 18 |
+
>>> should print " missing."
|
| 19 |
+
```
|