Skip to content

Commit 2d17a1d

Browse files
satraclaude
andauthored
Minimal installs per tutorial + restart runtime admonition (#458)
- Each tutorial installs only the extras it needs: - Most: just "senselab" (core audio) - forced_alignment, speech_to_text: "senselab[nlp]" - pose_estimation: "senselab[video]" - Added restart admonition after install cell: uv upgrades packages (numpy etc.) without Colab's restart prompt Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1adefbe commit 2d17a1d

16 files changed

Lines changed: 332 additions & 23 deletions

tutorials/audio/00_getting_started.ipynb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@
4040
},
4141
"outputs": [],
4242
"source": [
43-
"# Install senselab and dependencies\n",
44-
"!pip install -q uv\n",
45-
"!uv pip install --pre --system \"senselab[nlp,text,video]\""
43+
"# Install senselab and dependencies\n!pip install -q uv\n!uv pip install --pre --system \"senselab\"\n"
44+
]
45+
},
46+
{
47+
"cell_type": "markdown",
48+
"metadata": {},
49+
"source": [
50+
"> **\u26a0\ufe0f Restart runtime after install**\n",
51+
">\n",
52+
"> The install may upgrade packages (e.g., numpy) that are already loaded.\n",
53+
"> Go to **Runtime \u2192 Restart session**, then **run all cells below** (skip this install cell).\n"
4654
]
4755
},
4856
{

tutorials/audio/audio_data_augmentation.ipynb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@
2727
"source": [
2828
"# Install senselab and dependencies\n",
2929
"!pip install -q uv\n",
30-
"!uv pip install --pre --system \"senselab[nlp,text,video]\""
30+
"!uv pip install --pre --system \"senselab\""
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"metadata": {},
36+
"source": [
37+
"> **\u26a0\ufe0f Restart runtime after install**\n",
38+
">\n",
39+
"> The install may upgrade packages (e.g., numpy) that are already loaded.\n",
40+
"> Go to **Runtime \u2192 Restart session**, then **run all cells below** (skip this install cell).\n"
3141
]
3242
},
3343
{

tutorials/audio/conversational_data_exploration.ipynb

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,18 @@
4444
"source": [
4545
"# Install senselab and dependencies\n",
4646
"!pip install -q uv\n",
47-
"!uv pip install --pre --system \"senselab[nlp,text,video]\""
47+
"!uv pip install --pre --system \"senselab\""
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"id": "9a63283cbaf04dbcab1f6479b197f3a8",
53+
"metadata": {},
54+
"source": [
55+
"> **\u26a0\ufe0f Restart runtime after install**\n",
56+
">\n",
57+
"> The install may upgrade packages (e.g., numpy) that are already loaded.\n",
58+
"> Go to **Runtime \u2192 Restart session**, then **run all cells below** (skip this install cell).\n"
4859
]
4960
},
5061
{
@@ -118,7 +129,40 @@
118129
"metadata": {},
119130
"outputs": [],
120131
"source": [
121-
"# Necessary libraries\nimport json\nimport os\n\nimport torch\n\n# Audio data structure\nfrom senselab.audio.data_structures import Audio\n\n# Feature extraction API\nfrom senselab.audio.tasks.features_extraction import extract_features_from_audios\nfrom senselab.audio.tasks.input_output.utils import read_audios\n\n# Pre\u2011processing functions\nfrom senselab.audio.tasks.preprocessing.preprocessing import (\n downmix_audios_to_mono,\n extract_segments,\n resample_audios,\n)\n\n# Speaker diarization API\nfrom senselab.audio.tasks.speaker_diarization import diarize_audios\n\n# Speaker embeddings extraction API\nfrom senselab.audio.tasks.speaker_embeddings import extract_speaker_embeddings_from_audios\n\n# Automatic Speech Recognition API\nfrom senselab.audio.tasks.speech_to_text import transcribe_audios\n\n# Self-supervised embeddings extraction API\nfrom senselab.audio.tasks.ssl_embeddings import extract_ssl_embeddings_from_audios\n\n# Utility classes for specifying models and devices\nfrom senselab.utils.data_structures import HFModel, SpeechBrainModel"
132+
"# Necessary libraries\n",
133+
"import json\n",
134+
"import os\n",
135+
"\n",
136+
"import torch\n",
137+
"\n",
138+
"# Audio data structure\n",
139+
"from senselab.audio.data_structures import Audio\n",
140+
"\n",
141+
"# Feature extraction API\n",
142+
"from senselab.audio.tasks.features_extraction import extract_features_from_audios\n",
143+
"from senselab.audio.tasks.input_output.utils import read_audios\n",
144+
"\n",
145+
"# Pre\u2011processing functions\n",
146+
"from senselab.audio.tasks.preprocessing.preprocessing import (\n",
147+
" downmix_audios_to_mono,\n",
148+
" extract_segments,\n",
149+
" resample_audios,\n",
150+
")\n",
151+
"\n",
152+
"# Speaker diarization API\n",
153+
"from senselab.audio.tasks.speaker_diarization import diarize_audios\n",
154+
"\n",
155+
"# Speaker embeddings extraction API\n",
156+
"from senselab.audio.tasks.speaker_embeddings import extract_speaker_embeddings_from_audios\n",
157+
"\n",
158+
"# Automatic Speech Recognition API\n",
159+
"from senselab.audio.tasks.speech_to_text import transcribe_audios\n",
160+
"\n",
161+
"# Self-supervised embeddings extraction API\n",
162+
"from senselab.audio.tasks.ssl_embeddings import extract_ssl_embeddings_from_audios\n",
163+
"\n",
164+
"# Utility classes for specifying models and devices\n",
165+
"from senselab.utils.data_structures import HFModel, SpeechBrainModel"
122166
]
123167
},
124168
{
@@ -169,7 +213,18 @@
169213
"metadata": {},
170214
"outputs": [],
171215
"source": [
172-
"# Perform speaker diarization on the pre\u2011processed audio.\n# We use the NVIDIA Sortformer model from Hugging\u00a0Face. You can change the model path\n# if you want to experiment with other diarization models.\n# \"nvidia/diar_sortformer_4spk-v1\" is generally pretty good, but can only detect up to 4 speakers\ndiar_model = HFModel(path_or_uri=\"nvidia/diar_sortformer_4spk-v1\")\n\n# Run the diarization. The output is a list (one per audio file) of lists of\n# `ScriptLine` objects. Each ScriptLine has a `speaker` label and start/end times (in seconds).\ndiarization_results = diarize_audios(\n audios=audios,\n model=diar_model,\n)"
216+
"# Perform speaker diarization on the pre\u2011processed audio.\n",
217+
"# We use the NVIDIA Sortformer model from Hugging\u00a0Face. You can change the model path\n",
218+
"# if you want to experiment with other diarization models.\n",
219+
"# \"nvidia/diar_sortformer_4spk-v1\" is generally pretty good, but can only detect up to 4 speakers\n",
220+
"diar_model = HFModel(path_or_uri=\"nvidia/diar_sortformer_4spk-v1\")\n",
221+
"\n",
222+
"# Run the diarization. The output is a list (one per audio file) of lists of\n",
223+
"# `ScriptLine` objects. Each ScriptLine has a `speaker` label and start/end times (in seconds).\n",
224+
"diarization_results = diarize_audios(\n",
225+
" audios=audios,\n",
226+
" model=diar_model,\n",
227+
")"
173228
]
174229
},
175230
{

tutorials/audio/extract_speaker_embeddings.ipynb

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@
2525
"source": [
2626
"# Install senselab and dependencies\n",
2727
"!pip install -q uv\n",
28-
"!uv pip install --pre --system \"senselab[nlp,text,video]\""
28+
"!uv pip install --pre --system \"senselab\""
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"> **\u26a0\ufe0f Restart runtime after install**\n",
36+
">\n",
37+
"> The install may upgrade packages (e.g., numpy) that are already loaded.\n",
38+
"> Go to **Runtime \u2192 Restart session**, then **run all cells below** (skip this install cell).\n"
2939
]
3040
},
3141
{
@@ -115,7 +125,60 @@
115125
"metadata": {},
116126
"outputs": [],
117127
"source": [
118-
"from senselab.utils.tasks.cosine_similarity import compute_cosine_similarity\n\n\n# DIRECTLY PLOT THE EMBEDDINGS FOR THE TWO FILES\ndef plot_embedding_heatmap(embeddings: List[torch.Tensor], titles: List[str]) -> None:\n \"\"\"Plot a heatmap of a list of speaker embeddings.\"\"\"\n fig, axes = plt.subplots(len(embeddings), 1, figsize=(10, 5 * len(embeddings)))\n if len(embeddings) == 1:\n axes = [axes]\n\n for ax, embedding, title in zip(axes, embeddings, titles):\n im = ax.imshow(embedding.cpu().unsqueeze(0), aspect=\"auto\", cmap=\"viridis\")\n ax.set_title(f\"Speaker Embedding: {title}\")\n ax.set_xlabel(\"Embedding Dimension\")\n fig.colorbar(im, ax=ax)\n\n plt.tight_layout()\n plt.show()\n\n\nplot_embedding_heatmap(embeddings, [\"file 1\", \"file 2\"])\n\n\n# PLOT THE COSINE SIMILARITY MATRIX FOR THE TWO FILES\ndef plot_similarity_matrix(embeddings: List[torch.Tensor], labels: List[str]) -> None:\n \"\"\"Plot a similarity matrix for a list of embeddings.\"\"\"\n n = len(embeddings)\n similarity_matrix = np.zeros((n, n))\n\n for i in range(n):\n for j in range(n):\n similarity_matrix[i, j] = compute_cosine_similarity(embeddings[i], embeddings[j])\n\n fig, ax = plt.subplots(figsize=(8, 6))\n im = ax.imshow(similarity_matrix, cmap=\"coolwarm\", vmin=-1, vmax=1)\n\n ax.set_xticks(np.arange(n))\n ax.set_yticks(np.arange(n))\n ax.set_xticklabels(labels)\n ax.set_yticklabels(labels)\n\n plt.setp(ax.get_xticklabels(), rotation=45, ha=\"right\", rotation_mode=\"anchor\")\n\n for i in range(n):\n for j in range(n):\n ax.text(j, i, f\"{similarity_matrix[i, j]:.2f}\", ha=\"center\", va=\"center\", color=\"black\")\n\n ax.set_title(\"Cosine Similarity Between Speaker Embeddings\")\n fig.colorbar(im)\n plt.tight_layout()\n plt.show()\n\n\nplot_similarity_matrix(embeddings, [\"file 1\", \"file 2\"])"
128+
"from senselab.utils.tasks.cosine_similarity import compute_cosine_similarity\n",
129+
"\n",
130+
"\n",
131+
"# DIRECTLY PLOT THE EMBEDDINGS FOR THE TWO FILES\n",
132+
"def plot_embedding_heatmap(embeddings: List[torch.Tensor], titles: List[str]) -> None:\n",
133+
" \"\"\"Plot a heatmap of a list of speaker embeddings.\"\"\"\n",
134+
" fig, axes = plt.subplots(len(embeddings), 1, figsize=(10, 5 * len(embeddings)))\n",
135+
" if len(embeddings) == 1:\n",
136+
" axes = [axes]\n",
137+
"\n",
138+
" for ax, embedding, title in zip(axes, embeddings, titles):\n",
139+
" im = ax.imshow(embedding.cpu().unsqueeze(0), aspect=\"auto\", cmap=\"viridis\")\n",
140+
" ax.set_title(f\"Speaker Embedding: {title}\")\n",
141+
" ax.set_xlabel(\"Embedding Dimension\")\n",
142+
" fig.colorbar(im, ax=ax)\n",
143+
"\n",
144+
" plt.tight_layout()\n",
145+
" plt.show()\n",
146+
"\n",
147+
"\n",
148+
"plot_embedding_heatmap(embeddings, [\"file 1\", \"file 2\"])\n",
149+
"\n",
150+
"\n",
151+
"# PLOT THE COSINE SIMILARITY MATRIX FOR THE TWO FILES\n",
152+
"def plot_similarity_matrix(embeddings: List[torch.Tensor], labels: List[str]) -> None:\n",
153+
" \"\"\"Plot a similarity matrix for a list of embeddings.\"\"\"\n",
154+
" n = len(embeddings)\n",
155+
" similarity_matrix = np.zeros((n, n))\n",
156+
"\n",
157+
" for i in range(n):\n",
158+
" for j in range(n):\n",
159+
" similarity_matrix[i, j] = compute_cosine_similarity(embeddings[i], embeddings[j])\n",
160+
"\n",
161+
" fig, ax = plt.subplots(figsize=(8, 6))\n",
162+
" im = ax.imshow(similarity_matrix, cmap=\"coolwarm\", vmin=-1, vmax=1)\n",
163+
"\n",
164+
" ax.set_xticks(np.arange(n))\n",
165+
" ax.set_yticks(np.arange(n))\n",
166+
" ax.set_xticklabels(labels)\n",
167+
" ax.set_yticklabels(labels)\n",
168+
"\n",
169+
" plt.setp(ax.get_xticklabels(), rotation=45, ha=\"right\", rotation_mode=\"anchor\")\n",
170+
"\n",
171+
" for i in range(n):\n",
172+
" for j in range(n):\n",
173+
" ax.text(j, i, f\"{similarity_matrix[i, j]:.2f}\", ha=\"center\", va=\"center\", color=\"black\")\n",
174+
"\n",
175+
" ax.set_title(\"Cosine Similarity Between Speaker Embeddings\")\n",
176+
" fig.colorbar(im)\n",
177+
" plt.tight_layout()\n",
178+
" plt.show()\n",
179+
"\n",
180+
"\n",
181+
"plot_similarity_matrix(embeddings, [\"file 1\", \"file 2\"])"
119182
]
120183
},
121184
{

tutorials/audio/features_extraction.ipynb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@
2020
"source": [
2121
"# Install senselab and dependencies\n",
2222
"!pip install -q uv\n",
23-
"!uv pip install --pre --system \"senselab[nlp,text,video]\""
23+
"!uv pip install --pre --system \"senselab\""
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"metadata": {},
29+
"source": [
30+
"> **\u26a0\ufe0f Restart runtime after install**\n",
31+
">\n",
32+
"> The install may upgrade packages (e.g., numpy) that are already loaded.\n",
33+
"> Go to **Runtime \u2192 Restart session**, then **run all cells below** (skip this install cell).\n"
2434
]
2535
},
2636
{

tutorials/audio/forced_alignment.ipynb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@
2323
"source": [
2424
"# Install senselab and dependencies\n",
2525
"!pip install -q uv\n",
26-
"!uv pip install --pre --system \"senselab[nlp,text,video]\""
26+
"!uv pip install --pre --system \"senselab[nlp]\""
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"id": "7fb27b941602401d91542211134fc71a",
32+
"metadata": {},
33+
"source": [
34+
"> **\u26a0\ufe0f Restart runtime after install**\n",
35+
">\n",
36+
"> The install may upgrade packages (e.g., numpy) that are already loaded.\n",
37+
"> Go to **Runtime \u2192 Restart session**, then **run all cells below** (skip this install cell).\n"
2738
]
2839
},
2940
{

tutorials/audio/speaker_diarization.ipynb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@
1919
"source": [
2020
"# Install senselab and dependencies\n",
2121
"!pip install -q uv\n",
22-
"!uv pip install --pre --system \"senselab[nlp,text,video]\""
22+
"!uv pip install --pre --system \"senselab\""
23+
]
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"metadata": {},
28+
"source": [
29+
"> **\u26a0\ufe0f Restart runtime after install**\n",
30+
">\n",
31+
"> The install may upgrade packages (e.g., numpy) that are already loaded.\n",
32+
"> Go to **Runtime \u2192 Restart session**, then **run all cells below** (skip this install cell).\n"
2333
]
2434
},
2535
{

tutorials/audio/speaker_verification.ipynb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@
2121
"source": [
2222
"# Install senselab and dependencies\n",
2323
"!pip install -q uv\n",
24-
"!uv pip install --pre --system \"senselab[nlp,text,video]\""
24+
"!uv pip install --pre --system \"senselab\""
25+
]
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"metadata": {},
30+
"source": [
31+
"> **\u26a0\ufe0f Restart runtime after install**\n",
32+
">\n",
33+
"> The install may upgrade packages (e.g., numpy) that are already loaded.\n",
34+
"> Go to **Runtime \u2192 Restart session**, then **run all cells below** (skip this install cell).\n"
2535
]
2636
},
2737
{

0 commit comments

Comments
 (0)