jefffffff9 Claude Sonnet 4.6 commited on
Commit
262db3e
·
1 Parent(s): 65e1d64

Fix Cell 12: add diagnostics + synthetic fallback cell (12b)

Browse files

Cell 12 now prints which sources loaded and why before raising so the
user knows exactly what to fix (HF_TOKEN not attached, Common Voice
terms not accepted, etc.).

Cell 12b (new): synthetic fallback using vocabulary.jsonl entries and
silent audio so the training pipeline can be validated end-to-end even
before real data is available. Skips itself if Cell 12 succeeded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

notebooks/kaggle_master_trainer.ipynb CHANGED
@@ -119,7 +119,15 @@
119
  "id": "cell-merge",
120
  "metadata": {},
121
  "outputs": [],
122
- "source": "# ── Cell 12: Build & merge all datasets ──────────────────────────────────────\n# Order of priority: user corrections (upsampled) → WaxalNLP → external\nfrom datasets import Dataset, Audio as HFAudio, concatenate_datasets\nfrom functools import partial\n\nall_parts = []\n\n# ── Part A: User corrections from sahel-agri-feedback ─────────────────────\nif correction_records:\n print(f'Part A: {len(correction_records)} corrections × {CORRECTION_REPEAT} upsample')\n rec_list = correction_records * CORRECTION_REPEAT\n corr_ds = Dataset.from_dict({\n 'audio': [r['local_audio'] for r in rec_list],\n 'transcription': [\n r.get('corrected_text') or r.get('transcription', '') for r in rec_list\n ],\n })\n corr_ds = corr_ds.cast_column('audio', HFAudio(sampling_rate=TARGET_SR))\n corr_ds = corr_ds.map(\n partial(prepare_dataset, text_col='transcription'),\n remove_columns=corr_ds.column_names,\n )\n all_parts.append(corr_ds)\n print(f' → {len(corr_ds)} samples ready')\nelse:\n print('Part A: no corrections available — skipping')\n\n# ── Part B: WaxalNLP / FLEURS ──────────────────────────────────────────────\nif waxal_ds is not None:\n print(f'Part B: materialising up to {MAX_WAXAL_TRAIN} WaxalNLP samples ...')\n waxal_capped = waxal_ds.take(MAX_WAXAL_TRAIN)\n waxal_rows = list(waxal_capped)\n print(f' Fetched {len(waxal_rows)} rows')\n\n waxal_local = Dataset.from_dict({\n 'audio': [r['audio'] for r in waxal_rows],\n 'transcription': [r.get(WAXAL_TEXT_COL, '') for r in waxal_rows],\n })\n waxal_local = waxal_local.cast_column('audio', HFAudio(sampling_rate=TARGET_SR))\n waxal_local = waxal_local.map(\n partial(prepare_dataset, text_col='transcription'),\n remove_columns=waxal_local.column_names,\n num_proc=2,\n )\n all_parts.append(waxal_local)\n print(f' → {len(waxal_local)} samples ready')\n\n# ── Part C: External datasets ─────────────────────────────────────────────\nfor ext_ds, text_col in external_datasets:\n ext_rows = list(ext_ds) # already capped by .take() in Cell 9\n if not ext_rows:\n continue\n ext_local = Dataset.from_dict({\n 'audio': [r['audio'] for r in ext_rows],\n 'transcription': [r.get(text_col, '') for r in ext_rows],\n })\n ext_local = ext_local.cast_column('audio', HFAudio(sampling_rate=TARGET_SR))\n ext_local = ext_local.map(\n partial(prepare_dataset, text_col='transcription'),\n remove_columns=ext_local.column_names,\n num_proc=2,\n )\n all_parts.append(ext_local)\n print(f'Part C: {len(ext_local)} external samples ready')\n\n# ── Merge + train/eval split ──────────────────────────────────────────────\nif not all_parts:\n raise RuntimeError('No data loaded from any source — check config and HF_TOKEN')\n\ncombined = concatenate_datasets(all_parts).shuffle(seed=42)\nsplit = combined.train_test_split(test_size=min(0.05, 200 / len(combined)))\ntrain_ds = split['train']\neval_ds = split['test']\n\nprint(f'\\n✅ Dataset ready')\nprint(f' Train : {len(train_ds)}')\nprint(f' Eval : {len(eval_ds)}')"
 
 
 
 
 
 
 
 
123
  },
124
  {
125
  "cell_type": "markdown",
 
119
  "id": "cell-merge",
120
  "metadata": {},
121
  "outputs": [],
122
+ "source": "# -- Cell 12: Build & merge all datasets --------------------------------------\nfrom datasets import Dataset, Audio as HFAudio, concatenate_datasets\nfrom functools import partial\n\nall_parts = []\n\n# -- Part A: User corrections from sahel-agri-feedback ----------------------\nif correction_records:\n print(f'Part A: {len(correction_records)} corrections x {CORRECTION_REPEAT} upsample')\n rec_list = correction_records * CORRECTION_REPEAT\n corr_ds = Dataset.from_dict({\n 'audio': [r['local_audio'] for r in rec_list],\n 'transcription': [r.get('corrected_text') or r.get('transcription', '') for r in rec_list],\n })\n corr_ds = corr_ds.cast_column('audio', HFAudio(sampling_rate=TARGET_SR))\n corr_ds = corr_ds.map(\n partial(prepare_dataset, text_col='transcription'),\n remove_columns=corr_ds.column_names,\n )\n all_parts.append(corr_ds)\n print(f' -> {len(corr_ds)} samples ready')\nelse:\n print('Part A: no corrections available -- skipping')\n\n# -- Part B: WaxalNLP --------------------------------------------------------\nif waxal_ds is not None:\n print(f'Part B: materialising up to {MAX_WAXAL_TRAIN} WaxalNLP samples ...')\n waxal_rows = list(waxal_ds.take(MAX_WAXAL_TRAIN))\n print(f' fetched {len(waxal_rows)} rows')\n waxal_local = Dataset.from_dict({\n 'audio': [r['audio'] for r in waxal_rows],\n 'transcription': [r.get(WAXAL_TEXT_COL, '') for r in waxal_rows],\n })\n waxal_local = waxal_local.cast_column('audio', HFAudio(sampling_rate=TARGET_SR))\n waxal_local = waxal_local.map(\n partial(prepare_dataset, text_col='transcription'),\n remove_columns=waxal_local.column_names,\n num_proc=2,\n )\n all_parts.append(waxal_local)\n print(f' -> {len(waxal_local)} samples ready')\nelse:\n print('Part B: WaxalNLP not available -- skipping')\n\n# -- Part C: External datasets -----------------------------------------------\nfor ext_ds, text_col in external_datasets:\n ext_rows = list(ext_ds)\n if not ext_rows:\n print('Part C: external dataset empty -- skipping')\n continue\n print(f'Part C: processing {len(ext_rows)} external samples ...')\n ext_local = Dataset.from_dict({\n 'audio': [r['audio'] for r in ext_rows],\n 'transcription': [r.get(text_col, '') for r in ext_rows],\n })\n ext_local = ext_local.cast_column('audio', HFAudio(sampling_rate=TARGET_SR))\n ext_local = ext_local.map(\n partial(prepare_dataset, text_col='transcription'),\n remove_columns=ext_local.column_names,\n num_proc=2,\n )\n all_parts.append(ext_local)\n print(f' -> {len(ext_local)} samples ready')\n\n# -- Diagnostics before failing ----------------------------------------------\nprint(f'\\nData summary:')\nprint(f' corrections loaded : {len(correction_records)}')\nprint(f' waxal_ds available : {waxal_ds is not None}')\nprint(f' external sources : {len(external_datasets)}')\nprint(f' all_parts count : {len(all_parts)}')\n\nif not all_parts:\n print('\\nNo data was loaded. Common causes:')\n print(' 1. HF_TOKEN secret not attached (Add-ons -> Secrets -> toggle ON)')\n print(' 2. Common Voice terms not accepted at huggingface.co/datasets/mozilla-foundation/common_voice_17_0')\n print(' 3. TRAIN_LANG has no matching enabled dataset in Cell 4')\n print('\\nFor a quick test without any external data, run the cell below to')\n print('generate a small synthetic dataset and continue training.')\n raise RuntimeError('No data loaded -- see diagnostics above')\n\n# -- Merge + split -----------------------------------------------------------\ncombined = concatenate_datasets(all_parts).shuffle(seed=42)\nsplit = combined.train_test_split(test_size=min(0.05, 200 / len(combined)))\ntrain_ds = split['train']\neval_ds = split['test']\n\nprint(f'\\nDataset ready')\nprint(f' Train : {len(train_ds)}')\nprint(f' Eval : {len(eval_ds)}')"
123
+ },
124
+ {
125
+ "cell_type": "code",
126
+ "id": "5beb513a",
127
+ "source": "# -- Cell 12b: Synthetic fallback (SKIP if Cell 12 succeeded) ----------------\n# Run this cell ONLY if Cell 12 raised \"No data loaded\".\n# Generates 50 short silent audio samples labelled with vocabulary.jsonl\n# entries so training can proceed and you can verify the pipeline works.\n# Replace with real data (accept Common Voice terms, or add corrections) for\n# a meaningful model.\n\nimport numpy as np\nfrom datasets import Dataset, Audio as HFAudio, concatenate_datasets\nfrom functools import partial\n\nif 'train_ds' in dir() and train_ds is not None:\n print('Cell 12 succeeded -- nothing to do here.')\nelse:\n print('Building synthetic fallback dataset from vocabulary.jsonl ...')\n\n # Use vocab entries if available, otherwise generic phrases\n if vocab_entries:\n phrases = [e.get('word', 'test') for e in vocab_entries[:50]]\n else:\n phrases = [f'word {i}' for i in range(50)]\n\n SR = TARGET_SR\n rows = []\n for phrase in phrases:\n # 1-second silent audio (safe baseline for feature extraction)\n audio_array = np.zeros(SR, dtype=np.float32)\n rows.append({'audio_array': audio_array, 'transcription': phrase})\n\n # Build dataset directly from numpy arrays\n synth_ds = Dataset.from_dict({\n 'transcription': [r['transcription'] for r in rows],\n })\n\n # Add audio column manually\n def _add_audio(batch, idx):\n batch['input_features'] = processor.feature_extractor(\n np.zeros(TARGET_SR, dtype=np.float32), sampling_rate=TARGET_SR\n ).input_features[0]\n cleaned = clean_text(rows[idx]['transcription'], lang=TRAIN_LANG)\n batch['labels'] = processor.tokenizer(cleaned).input_ids\n return batch\n\n synth_processed = synth_ds.map(\n _add_audio,\n with_indices=True,\n remove_columns=synth_ds.column_names,\n )\n\n split = synth_processed.train_test_split(test_size=0.1, seed=42)\n train_ds = split['train']\n eval_ds = split['test']\n print(f'Synthetic fallback: {len(train_ds)} train, {len(eval_ds)} eval')\n print('WARNING: training on synthetic data produces a non-functional model.')\n print('Accept Common Voice terms and re-run Cell 9 + Cell 12 for real data.')",
128
+ "metadata": {},
129
+ "execution_count": null,
130
+ "outputs": []
131
  },
132
  {
133
  "cell_type": "markdown",