toth235a commited on
Commit
cd4f07d
·
verified ·
1 Parent(s): 651333d

Upload qc_viewer_colab.ipynb with huggingface_hub

Browse files
Files changed (1) hide show
  1. qc_viewer_colab.ipynb +226 -0
qc_viewer_colab.ipynb ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# VoxPopuli QC Samples V3 - CER Viewer\n",
8
+ "\n",
9
+ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/toth235a/voxpopuli-qc-samples-v3/blob/main/qc_viewer_colab.ipynb)\n",
10
+ "\n",
11
+ "Quality control samples categorized by Character Error Rate (CER) between Whisper and Parakeet transcriptions.\n",
12
+ "\n",
13
+ "**CER Bins:**\n",
14
+ "- `cer_02_05`: 2-5% CER (good reference)\n",
15
+ "- `cer_05_10`: 5-10% CER (slight difference)\n",
16
+ "- `cer_10_20`: 10-20% CER (moderate difference)\n",
17
+ "- `cer_20_30`: 20-30% CER (significant difference)\n",
18
+ "- `cer_30_50`: 30-50% CER (very different)\n",
19
+ "- `cer_50_plus`: 50%+ CER (extremely different)"
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "execution_count": null,
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "# Install dependencies\n",
29
+ "!pip install -q datasets ipywidgets"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": null,
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "from datasets import load_dataset\n",
39
+ "from IPython.display import display, Audio, HTML, clear_output\n",
40
+ "import ipywidgets as widgets\n",
41
+ "\n",
42
+ "# Load dataset from HuggingFace\n",
43
+ "ds = load_dataset(\"toth235a/voxpopuli-qc-samples-v3\", split=\"train\")\n",
44
+ "print(f\"Loaded {len(ds)} samples\")\n",
45
+ "print(f\"Columns: {ds.column_names}\")"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": null,
51
+ "metadata": {},
52
+ "outputs": [],
53
+ "source": [
54
+ "# Group by CER bin\n",
55
+ "bins = {}\n",
56
+ "for i, sample in enumerate(ds):\n",
57
+ " bin_name = sample['cer_bin']\n",
58
+ " if bin_name not in bins:\n",
59
+ " bins[bin_name] = []\n",
60
+ " bins[bin_name].append((i, sample))\n",
61
+ "\n",
62
+ "bin_order = ['cer_02_05', 'cer_05_10', 'cer_10_20', 'cer_20_30', 'cer_30_50', 'cer_50_plus']\n",
63
+ "print(f\"Bins: {[b for b in bin_order if b in bins]}\")"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": null,
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "def display_sample(idx, sample):\n",
73
+ " \"\"\"Display a single sample with full transcripts (NO truncation).\"\"\"\n",
74
+ " \n",
75
+ " # Header with metadata\n",
76
+ " html = f\"\"\"\n",
77
+ " <div style=\"border: 2px solid #333; padding: 15px; margin: 10px 0; border-radius: 8px; background: #f9f9f9;\">\n",
78
+ " <h3 style=\"margin-top: 0;\">Sample: {sample['id']}</h3>\n",
79
+ " <table style=\"width: 100%; margin-bottom: 15px;\">\n",
80
+ " <tr>\n",
81
+ " <td><b>CER Bin:</b> {sample['cer_bin']}</td>\n",
82
+ " <td><b>CER:</b> {sample['cer']:.1%}</td>\n",
83
+ " <td><b>Duration:</b> {sample['duration']:.1f}s</td>\n",
84
+ " </tr>\n",
85
+ " </table>\n",
86
+ " </div>\n",
87
+ " \"\"\"\n",
88
+ " display(HTML(html))\n",
89
+ " \n",
90
+ " # Audio player\n",
91
+ " audio_data = sample['audio']\n",
92
+ " display(Audio(audio_data['array'], rate=audio_data['sampling_rate']))\n",
93
+ " \n",
94
+ " # Full transcripts - NO TRUNCATION\n",
95
+ " whisper = sample['whisper_text']\n",
96
+ " parakeet = sample['parakeet_text']\n",
97
+ " \n",
98
+ " transcript_html = f\"\"\"\n",
99
+ " <div style=\"margin-top: 15px;\">\n",
100
+ " <div style=\"background: #e8f4e8; padding: 12px; border-radius: 6px; margin-bottom: 10px;\">\n",
101
+ " <b style=\"color: #2d5a2d;\">Whisper ({len(whisper)} chars):</b>\n",
102
+ " <p style=\"white-space: pre-wrap; word-wrap: break-word; margin: 8px 0 0 0; font-family: monospace; font-size: 13px;\">{whisper}</p>\n",
103
+ " </div>\n",
104
+ " <div style=\"background: #e8e8f4; padding: 12px; border-radius: 6px;\">\n",
105
+ " <b style=\"color: #2d2d5a;\">Parakeet ({len(parakeet)} chars):</b>\n",
106
+ " <p style=\"white-space: pre-wrap; word-wrap: break-word; margin: 8px 0 0 0; font-family: monospace; font-size: 13px;\">{parakeet}</p>\n",
107
+ " </div>\n",
108
+ " </div>\n",
109
+ " \"\"\"\n",
110
+ " display(HTML(transcript_html))"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": null,
116
+ "metadata": {},
117
+ "outputs": [],
118
+ "source": [
119
+ "# Interactive viewer\n",
120
+ "bin_dropdown = widgets.Dropdown(\n",
121
+ " options=[(f\"{b} ({len(bins.get(b, []))} samples)\", b) for b in bin_order if b in bins],\n",
122
+ " description='CER Bin:',\n",
123
+ " style={'description_width': '80px'}\n",
124
+ ")\n",
125
+ "\n",
126
+ "sample_slider = widgets.IntSlider(\n",
127
+ " min=0, max=9, value=0,\n",
128
+ " description='Sample #:',\n",
129
+ " style={'description_width': '80px'}\n",
130
+ ")\n",
131
+ "\n",
132
+ "output = widgets.Output()\n",
133
+ "\n",
134
+ "def update_display(*args):\n",
135
+ " with output:\n",
136
+ " clear_output(wait=True)\n",
137
+ " bin_name = bin_dropdown.value\n",
138
+ " idx = sample_slider.value\n",
139
+ " if bin_name in bins and idx < len(bins[bin_name]):\n",
140
+ " ds_idx, sample = bins[bin_name][idx]\n",
141
+ " display_sample(ds_idx, sample)\n",
142
+ "\n",
143
+ "def on_bin_change(*args):\n",
144
+ " bin_name = bin_dropdown.value\n",
145
+ " sample_slider.max = len(bins.get(bin_name, [])) - 1\n",
146
+ " sample_slider.value = 0\n",
147
+ " update_display()\n",
148
+ "\n",
149
+ "bin_dropdown.observe(on_bin_change, names='value')\n",
150
+ "sample_slider.observe(update_display, names='value')\n",
151
+ "\n",
152
+ "# Navigation buttons\n",
153
+ "prev_btn = widgets.Button(description='< Prev', button_style='info')\n",
154
+ "next_btn = widgets.Button(description='Next >', button_style='info')\n",
155
+ "\n",
156
+ "def on_prev(b):\n",
157
+ " if sample_slider.value > 0:\n",
158
+ " sample_slider.value -= 1\n",
159
+ "\n",
160
+ "def on_next(b):\n",
161
+ " if sample_slider.value < sample_slider.max:\n",
162
+ " sample_slider.value += 1\n",
163
+ "\n",
164
+ "prev_btn.on_click(on_prev)\n",
165
+ "next_btn.on_click(on_next)\n",
166
+ "\n",
167
+ "# Layout\n",
168
+ "controls = widgets.HBox([bin_dropdown, sample_slider, prev_btn, next_btn])\n",
169
+ "display(controls)\n",
170
+ "display(output)\n",
171
+ "\n",
172
+ "# Initial display\n",
173
+ "on_bin_change()"
174
+ ]
175
+ },
176
+ {
177
+ "cell_type": "markdown",
178
+ "metadata": {},
179
+ "source": [
180
+ "---\n",
181
+ "## Browse All Samples in a Bin"
182
+ ]
183
+ },
184
+ {
185
+ "cell_type": "code",
186
+ "execution_count": null,
187
+ "metadata": {},
188
+ "outputs": [],
189
+ "source": [
190
+ "# Change this to view different bins\n",
191
+ "BIN_TO_SHOW = 'cer_50_plus'\n",
192
+ "\n",
193
+ "for ds_idx, sample in bins.get(BIN_TO_SHOW, []):\n",
194
+ " display_sample(ds_idx, sample)\n",
195
+ " display(HTML(\"<hr style='border: 1px dashed #ccc; margin: 20px 0;'>\"))"
196
+ ]
197
+ },
198
+ {
199
+ "cell_type": "code",
200
+ "execution_count": null,
201
+ "metadata": {},
202
+ "outputs": [],
203
+ "source": [
204
+ "# Summary table\n",
205
+ "print(\"All samples summary:\")\n",
206
+ "print(f\"{'ID':<20} {'Bin':<15} {'CER':>8} {'Duration':>10}\")\n",
207
+ "print(\"-\" * 55)\n",
208
+ "for sample in sorted(ds, key=lambda x: (x['cer_bin'], x['cer'])):\n",
209
+ " print(f\"{sample['id']:<20} {sample['cer_bin']:<15} {sample['cer']:>7.1%} {sample['duration']:>9.1f}s\")"
210
+ ]
211
+ }
212
+ ],
213
+ "metadata": {
214
+ "kernelspec": {
215
+ "display_name": "Python 3",
216
+ "language": "python",
217
+ "name": "python3"
218
+ },
219
+ "language_info": {
220
+ "name": "python",
221
+ "version": "3.10.0"
222
+ }
223
+ },
224
+ "nbformat": 4,
225
+ "nbformat_minor": 4
226
+ }