transformers
transformers copied to clipboard
pipeline does not do truncation on long texts input, error message found
🐛 Bug
Information
Model I am using (Bert, XLNet ...): No specified
Language I am using the model on (English, Chinese ...): English
The problem arises when using:
- [ ] the official example scripts: (give details below)
- [X] my own modified scripts: (give details below)
The tasks I am working on is:
- [ ] an official GLUE/SQUaD task: (give the name)
- [X] my own task or dataset: (give details below)
To reproduce
Steps to reproduce the behavior:
- I have tried using pipeline on my own purpose, but I realized it will cause errors if I input long sentence on some tasks, it should do truncation automatically, but it does not. And the pipeline function does not take extra argument so we cannot add something like
truncation=True. Here is an example on sentiment-analysis task:
from transformers import pipeline
nlp = pipeline('sentiment-analysis')
text = "This is an example"*300
nlp(text)
- The error message is below:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-31-0a8ce849cc29> in <module>()
2 nlp = pipeline('sentiment-analysis')
3 text = "This is an example"*300
----> 4 nlp(text)
11 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in embedding(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse)
1722 # remove once script supports set_grad_enabled
1723 _no_grad_embedding_renorm_(weight, input, max_norm, norm_type)
-> 1724 return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
1725
1726
IndexError: index out of range in self
- same error on NER task, maybe some other task as well.
Expected behavior
Environment info
transformersversion: 3.0.2- Platform: Google Colab
- Python version: Python 3.6.9
- PyTorch version (GPU?):1.5.1+cu101, no GPU
- Tensorflow version (GPU?): no
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no
Duplicate of #4224