huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
134.34k stars 26.86k forks source link

Cannot import DataCollatorForSeq2Seq from Transformers library #10035

Closed Arman-IMRSV closed 3 years ago

Arman-IMRSV commented 3 years ago

Environment info

Who can help

@patil-suraj @sgugger

Information

Model I am using (Bert, XLNet ...): mT5

The problem arises when using:

The tasks I am working on is:

To reproduce

Steps to reproduce the behavior:

python run_seq2seq.py \
    --model_name_or_path google/mt5-small \
    --do_train \
    --do_eval \
    --task translation_en_to_fa \
    --train_file Persian/seq2seq_train.json \
    --validation_file Persian/seq2seq_val.json \
    --output_dir translation_task_output \
    --overwrite_output_dir \
    --per_device_train_batch_size=4 \
    --per_device_eval_batch_size=4 \
    --predict_with_generate \
    --text_column text_column_name \
    --max_source_length 64 \
    --max_target_length 64 \
    --max_train_samples 10240 \
    --max_val_samples 512 \
    --source_lang en \
    --target_lang fa \
    --eval_beams 1 \
    --source_prefix "translate English to Persian: "

Error:

File "run_seq2seq.py", line 31, in <module>
    from transformers import (
ImportError: cannot import name 'DataCollatorForSeq2Seq' from 'transformers' (unknown location)
patil-suraj commented 3 years ago

Could you try running this on master ? I just ran this script on master and it's working fine.

sgugger commented 3 years ago

As mentioned in the README of the examples folder, all examples require a source install.

DataCollatorForSeq2Seq is not in the last release, it was introduced since then.

Arman-IMRSV commented 3 years ago

@sgugger @patil-suraj Thanks :)