New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: You have to specify either input_ids or inputs_embeds! #3626
Comments
Just noticed that the Examples docstring for TF T5 was wrong. Is fixed with #3636 . |
@patrickvonplaten Importsfrom transformers import TFAutoModel, AutoTokenizer
# First load the real tokenizer
tokenizer = AutoTokenizer.from_pretrained('t5-small')
transformer_layer = TFAutoModel.from_pretrained('t5-small') Define Encoderdef encode(texts, tokenizer, maxlen=512):
enc_di = tokenizer.batch_encode_plus(
texts,
return_attention_masks=False,
return_token_type_ids=False,
pad_to_max_length=True,
max_length=maxlen
)
return np.array(enc_di['input_ids'])
# tokenized
x_train = encode('text', tokenizer, maxlen=200)
y_train Define Model and Calldef build_mod(transformer, max_len=512):
input_word_ids = Input(shape=(max_len,), dtype=tf.int32, name="input_word_ids")
sequence_output = transformer(input_word_ids)[0]
cls_token = sequence_output[:, 0, :]
out = Dense(1, activation='sigmoid')(cls_token)
model = Model(inputs=input_word_ids, outputs=out)
model.compile(Adam(lr=1e-5), loss='binary_crossentropy', metrics=['accuracy'])
return model
# calling
model = build_model(transformer_layer, max_len=200) Now, according to the docstring, should I do,
? |
I'm not 100% sure what you want to do here exactly. T5 is always trained in a text-to-text format. We have a section here on how to train T5: https://huggingface.co/transformers/model_doc/t5.html#training Otherwise I'd recommend taking a look at the official paper. |
@patrickvonplaten Thanks for this. I encountered the same issue and this resolved it! I'm wondering if it makes sense to make the error message capture the requirement of having both I.e., for encoded-decoder models, switch the error message from:
to:
I can sent this as a PR as well if you think it makes sense! |
Hi @enzoampil, A PR for a cleaner Error message would be nice if you feel like it :-). It would be good if the error message could change between |
Got it will do. Thanks for the pointers! 😄 |
Hi, I also got the same error when training seq2seq on tf.keras and I could not follow the example you provide on https://huggingface.co/transformers/model_doc/t5.html#training (this example is for pytorch I think) I create model = TFT5Model.from_pretrained('t5-base') So when I want to train the model I simply do where I clearly provide Note that changing input from dict to list got the same error. Changing model from TFT5Model to TFT5ForConditionalGeneration got the same error. Changing loss to BCE got the same error. Moreover, changing input to only one array
|
In I found this line (899-900):
Shouldn't it be |
@ratthachat - thanks for you message! In TF we use the naming convention |
Thanks for your consideration, Patrick! |
@patrickvonplaten Sorry to tag you in this old thread, but is there any official T5 TF example (as you mentioned in the last thread)? |
@ratthachat - no worries, we should definitely add more TF T5 examples and we still don't have a good TF T5 notebook. |
Hi @patrickvonplaten i wanted to fine tune using T5 using TF 2.0 but its soo confusing at each end as compared to pytorch which is really well documented all current examples (community + offcial) are for pytorch. is the work for TFT5 notebook underway? |
Okey, seems like no-one has a complete TF T5 notebook. I will start working on it this week: https://discuss.huggingface.co/t/how-to-train-t5-with-tensorflow/641/6 Should be done by next week sometime :-) |
Hi @patrickvonplaten I'm doing inference with a T5-base model which I finetuned on GLUE tasks. It's giving error like While doing inference, we just need to provide input_ids for the encoder right? And as it's inference, my Waiting for your reply. |
@prashant-kikani it is indeed a strange behavior. have you tried passing
|
Hi @HarrisDePerceptron You see, T5 which Transformer itself, is a text to text model. But, when label is not available, we need to go sequentially by doing forward pass in decoder for each word till What do you think? |
@prashant-kikani @HarrisDePerceptron For We can see a concrete example by looking at the function See line 298 in the above link :
and line 331:
and see T5's transformers/src/transformers/modeling_tf_t5.py Line 1367 in 08f534d
|
Hi @patrickvonplaten Patrick, Thanks for your great work and great comment. I mimic the process of inferencing T5 as below and I got a bug, is it possible that you could help me to advise what has happended? from transformers import AutoModel, AutoTokenizer
model_name = "castorini/t5-base-canard"
model = AutoModel.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
context = '''
Frank Zappa ||| Disbandment ||| What group disbanded ||| Zappa and the Mothers of Invention ||| When did they disband?
'''
encoded_input = tokenizer(
context,
padding='max_length',
max_length=512,
truncation=True,
return_tensors="pt",
)
decoder_input = tokenizer(
context,
padding='max_length',
max_length=512,
truncation=True,
return_tensors="pt",
)
encoder_output = model.generate(input_ids=encoded_input["input_ids"], decoder_input_ids=decoder_input["input_ids"])
output = tokenizer.decode(
encoder_output[0],
skip_special_tokens=True
)
output I got error, though I alreadly provided
Thanks! |
Hey @dxlong2000, I'll open a new issue for this to make it more visible as I think this error happens quite often. See: #16234 |
Good issue! really helps me. |
Details
I'm quite new to NLP task. However, I was trying to train the T5-large model and set things as follows. But unfortunately, I've got an error.
It thorws
The text was updated successfully, but these errors were encountered: