transformers
`intial_prompt` support for automatic-speech-recognition (whisper) pipeline
#28554
Closed

`intial_prompt` support for automatic-speech-recognition (whisper) pipeline #28554

Biswajit2902 wants to merge 11 commits into huggingface:main from Biswajit2902:main
Biswajit2902
Biswajit29021 year ago (edited 1 year ago)

What does this PR do?

Fixes # (feature)

  • initial_prompt support for whisper Pipeline (automatic-speech-recognition)

Before submitting

  • Added initial_prompt as an option for whisper model
  • To handle initial prompt processor considered as optional parameter
  • Current implementation supports only Torch version of decoding.
  • how to use initial prompt;
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
from datasets import load_dataset

model_id = "openai/whisper-small"
model = AutoModelForSpeechSeq2Seq.from_pretrained(
    model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
)
model.to(device)

processor = AutoProcessor.from_pretrained(model_id)

pipe = pipeline(
    "automatic-speech-recognition",
    model=model,
    tokenizer=processor.tokenizer,
    feature_extractor=processor.feature_extractor,
    max_new_tokens=128,
    chunk_length_s=15,
    batch_size=16,
    torch_dtype=torch_dtype,
    device=device,
    processor=processor
)

dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
sample = dataset[0]["audio"]

# including timestamp
print(pipe(audio, initial_prompt = "Biswajit, Whisper", return_timestamps=True))

# without timestamp
print(pipe(audio, initial_prompt = "Biswajit, Whisper"))

Who can review?

Anyone in the community is free to review the PR once the tests have passed. @sanchit-gandhi , @Narsil, Can anyone help to take this PR forward please. Let me know, if anything is needed.

Biswajit2902 test
befe862e
Biswajit2902 revert back
9eb6bf51
Biswajit2902 added option for inital_prompt for whisper API
caecfd23
Biswajit2902 added option for inital_prompt for whisper API
8eb31790
Biswajit2902 added option for inital_prompt for whisper API
74c505e6
Biswajit2902 added option for inital_prompt for whisper API
47e770f1
Biswajit2902 added option for inital_prompt for whisper API
de2f27ad
Biswajit2902 added option for inital_prompt for whisper API
cf15d96c
Biswajit2902 Merge pull request #1 from Biswajit2902/dev
a461d273
Biswajit2902 Update automatic_speech_recognition.py
62cf72b7
Biswajit2902 Update automatic_speech_recognition.py
8e50b7f7
Biswajit2902 Biswajit2902 marked this pull request as ready for review 1 year ago
Biswajit2902 Biswajit2902 closed this 1 year ago

Login to write a write a comment.

Login via GitHub

Reviewers
No reviews
Assignees
No one assigned
Labels
Milestone