Skip to content
Open
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
21 changes: 5 additions & 16 deletions src/transformers/models/whisper/processing_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,17 @@ def get_decoder_prompt_ids(self, task=None, language=None, no_timestamps=True):
@auto_docstring
def __call__(self, *args, **kwargs):
audio = kwargs.pop("audio", None)
sampling_rate = kwargs.pop("sampling_rate", None)
text = kwargs.pop("text", None)

# for BC
if len(args) > 0:
audio = args[0]
args = args[1:]

if audio is None and text is None:
raise ValueError("You need to specify either an `audio` or `text` input to process.")

if audio is not None:
inputs = self.feature_extractor(audio, *args, sampling_rate=sampling_rate, **kwargs)
outputs = super().__call__(audio=audio, text=text, **kwargs)
if text is not None:
encodings = self.tokenizer(text, **kwargs)

if text is None:
return inputs

elif audio is None:
return encodings
else:
inputs["labels"] = encodings["input_ids"]
return inputs
outputs["labels"] = outputs["input_ids"]
return outputs

def get_prompt_ids(self, text: str, return_tensors="np"):
return self.tokenizer.get_prompt_ids(text, return_tensors=return_tensors)
Expand Down