Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
tags:
|
| 4 |
+
- tapex
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
inference: false
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
TAPEX-large model pre-trained-only model. This model was proposed in [TAPEX: Table Pre-training via Learning a Neural SQL Executor](https://arxiv.org/abs/2107.07653) by Qian Liu, Bei Chen, Jiaqi Guo, Morteza Ziyadi, Zeqi Lin, Weizhu Chen, Jian-Guang Lou. Original repo can be found [here](https://github.com/microsoft/Table-Pretraining).
|
| 10 |
+
|
| 11 |
+
To load it and run inference, you can do the following:
|
| 12 |
+
|
| 13 |
+
```
|
| 14 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
| 15 |
+
import pandas as pd
|
| 16 |
+
|
| 17 |
+
tokenizer = BartTokenizer.from_pretrained("nielsr/tapex-large")
|
| 18 |
+
model = BartForConditionalGeneration.from_pretrained("nielsr/tapex-large")
|
| 19 |
+
|
| 20 |
+
# create table
|
| 21 |
+
data = {'Actors': ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"], 'Number of movies': ["87", "53", "69"]}
|
| 22 |
+
table = pd.DataFrame.from_dict(data)
|
| 23 |
+
|
| 24 |
+
# turn into dict
|
| 25 |
+
table_dict = {"header": list(table.columns), "rows": [list(row.values) for i,row in table.iterrows()]}
|
| 26 |
+
|
| 27 |
+
# turn into format TAPEX expects
|
| 28 |
+
# define the linearizer based on this code: https://github.com/microsoft/Table-Pretraining/blob/main/tapex/processor/table_linearize.py
|
| 29 |
+
linearizer = IndexedRowTableLinearize()
|
| 30 |
+
linear_table = linearizer.process_table(table_dict)
|
| 31 |
+
|
| 32 |
+
# add query
|
| 33 |
+
query = "SELECT ... FROM ..."
|
| 34 |
+
joint_input = query + " " + linear_table
|
| 35 |
+
|
| 36 |
+
# encode
|
| 37 |
+
encoding = tokenizer(joint_input, return_tensors="pt")
|
| 38 |
+
|
| 39 |
+
# forward pass
|
| 40 |
+
outputs = model.generate(**encoding)
|
| 41 |
+
|
| 42 |
+
# decode
|
| 43 |
+
tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
| 44 |
+
```
|