# Inconsistent output between PyTorch and HF whisper medium models

**URL:** <https://discuss.huggingface.co/t/inconsistent-output-between-pytorch-and-hf-whisper-medium-models/46476>\
**Category:** 🤗Transformers\
**Created:** [July 11, 2023, 7:11pm UTC](https://discuss.huggingface.co/t/inconsistent-output-between-pytorch-and-hf-whisper-medium-models/46476 "2023-07-11T19:11:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![picheny](https://avatars.discourse-cdn.com/v4/letter/p/77aa72/32.png) [@picheny](https://discuss.huggingface.co/u/picheny)\
**Post date:** [July 11, 2023, 7:11pm UTC](https://discuss.huggingface.co/t/inconsistent-output-between-pytorch-and-hf-whisper-medium-models/46476/1 "2023-07-11T19:11:11Z")

</div>

I am running “original” and HF versions of the whisper medium model and get inconsistent output. In particular, there are a few utterances in which the HF medium model generates a lot of “Hallucinations” but the PyTorch version does not:

Ref: BOOP BOOP BOOP BOOP BOOP BOOP  
PyTorch: GO GO GO GO GO GO GO GO  
HF: HYP: GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO GO

The speech is not great quality (It is a mother interacting with a baby, regrettably I can not share the waveform).

This happens on a few utterances and significantly changes the WER because of the massive number of insertions.

**Here is the main code loop I am using for the non-HF model: (args.language = ‘en’).**

if args.language != ‘’:  
options = dict(language=args.language)  
transcribe\_options = dict(task=“transcribe”, \*\*options)

for index, row in test\_df.iterrows():

```
if (index % args.batches) != args.offset :
    continue
if args.language != "":
    pred_transcription = whisper.transcribe(model, row['path'], **transcribe_options)
else:
    pred_transcription = whisper.transcribe(model, row['path'])

for segment in pred_transcription['segments'] :
    del segment['tokens']
    del segment['seek']
    del segment['temperature']
    del segment['compression_ratio']
    segment['filename'] = row['path']
    print(segment)
    if args.results is not None:
        print(segment, file=f)

```

**and here is the main loop for the HF version:**

args.whisper is set to “openai/whisper-medium”

tokenizer = WhisperTokenizer.from\_pretrained(args.whisper, language=“English”)  
feature\_extractor = WhisperFeatureExtractor.from\_pretrained(args.whisper)  
processor = WhisperProcessor.from\_pretrained(args.whisper, language=“English”)

model = WhisperForConditionalGeneration.from\_pretrained(args.whisper)

model.config.forced\_decoder\_ids = None  
model.config.suppress\_tokens =

forced\_decoder\_ids = processor.get\_decoder\_prompt\_ids(language=“English”, task=“transcribe”)

def map\_to\_result(batch):  
with torch.no\_grad():  
input\_features = processor(batch[“audio”][“array”], sampling\_rate=batch[“audio”][“sampling\_rate”],return\_tensors=“pt”).input\_features  
predicted\_ids = model.generate(input\_features, forced\_decoder\_ids=forced\_decoder\_ids)  
transcription = processor.batch\_decode(predicted\_ids, skip\_special\_tokens=True)  
batch[“pred\_str”] = re.sub(chars\_to\_ignore\_regex, ‘’, transcription[0]).upper() + " "  
batch[“ref”] = batch[“text”]  
return batch

results = test\_dataset.map(map\_to\_result, remove\_columns=test\_dataset.column\_names)

Does anyone have any insights on why the HF versions tends to hallucinate significantly more than the non-HF version, and also if there is a quick fix for the hallucination problem (I do see stuff out there but not sure exactly which parameters to set where).

Thanks  
Michael
