Learning Fast and Stable Linguistic Units for Spoken Language Models Without Supervision
Project description
SpidR: Learning Fast and Stable Linguistic Units for Spoken Language Models Without Supervision
This repository contains the checkpoints and training code for the self-supervised speech models in the SpidR paper (coming soon!).
Overview
SpidR is a self-supervised speech representation model that efficiently learns strong representations for spoken language modeling. It is trained on unlabelled speech using a masked prediction objective combined with self-distillation and online clustering. The intermediate layers of the student model learn to predict assignments derived from the teacher intermediate layers. This learning objective stabilizes the online clustering procedure compared to previous approaches, resulting in higher-quality codebooks. SpidR outperforms previous state-of-the-art methods on downstream language modeling metrics.
With this codebase you can pretrain SpidR for 400k steps in only a day on 16 A100, and in 15 hours on 16 H100. We distribute two checkpoints: SpidR and DinoSR pretrained with this codebase on LibriSpeech.
Installation
This is available as a package on PyPI.
To use the pretrained models, the only dependencies are torch>=2.8.0 and numpy>=1.26.4, with Python 3.12 at least.
If you want to train your own model, install the optional train dependencies[^1].
[^1]: polars, submitit, torchcodec, tqdm, viztracer, and wandb
For inference:
pip install spidr
For training:
pip install spidr[train]
Or if you want to tinker with this repository, clone it and create a virtual environment with uv:
git clone https://github.com/facebookresearch/spidr
cd spidr
uv sync --extra train
You need the optional dependencies to import spidr.data, spidr.slurm, spidr.train,
spidr.validate, and to run the scripts in paper/.
As we use TorchCodec, you will need to have FFmpeg installed for training.
Usage
Using a pretrained model
We distribute two checkpoints used in our paper: spidr_base and dinosr_base_reproduced.
Both are pretrained on LibriSpeech 960h.
You can load them like this:
from spidr.models import spidr_base, dinosr_base_reproduced
spidr_model = spidr_base().to("cuda")
dinosr_model = dinosr_base_reproduced().to("cuda")
Or if you don't want to install this library, you can use torch.hub.load:
import torch
spidr_model = torch.hub.load("facebookresearch/spidr", "spidr_base")
dinosr_model = torch.hub.load("facebookresearch/spidr", "dinor_base_reproduced")
Similarly, you can use the spidr.models.dinosr_base_original function to load the original DinoSR checkpoint.
The forward function of SpidR and DinoSR returns the loss and the perplexities.
To get intermediate representations use the get_intermediate_outputs method, or the get_codebooks method
if you prefer to extract the codebook predictions from the student model.
See paper/extract_features.py for an example of how to use the pretrained models.
[!WARNING] The models have been trained with standardized audio (mean of 0 and variance of 1). The standardization is not done inside the model. Either do it yourself, or use the function
spidr.data.speech_datasetwithnormalize=Trueto create your dataset.
Launching training runs
Manifest files
First, create a manifest file that contains the paths to the audio files and the number of samples (either CSV file or TSV like in fairseq).
We support loading audio files from an uncompressed tar archive.
Use spidr.data.write_manifest to easily create it:
❯ python -m spidr.data.write_manifest --help
usage: write_manifest.py [-h] [--ext EXT] [--fairseq] dataset output
Write manifest files.
positional arguments:
dataset Path to the dataset directory or uncompressed tar file.
output Path to the output manifest file.
options:
-h, --help show this help message and exit
--ext EXT Extension of audio files. (default: .wav)
--fairseq Write a Fairseq-style TSV manifest, instead of CSV.
Configuration
Create a TOML configuration file for the training run. This will be used to create an instance of spidr.config.Config.
Check out src/spidr/config.py to see the available fields.
You can start from configs/example.toml (it only specifies the required fields).
Training
We provide utilities to launch jobs on a SLURM cluster. The training run is in one job, and the validation is launched in separate jobs to not interrupt training. You can launch a training run from your terminal:
❯ python -m spidr --help
usage: __main__.py [-h] -A ACCOUNT -N NODES -G GPUS_PER_NODE [-c CPUS_PER_TASK] [--mem-per-gpu MEM_PER_GPU] [-t TIME]
[-C CONSTRAINT] [-q QOS] [--dump DUMP]
configs [configs ...]
Launch training runs.
positional arguments:
configs TOML config file(s) for the training run(s).
options:
-h, --help show this help message and exit
-A ACCOUNT, --account ACCOUNT
SLURM account (default: None)
-N NODES, --nodes NODES
Number of nodes (default: None)
-G GPUS_PER_NODE, --gpus-per-node GPUS_PER_NODE
GPUs per node (default: None)
-c CPUS_PER_TASK, --cpus-per-task CPUS_PER_TASK
CPUs per task (default: None)
--mem-per-gpu MEM_PER_GPU
Memory per GPU (default: None)
-t TIME, --time TIME Time limit in minutes (default: None)
-C CONSTRAINT, --constraint CONSTRAINT
SLURM constraint (default: None)
-q QOS, --qos QOS SLURM qos (default: None)
--dump DUMP Submitit dump (default: None)
By default we use torch.compile, the first batches will be quite slow to process. To speed up training, you can also remove the computation of the perplexities in the source code if you do not care about it.
License
The source code and our two model checkpoints are provided under the CC BY-NC 4.0 License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spidr-0.1.0.tar.gz.
File metadata
- Download URL: spidr-0.1.0.tar.gz
- Upload date:
- Size: 43.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64636a832464fe62988baecc74ca3cc723557f3ff6df71ae6aee13ae9a972603
|
|
| MD5 |
8acdbe4732aa25e28e59529b49bb51ed
|
|
| BLAKE2b-256 |
78917e24314579c87971d93bd1ca3e6ef97036535012f9c860f295670b3b4720
|
File details
Details for the file spidr-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spidr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 50.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8420383b6f41d50f015a3dc0ea4d25c0f0e9880245513b24e7e58a29f50904d
|
|
| MD5 |
3f03164c07cb708be46bc8fab949d3a0
|
|
| BLAKE2b-256 |
38dbb6bcc607801fe95ac5956221ac925e7f3be0466ad8fc0b582fb1cf7424e0
|