After studying this material, students should be able to:
Definition:
Code-switching is the alternation between two or more languages within a single utterance or conversation
"I went to the tienda yesterday,
pero they were cerrado"
English ──────────────────────────────────
Spanish ↑ ↑ ↑
| Reason | Example |
|---|---|
| No equivalent word exists | Using "software" in any language |
| Social identity | Showing belonging to a group |
| Ease of expression | Switching when one language feels more natural |
Code-switching is extremely common in multilingual communities but rarely represented in training data for AI systems
Traditional AI Pipeline:
Speech → [Monolingual Model] → Output
↑
Trained on ONE language
Result: FAILS when speaker switches languages
1. Automatic Speech Recognition (ASR)
Input: "I want to comprar some milk"
Bad output: "I want to ??? some milk"
↑
Model doesn't recognize
Spanish word
2. Language Identification
Standard LID asks: "What language is this?"
CS utterance answer: "BOTH" ← systems aren't built for this
3. Speech Translation
Input (CS): English + Spanish mixed
System expects: ONE source language
Result: Translation errors or system failure
Typical Training Corpus:
[English data ████████████████████]
[Spanish data ████████████████████]
[French data ████████████████████]
[CS data ██ ] ← Very small!
Need CS data to train CS models
↓
Need CS models to find CS data
↑
Step 1: Transcribe speech → text
Step 2: Detect language switches in text
Step 3: Label as CS
Problem: Requires ACCURATE multilingual transcription
Which itself is hard without good CS models!
Think of them as pre-trained general-purpose models trained on massive amounts of data
Foundation Model Training:
Massive Speech Data → [Deep Neural Network] → Learned Representations
(thousands of hours) ↑
Learns general patterns
about speech, language,
acoustics, etc.
| Model | Type | What It Does |
|---|---|---|
| Whisper | Encoder-Decoder | Speech recognition across many languages |
| HuBERT | Self-supervised | Learns speech representations without labels |
| CNN baseline | Simple classifier | Basic language identification |
Input Audio Frame
↓
[Layer 1] → hidden state h₁ (vector of numbers)
↓
[Layer 2] → hidden state h₂
↓
[Layer N] → hidden state hₙ
↓
Output
Each hidden state is a high-dimensional vector encoding information about the input
A hidden state vector looks like:
h = [0.2, -0.8, 1.3, 0.0, -0.5, 2.1, ...]
dim1 dim2 dim3 dim4 dim5 dim6
Not all dimensions carry the same information!
Full Hidden State Vector:
[0.2, -0.8, 1.3, 0.0, -0.5, 2.1, 0.9, -1.2, ...]
Language-Selective Dimensions (subset):
[ -0.8, 0.0, 2.1, -1.2 ]
↑ ↑
Activates for Activates for
English Spanish
Think of it like a mixing board in a recording studio:
🎚️ Mixing Board (Hidden State)
Channel 1 (Bass): ████░░░░ ← General audio info
Channel 2 (Treble): ██████░░ ← General audio info
Channel 3 (English): ████████ ← LANGUAGE SELECTIVE!
Channel 4 (Spanish): ░░░░░░░░ ← LANGUAGE SELECTIVE!
Channel 5 (Rhythm): █████░░░ ← General audio info
Input: Monolingual recordings (English only, Spanish only)
For each dimension d in hidden state:
- Measure activation when processing English audio
- Measure activation when processing Spanish audio
- If activation differs significantly → LANGUAGE SELECTIVE!
Output: Set of dimensions D_English, D_Spanish
Visual:
Dimension 42:
English audio: activation = +2.3 ↑ HIGH
Spanish audio: activation = -0.1 ↓ LOW
→ Language-selective for English! ✓
Dimension 17:
English audio: activation = +1.1
Spanish audio: activation = +1.0
→ NOT language-selective ✗
Audio Utterance (3 seconds):
|-----|-----|-----|-----|-----|-----|
t1 t2 t3 t4 t5 t6 ← frames
For each frame, check language-selective dimensions:
t1: English dims HIGH, Spanish dims LOW → English
t2: English dims HIGH, Spanish dims LOW → English
t3: English dims LOW, Spanish dims HIGH → Spanish ← SWITCH!
t4: English dims LOW, Spanish dims HIGH → Spanish
t5: English dims HIGH, Spanish dims LOW → English ← SWITCH!
t6: English dims HIGH, Spanish dims LOW → English
Frame-level predictions: [EN, EN, ES, ES, EN, EN]
Question: Is this utterance code-switched?
If ONLY one language detected → NOT code-switched
If BOTH languages detected → CODE-SWITCHED ✓
Decision Rule (tuned on small CS set):
threshold θ: minimum % of frames in second language
If Spanish_frames / total_frames > θ → CS = True
Approach 1: Full Transcription Pipeline
Speech → [Large ASR Model] → Text → [Language Detector] → CS Label
Cost: HIGH (needs accurate multilingual ASR)
Data needed: LOTS
Approach 2: Train CS Classifier
Speech → [Collect CS data] → [Train model] → CS Label
Cost: MEDIUM
Data needed: LOTS of labeled CS data
Approach 3: This Paper's Method ← LIGHTWEIGHT
Speech → [Pretrained Encoder] → [Select dimensions] → CS Label
Cost: LOW
Data needed: Small CS set just for threshold tuning
| Component | Requirement |
|---|---|
| Pretrained model | Already exists (Whisper) |
| Monolingual data | Easily available |
| CS labeled data | Very small set (just for threshold) |
| Training | None (no fine-tuning needed) |
CS-FLEURS Dataset:
- 14 language pairs
- Real code-switched speech
- Ground truth labels available
Method F1 Score
─────────────────────────────────────────
This paper (Whisper-small) 0.798 ████████████████████ ← BEST
CNN baseline 0.776 ███████████████████
HuBERT linear baseline 0.751 ██████████████████
─────────────────────────────────────────
F1 Score: 0 = worst, 1.0 = perfect
F1 = 2 × (Precision × Recall) / (Precision + Recall)
Precision: Of utterances labeled CS, how many actually are CS?
Recall: Of actual CS utterances, how many did we find?
F1 balances both concerns
Current State:
Large Speech Collections → [Filter for CS] → CS Training Data
↑
This step is HARD
With This Method:
Large Speech Collections → [Lightweight CS Detector] → CS Training Data
↑
Fast, accurate,
no transcription needed
Better CS Detection
↓
More CS Training Data Found
↓
Better CS Models Trained
↓
Better CS Detection ← (cycle continues)
PROBLEM: Code-switching is hard for AI
Paper 1 (This paper):
"How do we FIND CS utterances in large datasets?"
Solution: Language-selective dimensions in speech encoders
Paper 2 (Progressive Refinement):
"How do we TRAIN better CS-ASR with limited data?"
Solution: Iterative pseudo-labeling
Paper 3 (End-to-End ST):
"How do we TRANSLATE CS speech?"
Solution: End-to-end speech translation models
Raw Audio Data
↓
[Paper 1: Detect CS utterances]
↓
CS-labeled Data
↓
[Paper 2: Train CS-ASR with pseudo-labeling]
↓
CS Transcriptions
↓
[Paper 3: Translate CS speech]
↓
Final Translation Output
| Concept | Core Idea |
|---|---|
| Code-switching | Mixing languages within one utterance |
| The problem | CS is common but underrepresented in AI training data |
| Foundation models | Pre-trained models encode rich language information |
| Language-selective dimensions | Specific hidden state dimensions activate for specific languages |
| Frame-level analysis | Analyzing speech moment-by-moment to detect language switches |
| Lightweight detection | No fine-tuning needed; small CS set sufficient for threshold tuning |
| Impact | Enables building better, more representative multilingual datasets |