Hello AlexN,
I am experiencing the same issue 
I think the solution can be found on this issue thread:
  

      github.com/huggingface/transformers
  

  
    
  
	  
  

  
    
      Logits size does not match vocabulary size when using pyctcdecode for a fine-tuned wav2vec 2.0 model 4
    

    
      
        opened 
        
          
        
        Jan 28, 2022
      
      


      
        
          
          iskaj
        
      
    

    
    
  


  
    ## Environment info
- `transformers` version: 4.17.0.dev0
- Platform: Linux-5.…4.0-1063-azure-x86_64-with-glibc2.29
- Python version: 3.8.10
- PyTorch version (GPU?): 1.10.2+cu102 (True)
- Tensorflow version (GPU?): 2.6.0 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: Yes (device = 'cuda')
- Using distributed or parallel set-up in script?: No

## Who can help
@patrickvonplaten, @anton-l

## Dataset used
https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0

## Information
Model I am using: https://huggingface.co/Iskaj/xlsr300m_cv_7.0_nl_lm, (dataset = https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0) The model fine-tuned version of https://huggingface.co/facebook/wav2vec2-xls-r-300m

The problem arises when using:

```python
import torch
from datasets import load_dataset
from transformers import AutoModelForCTC, AutoProcessor
import torchaudio.functional as F

model_id = "Iskaj/xlsr300m_cv_7.0_nl_lm"

sample_iter = iter(load_dataset("mozilla-foundation/common_voice_8_0", "nl", split="test", streaming=True, use_auth_token=True))

sample = next(sample_iter)
resampled_audio = F.resample(torch.tensor(sample["audio"]["array"]), 48_000, 16_000).numpy()

model = AutoModelForCTC.from_pretrained(model_id)
processor = AutoProcessor.from_pretrained(model_id)

input_values = processor(resampled_audio, return_tensors="pt").input_values

with torch.no_grad():
    logits = model(input_values).logits

transcription = processor.batch_decode(logits.numpy()).text
```

## To reproduce

Steps to reproduce the behavior:

1. install packages using: `!pip install https://github.com/kpu/kenlm/archive/master.zip pyctcdecode
!pip install git+https://github.com/huggingface/transformers.git
!pip install git+https://github.com/huggingface/datasets.git
!pip install torchaudio soundfile librosa Levenshtein telwoord wandb jiwer`
2. run: 
```
import torch
from datasets import load_dataset
from transformers import AutoModelForCTC, AutoProcessor
import torchaudio.functional as F

model_id = "Iskaj/xlsr300m_cv_7.0_nl_lm"

sample_iter = iter(load_dataset("mozilla-foundation/common_voice_8_0", "nl", split="test", streaming=True, use_auth_token=True))

sample = next(sample_iter)
resampled_audio = F.resample(torch.tensor(sample["audio"]["array"]), 48_000, 16_000).numpy()

model = AutoModelForCTC.from_pretrained(model_id)
processor = AutoProcessor.from_pretrained(model_id)

input_values = processor(resampled_audio, return_tensors="pt").input_values

with torch.no_grad():
    logits = model(input_values).logits

transcription = processor.batch_decode(logits.numpy()).text
```
3. Observe the error: `ValueError: Input logits of size 48, but vocabulary is size 50

## Expected behavior
I would expect pyctc-decode to work correctly and give me a transcription. 
I suspect it has something to do with `<s>` and `</s>`. I've been struggling a bit with the length of the logits not matching up with the length of the vocabulary, when using pyctcdecode. For example in this repo that uses the LM: https://huggingface.co/patrickvonplaten/wav2vec2-base-100h-with-lm/blob/main/vocab.json the vocab.json includes <s> and </s>, but in this repo it doesn't: https://huggingface.co/hf-test/xls-r-300m-sv/blob/main/vocab.json Maybe that helps
  

  

  
    
    
  

  


 → Add the following input arguments to the Tokenizer

eos_token=None, bos_token=None