Skip to content

Commit

Permalink
add code example
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchit-gandhi committed Mar 7, 2023
1 parent 3df6c2e commit d6cba06
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/transformers/models/whisper/modeling_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,34 @@ def forward(
Returns:
"""
Example:
```python
>>> import torch
>>> from transformers import AutoFeatureExtractor, WhisperForAudioClassification
>>> from datasets import load_dataset
>>> feature_extractor = AutoFeatureExtractor.from_pretrained(
... "sanchit-gandhi/whisper-small-ft-common-language-id"
... )
>>> model = WhisperForAudioClassification.from_pretrained("sanchit-gandhi/whisper-small-ft-common-language-id")
>>> ds = load_dataset("facebook/multilingual_librispeech", "dutch", split="validation", streaming=True)
>>> sample = next(iter(ds))
>>> inputs = feature_extractor(
... sample["audio"]["array"], sampling_rate=sample["audio"]["sampling_rate"], return_tensors="pt"
... )
>>> input_features = inputs.input_features
>>> with torch.no_grad():
... logits = model(input_features).logits
>>> predicted_class_ids = torch.argmax(logits).item()
>>> predicted_label = model.config.id2label[predicted_class_ids]
>>> predicted_label
'Dutch'
```"""

output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
output_hidden_states = (
Expand Down

0 comments on commit d6cba06

Please sign in to comment.