Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ASR pipeline bug when using some kwargs #34663

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jhj0517
Copy link

@jhj0517 jhj0517 commented Nov 9, 2024

What does this PR do?

Always Thanks for your work.
In AutomaticSpeechRecognitionPipeline, when using temperature, no_speech_threshold and logprob_threshold kwargs, token_ids has List of float types and it occurs following TypeError:

  File "C:\Whisper_Project\Whisper-WebUI\venv\Lib\site-packages\transformers\tokenization_utils_fast.py", line 657, in _decode
    text = self._tokenizer.decode(token_ids, skip_special_tokens=skip_special_tokens)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument 'ids': 'float' object cannot be interpreted as an integer

Reproduction

from transformers import pipeline

input_path = "test_audio.mp3"

pipe = pipeline(
    "automatic-speech-recognition",
    model="openai/whisper-tiny",
    torch_dtype="float16",
    device="cuda",
)

kwargs = {
    "language": "en",
    "task": "transcribe",
    "temperature": 0.7,
    "no_speech_threshold": 0.6,
    "logprob_threshold": -1.0,
}
segments = pipe(
    inputs=[input_path],
    return_timestamps=True,
    chunk_length_s=30,
    batch_size=24,
    generate_kwargs=kwargs
)

This PR fixes the error by casting it to list of int if its type is float.

Fixes :

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@ArthurZucker

@jhj0517
Copy link
Author

jhj0517 commented Nov 9, 2024

This may be caused by to_py_obj():

token_ids = to_py_obj(token_ids)

def to_py_obj(obj):
"""
Convert a TensorFlow tensor, PyTorch tensor, Numpy array or python list to a python list.
"""

It's converted to list of float by this function when it should be list of int. This only occurs when using temperature, no_speech_threshold, and logprob_threshold parameters in the pipeline.

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.

1 participant