Add model card
Browse files
README.md
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This model corresponds to **tapas_masklm_small_reset** of the [original repository](https://github.com/google-research/tapas).
|
2 |
+
|
3 |
+
Here's how you can use it:
|
4 |
+
|
5 |
+
```python
|
6 |
+
from transformers import TapasTokenizer, TapasForMaskedLM
|
7 |
+
import pandas as pd
|
8 |
+
import torch
|
9 |
+
|
10 |
+
tokenizer = TapasTokenizer.from_pretrained("google/tapas-small-masklm")
|
11 |
+
model = TapasForMaskedLM.from_pretrained("google/tapas-small-masklm")
|
12 |
+
|
13 |
+
data = {'Actors': ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"],
|
14 |
+
'Age': ["56", "45", "59"],
|
15 |
+
'Number of movies': ["87", "53", "69"]
|
16 |
+
}
|
17 |
+
table = pd.DataFrame.from_dict(data)
|
18 |
+
query = "How many movies has Leonardo [MASK] Caprio played in?"
|
19 |
+
|
20 |
+
# prepare inputs
|
21 |
+
inputs = tokenizer(table=table, queries=query, padding="max_length", return_tensors="pt")
|
22 |
+
|
23 |
+
# forward pass
|
24 |
+
outputs = model(**inputs)
|
25 |
+
|
26 |
+
# return top 5 values and predictions
|
27 |
+
masked_index = torch.nonzero(inputs.input_ids.squeeze() == tokenizer.mask_token_id, as_tuple=False)
|
28 |
+
logits = outputs.logits[0, masked_index.item(), :]
|
29 |
+
probs = logits.softmax(dim=0)
|
30 |
+
values, predictions = probs.topk(5)
|
31 |
+
|
32 |
+
for value, pred in zip(values, predictions):
|
33 |
+
print(f"{tokenizer.decode([pred])} with confidence {value}")
|
34 |
+
```
|