ValueError when running the example script

#2
by qgallouedec HF staff - opened

When I run

import torch
from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
from datasets import load_dataset
import soundfile as sf

model = Speech2TextForConditionalGeneration.from_pretrained("facebook/s2t-small-covost2-fr-en-st")
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-covost2-fr-en-st")

def map_to_array(batch):
    speech, _ = sf.read(batch["file"])
    batch["speech"] = speech
    return batch

ds = load_dataset(
    "patrickvonplaten/librispeech_asr_dummy",
    "clean",
    split="validation"
)
ds = ds.map(map_to_array)

inputs = processor(
    ds["speech"][0],
    sampling_rate=48_000,
    return_tensors="pt"
)
generated_ids = model.generate(input_ids=inputs["input_features"], attention_mask=inputs["attention_mask"])

translation = processor.batch_decode(generated_ids, skip_special_tokens=True)

I get the following error.

(env) quentingallouedec@MacBook-Pro-de-Quentin gia % /Users/quentingallouedec/gia/env/bin/python /Users/qu
entingallouedec/gia/examples/s2t.py
WARNING:datasets.builder:Found cached dataset librispeech_asr_dummy (/Users/quentingallouedec/.cache/huggingface/datasets/patrickvonplaten___librispeech_asr_dummy/clean/2.1.0/f2c70a4d03ab4410954901bde48c54b85ca1b7f9bf7d616e7e2a72b5ee6ddbfc)
WARNING:datasets.arrow_dataset:Loading cached processed dataset at /Users/quentingallouedec/.cache/huggingface/datasets/patrickvonplaten___librispeech_asr_dummy/clean/2.1.0/f2c70a4d03ab4410954901bde48c54b85ca1b7f9bf7d616e7e2a72b5ee6ddbfc/cache-2944a8173f386e6d.arrow
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Traceback (most recent call last) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                                                                                  โ”‚
โ”‚ /Users/quentingallouedec/gia/examples/s2t.py:26 in <module>                                      โ”‚
โ”‚                                                                                                  โ”‚
โ”‚   23 โ”‚   sampling_rate=48_000,                                                                   โ”‚
โ”‚   24 โ”‚   return_tensors="pt"                                                                     โ”‚
โ”‚   25 )                                                                                           โ”‚
โ”‚ โฑ 26 generated_ids = model.generate(input_ids=inputs["input_features"], attention_mask=inputs    โ”‚
โ”‚   27                                                                                             โ”‚
โ”‚   28 translation = processor.batch_decode(generated_ids, skip_special_tokens=True)               โ”‚
โ”‚   29                                                                                             โ”‚
โ”‚ /Users/quentingallouedec/gia/env/lib/python3.10/site-packages/torch/utils/_contextlib.py:115 in  โ”‚
โ”‚ decorate_context                                                                                 โ”‚
โ”‚                                                                                                  โ”‚
โ”‚   112 โ”‚   @functools.wraps(func)                                                                 โ”‚
โ”‚   113 โ”‚   def decorate_context(*args, **kwargs):                                                 โ”‚
โ”‚   114 โ”‚   โ”‚   with ctx_factory():                                                                โ”‚
โ”‚ โฑ 115 โ”‚   โ”‚   โ”‚   return func(*args, **kwargs)                                                   โ”‚
โ”‚   116 โ”‚                                                                                          โ”‚
โ”‚   117 โ”‚   return decorate_context                                                                โ”‚
โ”‚   118                                                                                            โ”‚
โ”‚                                                                                                  โ”‚
โ”‚ /Users/quentingallouedec/gia/env/lib/python3.10/site-packages/transformers/generation/utils.py:1 โ”‚
โ”‚ 197 in generate                                                                                  โ”‚
โ”‚                                                                                                  โ”‚
โ”‚   1194 โ”‚   โ”‚                                                                                     โ”‚
โ”‚   1195 โ”‚   โ”‚   generation_config = copy.deepcopy(generation_config)                              โ”‚
โ”‚   1196 โ”‚   โ”‚   model_kwargs = generation_config.update(**kwargs)  # All unused kwargs must be m  โ”‚
โ”‚ โฑ 1197 โ”‚   โ”‚   self._validate_model_kwargs(model_kwargs.copy())                                  โ”‚
โ”‚   1198 โ”‚   โ”‚                                                                                     โ”‚
โ”‚   1199 โ”‚   โ”‚   # 2. Set generation parameters if not already defined                             โ”‚
โ”‚   1200 โ”‚   โ”‚   logits_processor = logits_processor if logits_processor is not None else LogitsP  โ”‚
โ”‚                                                                                                  โ”‚
โ”‚ /Users/quentingallouedec/gia/env/lib/python3.10/site-packages/transformers/generation/utils.py:1 โ”‚
โ”‚ 090 in _validate_model_kwargs                                                                    โ”‚
โ”‚                                                                                                  โ”‚
โ”‚   1087 โ”‚   โ”‚   โ”‚   โ”‚   unused_model_args.append(key)                                             โ”‚
โ”‚   1088 โ”‚   โ”‚                                                                                     โ”‚
โ”‚   1089 โ”‚   โ”‚   if unused_model_args:                                                             โ”‚
โ”‚ โฑ 1090 โ”‚   โ”‚   โ”‚   raise ValueError(                                                             โ”‚
โ”‚   1091 โ”‚   โ”‚   โ”‚   โ”‚   f"The following `model_kwargs` are not used by the model: {unused_model_  โ”‚
โ”‚   1092 โ”‚   โ”‚   โ”‚   โ”‚   " generate arguments will also show up in this list)"                     โ”‚
โ”‚   1093 โ”‚   โ”‚   โ”‚   )                                                                             โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
ValueError: The following `model_kwargs` are not used by the model: ['input_ids'] (note: typos in the 
generate arguments will also show up in this list)

Versions:

  • Python: 3.10.10
  • numpy: 1.24.2
  • sentencepiece: 0.1.98
  • soundfile: 0.12.1
  • tokenizers: 0.13.2
  • torch: 2.0.0
  • torchaudio: 2.0.1
  • transformers: 4.26.1

Sign up or log in to comment