Lhotse: a speech data representation library for the modern deep learning ecosystem

Piotr Żelasko, Daniel Povey, Jan "Yenda" Trmal, Sanjeev KhudanpurarXiv 2021

TL;DR

Lhotse is a new Python library designed to tame the "wild west" of speech data formats, bringing the robust data handling principles of the classic Kaldi toolkit into the modern PyTorch ecosystem. By introducing a flexible "Cut" abstraction, it allows researchers to easily mix, augment, and batch massive audio datasets with minimal memory overhead and maximum flexibility.

What Problem Does This Paper Address?

Speech data is notoriously messy. Unlike images, which are generally rectangular grids of pixels, audio comes in a dizzying array of codecs (FLAC, OPUS, sphere), varying lengths (from 1-second snippets to 10-hour podcasts), and inconsistent metadata formats (XML, JSON, TextGrid).

While the venerable Kaldi toolkit established a standard for organizing this data, its steep learning curve often alienates researchers coming from general deep learning backgrounds. Furthermore, modern deep learning requires data pipelines that can handle on-the-fly augmentation, lazy loading from the cloud, and complex multi-task training—features that were difficult to implement in older frameworks. Lhotse aims to bridge this gap, providing a Pythonic, high-performance bridge between raw audio files and deep learning models.

Methods

Lhotse’s architecture centers on four core manifest types: Recordings, SupervisionSegments, Features, and Cuts.

  • Recordings & Supervisions: These manifests decouple the physical audio file from its metadata (like transcripts or speaker IDs). A single API, Recording.load_audio(), handles everything from local files to cloud URLs.
  • The Cut: This is Lhotse’s "secret sauce." A Cut is a virtual "window" into a recording. It defines a specific start time and duration and carries its own supervision metadata.
  • CutSet: A collection of Cuts. Lhotse provides over 30 methods for CutSet manipulation, such as padding, truncating, or mixing audio. Crucially, most of these operations are lazy—the actual audio processing only happens when a batch is requested for training.
Figure 1: Recording, SupervisionSegments, and Cuts illustrated on waveform plots of a conversation with speakers A and B. The upper plot (A) shows cuts matching supervision boundaries in an "isolated utterances" scenario, e.g., for speech recognition. The bottom plot (B) shows how cuts are used to traverse the same recording in windows, useful in voice activity detection or speech diarization. Note that with different window sizes and offsets there are many ways to construct the training data.

As shown in Figure 1, the Cut abstraction allows the same recording to be repurposed easily: one setup might use cuts that match specific utterances for speech recognition (A), while another might use fixed-size sliding windows for voice activity detection (B).

Datasets

Lhotse is designed to be a "one-stop shop" for speech data. It includes data preparation recipes for over 30 popular speech corpora, including:

  • LibriSpeech and its variants (Multilingual, LibriLight).
  • GigaSpeech and The People’s Speech (large-scale, diverse English).
  • AMI and CHiME-6 (complex multi-channel meeting data).
  • SPGISpeech (financial audio).

By converting these diverse datasets into a common JSON manifest format, Lhotse allows researchers to combine multiple sources into a single training pipeline with just a few lines of code.

Key Insights and Ideas

  • Virtualization of Audio: By treating training examples as "Cuts" (virtual views) rather than physical files, Lhotse makes complex data wrangling (like adding background noise or changing speed) computationally cheap.
  • Dynamic Batching: In speech, utterance lengths vary wildly. Standard fixed-size batching leads to massive amounts of wasted computation on "padding" tokens. Lhotse’s CutSampler allows for dynamic batching based on the total duration of audio in a batch, significantly improving GPU efficiency.
  • Integration, not Reinvention: Lhotse doesn't try to be a new deep learning framework. Instead, it extends the standard PyTorch Dataset and DataLoader abstractions.
Figure 2: Lhotse implementation of the PyTorch data API.

Figure 2 illustrates this integration: the CutSampler manages the manifests, while the DataLoader handles the parallel I/O and transforms, resulting in a clean flow from disk to training loop.

Key Results

Lhotse serves as a foundational component of the "next-generation Kaldi" ecosystem, alongside k2 (for differentiable finite state automata) and Icefall (for reproducible training recipes).

  • Scalability: It seamlessly handles datasets with tens of thousands of hours of audio by using lazy manifests that don't need to be fully loaded into RAM.
  • Versatility: It supports advanced features like multi-channel audio, on-the-fly feature extraction, and efficient feature compression using the lilcom engine.

Limitations and Future Work

The authors are transparent about what Lhotse is not. It is not a standalone feature extraction library (it wraps tools like librosa and torchaudio) nor a full training framework.

One inherent trade-off mentioned is that lazy mode sacrifices true random access to elements in a dataset in exchange for minimal memory usage. Additionally, while Lhotse provides examples for common tasks like ASR and diarization, users still need to implement some custom logic in the Dataset class to transform CutSets into the specific tensor formats required by their unique models.

Summary updated

BibTeX
@misc{zelasko2021lhotse,
  author = {Piotr Żelasko and Daniel Povey and Jan "Yenda" Trmal and Sanjeev Khudanpur},
  title = {{Lhotse: a speech data representation library for the modern deep learning ecosystem}},
  year = {2021},
  eprint = {2110.12561},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2110.12561},
}
Figure