Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/transformers/models/whisper/tokenization_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,5 +583,6 @@ def _build_conversation_input_ids(self, conversation) -> List[int]:
return input_ids

def get_decoder_prompt_ids(self, task=None, language=None, no_timestamps=True):
self.set_prefix_tokens(task=task, language=language, predict_timestamps=no_timestamps)
return self.prefix_tokens
self.set_prefix_tokens(task=task, language=language, predict_timestamps=not no_timestamps)
forced_decoder_ids = [(rank + 1, token) for rank, token in enumerate(self.prefix_tokens)]
return forced_decoder_ids
Comment on lines +586 to +588
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! I should have realized when reviewing!

19 changes: 19 additions & 0 deletions tests/models/whisper/test_processor_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
from transformers import WhisperFeatureExtractor, WhisperProcessor


START_OF_TRANSCRIPT = 50257
TRANSCRIBE = 50358
NOTIMESTAMPS = 50362


@require_torch
@require_torchaudio
@require_sentencepiece
Expand Down Expand Up @@ -128,3 +133,17 @@ def test_model_input_names(self):
feature_extractor.model_input_names,
msg="`processor` and `feature_extractor` model input names do not match",
)

def test_get_decoder_prompt_ids(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

feature_extractor = self.get_feature_extractor()
tokenizer = self.get_tokenizer()

processor = WhisperProcessor(tokenizer=tokenizer, feature_extractor=feature_extractor)
forced_decoder_ids = processor.get_decoder_prompt_ids(task="transcribe", no_timestamps=True)

self.assertIsInstance(forced_decoder_ids, list)
for ids in forced_decoder_ids:
self.assertIsInstance(ids, (list, tuple))

expected_ids = [START_OF_TRANSCRIPT, TRANSCRIBE, NOTIMESTAMPS]
self.assertListEqual([ids[-1] for ids in forced_decoder_ids], expected_ids)