模型:
microsoft/tapex-base
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)解码器的变压器编码器-解码器(seq2seq)模型。
您可以使用原始模型来模拟神经SQL执行,即使用TAPEX来执行给定表格上的SQL查询。然而,该模型主要用于在监督数据集上进行微调。目前,TAPEX可以进行微调以应对表格问答任务和表格事实验证任务。请查看 model hub 以寻找您感兴趣的任务的微调版本。
以下是在transformers中使用该模型的方法:
from transformers import TapexTokenizer, BartForConditionalGeneration import pandas as pd tokenizer = TapexTokenizer.from_pretrained("microsoft/tapex-base") model = BartForConditionalGeneration.from_pretrained("microsoft/tapex-base") 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 = "select year where city = beijing" encoding = tokenizer(table=table, query=query, return_tensors="pt") outputs = model.generate(**encoding) print(tokenizer.batch_decode(outputs, skip_special_tokens=True)) # ['2008']
请查找微调脚本 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} }