Skip to content

Conversation

gante
Copy link
Member

@gante gante commented Aug 22, 2025

What does this PR do?

Related to #25084

Makes the ASR pipeline behave as other text-generating pipelines: kwargs at call time are forwared to generate, as opposed to needing a special keyword.


from transformers import pipeline
from datasets import load_dataset

model = "openai/whisper-tiny"
asr = pipeline("automatic-speech-recognition", model=model)
dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation[:1]")

# BC: with `generate_kwargs` as a dictionary
res = asr(
    dataset[0]["audio"],
    generate_kwargs={"task": "transcribe", "max_new_tokens": 256},
    chunk_length_s=30,
    batch_size=8,
)
print(res)

# New: kwargs forwarded to `generate`
res = asr(
    dataset[0]["audio"],
    max_new_tokens=256,
    task="transcribe",
    chunk_length_s=30,
    batch_size=8,
)
print(res)

@gante gante requested a review from ArthurZucker August 22, 2025 14:18
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@gante gante requested review from Cyrilvallez and removed request for ArthurZucker September 3, 2025 10:30
Copy link
Contributor

github-actions bot commented Sep 3, 2025

[For maintainers] Suggested jobs to run (before merge)

run-slow: whisper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants