transformers icon indicating copy to clipboard operation
transformers copied to clipboard

pipeline does not do truncation on long texts input, error message found

Open yuyongze opened this issue 6 years ago • 1 comments

🐛 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:

  1. 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)
  1. 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
  1. same error on NER task, maybe some other task as well.

Expected behavior

Environment info

  • transformers version: 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

yuyongze avatar Jul 22 '20 20:07 yuyongze

Duplicate of #4224

yuyongze avatar Jul 22 '20 21:07 yuyongze