Repository: huggingface/transformers
Pull request: wav2vec2 fixes

The `wav2vec2` model tests use a dataset that is no longer compatible with `datasets`, so this PR replaces it with a newer dataset and changes the expected transcriptions. They match the dataset labels close enough.

cc. @eustlb because this is an audio model

Changed files:
filename: tests/models/wav2vec2/test_modeling_wav2vec2.py
patch: @@ -97,7 +97,7 @@ def _test_wav2vec2_with_lm_invalid_pool(in_queue, out_queue, timeout):
     try:
         _ = in_queue.get(timeout=timeout)
 
-        ds = load_dataset("mozilla-foundation/common_voice_11_0", "es", split="test", streaming=True)
+        ds = load_dataset("fixie-ai/common_voice_17_0", "es", split="test", streaming=True)
         sample = next(iter(ds))
 
         resampled_audio = torchaudio.functional.resample(
@@ -118,16 +118,17 @@ def _test_wav2vec2_with_lm_invalid_pool(in_queue, out_queue, timeout):
         with CaptureLogger(pyctcdecode.decoder.logger) as cl, multiprocessing.get_context("spawn").Pool(1) as pool:
             transcription = processor.batch_decode(logits.cpu().numpy(), pool).text
 
+        expected_transcription = "el resto de los equipos se mantienen en su sede"
         unittest.TestCase().assertIn("Falling back to sequential decoding.", cl.out)
-        unittest.TestCase().assertEqual(transcription[0], "habitan aguas poco profundas y rocosas")
+        unittest.TestCase().assertEqual(transcription[0], expected_transcription)
 
         # force batch_decode to internally create a spawn pool, which should trigger a warning if different than fork
         multiprocessing.set_start_method("spawn", force=True)
         with CaptureLogger(processing_wav2vec2_with_lm.logger) as cl:
             transcription = processor.batch_decode(logits.cpu().numpy()).text
 
         unittest.TestCase().assertIn("Falling back to sequential decoding.", cl.out)
-        unittest.TestCase().assertEqual(transcription[0], "habitan aguas poco profundas y rocosas")
+        unittest.TestCase().assertEqual(transcription[0], expected_transcription)
     except Exception:
         error = f"{traceback.format_exc()}"
 
@@ -1828,7 +1829,7 @@ def test_phoneme_recognition(self):
     @require_pyctcdecode
     @require_torchaudio
     def test_wav2vec2_with_lm(self):
-        ds = load_dataset("mozilla-foundation/common_voice_11_0", "es", split="test", streaming=True)
+        ds = load_dataset("fixie-ai/common_voice_17_0", "es", split="test", streaming=True)
         sample = next(iter(ds))
 
         resampled_audio = torchaudio.functional.resample(
@@ -1847,12 +1848,13 @@ def test_wav2vec2_with_lm(self):
 
         transcription = processor.batch_decode(logits.cpu().numpy()).text
 
-        self.assertEqual(transcription[0], "habitan aguas poco profundas y rocosas")
+        expected_transcription = "el resto de los equipos se mantienen en su sede"
+        self.assertEqual(transcription[0], expected_transcription)
 
     @require_pyctcdecode
     @require_torchaudio
     def test_wav2vec2_with_lm_pool(self):
-        ds = load_dataset("mozilla-foundation/common_voice_11_0", "es", split="test", streaming=True)
+        ds = load_dataset("fixie-ai/common_voice_17_0", "es", split="test", streaming=True)
         sample = next(iter(ds))
 
         resampled_audio = torchaudio.functional.resample(
@@ -1873,7 +1875,8 @@ def test_wav2vec2_with_lm_pool(self):
         with multiprocessing.get_context("fork").Pool(2) as pool:
             transcription = processor.batch_decode(logits.cpu().numpy(), pool).text
 
-        self.assertEqual(transcription[0], "habitan aguas poco profundas y rocosas")
+        expected_transcription = "el resto de los equipos se mantienen en su sede"
+        self.assertEqual(transcription[0], expected_transcription)
 
         # user-managed pool + num_processes should trigger a warning
         with (
@@ -1885,7 +1888,7 @@ def test_wav2vec2_with_lm_pool(self):
         self.assertIn("num_process", cl.out)
         self.assertIn("it will be ignored", cl.out)
 
-        self.assertEqual(transcription[0], "habitan aguas poco profundas y rocosas")
+        self.assertEqual(transcription[0], expected_transcription)
 
     @require_pyctcdecode
     @require_torchaudio
@@ -1951,7 +1954,7 @@ def test_inference_mms_1b_all(self):
         LANG_MAP = {"it": "ita", "es": "spa", "fr": "fra", "en": "eng"}
 
         def run_model(lang):
-            ds = load_dataset("mozilla-foundation/common_voice_11_0", lang, split="test", streaming=True)
+            ds = load_dataset("fixie-ai/common_voice_17_0", lang, split="test", streaming=True)
             sample = next(iter(ds))
 
             wav2vec2_lang = LANG_MAP[lang]
@@ -1976,9 +1979,9 @@ def run_model(lang):
             return transcription
 
         TRANSCRIPTIONS = {
-            "it": "il libro ha suscitato molte polemiche a causa dei suoi contenuti",
-            "es": "habitan aguas poco profundas y rocosas",
-            "fr": "ce dernier est volé tout au long de l'histoire romaine",
+            "it": "viaggiarono in italia dove lavorarono con hamilton",
+            "es": "el resto de los equipos se mantienen en su sede",
+            "fr": "il a obtenu son batchelor of lows",
             "en": "joe keton disapproved of films and buster also had reservations about the media",
         }