Compare commits

..

No commits in common. "b60f7b51d94d083c05e8b716d6cbaf7b74d123a4" and "a1180b7b528cc95518f48b55aab29962993a1ac0" have entirely different histories.

5 changed files with 137 additions and 115 deletions

127
README.md
View File

@ -1,65 +1,64 @@
--- ---
language: en language: en
tags: tags:
- tapex - tapex
- table-question-answering license: apache-2.0
license: mit ---
---
# TAPEX (base-sized model)
# TAPEX (base-sized model)
TAPEX 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. The original repo can be found [here](https://github.com/microsoft/Table-Pretraining).
TAPEX 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. The original repo can be found [here](https://github.com/microsoft/Table-Pretraining).
## Model description
## Model description
TAPEX (**Ta**ble **P**re-training via **Ex**ecution) is a conceptually simple and empirically powerful pre-training approach to empower existing models with *table reasoning* skills. TAPEX realizes table pre-training by learning a neural SQL executor over a synthetic corpus, which is obtained by automatically synthesizing executable SQL queries.
TAPEX (**Ta**ble **P**re-training via **Ex**ecution) is a conceptually simple and empirically powerful pre-training approach to empower existing models with *table reasoning* skills. TAPEX realizes table pre-training by learning a neural SQL executor over a synthetic corpus, which is obtained by automatically synthesizing executable SQL queries.
TAPEX is based on the BART architecture, the transformer encoder-encoder (seq2seq) model with a bidirectional (BERT-like) encoder and an autoregressive (GPT-like) decoder.
TAPEX is based on the BART architecture, the transformer encoder-decoder (seq2seq) model with a bidirectional (BERT-like) encoder and an autoregressive (GPT-like) decoder.
## Intended Uses
## Intended Uses
You can use the raw model for simulating neural SQL execution, i.e., employ TAPEX to execute a SQL query on a given table. However, the model is mostly meant to be fine-tuned on a supervised dataset. Currently TAPEX can be fine-tuned to tackle table question answering tasks and table fact verification tasks. See the [model hub](https://huggingface.co/models?search=tapex) to look for fine-tuned versions on a task that interests you.
You can use the raw model for simulating neural SQL execution, i.e., employ TAPEX to execute a SQL query on a given table. However, the model is mostly meant to be fine-tuned on a supervised dataset. Currently TAPEX can be fine-tuned to tackle table question answering tasks and table fact verification tasks. See the [model hub](https://huggingface.co/models?search=tapex) to look for fine-tuned versions on a task that interests you.
### How to Use
### How to Use
Here is how to use this model in transformers:
Here is how to use this model in transformers:
```python
```python from transformers import TapexTokenizer, BartForConditionalGeneration
from transformers import TapexTokenizer, BartForConditionalGeneration import pandas as pd
import pandas as pd
tokenizer = TapexTokenizer.from_pretrained("microsoft/tapex-base")
tokenizer = TapexTokenizer.from_pretrained("microsoft/tapex-base") model = BartForConditionalGeneration.from_pretrained("microsoft/tapex-base")
model = BartForConditionalGeneration.from_pretrained("microsoft/tapex-base")
data = {
data = { "year": [1896, 1900, 1904, 2004, 2008, 2012],
"year": [1896, 1900, 1904, 2004, 2008, 2012], "city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"] }
} table = pd.DataFrame.from_dict(data)
table = pd.DataFrame.from_dict(data)
# tapex accepts uncased input since it is pre-trained on the uncased corpus
# tapex accepts uncased input since it is pre-trained on the uncased corpus query = "select year where city = beijing"
query = "select year where city = beijing" encoding = tokenizer(table=table, query=query, return_tensors="pt")
encoding = tokenizer(table=table, query=query, return_tensors="pt")
outputs = model.generate(**encoding)
outputs = model.generate(**encoding)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
print(tokenizer.batch_decode(outputs, skip_special_tokens=True)) # ['2008']
# ['2008'] ```
```
### How to Fine-tuning
### How to Fine-tuning
Please find the fine-tuning script [here](https://github.com/SivilTaram/transformers/tree/add_tapex_bis/examples/research_projects/tapex).
Please find the fine-tuning script [here](https://github.com/SivilTaram/transformers/tree/add_tapex_bis/examples/research_projects/tapex).
### BibTeX entry and citation info
### BibTeX entry and citation info
```bibtex
```bibtex @inproceedings{
@inproceedings{ liu2022tapex,
liu2022tapex, title={{TAPEX}: Table Pre-training via Learning a Neural {SQL} Executor},
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},
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},
booktitle={International Conference on Learning Representations}, year={2022},
year={2022}, url={https://openreview.net/forum?id=O50443AsCP}
url={https://openreview.net/forum?id=O50443AsCP} }
}
``` ```

View File

@ -1,39 +1,73 @@
{ {
"_name_or_path": "microsoft/tapex-base", "_name_or_path": "bart-base",
"activation_dropout": 0.0, "activation_dropout": 0.0,
"activation_function": "gelu", "activation_function": "gelu",
"architectures": [ "add_bias_logits": false,
"BartForConditionalGeneration" "add_final_layer_norm": false,
], "architectures": [
"attention_dropout": 0.1, "BartModel"
"bos_token_id": 0, ],
"classifier_dropout": 0.0, "attention_dropout": 0.1,
"d_model": 768, "bos_token_id": 0,
"decoder_attention_heads": 12, "classifier_dropout": 0.0,
"decoder_ffn_dim": 3072, "d_model": 768,
"decoder_layerdrop": 0.0, "decoder_attention_heads": 12,
"decoder_layers": 6, "decoder_ffn_dim": 3072,
"decoder_start_token_id": 2, "decoder_layerdrop": 0.0,
"dropout": 0.1, "decoder_layers": 6,
"encoder_attention_heads": 12, "decoder_start_token_id": 2,
"encoder_ffn_dim": 3072, "dropout": 0.1,
"encoder_layerdrop": 0.0, "early_stopping": true,
"encoder_layers": 6, "encoder_attention_heads": 12,
"eos_token_id": 2, "encoder_ffn_dim": 3072,
"forced_bos_token_id": 0, "encoder_layerdrop": 0.0,
"forced_eos_token_id": 2, "encoder_layers": 6,
"init_std": 0.02, "eos_token_id": 2,
"is_encoder_decoder": true, "forced_eos_token_id": 2,
"max_position_embeddings": 1024, "gradient_checkpointing": false,
"model_type": "bart", "id2label": {
"normalize_before": false, "0": "LABEL_0",
"normalize_embedding": true, "1": "LABEL_1",
"num_beams": 4, "2": "LABEL_2"
"num_hidden_layers": 6, },
"pad_token_id": 1, "init_std": 0.02,
"scale_embedding": false, "is_encoder_decoder": true,
"torch_dtype": "float32", "label2id": {
"transformers_version": "4.17.0.dev0", "LABEL_0": 0,
"use_cache": true, "LABEL_1": 1,
"vocab_size": 50265 "LABEL_2": 2
} },
"max_position_embeddings": 1024,
"model_type": "bart",
"no_repeat_ngram_size": 3,
"normalize_before": false,
"normalize_embedding": true,
"num_beams": 4,
"num_hidden_layers": 6,
"pad_token_id": 1,
"scale_embedding": false,
"task_specific_params": {
"summarization": {
"length_penalty": 1.0,
"max_length": 128,
"min_length": 12,
"num_beams": 4
},
"summarization_cnn": {
"length_penalty": 2.0,
"max_length": 142,
"min_length": 56,
"num_beams": 4
},
"summarization_xsum": {
"length_penalty": 1.0,
"max_length": 62,
"min_length": 11,
"num_beams": 6
}
},
"torch_dtype": "float32",
"transformers_version": "4.12.0.dev0",
"use_cache": true,
"vocab_size": 50265
}

View File

@ -1,11 +0,0 @@
{
"_from_model_config": true,
"bos_token_id": 0,
"decoder_start_token_id": 2,
"eos_token_id": 2,
"forced_bos_token_id": 0,
"forced_eos_token_id": 2,
"num_beams": 4,
"pad_token_id": 1,
"transformers_version": "4.27.0.dev0"
}

1
tokenizer.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
{"do_lower_case": true, "errors": "replace", "bos_token": {"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "unk_token": {"content": "<unk>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "sep_token": {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "cls_token": {"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "pad_token": {"content": "<pad>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "add_prefix_space": false, "max_cell_length": 15, "model_max_length": 1024, "special_tokens_map_file": null, "name_or_path": "microsoft/tapex-base", "tokenizer_class": "TapexTokenizer"}