模型:
microsoft/tapex-base-finetuned-wikisql
TAPEX是由Qian Liu、Bei Chen、Jiaqi Guo、Morteza Ziyadi、Zeqi Lin、Weizhu Chen、Jian-Guang Lou于 TAPEX: Table Pre-training via Learning a Neural SQL Executor 提出的。原始存储库可以在 here 中找到。
TAPEX(表格预训练通过执行)是一种概念上简单、经验上强大的预训练方法,用于使现有模型具备表格推理技能。TAPEX通过在合成的语料库上学习神经SQL执行器来实现表格预训练,该语料库是通过自动合成可执行的SQL查询获得的。
TAPEX基于BART架构,是一个具有双向(类似BERT的)编码器和自回归(类似GPT的)解码器的transformer编码-解码模型。
此模型是在 WikiSQL 数据集上微调的tapex-base模型。
您可以使用该模型回答相对简单的表格问题。下面显示了一些可解答的问题(对应的表格未显示):
| Question | Answer |
|---|---|
| tell me what the notes are for south australia | no slogan on current series |
| what position does the player who played for butler cc (ks) play? | guard-forward |
| how many schools did player number 3 play at? | 1.0 |
| how many winning drivers in the kraco twin 125 (r2) race were there? | 1.0 |
| for the episode(s) aired in the u.s. on 4 april 2008, what were the names? | "bust a move" part one, "bust a move" part two |
在transformers中使用此模型的方法如下:
from transformers import TapexTokenizer, BartForConditionalGeneration
import pandas as pd
tokenizer = TapexTokenizer.from_pretrained("microsoft/tapex-base-finetuned-wikisql")
model = BartForConditionalGeneration.from_pretrained("microsoft/tapex-base-finetuned-wikisql")
data = {
"year": [1896, 1900, 1904, 2004, 2008, 2012],
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
}
table = pd.DataFrame.from_dict(data)
# tapex accepts uncased input since it is pre-trained on the uncased corpus
query = "In which year did beijing host the Olympic Games?"
encoding = tokenizer(table=table, query=query, return_tensors="pt")
outputs = model.generate(**encoding)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
# [' 2008.0']
请找到评估脚本 here 。
@inproceedings{
liu2022tapex,
title={{TAPEX}: Table Pre-training via Learning a Neural {SQL} Executor},
author={Qian Liu and Bei Chen and Jiaqi Guo and Morteza Ziyadi and Zeqi Lin and Weizhu Chen and Jian-Guang Lou},
booktitle={International Conference on Learning Representations},
year={2022},
url={https://openreview.net/forum?id=O50443AsCP}
}