Repository: huggingface/transformers

Issue:
pipeline("sentiment-analysis")() can't handle more than 2 sentences
# 🐛 Bug

## Information

Model I am using (Bert, XLNet ...): pipeline("sentiment-analysis")

Language I am using the model on (English, Chinese ...): English

The problem arises when using:
* [x] the official example scripts: (give details below)
* [ ] 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:

```
>>> from transformers import pipeline
>>> analyzer = pipeline('sentiment-analysis')
Downloading: 100%|██████████████████████████████| 230/230 [00:00<00:00, 146kB/s]
>>> analyzer(["OK"]*10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../lib/python3.6/site-packages/transformers/pipelines.py", line 490, in __call__
    scores = np.exp(outputs) / np.exp(outputs).sum(-1)
ValueError: operands could not be broadcast together with shapes (10,2) (10,) 
>>> 
```


`

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

<!-- A clear and concise description of what you would expect to happen. -->
Getting 10 results

## Environment info
<!-- You can run the command `python transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->
     
- `transformers` version: 2.5.0
- Platform: ubuntu 19.04
- Python version: 3.6
- PyTorch version (GPU?): 1.4.0 GPU
- Tensorflow version (GPU?): 1.14.0 GPU
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No



Discussion:
`scores = np.exp(outputs) / np.exp(outputs).sum(-1).reshape(-1,1)` works for me, but I'm not sure whether it breaks other things.
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.

This still happens on the latest version. I still have to apply
`scores = np.exp(outputs) / np.exp(outputs).sum(-1).reshape(-1,1)`
For the code to work.

Resolving patch:
diff --git a/src/transformers/pipelines.py b/src/transformers/pipelines.py
--- a/src/transformers/pipelines.py
+++ b/src/transformers/pipelines.py
@@ -656,8 +656,8 @@ class TextClassificationPipeline(Pipeline):
 
     def __call__(self, *args, **kwargs):
         outputs = super().__call__(*args, **kwargs)
-        scores = np.exp(outputs) / np.exp(outputs).sum(-1)
-        return [{"label": self.model.config.id2label[item.argmax()], "score": item.max()} for item in scores]
+        scores = np.exp(outputs) / np.exp(outputs).sum(-1, keepdims=True)
+        return [{"label": self.model.config.id2label[item.argmax()], "score": item.max().item()} for item in scores]
 
 
 class FillMaskPipeline(Pipeline):


Test patch: