How architparnami/few-shot-kws works
Purpose and execution surface
This is a research Python package for few-shot keyword spotting using prototypical networks. It prepares a speech-command dataset, trains episodic N-way/K-shot models, evaluates saved experiments, and analyzes result tables. Package installation is via setup.py; operational entry points are data/download_prepare_data.py, scripts/train/few_shot/run_train.py, scripts/train/few_shot/run_trainval.py, and scripts/predict/few_shot/eval.py.
Dataset preparation and episodic data boundary
data/download_prepare_data.py acquires and prepares the FS-KWS data consumed by the training package. protonets/data/FewShotSpeechData.py is the domain-specific dataset layer: it encodes keyword classes and experimental variants including background, silence, and unknown categories. protonets/data/base.py provides the base episodic-data abstraction. The key boundary is from prepared audio/features on disk into support/query episodes used by few-shot training and evaluation.
Paths:
• data/download_prepare_data.py
• protonets/data/FewShotSpeechData.py
• protonets/data/base.py
Prototypical-learning core
The few-shot model computes embeddings for support and query examples, forms class prototypes from support embeddings, and classifies queries by prototype distance. This logic is centered in protonets/models/few_shot.py; shared tensor/model operations are in protonets/models/utils.py. The generic training/evaluation orchestration is in protonets/engine.py, separating episodic optimization from speech-specific data and encoder choice.
Paths:
• protonets/models/few_shot.py
• protonets/engine.py
• protonets/models/utils.py
Pluggable speech embedding encoders
Encoder architectures are selected through a model factory rather than hardwired into the few-shot classifier. protonets/models/factory.py constructs configured models. Available embedding backbones include Google-style keyword-spotting CNNs and TC-ResNet variants, with common encoder utilities and defaults under the encoder package.
Paths:
• protonets/models/factory.py
• protonets/models/encoder/GoogleKWS.py
• protonets/models/encoder/TCResNet.py
Training control flow and experiment launch
Training wrappers receive num_ways, num_shots, experiment type, and experiment ID, then invoke Python runners. run_train.py/run_trainval.py drive training modes, while train.py/trainval.py implement the corresponding execution paths. Shell wrappers package standard experiments and include PBS/Grid Engine-style submission scripts, indicating optional HPC batch execution.
Paths:
• scripts/train/few_shot/run_train.py
• scripts/train/few_shot/train.py
• scripts/train/few_shot/fewshotspeech/qsub_train.sh
Evaluation and persisted outputs
Evaluation is separate from training and operates over saved experiment directories/checkpoints. scripts/predict/few_shot/eval.py performs episodic prediction; eval_results.py aggregates or reports results, and run_eval.py is a launcher. Results are persisted as experiment artifacts and CSV summaries, then explored through notebooks.
Paths:
• scripts/predict/few_shot/eval.py
• scripts/predict/few_shot/eval_results.py
• results/Analyze Results.ipynb
Runtime and dependencies
The runtime is Python with a locally installable protonets package, dependency set in requirements.txt, and likely deep-learning/audio libraries implied by the model and speech pipeline. Infrastructure is filesystem-based datasets, experiment/checkpoint directories, and optional cluster queue submission; no web service, database, or external online inference API is represented.
Paths:
• setup.py
• requirements.txt
• protonets/__init__.py
Main entry points: engine.py Episodic engine · factory.py Model factory · eval.py Episodic evaluation · few_shot.py Prototype classifier
Components 18
Data pipeline
- Dataset preparation · Downloads and prepares FS-KWS data on disk.
data/download_prepare_data.py - Speech dataset variants · Defines keyword, background, silence, and unknown classes.
protonets/data/FewShotSpeechData.py - Episodic data base · Builds support/query episode boundaries.
protonets/data/base.py
Prototypical learning
- Model factory · Selects configured embedding encoders.
protonets/models/factory.py - Google KWS encoder
protonets/models/encoder/GoogleKWS.py - TC-ResNet encoder
protonets/models/encoder/TCResNet.py - Prototype classifier · Embeds episodes, forms prototypes, and classifies queries by distance.
protonets/models/few_shot.py - Model tensor utilities
protonets/models/utils.py - Episodic engine · Separates episodic optimization from speech data and encoder choice.
protonets/engine.py
Training
- Training launcher · Receives ways, shots, experiment type, and experiment ID.
scripts/train/few_shot/run_train.py - Training execution
scripts/train/few_shot/train.py - HPC submission · Optionally submits training to PBS/Grid Engine.
scripts/train/few_shot/fewshotspeech/qsub_train.sh
Evaluation & analysis
- Experiment artifacts · Saved experiment directories, checkpoints, and CSV summaries.
- Episodic evaluation · Evaluates saved experiments and checkpoints.
scripts/predict/few_shot/eval.py - Result aggregation
scripts/predict/few_shot/eval_results.py - Results analysis
results/Analyze Results.ipynb
Other components
- Package installation · Installs the local protonets package.
setup.py - Dependencies
requirements.txt
Connections 18
- Package installation → Dependencies: installs with
- Dataset preparation → Speech dataset variants: prepared audio/features
- Speech dataset variants → Episodic data base: specializes
- Model factory → Google KWS encoder: constructs
- Model factory → TC-ResNet encoder: constructs
- Model factory → Prototype classifier: supplies encoder
- Model tensor utilities → Prototype classifier: shared operations
- Episodic data base → Episodic engine: support/query episodes
- Prototype classifier → Episodic engine: episodic model
- Training launcher → Training execution: launches
- HPC submission → Training launcher: submits
- Training execution → Episodic engine: trains through
- Episodic engine → Experiment artifacts: writes checkpoints/results
- Experiment artifacts → Episodic evaluation: saved experiments
- Episodic evaluation → Episodic engine: evaluates through
- Episodic evaluation → Result aggregation: evaluation results
- Result aggregation → Experiment artifacts: writes CSV summaries
- Experiment artifacts → Results analysis: explored in