Views
No views yet
1from transformers import TapexTokenizer, BartForConditionalGeneration
2import pandas as pd
3
4tokenizer = TapexTokenizer.from_pretrained("microsoft/tapex-large-sql-execution")
5model = BartForConditionalGeneration.from_pretrained("microsoft/tapex-large-sql-execution")
6
7data = {
8 "year": [1896, 1900, 1904, 2004, 2008, 2012],
9 "city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
10}
11table = pd.DataFrame.from_dict(data)
12
13# tapex accepts uncased input since it is pre-trained on the uncased corpus
14query = "select year where city = beijing"
15encoding = tokenizer(table=table, query=query, return_tensors="pt")
16
17outputs = model.generate(**encoding)
18
19print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
20# ['2008']This separation of two models for two kinds of intention is because of a known issue in BART large, and we recommend readers to see this comment for more details.
1@inproceedings{
2 liu2022tapex,
3 title={{TAPEX}: Table Pre-training via Learning a Neural {SQL} Executor},
4 author={Qian Liu and Bei Chen and Jiaqi Guo and Morteza Ziyadi and Zeqi Lin and Weizhu Chen and Jian-Guang Lou},
5 booktitle={International Conference on Learning Representations},
6 year={2022},
7 url={https://openreview.net/forum?id=O50443AsCP}
8}