Code Monkey home page Code Monkey logo

tapas's Introduction

TAble PArSing (TAPAS)

Code and checkpoints for training the transformer-based Table QA models introduced in the paper TAPAS: Weakly Supervised Table Parsing via Pre-training.

News

2021/09/15

2021/08/24

  • Added a colab to try predictions on open domain question answering.

2021/08/20

2021/07/23

2021/05/13

2021/03/23

2020/12/17

2020/10/19

  • Small change to WTQ training example creation
    • Questions with ambiguous cell matches will now be discarded
    • This improves denotation accuracy by ~1 point
    • For more details see this issue.
  • Added option to filter table columns by textual overlap with question

2020/10/09

2020/08/26

  • Added a colab to try predictions on WTQ

2020/08/05

  • New pre-trained models (see Data section below)
  • reset_position_index_per_cell: New option that allows to train models that instead of using absolute position indices reset the position index when a new cell starts.

2020/06/10

  • Bump TensorFlow to v2.2

2020/06/08

2020/05/07

  • Added a colab to try predictions on SQA

Installation

The easiest way to try out TAPAS with free GPU/TPU is in our Colab, which shows how to do predictions on SQA.

The repository uses protocol buffers, and requires the protoc compiler to run. You can download the latest binary for your OS here. On Ubuntu/Debian, it can be installed with:

sudo apt-get install protobuf-compiler

Afterwards, clone and install the git repository:

git clone https://github.com/google-research/tapas
cd tapas
pip install -e .

To run the test suite we use the tox library which can be run by calling:

pip install tox
tox

Models

We provide pre-trained models for different model sizes.

The metrics are computed by our tool and not the official metrics of the respective tasks. We provide them so one can verify whether one's own runs are in the right ballpark. They are medians over three individual runs.

Models with intermediate pre-training (2020/10/07).

New models based on the ideas discussed in Understanding tables with intermediate pre-training. Learn more about the methods use here.

WTQ

Trained from Mask LM, intermediate data, SQA, WikiSQL.

Size Reset Dev Accuracy Link
LARGE noreset 0.5062 tapas_wtq_wikisql_sqa_inter_masklm_large.zip
LARGE reset 0.5097 tapas_wtq_wikisql_sqa_inter_masklm_large_reset.zip
BASE noreset 0.4525 tapas_wtq_wikisql_sqa_inter_masklm_base.zip
BASE reset 0.4638 tapas_wtq_wikisql_sqa_inter_masklm_base_reset.zip
MEDIUM noreset 0.4324 tapas_wtq_wikisql_sqa_inter_masklm_medium.zip
MEDIUM reset 0.4324 tapas_wtq_wikisql_sqa_inter_masklm_medium_reset.zip
SMALL noreset 0.3681 tapas_wtq_wikisql_sqa_inter_masklm_small.zip
SMALL reset 0.3762 tapas_wtq_wikisql_sqa_inter_masklm_small_reset.zip
MINI noreset 0.2783 tapas_wtq_wikisql_sqa_inter_masklm_mini.zip
MINI reset 0.2854 tapas_wtq_wikisql_sqa_inter_masklm_mini_reset.zip
TINY noreset 0.0823 tapas_wtq_wikisql_sqa_inter_masklm_tiny.zip
TINY reset 0.1039 tapas_wtq_wikisql_sqa_inter_masklm_tiny_reset.zip

WIKISQL

Trained from Mask LM, intermediate data, SQA.

Size Reset Dev Accuracy Link
LARGE noreset 0.8948 tapas_wikisql_sqa_inter_masklm_large.zip
LARGE reset 0.8979 tapas_wikisql_sqa_inter_masklm_large_reset.zip
BASE noreset 0.8859 tapas_wikisql_sqa_inter_masklm_base.zip
BASE reset 0.8855 tapas_wikisql_sqa_inter_masklm_base_reset.zip
MEDIUM noreset 0.8766 tapas_wikisql_sqa_inter_masklm_medium.zip
MEDIUM reset 0.8773 tapas_wikisql_sqa_inter_masklm_medium_reset.zip
SMALL noreset 0.8552 tapas_wikisql_sqa_inter_masklm_small.zip
SMALL reset 0.8615 tapas_wikisql_sqa_inter_masklm_small_reset.zip
MINI noreset 0.8063 tapas_wikisql_sqa_inter_masklm_mini.zip
MINI reset 0.82 tapas_wikisql_sqa_inter_masklm_mini_reset.zip
TINY noreset 0.3198 tapas_wikisql_sqa_inter_masklm_tiny.zip
TINY reset 0.6046 tapas_wikisql_sqa_inter_masklm_tiny_reset.zip

TABFACT

Trained from Mask LM, intermediate data.

Size Reset Dev Accuracy Link
LARGE noreset 0.8101 tapas_tabfact_inter_masklm_large.zip
LARGE reset 0.8159 tapas_tabfact_inter_masklm_large_reset.zip
BASE noreset 0.7856 tapas_tabfact_inter_masklm_base.zip
BASE reset 0.7918 tapas_tabfact_inter_masklm_base_reset.zip
MEDIUM noreset 0.7585 tapas_tabfact_inter_masklm_medium.zip
MEDIUM reset 0.7587 tapas_tabfact_inter_masklm_medium_reset.zip
SMALL noreset 0.7321 tapas_tabfact_inter_masklm_small.zip
SMALL reset 0.7346 tapas_tabfact_inter_masklm_small_reset.zip
MINI noreset 0.6166 tapas_tabfact_inter_masklm_mini.zip
MINI reset 0.6845 tapas_tabfact_inter_masklm_mini_reset.zip
TINY noreset 0.5425 tapas_tabfact_inter_masklm_tiny.zip
TINY reset 0.5528 tapas_tabfact_inter_masklm_tiny_reset.zip

SQA

Trained from Mask LM, intermediate data.

Size Reset Dev Accuracy Link
LARGE noreset 0.7223 tapas_sqa_inter_masklm_large.zip
LARGE reset 0.7289 tapas_sqa_inter_masklm_large_reset.zip
BASE noreset 0.6737 tapas_sqa_inter_masklm_base.zip
BASE reset 0.6874 tapas_sqa_inter_masklm_base_reset.zip
MEDIUM noreset 0.6464 tapas_sqa_inter_masklm_medium.zip
MEDIUM reset 0.6561 tapas_sqa_inter_masklm_medium_reset.zip
SMALL noreset 0.5876 tapas_sqa_inter_masklm_small.zip
SMALL reset 0.6155 tapas_sqa_inter_masklm_small_reset.zip
MINI noreset 0.4574 tapas_sqa_inter_masklm_mini.zip
MINI reset 0.5148 tapas_sqa_inter_masklm_mini_reset.zip
TINY noreset 0.2004 tapas_sqa_inter_masklm_tiny.zip
TINY reset 0.2375 tapas_sqa_inter_masklm_tiny_reset.zip

INTERMEDIATE

Trained from Mask LM.

Size Reset Dev Accuracy Link
LARGE noreset 0.9309 tapas_inter_masklm_large.zip
LARGE reset 0.9317 tapas_inter_masklm_large_reset.zip
BASE noreset 0.9134 tapas_inter_masklm_base.zip
BASE reset 0.9163 tapas_inter_masklm_base_reset.zip
MEDIUM noreset 0.8988 tapas_inter_masklm_medium.zip
MEDIUM reset 0.9005 tapas_inter_masklm_medium_reset.zip
SMALL noreset 0.8788 tapas_inter_masklm_small.zip
SMALL reset 0.8798 tapas_inter_masklm_small_reset.zip
MINI noreset 0.8218 tapas_inter_masklm_mini.zip
MINI reset 0.8333 tapas_inter_masklm_mini_reset.zip
TINY noreset 0.6359 tapas_inter_masklm_tiny.zip
TINY reset 0.6615 tapas_inter_masklm_tiny_reset.zip

Small Models & position index reset (2020/08/08)

Based on the pre-trained checkpoints available at the BERT github page. See the page or the paper for detailed information on the model dimensions.

Reset refers to whether the parameter reset_position_index_per_cell was set to true or false during training. In general it's recommended to set it to true.

The accuracy depends on the respective task. It's denotation accuracy for WTQ and WIKISQL, average position accuracy with gold labels for the previous answers for SQA and Mask-LM accuracy for Mask-LM.

The models were trained in a chain as indicated by the model name. For example, sqa_masklm means the model was first trained on the Mask-LM task and then on SQA. No destillation was performed.

WTQ

Size Reset Dev Accuracy Link
LARGE noreset 0.4822 tapas_wtq_wikisql_sqa_masklm_large.zip
LARGE reset 0.4952 tapas_wtq_wikisql_sqa_masklm_large_reset.zip
BASE noreset 0.4288 tapas_wtq_wikisql_sqa_masklm_base.zip
BASE reset 0.4433 tapas_wtq_wikisql_sqa_masklm_base_reset.zip
MEDIUM noreset 0.4158 tapas_wtq_wikisql_sqa_masklm_medium.zip
MEDIUM reset 0.4097 tapas_wtq_wikisql_sqa_masklm_medium_reset.zip
SMALL noreset 0.3267 tapas_wtq_wikisql_sqa_masklm_small.zip
SMALL reset 0.3670 tapas_wtq_wikisql_sqa_masklm_small_reset.zip
MINI noreset 0.2275 tapas_wtq_wikisql_sqa_masklm_mini.zip
MINI reset 0.2409 tapas_wtq_wikisql_sqa_masklm_mini_reset.zip
TINY noreset 0.0901 tapas_wtq_wikisql_sqa_masklm_tiny.zip
TINY reset 0.0947 tapas_wtq_wikisql_sqa_masklm_tiny_reset.zip

WIKISQL

Size Reset Dev Accuracy Link
LARGE noreset 0.8862 tapas_wikisql_sqa_masklm_large.zip
LARGE reset 0.8917 tapas_wikisql_sqa_masklm_large_reset.zip
BASE noreset 0.8772 tapas_wikisql_sqa_masklm_base.zip
BASE reset 0.8809 tapas_wikisql_sqa_masklm_base_reset.zip
MEDIUM noreset 0.8687 tapas_wikisql_sqa_masklm_medium.zip
MEDIUM reset 0.8736 tapas_wikisql_sqa_masklm_medium_reset.zip
SMALL noreset 0.8285 tapas_wikisql_sqa_masklm_small.zip
SMALL reset 0.8550 tapas_wikisql_sqa_masklm_small_reset.zip
MINI noreset 0.7672 tapas_wikisql_sqa_masklm_mini.zip
MINI reset 0.7944 tapas_wikisql_sqa_masklm_mini_reset.zip
TINY noreset 0.3237 tapas_wikisql_sqa_masklm_tiny.zip
TINY reset 0.3608 tapas_wikisql_sqa_masklm_tiny_reset.zip

SQA

Size Reset Dev Accuracy Link
LARGE noreset 0.7002 tapas_sqa_masklm_large.zip
LARGE reset 0.7130 tapas_sqa_masklm_large_reset.zip
BASE noreset 0.6393 tapas_sqa_masklm_base.zip
BASE reset 0.6689 tapas_sqa_masklm_base_reset.zip
MEDIUM noreset 0.6026 tapas_sqa_masklm_medium.zip
MEDIUM reset 0.6141 tapas_sqa_masklm_medium_reset.zip
SMALL noreset 0.4976 tapas_sqa_masklm_small.zip
SMALL reset 0.5589 tapas_sqa_masklm_small_reset.zip
MINI noreset 0.3779 tapas_sqa_masklm_mini.zip
MINI reset 0.3687 tapas_sqa_masklm_mini_reset.zip
TINY noreset 0.2013 tapas_sqa_masklm_tiny.zip
TINY reset 0.2194 tapas_sqa_masklm_tiny_reset.zip

MASKLM

Size Reset Dev Accuracy Link
LARGE noreset 0.7513 tapas_masklm_large.zip
LARGE reset 0.7528 tapas_masklm_large_reset.zip
BASE noreset 0.7323 tapas_masklm_base.zip
BASE reset 0.7335 tapas_masklm_base_reset.zip
MEDIUM noreset 0.7059 tapas_masklm_medium.zip
MEDIUM reset 0.7054 tapas_masklm_medium_reset.zip
SMALL noreset 0.6818 tapas_masklm_small.zip
SMALL reset 0.6856 tapas_masklm_small_reset.zip
MINI noreset 0.6382 tapas_masklm_mini.zip
MINI reset 0.6425 tapas_masklm_mini_reset.zip
TINY noreset 0.4826 tapas_masklm_tiny.zip
TINY reset 0.5282 tapas_masklm_tiny_reset.zip

Original Models

The pre-trained TAPAS checkpoints can be downloaded here:

The first two models are pre-trained on the Mask-LM task and the last two on the Mask-LM task first and SQA second.

Fine-Tuning Data

You also need to download the task data for the fine-tuning tasks:

Pre-Training

Note that you can skip pre-training and just use one of the pre-trained checkpoints provided above.

Information about the pre-taining data can be found here.

The TF examples for pre-training can be created using Google Dataflow:

python3 setup.py sdist
python3 tapas/create_pretrain_examples_main.py \
  --input_file="gs://tapas_models/2020_05_11/interactions.txtpb.gz" \
  --vocab_file="gs://tapas_models/2020_05_11/vocab.txt" \
  --output_dir="gs://your_bucket/output" \
  --runner_type="DATAFLOW" \
  --gc_project="you-project" \
  --gc_region="us-west1" \
  --gc_job_name="create-pretrain" \
  --gc_staging_location="gs://your_bucket/staging" \
  --gc_temp_location="gs://your_bucket/tmp" \
  --extra_packages=dist/tapas-0.0.1.dev0.tar.gz

You can also run the pipeline locally but that will take a long time:

python3 tapas/create_pretrain_examples_main.py \
  --input_file="$data/interactions.txtpb.gz" \
  --output_dir="$data/" \
  --vocab_file="$data/vocab.txt" \
  --runner_type="DIRECT"

This will create two tfrecord files for training and testing. The pre-training can then be started with the command below. The init checkpoint should be a standard BERT checkpoint.

python3 tapas/experiments/tapas_pretraining_experiment.py \
  --eval_batch_size=32 \
  --train_batch_size=512 \
  --tpu_iterations_per_loop=5000 \
  --num_eval_steps=100 \
  --save_checkpoints_steps=5000 \
  --num_train_examples=512000000 \
  --max_seq_length=128 \
  --input_file_train="${data}/train.tfrecord" \
  --input_file_eval="${data}/test.tfrecord" \
  --init_checkpoint="${tapas_data_dir}/model.ckpt" \
  --bert_config_file="${tapas_data_dir}/bert_config.json" \
  --model_dir="..." \
  --compression_type="" \
  --do_train

Where compression_type should be set to GZIP if the tfrecords are compressed. You can start a separate eval job by setting --nodo_train --doeval.

Running a fine-tuning task

We need to create the TF examples before starting the training. For example, for SQA that would look like:

python3 tapas/run_task_main.py \
  --task="SQA" \
  --input_dir="${sqa_data_dir}" \
  --output_dir="${output_dir}" \
  --bert_vocab_file="${tapas_data_dir}/vocab.txt" \
  --mode="create_data"

Optionally, to handle big tables, we can add a --prune_columns flag to apply the HEM method described section 3.3 of our paper to discard some columns based on textual overlap with the sentence.

Afterwards, training can be started by running:

python3 tapas/run_task_main.py \
  --task="SQA" \
  --output_dir="${output_dir}" \
  --init_checkpoint="${tapas_data_dir}/model.ckpt" \
  --bert_config_file="${tapas_data_dir}/bert_config.json" \
  --mode="train" \
  --use_tpu

This will use the preset hyper-parameters set in hparam_utils.py.

It's recommended to start a separate eval job to continuously produce predictions for the checkpoints created by the training job. Alternatively, you can run the eval job after training to only get the final results.

python3 tapas/run_task_main.py \
  --task="SQA" \
  --output_dir="${output_dir}" \
  --init_checkpoint="${tapas_data_dir}/model.ckpt" \
  --bert_config_file="${tapas_data_dir}/bert_config.json" \
  --mode="predict_and_evaluate"

Another tool to run experiments is tapas_classifier_experiment.py. It's more flexible than run_task_main.py but also requires setting all the hyper-parameters (via the respective command line flags).

Evaluation

Here we explain some details about different tasks.

SQA

By default, SQA will evaluate using the reference answers of the previous questions. The number in the paper (Table 5) are computed using the more realistic setup where the previous answer are model predictions. run_task_main.py will output additional prediction files for this setup as well if run on GPU.

WTQ

For the official evaluation results one should convert the TAPAS predictions to the WTQ format and run the official evaluation script. This can be done using convert_predictions.py.

WikiSQL

As discussed in the paper our code will compute evaluation metrics that deviate from the official evaluation script (Table 3 and 10).

Hardware Requirements

TAPAS is essentialy a BERT model and thus has the same requirements. This means that training the large model with 512 sequence length will require a TPU. You can use the option max_seq_length to create shorter sequences. This will reduce accuracy but also make the model trainable on GPUs. Another option is to reduce the batch size (train_batch_size), but this will likely also affect accuracy. We added an options gradient_accumulation_steps that allows you to split the gradient over multiple batches. Evaluation with the default test batch size (32) should be possible on GPU.

How to cite TAPAS?

You can cite the ACL 2020 paper and the EMNLP 2020 Findings paper for the laters work on pre-training objectives.

Disclaimer

This is not an official Google product.

Contact information

For help or issues, please submit a GitHub issue.

tapas's People

Contributors

chayanbansal avatar eisenjulian avatar kamalkraj avatar lysandrejik avatar martin36 avatar muelletm avatar susmitpy avatar syrinekrichene avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tapas's Issues

Fine tune tapas_wikisql_sqa_masklm_large on WTQ

I have been fining tune the program of tapas_wikisql_sqa_masklm_large on WTQ dataset to get the tapas_wtq_wikisql_sqa_masklm_large model for a few days on GPU. But the dev acc only is 30%. What is the problem about this phenomenon?

Script to convert Wikipedia article infobox to required tabular format

Hi, in the Colab notebook, I noticed the table has to be in a specific format (using pipes for columns) for the prediction to work. Also, in pre-training, it is mentioned that tables were extracted from Wikipedia into the "proto text format".

I looked into the code and could not find any scripts that: (1) given Wikipedia page url, scrape the corresponding infobox to produce a table, and (2) produce that table in the piped format which is in the colab notebook.

Initially I was planning to write my own scraper for Wikipedia infobox, but it would be really time consuming, especially if you have a script already for it, then that would be great. Thanks!

WTQ fine-tune

I plan to fine-tune WTQ on pre-trained SQA model. How do I create the correct format of WTQ?

"Can't convert interaction: error: Too many rows" and "Can't convert interaction: Sequence too long"

A big thank you to all the developers for this wonderful concept and for making the implementation open-sourced. I was trying to perform prediction (using the sqa base model) on a table of size 1801330 X 59.

When I try with reducing the number of columns (to 3 in my case) and using the total number of rows - it returns a "Can't convert interaction: error: Too many rows" error. It returns this error thrice, without printing any interaction.id, prompting me to believe it happens for particular rows only. Please correct me if I am mistaken.

When I reduce the number of rows and use all 59 rows it returns "Can't convert interaction: error: Too many rows", without any interaction id.

I am performing my tests in Colab with a RAM 12.72 GB and Diskspace: 68.40 GB. The table contains a mix of dates, integers, floats and characters.

I would appreciate any input for a workaround. Thank you.

About the pre-training data

Hi, I'm quite curious about what the pre-training data looks like. Is there any chance you can demonstrate a small subsample in the repo.

Integration with RDBMS

Is there any way to integrate the model with an RDBMS instead of giving the table input each time for prediction?

Trained Model on WikiTable Questions

Hi, can you share the trained model on WikiTableQuestion please?

Because I tried all base models that you shared without doing any fine-tuning and got error like this tensorflow.python.framework.errors_impl.NotFoundError: Key column_output_bias not found in checkpoint. I guess the base model are not trained using WikiTableQuestions right?

Run on Custom data

I tried to run the custom data mentioned in the ipython notebook example in this repository. In that example the code converts a table and queries directly to the tfexamples. Now when I run the code to do prediction I get the following error

`E0617 16:23:59.204641 139751394191168 error_handling.py:70] Error recorded from prediction_loop: 2 root error(s) found.
(0) Data loss: inflate() failed with error -3: incorrect header check
[[node IteratorGetNext (defined at /data/t-mdra/projects/tapas/tapas/experiments/prediction_utils.py:199) ]]
[[IteratorGetNext/_1269]]
(1) Data loss: inflate() failed with error -3: incorrect header check
[[node IteratorGetNext (defined at /data/t-mdra/projects/tapas/tapas/experiments/prediction_utils.py:199) ]]
0 successful operations.
0 derived errors ignored.

Original stack trace for 'IteratorGetNext':
File "tapas/run_task_main.py", line 776, in
app.run(main)
File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 300, in run
_run_main(main, args)
File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "tapas/run_task_main.py", line 761, in main
loop_predict=FLAGS.loop_predict,
File "tapas/run_task_main.py", line 467, in _train_and_predict
global_step=current_step,
File "tapas/run_task_main.py", line 516, in _predict
global_step=None,
File "tapas/run_task_main.py", line 575, in _predict_for_set
cell_classification_threshold=_CELL_CLASSIFICATION_THRESHOLD)
File "/data/t-mdra/projects/tapas/tapas/experiments/prediction_utils.py", line 199, in write_predictions
for prediction in predictions:
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/tpu/tpu_estimator.py", line 2913, in predict
yield_single_examples=yield_single_examples):
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 617, in predict
input_fn, ModeKeys.PREDICT)
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 994, in _get_features_from_input_fn
result, _, hooks = estimator_util.parse_input_fn_result(result)
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/util.py", line 65, in parse_input_fn_result
result = iterator.get_next()
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow/python/data/ops/iterator_ops.py", line 426, in get_next
output_shapes=self._structure._flat_shapes, name=name)
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow/python/ops/gen_dataset_ops.py", line 1947, in iterator_get_next
output_shapes=output_shapes, name=name)
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3616, in create_op
op_def=op_def)
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2005, in init
self._traceback = tf_stack.extract_stack()

Traceback (most recent call last):
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1356, in _do_call
return fn(*args)
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1341, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "/home/t-mdra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1429, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.DataLossError: 2 root error(s) found.
(0) Data loss: inflate() failed with error -3: incorrect header check
[[{{node IteratorGetNext}}]]
[[IteratorGetNext/_1269]]
(1) Data loss: inflate() failed with error -3: incorrect header check
[[{{node IteratorGetNext}}]]
0 successful operations.
0 derived errors ignored.

`

Basic steps to try this on my data?

Hi, I would love to try this out on some of our data. The basic experiment I'm thinking of is based on user interactions with specific features in our product. So in general the table would have columns such as: date, user_id, user_meta1, user_meta2, ..., feature_X_interaction_count, feature_Y_interaction_count, ...

I'd like to ask questions like "How many new users interacted with feature X?" or "what country has the highest percentage of users who interacted with feature Y?", or "which features do users from North America use the most?"; etc.

Does this sound like a feasible experiment, and if so can you give me some very high-level steps to try. E.g. can I start with one of your pretrained models and either fine-tune or predict directly? If I do need to train from scratch, can you suggest how I would generate training examples?

Thanks so much in advance for pointing me in the right direction!

Failed to import test module: tapas.experiments.prediction_utils_test when using tox on Python 3.7

Hi, so, rerunning the repo with Python 3.7 and finally on step tox, got this error (I am skipping the warning outputs that came before this):

======================================================================
ERROR: tapas.experiments.prediction_utils_test (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tapas.experiments.prediction_utils_test
Traceback (most recent call last):
  File "/usr/local/apps/python-3.7.4/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/local/apps/python-3.7.4/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/gaurang.tandon/tables/tapas/tapas/experiments/prediction_utils_test.py", line 21, in <module>
    from tapas.experiments import prediction_utils
  File "/home/gaurang.tandon/tables/tapas/tapas/experiments/prediction_utils.py", line 25, in <module>
    from tapas.models import tapas_classifier_model
  File "/home/gaurang.tandon/tables/tapas/tapas/models/tapas_classifier_model.py", line 31, in <module>
    import tensorflow_probability as tfp
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/__init__.py", line 76, in <module>
    from tensorflow_probability.python import *  # pylint: disable=wildcard-import
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/__init__.py", line 23, in <module>
    from tensorflow_probability.python import distributions
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/distributions/__init__.py", line 88, in <module>
    from tensorflow_probability.python.distributions.pixel_cnn import PixelCNN
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/distributions/pixel_cnn.py", line 37, in <module>
    from tensorflow_probability.python.layers import weight_norm
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/layers/__init__.py", line 31, in <module>
    from tensorflow_probability.python.layers.distribution_layer import CategoricalMixtureOfOneHotCategorical
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/layers/distribution_layer.py", line 28, in <module>
    from cloudpickle.cloudpickle import CloudPickler
ImportError: cannot import name 'CloudPickler' from 'cloudpickle.cloudpickle' (/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/cloudpickle/cloudpickle.py)


======================================================================
ERROR: tapas.models.tapas_classifier_model_test (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tapas.models.tapas_classifier_model_test
Traceback (most recent call last):
  File "/usr/local/apps/python-3.7.4/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/local/apps/python-3.7.4/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/gaurang.tandon/tables/tapas/tapas/models/tapas_classifier_model_test.py", line 22, in <module>
    from tapas.models import tapas_classifier_model
  File "/home/gaurang.tandon/tables/tapas/tapas/models/tapas_classifier_model.py", line 31, in <module>
    import tensorflow_probability as tfp
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/__init__.py", line 76, in <module>
    from tensorflow_probability.python import *  # pylint: disable=wildcard-import
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/__init__.py", line 23, in <module>
    from tensorflow_probability.python import distributions
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/distributions/__init__.py", line 88, in <module>
    from tensorflow_probability.python.distributions.pixel_cnn import PixelCNN
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/distributions/pixel_cnn.py", line 37, in <module>
    from tensorflow_probability.python.layers import weight_norm
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/layers/__init__.py", line 31, in <module>
    from tensorflow_probability.python.layers.distribution_layer import CategoricalMixtureOfOneHotCategorical
  File "/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/tensorflow_probability/python/layers/distribution_layer.py", line 28, in <module>
    from cloudpickle.cloudpickle import CloudPickler
ImportError: cannot import name 'CloudPickler' from 'cloudpickle.cloudpickle' (/home/gaurang.tandon/tables/tapas/.tox/py37/lib/python3.7/site-packages/cloudpickle/cloudpickle.py)


----------------------------------------------------------------------
Ran 163 tests in 21.259s

FAILED (errors=2, skipped=6)
ERROR: InvocationError for command /home/gaurang.tandon/tables/tapas/.tox/py37/bin/python -m unittest discover -p '*_test.py' (exited with code 1)
_____________________________________________________ summary _____________________________________________________
ERROR:  py36: InterpreterNotFound: python3.6
ERROR:   py37: commands failed

I had completed python -m pip install -e . succesfully. What should I do here?

Multi-gpu issues (not utilizing >1 gpu?)

Hello,

I am trying to run this codebase on a single machine with eight GPUs. I have installed all through requirements.txt and prepped the data. When I run, I am only able to use train_batch_size=8 and notice that only one of the eight GPUs is utilized (the other 7 show ~300MB of data on device while the first GPU shows ~15GB). Additionally, while I can see this usage of the GPU(s) by the run script, I get an output message in the train log of: I0514 19:25:27.752172 139628342118208 tpu_estimator.py:2965] Running train on CPU, though I have been ignoring this for now. So I am trying to get the other seven GPUs in the loop so that I can train with train_batch_size=64.

I initially tried wrapping the optimization code in:

strategy = tf.distribute.MirroredStrategy()
with strategy.scope():
   # rest here from bert/optimization.py

and I notice that the model is properly replicated across the eight GPUs, however I cannot expand my train_batch_size to any multiple larger than 8. I tried wrapping the dataset object, at the end of input_fn before returning, in strategy.experimental_distribute_dataset(ds) to see if it was a matter of not sending batches to each device. However, I ran into deeper errors that I am unfamiliar with when pursuing this route (if this is a preferable way to enable multi-GPU I could update this issue with stack traces I got after running with the aforementioned changes).

Before debugging further in this direction, I tried to step back to the outer run_task_main.py after reading that you can instead pass MirroredStrategy or CentralStorageStrategy objects directly into the RunConfig that goes into an Estimator. So I undid the aforementioned changes that I manually made in the lower levels (e.g. reset repo back to master) and added to:

run_config = tf.estimator.tpu.RunConfig(
  ...
  train_distribute=strategy,
  ...

However, I now run into the error:

Traceback (most recent call last):
  File "tapas/run_task_main.py", line 777, in <module>
    app.run(main)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/absl/app.py", line 299, in run
    _run_main(main, args)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main
    sys.exit(main(argv))
  File "tapas/run_task_main.py", line 762, in main
    loop_predict=FLAGS.loop_predict,
  File "tapas/run_task_main.py", line 440, in _train_and_predict
    max_steps=tapas_config.num_train_steps,
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/tpu/tpu_estimator.py", line 2876, in train
    rendezvous.raise_errors()
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/tpu/error_handling.py", line 131, in raise_errors
    six.reraise(typ, value, traceback)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/six.py", line 703, in reraise
    raise value
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/tpu/tpu_estimator.py", line 2871, in train
    saving_listeners=saving_listeners)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 367, in train
    loss = self._train_model(input_fn, hooks, saving_listeners)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1156, in _train_model
    return self._train_model_distributed(input_fn, hooks, saving_listeners)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1219, in _train_model_distributed
    self._config._train_distribute, input_fn, hooks, saving_listeners)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1255, in _actual_train_model_distributed
    input_fn, ModeKeys.TRAIN, strategy)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1009, in _get_iterator_from_input_fn
    lambda input_context: self._call_input_fn(input_fn, mode,
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow/python/distribute/distribute_lib.py", line 774, in make_input_fn_iterator
    input_fn, replication_mode)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow/python/distribute/distribute_lib.py", line 406, in make_input_fn_iterator
    input_fn, replication_mode=replication_mode)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow/python/distribute/parameter_server_strategy.py", line 318, in _make_input_fn_iterator
    self._container_strategy())
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow/python/distribute/input_lib.py", line 550, in __init__
    result = input_fn(ctx)
  File "/mydata/repos/tapas2/venv/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1010, in <lambda>
    input_context))
TypeError: _call_input_fn() takes 3 positional arguments but 4 were given

which I suspect may have to do with the functools.partial wrap around input_fn, but I am having trouble understanding this or determining next steps (I am generally unfamiliar with Tensorflow as a library).

If anybody can help me with this it would be greatly appreciated. Thanks so much for the work and time!

[script parameter error] tapas_pretraining_experiment.py missing compression_type=

python3 tapas/experiments/tapas_pretraining_experiment.py
--eval_batch_size=32
--train_batch_size=512
--tpu_iterations_per_loop=5000
--num_eval_steps=100
--save_checkpoints_steps=5000
--num_train_examples=512000000
--max_seq_length=128
--input_file_train="${data}/train.tfrecord"
--input_file_eval="${data}/test.tfrecord"
--init_checkpoint="${tapas_data_dir}/model.ckpt"
--bert_config_file="${tapas_data_dir}/bert_config.json"
--model_dir="..."
--do_train

should be changed to
python3 tapas/experiments/tapas_pretraining_experiment.py
--eval_batch_size=32
--train_batch_size=512
--tpu_iterations_per_loop=5000
--num_eval_steps=100
--save_checkpoints_steps=5000
--num_train_examples=512000000
--max_seq_length=128
--input_file_train="${data}/train.tfrecord"
--input_file_eval="${data}/test.tfrecord"
--init_checkpoint="${tapas_data_dir}/model.ckpt"
--bert_config_file="${tapas_data_dir}/bert_config.json"
--model_dir="..."
--do_train
-- compression_type=

Where we can download WIKISQL pre-trained tapas model?

First of all, thank you for this awesome work and making it open source.

SQA large model is not supporting Logical Form and Aggregation based questions. As shown in the paper WIKISQL model consists of both Logical Form and Aggregation.

From where we can download WIKISQL checkpoint of the trained model?

  • Aaditya

ERROR: Could not find a version that satisfies the requirement pandas~=1.0.0

  1. Cloned the repo.
  2. Ran python -m pip install -e . (Python is v3.5).

Expected: all packages should install.
Actual:

$ python -m pip install -e .
Obtaining file:///home/gaurang.tandon/tables/tapas
Collecting apache-beam[gcp]==2.20.0
  Downloading apache_beam-2.20.0-cp35-cp35m-manylinux1_x86_64.whl (3.4 MB)
     |โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 3.4 MB 165 kB/s 
Collecting frozendict==1.2
  Downloading frozendict-1.2.tar.gz (2.6 kB)
ERROR: Could not find a version that satisfies the requirement pandas~=1.0.0 (from tapas==0.0.1.dev0) (from versions: 0.1, 0.2b0, 0.2b1, 0.2, 0.3.0b0, 0.3.0b2, 0.3.0, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.6.0, 0.6.1, 0.7.0rc1, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0rc1, 0.8.0rc2, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0rc1, 0.19.0, 0.19.1, 0.19.2, 0.20.0rc1, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.21.0rc1, 0.21.0, 0.21.1, 0.22.0, 0.23.0rc2, 0.23.0, 0.23.1, 0.23.2, 0.23.3, 0.23.4, 0.24.0rc1, 0.24.0, 0.24.1, 0.24.2)
ERROR: No matching distribution found for pandas~=1.0.0 (from tapas==0.0.1.dev0)

How to fix this? I am on commit id 32f90d6. Thanks!

Weird results when running custom question on Colab example

Hello Again,
I tried to create a simple question: "what is the average Points?" from the example table you published on the Colab notebook.
I got the Column 'Points' just printed out. I tried both base and large models and the results didn't change.

Any thoughts?

About batch size

Hi there, I try to run your code on wikitable questions on GPU, but the default batch size 512 is way too large. I decrease it to 8 to fit in my RTX card (24 GB), is there anything that I missed? Why is your default batch size so large?

TF records for pretraining data

@muelletm @ebursztein
Can you release the tfrecords data for pre-training? I want to develop a 6 layers pretrained checkpoint for TAPAS.

I am currently running the pre-training data generation in my single CPU machine and it has been running for 3 days. Does it take so long on CPU? Should it create any temporary files? Because I cannot see train.tfrecords and test.tfrecords file even though it has been running for 3 days.

Can we run pre-training data on GPU? I tried to allocate the gpu but the existing code is not using any?

Slow performance

Hi,

Thanks for releasing this in open source. Wonderful concept and very different for other seq2seq or ln2sql like approaches.

I am facing performance issues when trying with sqa prediction notebook (using SQA Large). It takes more than 60 seconds on a dual gpu machine for evaluating the model and giving response to a query. Is this normal? How can we improve the prediction time?

Thanks,
Manish

[bug] tapas_pretraining_experiment.py missing Flag "model_dir" parameter

model_dir flag is missing in the tapas_pretraining_experiment.py I have added the flag in the file. Please update the file accordingly,

python tapas/experiments/tapas_pretraining_experiment.py
--eval_batch_size=32
--train_batch_size=512
--tpu_iterations_per_loop=5000
--num_eval_steps=100
--save_checkpoints_steps=600
--num_train_examples=512000000
--max_seq_length=128
--input_file_train="/data/t-mdra/data/tapas_pretrainig_data/train.tfrecord"
--input_file_eval="/data/t-mdra/data/tapas_pretrainig_data/test.tfrecord"
--init_checkpoint="/data/t-mdra/projects/tapas/bert_checkpoints/L-6_H-256/model.ckpt"
--bert_config_file="/data/t-mdra/projects/tapas/bert_checkpoints/L-6_H-256/bert_config.json"
--model_dir="/data/t-mdra/projects/tapas/tapas/pretrained_model/"
--do_train

Corrupted SQA tfrecords

I ran the following command to create tfrecords from the SQA TSV files (I'm on Windows, Python version 3.6.4, installed the protobuf compiler and tapas package as explained in your README):

python tapas/run_task_main.py \
  --task="SQA" \
  --input_dir="./SQA release 1.0" \
  --output_dir="./output" \
  --bert_vocab_file="vocab.txt" \
  --mode="create_data"

This printed the following:

WARNING:tensorflow:From C:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tapas\scripts\prediction_utils.py:41: tf_record_iterator (from tensorflow.python.lib.io.tf_record) is deprecated and will be removed in a future version.
Instructions for updating:
Use eager execution and:
`tf.data.TFRecordDataset(path)`
W0813 12:00:32.413115  7056 deprecation.py:323] From C:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tapas\scripts\prediction_utils.py:41: tf_record_iterator (from tensorflow.python.lib.io.tf_record) is deprecated and will be removed in a future version.
Instructions for updating:
Use eager execution and:
`tf.data.TFRecordDataset(path)`
I0813 12:00:32.430038  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Title"
) {0: [], 1: [float_value: 1.0
, float_value: 2.0
], 2: [float_value: 1.0
, float_value: 1945.0
, date {
  year: 1945
}
], 3: [float_value: 2.0
], 4: [float_value: 3.0
], 5: [], 6: [], 7: []} 4
I0813 12:00:37.874481  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Album"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [float_value: 5.0
], 6: [], 7: [], 8: [], 9: [float_value: 91.0
]} 2
I0813 12:00:43.282050  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Competition"
) {0: [float_value: 4.0
], 1: [], 2: [], 3: [], 4: [float_value: 1.0
], 5: [float_value: 2.0
], 6: [], 7: [float_value: 2.0
], 8: [float_value: 2.0
], 9: [], 10: [float_value: 2.0
], 11: [], 12: [], 13: []} 6
I0813 12:00:48.533008  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Roma"
) {0: [float_value: 6.5
], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [float_value: 2.5999999046325684
], 7: [], 8: [float_value: 6.0
], 9: [float_value: 1.7000000476837158
], 10: [float_value: 4.900000095367432
], 11: [float_value: 11.600000381469727
], 12: [float_value: 13.600000381469727
], 13: [float_value: 17.899999618530273
]} 8
I0813 12:00:54.263187  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Position"
) {0: [float_value: 1.0
], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [float_value: 3.0
], 8: [float_value: 3.0
], 9: [float_value: 1.0
], 10: [], 11: [], 12: [], 13: [], 14: [float_value: 1.0
], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: [], 26: [], 27: [], 28: [], 29: []} 5
I0813 12:01:01.409110  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Notes"
) {0: [float_value: 1.0
, float_value: 2.0
], 1: [float_value: 1.0
], 2: [float_value: 2.0
], 3: [], 4: [], 5: [], 6: [], 7: [], 8: []} 3
I0813 12:01:07.108868  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Position"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [float_value: 1.0
], 7: [], 8: [], 9: [], 10: [float_value: 3.0
], 11: [], 12: [], 13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [float_value: 1.0
], 23: [], 24: [float_value: 2.0
], 25: []} 4
I0813 12:01:13.811882  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Club"
) {0: [], 1: [float_value: 1.0
], 2: [float_value: 2000.0
, date {
  year: 2000
}
], 3: [float_value: 60.0
], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: []} 3
I0813 12:01:19.658277  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Notes"
) {0: [float_value: 6.0
, float_value: 666.0
], 1: [float_value: 666.0
], 2: [float_value: 6.0
, float_value: 666.0
], 3: [float_value: 4.0
, float_value: 666.0
, float_value: 666.0
], 4: [], 5: [], 6: []} 4
I0813 12:01:24.497306  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Release date"
) {0: [date {
  year: 1943
  month: 7
  day: 2
}
], 1: [], 2: [date {
  year: 1943
  month: 1
  day: 25
}
, date {
  year: 1943
  month: 3
  day: 3
}
], 3: [date {
  year: 1943
  month: 1
  day: 16
}
], 4: [], 5: [date {
  year: 1943
  month: 9
  day: 22
}
], 6: [date {
  year: 1943
  month: 6
  day: 14
}
], 7: [], 8: [], 9: [date {
  year: 1943
  month: 4
  day: 10
}
], 10: [date {
  year: 1943
  month: 10
  day: 28
}
], 11: []} 7
I0813 12:01:31.469692  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Device"
) {0: [], 1: [float_value: 25.0
, float_value: 2.0
], 2: [float_value: 25.0
], 3: [], 4: [float_value: 3.0
], 5: [], 6: [float_value: 4.0
], 7: [float_value: 20.0
], 8: [], 9: [], 10: [float_value: 3.0
, float_value: 2.0
], 11: [], 12: [float_value: 3200.0
], 13: [], 14: [float_value: 1.0
], 15: [float_value: 3010.0
, float_value: 6010.0
], 16: [float_value: 720.0
], 17: [float_value: 4.0
], 18: [], 19: [float_value: 6000.0
], 20: [float_value: 630.0
], 21: [], 22: [float_value: 2.0
, float_value: 4.0
], 23: [float_value: 70.0
], 24: [float_value: 2.0
], 25: [float_value: 6240.0
], 26: [float_value: 2.0
]} 18
I0813 12:01:38.270512  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Mission result"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [float_value: 1977.0
, date {
  year: 1977
}
, float_value: 500.0
, float_value: 18.0
], 12: [], 13: [], 14: [], 15: [float_value: 200.0
, float_value: 7.099999904632568
], 16: [], 17: [float_value: 60.0
, float_value: 2.0
, float_value: 2.0999999046325684
, float_value: 4.400000095367432
], 18: [float_value: 2.0
, float_value: 4.400000095367432
], 19: [], 20: [float_value: 1.0
, float_value: 2.200000047683716
], 21: [], 22: [float_value: 200.0
, float_value: 7.099999904632568
], 23: [], 24: [float_value: 200.0
, float_value: 440.0
]} 7
I0813 12:01:45.194988  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Driver"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [], 13: [float_value: 2.0
], 14: [], 15: [], 16: []} 1
I0813 12:01:50.528725  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Time/Retired"
) {0: [float_value: 1.0
, float_value: 36.0
, float_value: 24.226999282836914
], 1: [float_value: 16.4950008392334
], 2: [float_value: 23.351999282836914
], 3: [float_value: 42.62699890136719
], 4: [float_value: 43.933998107910156
], 5: [float_value: 47.775001525878906
], 6: [float_value: 53.59700012207031
], 7: [float_value: 54.119998931884766
], 8: [float_value: 54.43299865722656
], 9: [float_value: 54.749000549316406
], 10: [float_value: 1.0
, float_value: 7.539999961853027
], 11: [float_value: 1.0
, float_value: 11.298999786376953
], 12: [float_value: 1.0
], 13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: []} 13
I0813 12:01:55.352831  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "UK"
) {0: [], 1: [float_value: 31.0
], 2: [float_value: 31.0
], 3: [float_value: 168.0
], 4: [float_value: 108.0
], 5: [], 6: [], 7: [], 8: [], 9: []} 4
I0813 12:02:01.081506  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Storage"
) {0: [], 1: [float_value: 8.0
], 2: [float_value: 6.0
], 3: [], 4: [], 5: [float_value: 1600.0
, float_value: 9427.0
, float_value: 1.0
, float_value: 1.0
], 6: [], 7: [float_value: 9427.0
, float_value: 4.0
, float_value: 2.0
, float_value: 8000.0
], 8: [float_value: 32.0
, float_value: 18.0
, float_value: 8.0
, float_value: 32.0
, float_value: 1.0
, float_value: 9427.0
, float_value: 2.0
, float_value: 232.0
, float_value: 4.0
, float_value: 2.0
, float_value: 4.0
, float_value: 2.0
], 9: [float_value: 7.0
, float_value: 2.0
, float_value: 4.0
, float_value: 32.0
, float_value: 18.0
, float_value: 8.0
, float_value: 32.0
], 10: [float_value: 7.0
, float_value: 2.0
, float_value: 4.0
, float_value: 32.0
, float_value: 18.0
, float_value: 8.0
, float_value: 32.0
], 11: []} 7
I0813 12:02:10.043508  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Features"
) {0: [float_value: 2.5
, float_value: 720.0
, float_value: 7.300000190734863
], 1: [], 2: [float_value: 2.299999952316284
, float_value: 3.5
, float_value: 1080.0
], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [float_value: 1080.0
], 9: [float_value: 1080.0
], 10: [float_value: 9200.0
]} 5
I0813 12:02:14.576418  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "ARQB"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [float_value: 28.0
], 10: [], 11: [], 12: [], 13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: []} 1
I0813 12:02:19.323728  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Club"
) {0: [], 1: [float_value: 1.0
], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [], 13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: []} 1
I0813 12:02:27.257509  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Synopsis"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [float_value: 2.0
], 9: [], 10: []} 1
I0813 12:02:33.690273  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Film"
) {0: [], 1: [], 2: [], 3: [float_value: 3.0
], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [float_value: 7.0
], 11: [], 12: [], 13: [], 14: [], 15: [float_value: 101.0
], 16: []} 3
I0813 12:02:40.156911  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Record"
) {0: [float_value: 5.0
, float_value: 4.0
, float_value: 0.0
], 1: [], 2: [], 3: [float_value: 4.0
, float_value: 5.0
, float_value: 0.0
], 4: [], 5: [], 6: [], 7: [float_value: 21.0
, float_value: 23.0
, float_value: 0.0
], 8: [float_value: 90.0
, float_value: 76.0
, float_value: 2.0
], 9: [float_value: 17.0
, float_value: 8.0
, float_value: 0.0
], 10: [float_value: 59.0
, float_value: 37.0
, float_value: 1.0
], 11: [float_value: 515.0
, float_value: 376.0
, float_value: 0.0
], 12: [float_value: 634.0
, float_value: 328.0
, float_value: 0.0
], 13: [float_value: 145.0
, float_value: 92.0
, float_value: 0.0
], 14: [float_value: 115.0
, float_value: 113.0
, float_value: 0.0
], 15: [float_value: 167.0
, float_value: 126.0
], 16: [float_value: 17.0
, float_value: 8.0
, float_value: 0.0
], 17: []} 12
I0813 12:02:46.707394  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Laid down"
) {0: [], 1: [], 2: [], 3: [date {
  year: 1899
  month: 4
  day: 10
}
], 4: [date {
  year: 1899
  month: 4
  day: 10
}
], 5: [], 6: []} 2
I0813 12:02:49.988619  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Moved To"
) {0: [float_value: 1932.0
, date {
  year: 1932
}
], 1: [float_value: 2003.0
, date {
  year: 2003
}
], 2: [float_value: 1994.0
, date {
  year: 1994
}
], 3: [], 4: [float_value: 1987.0
, date {
  year: 1987
}
], 5: [float_value: 2008.0
, date {
  year: 2008
}
], 6: [float_value: 1987.0
, date {
  year: 1987
}
], 7: [], 8: []} 6
I0813 12:02:54.348928  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "TV"
) {0: [], 1: [], 2: [], 3: [], 4: [float_value: 12.0
], 5: [float_value: 12.0
], 6: [float_value: 12.0
], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [], 13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: [], 26: [], 27: [], 28: [], 29: []} 3
I0813 12:03:00.832618  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Motto"
) {0: [], 1: [], 2: [], 3: [float_value: 1.0
], 4: [], 5: [], 6: [], 7: []} 1
I0813 12:03:08.307635  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Player"
) {0: [date {
  month: 1
}
], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: []} 1
I0813 12:03:16.709165  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "College/Junior/Club Team"
) {0: [], 1: [], 2: [], 3: [], 4: [float_value: 67.0
], 5: [], 6: [], 7: [], 8: []} 1
I0813 12:03:23.995716  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Mouth coordinates"
) {0: [float_value: 33.0
, float_value: 30.0
, float_value: 38.0
, float_value: 117.0
, float_value: 45.0
, float_value: 12.0
, float_value: 33.510501861572266
, float_value: 117.7531967163086
], 1: [float_value: 33.0
, float_value: 32.0
, float_value: 28.0
, float_value: 117.0
, float_value: 44.0
, float_value: 13.0
, float_value: 33.541099548339844
, float_value: 117.73690032958984
], 2: [float_value: 33.0
, float_value: 32.0
, float_value: 32.0
, float_value: 117.0
, float_value: 42.0
, float_value: 16.0
, float_value: 33.542198181152344
, float_value: 117.70439910888672
], 3: [], 4: [], 5: [], 6: [], 7: [float_value: 33.0
, float_value: 37.0
, float_value: 42.0
, float_value: 117.0
, float_value: 40.0
, float_value: 52.0
, float_value: 33.628299713134766
, float_value: 117.68109893798828
], 8: []} 4
I0813 12:03:29.895905  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Points"
) {0: [float_value: 8.0
], 1: [float_value: 6.0
], 2: [float_value: 4.0
], 3: [float_value: 3.0
], 4: [float_value: 2.0
], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [float_value: 1.0
], 11: [], 12: [], 13: [], 14: []} 6
I0813 12:03:34.506606  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Main Functionality"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [float_value: 1.0
], 11: [], 12: [], 13: [], 14: [], 15: [], 16: []} 1
I0813 12:03:43.860592  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Developer(s)"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [], 13: [float_value: 2.0
], 14: [], 15: [], 16: [], 17: []} 1
Processed: random-split-1-train.tfrecord
I0813 12:03:48.029445  7056 run_task_main.py:152] Processed: random-split-1-train.tfrecord
Num questions processed: 12276
I0813 12:03:48.030410  7056 run_task_main.py:152] Num questions processed: 12276
Num examples: 12276
I0813 12:03:48.030410  7056 run_task_main.py:152] Num examples: 12276
Num conversion errors: 0
I0813 12:03:48.031406  7056 run_task_main.py:152] Num conversion errors: 0
I0813 12:03:52.458602  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Title"
) {0: [], 1: [], 2: [float_value: 1.0
], 3: [], 4: [], 5: [float_value: 2.0
], 6: [float_value: 2.0
], 7: [], 8: [], 9: [float_value: 3.0
], 10: [], 11: [], 12: [], 13: [float_value: 4.0
], 14: [], 15: [], 16: [], 17: [], 18: [], 19: []} 5
I0813 12:03:59.948574  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Name"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [], 13: [float_value: 21.0
, float_value: 2.0
], 14: [], 15: [], 16: [], 17: [float_value: 21.0
, float_value: 1.0
], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: []} 2
I0813 12:04:09.289596  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Stamp set"
) {0: [float_value: 1873.0
, date {
  year: 1873
}
, float_value: 1973.0
, date {
  year: 1973
}
], 1: [float_value: 400.0
], 2: [float_value: 19.0
], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [float_value: 150.0
], 12: [], 13: [], 14: [], 15: []} 4
I0813 12:04:14.832739  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Nominated work"
) {0: [], 1: [], 2: [], 3: [float_value: 12.0
], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [], 13: [], 14: [], 15: [], 16: [], 17: [], 18: []} 1
I0813 12:04:21.392229  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Name"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [], 13: [float_value: 21.0
, float_value: 2.0
], 14: [], 15: [], 16: [], 17: [float_value: 21.0
, float_value: 1.0
], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: []} 2
I0813 12:04:29.098621  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Club"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [float_value: 11.0
], 13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: []} 1
Processed: random-split-1-dev.tfrecord
I0813 12:04:30.313367  7056 run_task_main.py:152] Processed: random-split-1-dev.tfrecord
Num questions processed: 2265
I0813 12:04:30.317362  7056 run_task_main.py:152] Num questions processed: 2265
Num examples: 2265
I0813 12:04:30.318328  7056 run_task_main.py:152] Num examples: 2265
Num conversion errors: 0
I0813 12:04:30.318328  7056 run_task_main.py:152] Num conversion errors: 0
Padded with 7 examples.
I0813 12:04:30.327304  7056 run_task_main.py:152] Padded with 7 examples.
I0813 12:04:36.732208  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Comments"
) {0: [float_value: 202.60000610351562
, float_value: 126.0
, float_value: 201.1999969482422
, float_value: 125.0
, float_value: 9.0
], 1: [], 2: [float_value: 127.0999984741211
, float_value: 205.0
, float_value: 1905.0
], 3: [float_value: 2011.0
], 4: [float_value: 112.5
, float_value: 181.0
, float_value: 14.0
, float_value: 23.0
, float_value: 136.0
, float_value: 219.0
, float_value: 74.9000015258789
, float_value: 121.0
], 5: [float_value: 112.5
], 6: [float_value: 1.0
, float_value: 100.0
], 7: [float_value: 75.5
, float_value: 122.0
, float_value: 85.0
, float_value: 137.0
, float_value: 89.91999816894531
, float_value: 145.0
, float_value: 68.9000015258789
, float_value: 110.9000015258789
], 8: [float_value: 1.0
, float_value: 100.0
, float_value: 161.0
], 9: [float_value: 1934.0
, date {
  year: 1934
}
, float_value: 1.0
, float_value: 100.0
, float_value: 161.0
], 10: [], 11: [], 12: [float_value: 112.0
, float_value: 180.0
, float_value: 1.0
, float_value: 100.0
, float_value: 161.0
], 13: [float_value: 80.0
, float_value: 129.0
], 14: [float_value: 1.0
, float_value: 60.0
, float_value: 97.0
, float_value: 26.0
, float_value: 42.0
, float_value: 26.0
], 15: [], 16: [], 17: []} 12
I0813 12:04:45.114791  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Ora."
) {0: [float_value: 42.0
], 1: [float_value: 38.0
], 2: [float_value: 28.0
], 3: [float_value: 34.0
], 4: [float_value: 28.0
], 5: [float_value: 10.0
], 6: [float_value: 11.0
], 7: [float_value: 24.0
], 8: [], 9: [float_value: 32.0
], 10: [], 11: [float_value: 11.0
], 12: [], 13: [float_value: 28.0
], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [float_value: 10.0
], 23: []} 12
I0813 12:04:51.605434  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Invitational"
) {0: [float_value: 8.0
, float_value: 1999.0
, date {
  year: 1999
}
, float_value: 2000.0
, date {
  year: 2000
}
, float_value: 2001.0
, date {
  year: 2001
}
, float_value: 2005.0
, date {
  year: 2005
}
, float_value: 2006.0
, date {
  year: 2006
}
, float_value: 2007.0
, date {
  year: 2007
}
, float_value: 2009.0
, date {
  year: 2009
}
, float_value: 2013.0
, date {
  year: 2013
}
], 1: [], 2: [float_value: 1.0
, float_value: 2003.0
, date {
  year: 2003
}
], 3: [], 4: [float_value: 1.0
, float_value: 2010.0
, date {
  year: 2010
}
], 5: [], 6: []} 3
I0813 12:04:57.410878  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "National Cup"
) {0: [], 1: [float_value: 1.0
], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [], 13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: [], 26: []} 1
I0813 12:05:02.878291  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Team"
) {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [float_value: 2.0
], 8: [], 9: []} 1
I0813 12:05:09.434752  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "Time/Retired"
) {0: [float_value: 1.0
, float_value: 48.0
, float_value: 31.299999237060547
], 1: [float_value: 9.5
], 2: [float_value: 2.0
], 3: [float_value: 2.0
], 4: [float_value: 3.0
], 5: [float_value: 3.0
], 6: [float_value: 4.0
], 7: [float_value: 4.0
], 8: [], 9: [], 10: [], 11: [], 12: [], 13: [], 14: [], 15: [], 16: [], 17: []} 8
I0813 12:05:14.051411  7056 number_annotation_utils.py:150] Can't consolidate types: (None, text: "1941/42"
) {0: [], 1: [float_value: 116000.0
], 2: [float_value: 220000.0
], 3: [float_value: 71000.0
], 4: [], 5: [], 6: [float_value: 407000.0
]} 4
Processed: test.tfrecord
I0813 12:05:21.113520  7056 run_task_main.py:152] Processed: test.tfrecord
Num questions processed: 3012
I0813 12:05:21.117669  7056 run_task_main.py:152] Num questions processed: 3012
Num examples: 3012
I0813 12:05:21.118668  7056 run_task_main.py:152] Num examples: 3012
Num conversion errors: 0
I0813 12:05:21.119353  7056 run_task_main.py:152] Num conversion errors: 0
Padded with 28 examples.
I0813 12:05:21.151138  7056 run_task_main.py:152] Padded with 28 examples.

This resulted in 2 directories being created in the "output" directory, namely "interactions" and "tf_examples". In the "tf_examples" directory, only the first random split of training + dev seems to be created:
tapas_pic

However, parsing these tfrecord files as strings (as explained in the Tensorflow docs) results in an error:

filenames = "./tf_examples/test.tfrecord"
raw_dataset = tf.data.TFRecordDataset(filenames)

for raw_record in raw_dataset.take(1):
  example = tf.train.Example()
  example.ParseFromString(raw_record.numpy())
  print(example)

DataLossError                             Traceback (most recent call last)
c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tensorflow\python\eager\context.py in execution_mode(mode)
   1985       ctx.executor = executor_new
-> 1986       yield
   1987     finally:

c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py in _next_internal(self)
    654             output_types=self._flat_output_types,
--> 655             output_shapes=self._flat_output_shapes)
    656 

c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tensorflow\python\ops\gen_dataset_ops.py in iterator_get_next(iterator, output_types, output_shapes, name)
   2362     except _core._NotOkStatusException as e:
-> 2363       _ops.raise_from_not_ok_status(e, name)
   2364   # Add nodes to the TensorFlow graph.

c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tensorflow\python\framework\ops.py in raise_from_not_ok_status(e, name)
   6652   # pylint: disable=protected-access
-> 6653   six.raise_from(core._status_to_exception(e.code, message), None)
   6654   # pylint: enable=protected-access

c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\six.py in raise_from(value, from_value)

DataLossError: corrupted record at 0 [Op:IteratorGetNext]

During handling of the above exception, another exception occurred:

DataLossError                             Traceback (most recent call last)
 in 
      2 raw_dataset = tf.data.TFRecordDataset(filenames)
      3 
----> 4 for raw_record in raw_dataset.take(1):
      5   example = tf.train.Example()
      6   example.ParseFromString(raw_record.numpy())

c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py in __next__(self)
    629 
    630   def __next__(self):  # For Python 3 compatibility
--> 631     return self.next()
    632 
    633   def _next_internal(self):

c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py in next(self)
    668     """Returns a nested structure of `Tensor`s containing the next element."""
    669     try:
--> 670       return self._next_internal()
    671     except errors.OutOfRangeError:
    672       raise StopIteration

c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py in _next_internal(self)
    659         return self._element_spec._from_compatible_tensor_list(ret)  # pylint: disable=protected-access
    660       except AttributeError:
--> 661         return structure.from_compatible_tensor_list(self._element_spec, ret)
    662 
    663   @property

~\AppData\Local\Programs\Python\Python36\lib\contextlib.py in __exit__(self, type, value, traceback)
     97                 value = type()
     98             try:
---> 99                 self.gen.throw(type, value, traceback)
    100             except StopIteration as exc:
    101                 # Suppress StopIteration *unless* it's the same exception that

c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tensorflow\python\eager\context.py in execution_mode(mode)
   1987     finally:
   1988       ctx.executor = executor_old
-> 1989       executor_new.wait()
   1990 
   1991 

c:\Users\niels.rogge\Documents\Python projecten\testing_tapas\env\lib\site-packages\tensorflow\python\eager\executor.py in wait(self)
     65   def wait(self):
     66     """Waits for ops dispatched in this executor to finish."""
---> 67     pywrap_tfe.TFE_ExecutorWaitForAllPendingNodes(self._handle)
     68 
     69   def clear_error(self):

DataLossError: corrupted record at 0

Am I doing something wrong here?

Train model with custom data

Hello there,

I tried this model with SQA_large checkpoints and fine tune the model with SQA after this I want to train the model with my own custom data. I am curious to know how do I pass my own training data into it. After exploring issue #7 solution I found that first the dataset is converted into tsv file then from tsv to interaction, interaction to tf examples then from tf examples to tf records. I didn't found the solution for converting interaction to tf examples containing training data. Do I need to create my own conversion code or is there any predefined way to do this? Any suggestions? It will be more helpful if you update the colab file with conversion code for dealing custom data.

Thanks
Sparsh Bhawsar

Training file

Hi, I want to train sqa model with maximum position embeddings 2048..so to train the model which file or command needs to be run ? Where can I change position embeddings values ?

Results processing for computing cell coordinates takes a significant time in TAPAS

Hi,

I was trying to run your code on SQA model. I ran the command without running any fine-tuning (basically your NoteBook example)

python run_task_main.py --task="SQA" --output_dir="results" --noloop_predict --test_batch_size={len(queries)} --tapas_verbosity="ERROR" --compression_type= --init_checkpoint="tapas_sqa_base/model.ckpt" --bert_config_file="tapas_sqa_base/bert_config.json" --mode="predict"

In your run_task_main.py there is a line result = estimator.predict(input_fn=predict_input_fn) and then you did the following:

for prediction in result:
question_id = _get_question_id(prediction)
max_width = prediction["column_ids"].max()
max_height = prediction["row_ids"].max()

  if (max_width == 0 and max_height == 0 and
          question_id == text_utils.get_padded_question_id()):
      logging.info("Removing padded example: %s", question_id)
      continue

  cell_coords_to_prob = get_mean_cell_probs(prediction)

  # Select the answers above a classification threshold.
  answer_coordinates = []
  for col in range(max_width):
      for row in range(max_height):
          cell_prob = cell_coords_to_prob.get((col, row), None)
          if cell_prob is not None:
              if cell_prob > _CELL_CLASSIFICATION_THRESHOLD:
                  answer_coordinates.append(str((row, col)))

After analysing the code, I realized that this is post-processing of the results variables and apparently this is O(n^3) or more execution time to get the cell coordinates. Am I right? If so, it is not deployable for a real-time online question answering right? For one example, with 22 rows in my table it took almost 100 seconds to get the cell predictions.

Training got stuck during fine-tuning the model

I am running step-2 for fine-tuning the model with SQA data. I tried on both CPU and GPU machine on AWS, and here is the command that I am using:

Fine-tuning

!python tapas/tapas/run_task_main.py
--task="SQA" --output_dir="SQAOUT"
--init_checkpoint="tapas_sqa_base/model.ckpt"
--bert_config_file="tapas_sqa_base/bert_config.json"
--mode="train"

Here is the warning message from the training. It got stuck forever, never finished.

INFO:tensorflow:Running local_init_op.
I0511 20:14:13.866309 139910295869248 session_manager.py:500] Running local_init_op.
INFO:tensorflow:Done running local_init_op.
I0511 20:14:14.061791 139910295869248 session_manager.py:502] Done running local_init_op.
INFO:tensorflow:Saving checkpoints for 0 into SQAOUT/sqa/model/model.ckpt.
I0511 20:14:23.436616 139910295869248 basic_session_run_hooks.py:606] Saving checkpoints for 0 into SQAOUT/sqa/model/model.ckpt.
2020-05-11 20:14:38.721275: W tensorflow/core/framework/model.cc:474] Failed to find a tunable parameter that would decrease the output time. This means that the autotuning optimization got stuck in a local maximum. The optimization attempt will be aborted.
2020-05-11 20:14:41.283297: W tensorflow/core/framework/model.cc:474] Failed to find a tunable parameter that would decrease the output time. This means that the autotuning optimization got stuck in a local maximum. The optimization attempt will be aborted.
2020-05-11 20:14:46.404370: W tensorflow/core/framework/model.cc:474] Failed to find a tunable parameter that would decrease the output time. This means that the autotuning optimization got stuck in a local maximum. The optimization attempt will be aborted.
2020-05-11 20:14:56.645311: W tensorflow/core/framework/model.cc:474] Failed to find a tunable parameter that would decrease the output time. This means that the autotuning optimization got stuck in a local maximum. The optimization attempt will be aborted.

running Colab notebook

Hi all,

When trying to run the Colab notebook I get:

FileNotFoundError: [Errno 2] No such file or directory: 'results/sqa/model/test_sequence.tsv'

Also, when I tried to run the run_task_main.py on my local device I get
ModuleNotFoundError: No module named 'tapas'

I've checked and all the folders contains init.py file and not sure how to run it
Can you please advise?

TAPAS finetune.

When TAPAS is fine-tuned, are the parameters of Bert fixed?

Getting an error while running the model

Upon running the model step by step as in colab on my local machine I get the following error :

FileNotFoundError: [Errno 2] No such file or directory: 'results/sqa/model/test_sequence.tsv'

Can you please tell me how this was resolved ?

Thanks

Training got stuck

Hello, @jiabol thanks for the report, we haven't encountered that warning before, but on a first inspection, it seems to be triggered by the usage of the AUTOTUNE tapas/datasets/dataset.py, and it's logged here.

While we continue to investigate, can you try:
a) Use a bigger machine in terms of CPU / RAM, what are the spects of the one you are currently using?
b) Replace the usage of AUTOTUNE in tapas/datasets/dataset.py for specific values? Make sure you installed with -e for the changes to be reflected without re-installation.

Thanks!

Hello,

I got the same issue #6 while training I am using Google colab 12.72 GB RAM TPU will you please suggest How do I replace the usage of AUTOTUNE for specific value ? How to decide the value ?

Thanks!
Sparsh Bhawsar

Convert the TAPAS predictions to the WTQ format and run the official evaluation script.

When I convert the TAPAS predictions to the WTQ format and run the official evaluation script. The converted result is almost 0%. What's wrong with that?
python3 /home/cjc/tapas-master/tapas/scripts/convert_predictions.py
--interaction_files=/home/cjc/tapas-master/WTQ/wtq/interactions/test.tfrecord
--prediction_files=/home/cjc/tapas-master/WTQ/wtq/test.tsv
--output_directory=/home/cjc/tapas-master/tapas/experiments
--dataset_format=WIKITABLEQUESTIONS
python evaluator.py -t /home/cjc/tapas-master/WTQ/tagged/data /home/cjc/tapas-master/tapas/experiments/test.tsv

If I don't convert the TAPAS predictions to the WTQ format, what is the mean of the result of TAPAS prediction? Your released result 49.52% on tapas_wtq_wikisql_sqa_masklm_large_resst are converted or not?

The Result of WTQ on tapas_wtq_wikisql_sqa_masklm_large_reset model is only 39.04%

Thanks for releasing the new pre-trained model yesterday. I test the WTQ on tapas_wtq_wikisql_sqa_masklm_large_reset model. But the result is only 39.04% on the WTQ test dataset. What is the reason about that? My commend line is as follows:
python3 run_task_main.py
--task=WTQ
--output_dir=/home/cjc/tapas-master/WTQ --model_dir=/home/cjc/tapas-master/tapas_wtq_wikisql_sqa_masklm_large_reset
--init_checkpoint=/home/cjc/tapas-master/tapas_wtq_wikisql_sqa_masklm_large_reset/model.ckpt
--bert_config_file=/home/cjc/tapas-master/tapas_wtq_wikisql_sqa_masklm_large_reset/bert_config.json
--mode="predict_and_evaluate" --use_tpu=False --iterations_per_loop=5 --test_batch_size=4 --max_seq_length=512

Not able to run sample code

Hi, I am stuck at result path in sample code it throwing following error
[Errno 2] No such file or directory: 'results/sqa/model/test_sequence.tsv'
I even checked in result folder i did not find the test_sequence.tsv file

Run on custom data

Hi,

I am curious if you can guide or confirm how I can use TAPAS framework on my custom data. I couldn't find any resources which talks about this.

Thank you.

Docker Image

Hi All, is it possible that you guys release a docker image for TaPAS? That would be extremely helpful for batch jobs at AWS and GCP.

Error for preparing fine-tuning training data

Here is the error message when I run the first step of the sample code in TAPAS

/home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/dask/dataframe/utils.py:14: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
import pandas.util.testing as tm
Traceback (most recent call last):
File "tapas/tapas/run_task_main.py", line 32, in
from tapas.scripts import calc_metrics_utils
File "/home/ec2-user/SageMaker/tapas/tapas/scripts/calc_metrics_utils.py", line 35, in
@dataclasses.dataclass
File "/home/ec2-user/SageMaker/tapas/tapas/scripts/calc_metrics_utils.py", line 47, in Example
pred_agg_function: int = _AggregationFunction.NONE
AttributeError: 'EnumTypeWrapper' object has no attribute 'NONE'

Training loss

Is there a way to get the training loss in a fine tuning task?

Accommodating large tables

I tried to run the prediction on a table of size 1.8M X 60 (using the sqa large model) in the example colab file. The following are the steps that I had taken:

  1. Changed the following line in the bert_config.json max_position_embeddings: 2048
  2. Changed the max_seq_length max_seq_length = 2048

However, it just returns the table without any predictions.

Could you please provide the changes that one should make to accommodate a table of such size. Thank you.

It's not returning answer for my data

Hi,
I'm using tapas on open source data sets.when I tried with only fraction of data i.e. small data(200 to 300 rows) it's returning answer for queries but if the data is big(4000 rows) it's not returning answer but it's able to return table. It's prompting "can't convert too many rows and sometimes sequence too long". How can I resolve this issue ? I want to try on big data sets. will it work ?
Note : my system is not configured with GPU support and cuda. And I'm performing SQA task.

Show the cell location in predict

Is there any way to show the cell location for the answer in the result? For example, having the following table, the question is "Which player has the highest score" the answer would be "Ava".

| Score| Player|
| 20 | Ava |
| 10 | Bob |

In return, I want to know the coordination of "Ava" in the table. In this case, it is [1,2]. Since columns and rows are embedded in the model with the index I am expecting this to be possible.

WTQ prediction

I plan to predict WTQ. How can I set parameters when I run convert_prediction.py?

Pretraining Error

I executed the following command using a BERT Base Checkpoint from (https://github.com/google-research/bert)
python3 tapas/experiments/tapas_pretraining_experiment.py
--eval_batch_size=32
--train_batch_size=512
--tpu_iterations_per_loop=5000
--num_eval_steps=100
--save_checkpoints_steps=600
--num_train_examples=512000000
--max_seq_length=128
--input_file_train="${data}/train.tfrecord"
--input_file_eval="${data}/test.tfrecord"
--init_checkpoint="${tapas_data_dir}/model.ckpt"
--bert_config_file="${tapas_data_dir}/bert_config.json"
--model_dir="..."
--do_train

But I am getting the following error:

INFO:tensorflow:*** Features ***
I0720 17:14:49.422954 140139063854912 tapas_pretraining_model.py:127] *** Features ***
INFO:tensorflow: name = column_ids, shape = (512, 128)
I0720 17:14:49.423085 140139063854912 tapas_pretraining_model.py:129] name = column_ids, shape = (512, 128)
INFO:tensorflow: name = column_ranks, shape = (512, 128)
I0720 17:14:49.423201 140139063854912 tapas_pretraining_model.py:129] name = column_ranks, shape = (512, 128)
INFO:tensorflow: name = input_ids, shape = (512, 128)
I0720 17:14:49.423346 140139063854912 tapas_pretraining_model.py:129] name = input_ids, shape = (512, 128)
INFO:tensorflow: name = input_mask, shape = (512, 128)
I0720 17:14:49.423449 140139063854912 tapas_pretraining_model.py:129] name = input_mask, shape = (512, 128)
INFO:tensorflow: name = inv_column_ranks, shape = (512, 128)
I0720 17:14:49.423546 140139063854912 tapas_pretraining_model.py:129] name = inv_column_ranks, shape = (512, 128)
INFO:tensorflow: name = masked_lm_ids, shape = (512, 20)
I0720 17:14:49.423643 140139063854912 tapas_pretraining_model.py:129] name = masked_lm_ids, shape = (512, 20)
INFO:tensorflow: name = masked_lm_positions, shape = (512, 20)
I0720 17:14:49.423738 140139063854912 tapas_pretraining_model.py:129] name = masked_lm_positions, shape = (512, 20)
INFO:tensorflow: name = masked_lm_weights, shape = (512, 20)
I0720 17:14:49.423831 140139063854912 tapas_pretraining_model.py:129] name = masked_lm_weights, shape = (512, 20)
INFO:tensorflow: name = next_sentence_labels, shape = (512, 1)
I0720 17:14:49.423925 140139063854912 tapas_pretraining_model.py:129] name = next_sentence_labels, shape = (512, 1)
INFO:tensorflow: name = numeric_relations, shape = (512, 128)
I0720 17:14:49.424018 140139063854912 tapas_pretraining_model.py:129] name = numeric_relations, shape = (512, 128)
INFO:tensorflow: name = prev_label_ids, shape = (512, 128)
I0720 17:14:49.424111 140139063854912 tapas_pretraining_model.py:129] name = prev_label_ids, shape = (512, 128)
INFO:tensorflow: name = row_ids, shape = (512, 128)
I0720 17:14:49.424204 140139063854912 tapas_pretraining_model.py:129] name = row_ids, shape = (512, 128)
INFO:tensorflow: name = segment_ids, shape = (512, 128)
I0720 17:14:49.424312 140139063854912 tapas_pretraining_model.py:129] name = segment_ids, shape = (512, 128)
INFO:tensorflow:training_loop marked as finished
I0720 17:14:49.433129 140139063854912 error_handling.py:115] training_loop marked as finished
WARNING:tensorflow:Reraising captured error
W0720 17:14:49.433277 140139063854912 error_handling.py:149] Reraising captured error
Traceback (most recent call last):
File "/data/t-mdra/anaconda3/envs/TAPAS_pretrain/lib/python3.7/site-packages/tensorflow/python/util/nest.py", line 378, in assert_same_structure
expand_composites)
ValueError: The two structures don't have the same nested structure.

First structure: type=list str=[<tf.Tensor 'IteratorGetNext:12' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:0' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:11' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:10' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:1' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:4' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:9' shape=(512, 128) dtype=int32>]

Second structure: type=int str=2

More specifically: Substructure "type=list str=[<tf.Tensor 'IteratorGetNext:12' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:0' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:11' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:10' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:1' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:4' shape=(512, 128) dtype=int32>, <tf.Tensor 'IteratorGetNext:9' shape=(512, 128) dtype=int32>]" is a sequence, while substructure "type=int str=2" is not

Converting TaPas pretrained model to PyTorch

Hello,

as a summer project (and to learn a lot about both Tensorflow and PyTorch), I am working on incorporating a PyTorch implementation of the TAPAS algorithm into the Transformers library by HuggingFace. Similar to other models, the API would look something like this:

import pandas as pd
from transformers import TapasTokenizer, TapasForQuestionAnswering

data = {'Actors': ["Brad Pitt", "Leonardo Di Caprio"], 'Number of movies': [87, 53]}
table = pd.DataFrame.from_dict(data)
queries = ["What is the name of the first actor?", "How many movies has he played in?"]

tokenizer = TapasTokenizer.from_pretrained("tapas-base-finetuned-sqa")
model = TapasForQuestionAnswering.from_pretrained("tapas-base-finetuned-sqa")

inputs = tokenizer(table, queries, conversational=True, reset_position_index_per_cell=True, return_tensors="pt")
outputs = model(**inputs)

logits, probs, logits_aggregation, logits_cls, span_indexes, span_logits = outputs

I'm submitting this issue to get feedback on my current approach (as well as a couple of questions related to the token type embeddings), and to know whether you consent on incorporating this into the Transformers library. If yes, then I would submit this issue to the Transformers repository and start working on a pull request (hopefully with the help of other people).

To implement a new model in the Transformers library, 3 things need to be defined (each in a corresponding Python script):

  • a model configuration (configuration_tapas.py)
  • a model (modeling_tapas.py)
  • a tokenizer (tokenization_tapas.py)

Below, I describe my approach to each of these 3.

Configuration

As for the configuration of the base model, this seems to be a minor change of configuration_bert.py (I changed the default values of "max_position_embeddings" and "type_vocab_size"):

class TapasConfig(PretrainedConfig):
    """
    model_type = "tapas"

    def __init__(
        self,
        vocab_size=30522,
        hidden_size=768,
        num_hidden_layers=12,
        num_attention_heads=12,
        intermediate_size=3072,
        hidden_act="gelu",
        hidden_dropout_prob=0.1,
        attention_probs_dropout_prob=0.1,
        max_position_embeddings=1024,
        type_vocab_size=[3, 256, 256, 2, 256, 256, 10],
        initializer_range=0.02,
        layer_norm_eps=1e-12,
        pad_token_id=0,
        gradient_checkpointing=False,
        **kwargs
    ):
        super().__init__(pad_token_id=pad_token_id, **kwargs)

        self.vocab_size = vocab_size
        self.hidden_size = hidden_size
        self.num_hidden_layers = num_hidden_layers
        self.num_attention_heads = num_attention_heads
        self.hidden_act = hidden_act
        self.intermediate_size = intermediate_size
        self.hidden_dropout_prob = hidden_dropout_prob
        self.attention_probs_dropout_prob = attention_probs_dropout_prob
        self.max_position_embeddings = max_position_embeddings
        self.type_vocab_size = type_vocab_size
        self.initializer_range = initializer_range
        self.layer_norm_eps = layer_norm_eps
        self.gradient_checkpointing = gradient_checkpointing

However, the fine-tuned model has quite a lot of additional hyperparameters (as I see in tapas_classifier_model.py). I assume that these should also be defined in the class above, correct? (this is rather a question for Transformers folks)

Model

As I am not planning to retrain any pretrained/fine-tuned model, I would define the model architecture in PyTorch in modeling_tapas.py (which is very similar to modeling_bert.py - at least for the base model) and then load the weights from the Tensorflow checkpoints (for now, just MASKLM base and the fine-tuned model on SQA). The Transformers library already includes a script to convert Tensorflow checkpoints into PyTorch models, with a tutorial. This script would then be adapted for TAPAS specifically and saved as convert_tapas_original_tf_checkpoint_to_pytorch.py.

Starting off with the pretrained model (MASKLM base), this is almost identical to a pretrained BERT-base, with the only difference being the additional token_type_embeddings, as can be seen when printing out the variables of the checkpoint:

(...)
('bert/embeddings/token_type_embeddings_0', [3, 768]),
 ('bert/embeddings/token_type_embeddings_1', [256, 768]),
 ('bert/embeddings/token_type_embeddings_2', [256, 768]),
 ('bert/embeddings/token_type_embeddings_3', [2, 768]),
 ('bert/embeddings/token_type_embeddings_4', [256, 768]),
 ('bert/embeddings/token_type_embeddings_5', [256, 768]),
 ('bert/embeddings/token_type_embeddings_6', [10, 768]),
(...)

It's not really clear to me what these token type embeddings are (and in what order): token_type_embeddings_3 seem to correspond with segment ids, token_type_embeddings_1 and 2 with column and row ids, but then there are still the rank and previous answer ids. And also, what are the 2 additional token type embeddings, which do not seem to be mentioned in the paper (there are 7 token type embeddings here, but only 5 additional ids defined in the paper)? Update: appears to be "segment_ids", "column_ids", "row_ids", "prev_label_ids", "column_ranks", "inv_column_ranks" and "numeric_relations".

The core idea of loading Tensorflow weights into PyTorch is to convert variable scopes to corresponding PyTorch modules with the same name (as explained in the tutorial linked above). The code below is what I adapted from the BertEmbeddings class in the modeling_bert.py file:

class TapasEmbeddings(nn.Module):
    """Construct the embeddings from word, position and token_type embeddings.
    """

    def __init__(self, config):
        super().__init__()
        self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size, padding_idx=config.pad_token_id)
        self.position_embeddings = nn.Embedding(config.max_position_embeddings, config.hidden_size)
        self.token_type_embeddings_0 = nn.Embedding(config.type_vocab_size[0], config.hidden_size)
        self.token_type_embeddings_1 = nn.Embedding(config.type_vocab_size[1], config.hidden_size)
        self.token_type_embeddings_2 = nn.Embedding(config.type_vocab_size[2], config.hidden_size)
        self.token_type_embeddings_3 = nn.Embedding(config.type_vocab_size[3], config.hidden_size)
        self.token_type_embeddings_4 = nn.Embedding(config.type_vocab_size[4], config.hidden_size)
        self.token_type_embeddings_5 = nn.Embedding(config.type_vocab_size[5], config.hidden_size)
        self.token_type_embeddings_6 = nn.Embedding(config.type_vocab_size[6], config.hidden_size)
        self.number_of_token_type_embeddings = len(config.type_vocab_size)

        # self.LayerNorm is not snake-cased to stick with TensorFlow model variable name and be able to load
        # any TensorFlow checkpoint file
        self.LayerNorm = BertLayerNorm(config.hidden_size, eps=config.layer_norm_eps)
        self.dropout = nn.Dropout(config.hidden_dropout_prob)

    def forward(self, input_ids=None, token_type_ids=None, position_ids=None, inputs_embeds=None):
        if input_ids is not None:
            input_shape = input_ids.size()
        else:
            input_shape = inputs_embeds.size()[:-1]

        seq_length = input_shape[1]
        device = input_ids.device if input_ids is not None else inputs_embeds.device
        if position_ids is None:
            position_ids = torch.arange(seq_length, dtype=torch.long, device=device)
            position_ids = position_ids.unsqueeze(0).expand(input_shape)
        if token_type_ids is None:
            token_type_ids = torch.zeros((*input_shape, self.number_of_token_type_embeddings), dtype=torch.long, device=device)

        if inputs_embeds is None:
            inputs_embeds = self.word_embeddings(input_ids)
        position_embeddings = self.position_embeddings(position_ids)
        token_type_embeddings_0 = self.token_type_embeddings_0(token_type_ids[:,:,0])
        token_type_embeddings_1 = self.token_type_embeddings_1(token_type_ids[:,:,1])
        token_type_embeddings_2 = self.token_type_embeddings_2(token_type_ids[:,:,2])
        token_type_embeddings_3 = self.token_type_embeddings_3(token_type_ids[:,:,3])
        token_type_embeddings_4 = self.token_type_embeddings_4(token_type_ids[:,:,4])
        token_type_embeddings_5 = self.token_type_embeddings_5(token_type_ids[:,:,5])
        token_type_embeddings_6 = self.token_type_embeddings_6(token_type_ids[:,:,6])

        embeddings = inputs_embeds + position_embeddings + token_type_embeddings_0 + token_type_embeddings_1 + token_type_embeddings_2 + token_type_embeddings_3 + token_type_embeddings_4 + token_type_embeddings_5 + token_type_embeddings_6
        embeddings = self.LayerNorm(embeddings)
        embeddings = self.dropout(embeddings)
        return embeddings

Alternatively, one could also let TapasEmbeddings inherit from BertEmbeddingsand overwrite the changes (I see that this was done in modeling_roberta.py for example). In the original BERT, the token type ids are a Tensor of shape (batch_size, sequence_length) in a single forward pass. However, since we now have several token type ids for every training example, I assume the shape is (batch_size, sequence_length, len(config.type_vocab_size))?

Similarly, the forward pass of BertModel (also defined in modeling_bert.py) should be updated to account for the different shape of token type ids. The best way would be to define a class called TapasModel that inherits from BertModel and overwrite the changes:

class TapasModel(BertModel):
    """
    This class overrides :class:`~transformers.BertModel`. Please check the
    superclass for the appropriate documentation alongside usage examples.
    """

    config_class = TapasConfig
    base_model_prefix = "tapas"

    def __init__(self, config):
        super().__init__(config)

        self.embeddings = TapasEmbeddings(config)
        self.init_weights()

    def forward(...):
       (...) 
        if input_ids is not None and inputs_embeds is not None:
            raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
        elif input_ids is not None:
            input_shape = input_ids.size()
        elif inputs_embeds is not None:
            input_shape = inputs_embeds.size()[:-1]
        else:
            raise ValueError("You have to specify either input_ids or inputs_embeds")

        device = input_ids.device if input_ids is not None else inputs_embeds.device

        if attention_mask is None:
            attention_mask = torch.ones(input_shape, device=device)
        if token_type_ids is None:
            token_type_ids = torch.zeros((*input_shape, len(self.config.type_vocab_size)), dtype=torch.long, device=device)
       (...)

So far, these seem to be the only differences that need to defined for the base model. However, for the fine-tuned model, the classification heads and the calculation of the loss need to be defined. To implement this in the same way as other models in the Transformers library, one could define a model TapasForQuestionAnswering which has the additional heads on top of the pretrained TapasModel. In order to later load the weights from the Tensorflow checkpoint, the names of the PyTorch modules should have the same name. It would look something like this (also to be defined in modeling_tapas.py):

class TapasForQuestionAnswering(BertPreTrainedModel):
    config_class = TapasConfig
    base_model_prefix = "tapas"
    
    def __init__(self, config):
        super().__init__(config)

        self.tapas = TapasModel(config)
	self.output = nn.Linear(config.hidden_size, config.hidden_size)
        self.output_cls = nn.Linear(config.hidden_size, config.num_classification_labels)
        self.output_agg = nn.Linear(config.hidden_size, config.num_aggregation_labels)
        self.column_output = nn.Linear(config.hidden_size, config.hidden_size)
 
        self.init_weights()
            
    def forward(
        self,
        input_ids=None,
        attention_mask=None,
        token_type_ids=None,
        position_ids=None,
        head_mask=None,
        inputs_embeds=None,
        start_positions=None,
        end_positions=None,
        output_attentions=None,
        output_hidden_states=None,
    ):
        
        outputs = self.tapas(
            input_ids,
            attention_mask=attention_mask,
            token_type_ids=token_type_ids,
            position_ids=position_ids,
            head_mask=head_mask,
            inputs_embeds=inputs_embeds,
            output_attentions=output_attentions,
            output_hidden_states=output_hidden_states,
        )

        last_hidden_state = outputs[0] # last_hidden_state has shape (batch_size, seq_length, hidden_size)
        
        token_logits = self.output(last_hidden_state) / config.temperature
        (...)
        (code from tapas_classifier_model.py and tapas_classifier_model_utils.py)
        (...)

        logits_aggregation = self.output_agg(last_hidden_state[:,0,:])

        logits_cls = self.output_cls(last_hidden_state[:,0,:])

        (...)

        return outputs  # (loss), logits, probs, logits_aggregation, logits_cls, span_indexes, span_logits, (hidden_states), (attentions)

Here, the code from tapas_classifier_model.py and tapas_classifier_model_utils.py should be incorporated (and translated into PyTorch code). Looking at the code, it seems that the following heads on top of the pretrained model have to be defined:

  • output_weights and output_bias. These are used to compute the token logits.
  • output_weights_cls and output_bias_cls. These are used to compute the classification logits.
  • output_weights_agg and output_bias_agg. These are used to compute the aggregation logits.
  • column_output_weights and column_output_bias. These are used to compute the column logits. These are defined in tapas_classifier_model_utils.py.

When I looked at the variables of the checkpoint of the model fine-tuned on SQA, I got this:

(...)
('bert/pooler/dense/bias', [768]),
 ('bert/pooler/dense/kernel', [768, 768]),
 ('column_output_bias', []),
 ('column_output_bias/adam_m', []),
 ('column_output_bias/adam_v', []),
 ('column_output_weights', [768]),
 ('column_output_weights/adam_m', [768]),
 ('column_output_weights/adam_v', [768]),
 ('global_step', []),
 ('output_bias', []),
 ('output_bias/adam_m', []),
 ('output_bias/adam_v', []),
 ('output_weights', [768]),
 ('output_weights/adam_m', [768]),
 ('output_weights/adam_v', [768])]

There is no aggregation/classification layer included here, probably since SQA does not require aggregation and classification.

Tokenizer

The tokenizer prepares the inputs to feed them into the model (i.e. turn a table and its queries into input ids, token type ids, etc.). This also includes truncating a table if it's too big. Here, the code of tf_example_utils.py should be incorporated (and translated into PyTorch code). The end result should be in a script called tokenization_tapas.py.

An idea could be that the tokenizer accepts Pandas dataframes as table formats, and corresponding queries as a list of strings. This will also be far from trivial, maybe one should first convert a Pandas dataframe (together with the answer coordinates and answer text) into the intermediate Interaction format, and then convert that into PyTorch Tensors.

I know that all of this is quite challenging, but it would be awesome if it would be included in the HuggingFace repo ๐Ÿ˜„

Your feedback on all of this is greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.