Extracting embeddings through 'pipeline' and 'feature-extraction' not outputting correct length of values.
Author: abal6725
Pull request: no
Labels: name: bug

### System Info

transformers==4.20.1
Python3.7

### Who can help?

@Narsil

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

Hello,

I am trying to extract embeddings from a fine tuned multi-label model with added vocab. I have used the the following example https://github.com/abhimishra91/transformers-tutorials/blob/master/transformers_multi_label_classification.ipynb and modified with https://github.com/huggingface/transformers/issues/1413 to be able to add new tokens. 
 
Once I have fine-tuned the model on my own data I have saved it as such:

### Saving the files for inference
output_full_model_file = './models/pytorch_distilbert_categorization_complaints_test.bin'
output_embedding_model_file = './models/pytorch_distilbert_embedding_complaints_test.bin'
output_tokenizer_file = './models/tokenizer_distilbert_complaints_test'
torch.save(model, output_full_model_file)
torch.save(model.l1, output_embedding_model_file)
tokenizer.save_pretrained(output_tokenizer_file)


Now I am trying to use 'pipeline' with 'feature-extraction' to find the embeddings for the new vocab I have added, here is the code I use to do so:


from transformers import pipeline,AutoTokenizer,DistilBertTokenizer
import torch
output_full_model_file = './models/pytorch_distilbert_categorization_complaints_test.bin'
output_embedding_model_file = './models/pytorch_distilbert_embedding_complaints_test.bin'
output_tokenizer_file = './models/tokenizer_distilbert_complaints_test'
model = torch.load(output_embedding_model_file)
tokenizer1 = AutoTokenizer.from_pretrained(output_tokenizer_file)
tokenizer2 = DistilBertTokenizer.from_pretrained(output_tokenizer_file)
pipe = pipeline('feature-extraction', model=model, tokenizer=tokenizer1)
data_zelle = pipe("zelle")
len(data_zelle[0])
3




### Expected behavior

I was expecting the output to by a single vector of length 768 corresponding to the word 'zelle' instead it is an array of (3,768). I was expecting a single vector as it is a single word. Am I missing something here? Or is there another way to do what I am attempting? Thanks in advance for the help!! 

Comments:
Hey, this is perfectly normal. you tokenizer most likely has 3 input_ids when tokenizing this string (most likely BOS, "zelle", EOS).

Then the output of the model is actually (3, 768). 3 is the sequence_length and is perfectly normal. You're probably more interested in some locations that others so you can filter them out but by default the model does output all of this.

`sentence-transformers` is another library which does full sentence embedding and will do a reduction for you to get a single `(768,)` representation from this `(seq_length, 768)` .  (Model has to be finetuned respective to a reduction, afaik, non finetuned models are hard to reduce blindly)

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.