Closed gcervantes8 closed 3 years ago
Hey @gcervantes8,
I don't really understand why this change is needed:
source_lang = data_args.source_lang.split("_")[0]
target_lang = data_args.target_lang.split("_")[0]
What error do you get without making this change? Can you maybe copy-paste the command you run that gives you an error without having made the above changes
Hey @patrickvonplaten thanks for the help!
Without making the change I get this error:
Traceback (most recent call last):
File "/home/gcervantes/Desktop/work/Code/transformers/examples/tensorflow/translation/run_translation.py", line 620, in <module>
main()
File "/home/gcervantes/Desktop/work/Code/transformers/examples/tensorflow/translation/run_translation.py", line 450, in main
train_dataset = train_dataset.map(
File "/home/gcervantes/Desktop/work/python_envs/huggingface/lib/python3.8/site-packages/datasets/arrow_dataset.py", line 1686, in map
return self._map_single(
File "/home/gcervantes/Desktop/work/python_envs/huggingface/lib/python3.8/site-packages/datasets/arrow_dataset.py", line 185, in wrapper
out: Union["Dataset", "DatasetDict"] = func(self, *args, **kwargs)
File "/home/gcervantes/Desktop/work/python_envs/huggingface/lib/python3.8/site-packages/datasets/fingerprint.py", line 398, in wrapper
out = func(self, *args, **kwargs)
File "/home/gcervantes/Desktop/work/python_envs/huggingface/lib/python3.8/site-packages/datasets/arrow_dataset.py", line 2048, in _map_single
batch = apply_function_on_filtered_inputs(
File "/home/gcervantes/Desktop/work/python_envs/huggingface/lib/python3.8/site-packages/datasets/arrow_dataset.py", line 1939, in apply_function_on_filtered_inputs
function(*fn_args, effective_indices, **fn_kwargs) if with_indices else function(*fn_args, **fn_kwargs)
File "/home/gcervantes/Desktop/work/Code/transformers/examples/tensorflow/translation/run_translation.py", line 424, in preprocess_function
inputs = [ex[source_lang] for ex in examples["translation"]]
File "/home/gcervantes/Desktop/work/Code/transformers/examples/tensorflow/translation/run_translation.py", line 424, in <listcomp>
inputs = [ex[source_lang] for ex in examples["translation"]]
KeyError: 'en'
Process finished with exit code 1
I do this because in the ccaligned_multilingual
data, the keys used in the JSON file are ak_GH
and en_XX
.
The original code modifies the language code so that it only uses the characters before the _
, in this example it would give en
and ak
giving me a key error.
Without making any changes to the code, running _transformers/examples/tensorflow/translation/runtranslation.py with these arguments also gives the same error.
--do_train True --model_name_or_path google/mt5-base --tokenizer_name google/mt5-base --output_dir output --dataset_name opus_euconst --dataset_config_name cs-en --source_lang cs --target_lang en
Changing the model and tokenizer to google/byt5-base
gives no error.
Hey @gcervantes8,
Thanks for the answer! @Rocketknight1 - could you maybe give this a look? I think you've recently worked with the TF translation script no? :-)
@patrickvonplaten On my list, I'll try to investigate this today or tomorrow!
Hi @gcervantes8, sorry to be annoying, but can I ask you to test this with the TF translation notebook too? Just swap in the mT5 model and your dataset there, and then if you encounter the same issue, you can save and upload the notebook with your changes and the error outputs. I know it's a bit lazy of me, but it'll make it much easier for me to reproduce and locate the problem!
Hey @Rocketknight1 thanks for the help! So I tried running the model with the TF translation notebook, but I didn't encounter the issue strangely enough.
These are the changes I made to the TF Notebook.
I changed the model.
model_checkpoint = "google/mt5-base"
Changed the dataset
raw_datasets = load_dataset("opus_euconst", "cs-da")
I modified the source language and the target language specified before the preprocess function
source_lang = "cs"
target_lang = "da"
I modified the batch size because I was getting out of memory errors
batch_size = 1
And I also had to remove the validation_dataset
.
So this might be specific to the _transformers/examples/tensorflow/translation/runtranslation.py script
Hm, that's quite unusual because the scripts should be similar. I'll try to reproduce with the example script here in the next couple of days and let you know what I find.
I looked into it more and it seems that the resize_token_embeddings
function in _src/transformers/modeling_tfutils.py expects the get_output_embeddings
function in _src/transformers/models/t5/modeling_tft5.py to return an object with the attribute weight
or decoder
.
The model works for T5 because in the get_output_embeddings
T5 function, self.config.tie_word_embeddings
is True and it doesn't go to the else
part of the if
statement which only returns the Tensor.
I'm not really sure how the best way for this to be fixed is. @patrickvonplaten what do you think?
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
I think this issue still needs to be addressed, I'm still receiving the error retraining a mT5 Model using TensorFlow.
It seems this issue is the same (or maybe just similar?) as issue #13839 And it looks like #14329 will probably fix it, so I'll close this issue.
Environment info
transformers
version: 4.11.2Who can help
@patrickvonplaten
Information
Model I am using is mT5:
The problem arises when running the _transformers/examples/tensorflow/translation/runtranslation.py file.
I made this modification to get the machine translation to run:
Modified to:
And then I ran the script with these parameters:
--do_train True --model_name_or_path google/mt5-base --tokenizer_name google/mt5-base --output_dir output --dataset_name ccaligned_multilingual --dataset_config_name sentences-ak_GH --source_lang en_XX --target_lang ak_GH
And I ran into the error:
ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.
Changing the model and tokenizer from
google/mt5-base
tot5-base
will fix the error I am getting, so I think it's specific to the mT5 model.I appreciate any help or advice, I really like this library so far!
Full error