run_tf_text_classification.py giving "ValueError: too many values to unpack"
Author: Santosh-Gupta
Pull request: no
Labels: name: wontfix

I am trying to run this script for token classification

https://github.com/huggingface/transformers/blob/master/examples/text-classification/run_tf_text_classification.py

Accoring to the instructions here 

https://github.com/huggingface/transformers/tree/master/examples/text-classification

I formatted the data according> to the instructions 

>the CSV files must have a header corresponding to the column names and not more than three columns: one column for the id, one column for the text and another column for a second piece of text in case of an entailment classification for example.

However, I am getting this error 

> Dataset csv downloaded and prepared to /root/.cache/huggingface/datasets/csv/default-57112360018dd326/0.0.0/49187751790fa4d820300fd4d0707896e5b941f1a9c644652645b866716a4ac4. Subsequent calls will reuse this data.
> 10/19/2020 18:03:50 - INFO - filelock -   Lock 140266200732560 released on /root/.cache/huggingface/datasets/_root_.cache_huggingface_datasets_csv_default-57112360018dd326_0.0.0_49187751790fa4d820300fd4d0707896e5b941f1a9c644652645b866716a4ac4.lock
>   0% 0/5 [00:00<?, ?ba/s]Traceback (most recent call last):
>   File "/content/transformers/examples/text-classification/run_tf_text_classification.py", line 292, in <module>
>     main()
>   File "/content/transformers/examples/text-classification/run_tf_text_classification.py", line 231, in main
>     max_seq_length=data_args.max_seq_length,
>   File "/content/transformers/examples/text-classification/run_tf_text_classification.py", line 68, in get_tfds
>     batched=True,
>   File "/usr/local/lib/python3.6/dist-packages/datasets/arrow_dataset.py", line 1256, in map
>     update_data=update_data,
>   File "/usr/local/lib/python3.6/dist-packages/datasets/arrow_dataset.py", line 156, in wrapper
>     out: Union["Dataset", "DatasetDict"] = func(self, *args, **kwargs)
>   File "/usr/local/lib/python3.6/dist-packages/datasets/fingerprint.py", line 163, in wrapper
>     out = func(self, *args, **kwargs)
>   File "/usr/local/lib/python3.6/dist-packages/datasets/arrow_dataset.py", line 1517, in _map_single
>     batch, indices, check_same_num_examples=len(self.list_indexes()) > 0, offset=offset
>   File "/usr/local/lib/python3.6/dist-packages/datasets/arrow_dataset.py", line 1435, in apply_function_on_filtered_inputs
>     function(*fn_args, effective_indices, **fn_kwargs) if with_indices else function(*fn_args, **fn_kwargs)
>   File "/content/transformers/examples/text-classification/run_tf_text_classification.py", line 66, in <lambda>
>     padding="max_length",
>   File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils_base.py", line 2323, in batch_encode_plus
>     **kwargs,
>   File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils.py", line 560, in _batch_encode_plus
>     ids, pair_ids = ids_or_pair_ids
> ValueError: too many values to unpack (expected 2)
>   0% 0/5 [00:00<?, ?ba/s]

It looks like the issue may be the script itself. I was having a previous issue running the script, and it looks like it was due to the datasets library 

https://github.com/huggingface/datasets/issues/705#event-3839135529

It looks like the error is now with the script, or possibly the tokenizer. It sort of looks like the training wants only two types inputs, but is being passed all of the inputs from `batch_encode_plus`, which may be more than two (token id type, attention id type, segment id type, etc) 

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->
     
- `transformers` version:
- Platform: colab 
- Python version: version 3, colab default 
- PyTorch version (GPU?): colab default
- Tensorflow version (GPU?): colab default
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: no

### Who can help

I'm not sure, most likely the bug seems to be due to the example script itself, but could be the dataset, or tokenizer. 


## Information

Model I am using: Bert, specifically scibert 

The problem arises when using:
* [x ] the official example scripts: (give details below)

The tasks I am working on is:
* [x ] my own task or dataset: I am working with the chemprot dataset, for token classification. I following the instructions to have the data in a csv file, with two columns (one for label, another for text), and headers. 


## To reproduce

Here is a colab notebook of the issue. 

https://colab.research.google.com/drive/1r3XCKYA8RBtfYmU2jqHVJT-uTt1ii04S?usp=sharing

## Expected behavior

Should train without error. 

Comments:
Hey, I am getting the same error. 

I am using a three column CSV file which looks like this,

data.csv
label,sent1,sent2
0,he,so
1,yes,why

Any help would be appreciated. 

The error is caused by the following function
`
transformed_ds[k] = ds[k].map(
                lambda example: tokenizer.batch_encode_plus(
                    (example[features_name[0]], example[features_name[1]]),
                    truncation=True,
                    max_length=max_seq_length,
                    padding="max_length",
                ),
                batched=True,
            )
`
When I set `batched=False`, it could pass; however, another error arises. Any idea? @jplu

This issue has been automatically marked as stale and been closed because it has not had recent activity. Thank you for your contributions.

If you think this still needs to be addressed please comment on this thread.