huggingface / transformers

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

How to perform model.predict loop with TFRobertaForSequenceClassification? #8136

Closed MiriamFarber closed 3 years ago

MiriamFarber commented 4 years ago

I'd like to perform inference loop for the following roberta model:

model = TFRobertaForSequenceClassification.from_pretrained('roberta-base',return_dict=True,num_labels=2)

on a large set of pairs of sentences (couple of hundred thousands). I wanted to use model.predict and specify batch size, but there is no way to pass the below inputs (encoded_data is tokenization of the input data) to model.predict

attention_mask=encoded_data['attention_mask'], 
token_type_ids=encoded_data['token_type_ids']

So what is the alternative way to do that?

ratthachat commented 4 years ago

Hi, this Kaggle notebook shows a very concise way to efficiently train/predict Huggingface's XLMRoberta (which is the same format as Roberta) . Hope it help!

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.