textless-lib: a Library for Textless Spoken Language Processing
Eugene Kharitonov, Jade Copet, Kushal Lakhotia, Tu Anh Nguyen, Paden Tomasello, Ann Lee, Ali Elkahky, Wei-Ning Hsu, Abdelrahman Mohamed, Emmanuel Dupoux, Yossi Adi
Introduction
Textless spoken language modeling Lakhotia et al. (2021) consists in jointly learning the acoustic and linguistic characteristics of a natural language from raw audio samples without access to textual supervision (e.g. lexicon or transcriptions). This area of research has been made possible by converging progress in self-supervised speech representation learning Schneider et al. (2019); Baevski et al. (2020); Oord et al. (2018); Hsu et al. (2021); Chorowski et al. (2021); Chen et al. (2021); Chung et al. (2021); Wang et al. (2021); Ao et al. (2021), language modeling Peters et al. (2018); Devlin et al. (2019); Liu et al. (2019); Brown et al. (2020); Lewis et al. (2020), and speech synthesis Ren et al. (2019); Kumar et al. (2019); Yamamoto et al. (2020); Ren et al. (2020); Kong et al. (2020); Morrison et al. (2021).
Lakhotia et al. (2021) presented a Generative Spoken Language Modeling (GSLM) pipeline trained from raw audio, consisting in a speech encoder (converting speech to discrete units), a language model (based on units) and a decoder (converting units back to speech). These components enabled the generation of new speech by sampling units from the language model. Polyak et al. (2021) proposed an improved encoder/decoder working from disentangled quantized content and F0 units and showed how such a system could be used for efficient audio compression. Kharitonov et al. (2021a) proposed a modified language model system capable of jointly modelling content units and F0 yielding expressive generations. Lastly, Kreuk et al. (2021) demonstrated that the language model can be replaced by a sequence to sequence model achieving the first high quality speech emotion conversion system (including laughter and yawning).
The textless approach has several advantages. First, it would be beneficial for the majority of the world’s languages that do not have large textual resources or even a widely used standardized orthography (Swiss German, dialectal Arabic, Igbo, etc.). Despite being used by millions of people, these languages have little chance of being served by current text-based technology. Moreover, “high-resource” languages can benefit from such modeling where the oral and written forms are mismatched in terms of lexicon and syntax. Second, directly modeling spoken language from raw audio allows us to go beyond lexical content and also model linguistically relevant signals such as prosodic features, intonation, non-verbal vocalizations (e.g., laughter, yawning, etc.), speaker identity, etc. All of these are virtually absent in text.
Although great progress has been made in modeling spoken language, it still requires domain expertise and involves a complicated setting. For instance, the official implementation of the GSLM pipeline (Lakhotia et al., 2021) consists of roughly four different launching scripts with a few dozens of checkpoints. Similarly, running the official implementation of Polyak et al. (2021), requires using four scripts from two different repositories.
In this work, we present textless-lib, a PyTorch library for textless spoken language processing. textless-lib makes the processing, encoding, modeling, and generating of speech as simple as possible. With a few lines of code, one can perform speech continuation, audio-book compression, representation analysis by probing, speech-to-speech translation, etc. We provide all the necessary building blocks, example pipelines, and example tasks. We believe such a simple to use API will encourage both speech and NLP communities to deepen and extend the research work on modeling spoken language without text and unlock potential future research directions.
Background
Below we provide an overview of the common textless spoken language modeling pipeline. In a nutshell, such pipeline is usually comprised of: i) Speech-to-Units (S2U) encoders that automatically discover discrete representations or units which can be used to encode speech into "pseudo-text"; ii) Units-to-Units (U2U) models that are used for units modeling. This can take a form as Unit-Language-Model (uLM) for speech continuation Lakhotia et al. (2021); Kharitonov et al. (2021a), sequence-to-sequence models for speech emotion conversion Kreuk et al. (2021) or translation tasks Lee et al. (2021a, b); iii) Units-to-Speech (U2S) models to reconstruct back the speech signals.
Alternatively, one could drop the U2U component and perform a direct speech resynthesis Polyak et al. (2021). This can be used for speech compression, voice conversion, or developing a better understanding of the learned representation using probing methods. See Figure 1 for a visual description of the full system. We provide a detailed description for each of the above-mentioned components in the following subsections.
Next, as the representations obtained by are continuous, an additional quantization step is needed. We define a quantization function , which gets as input dense representations and outputs a sequence of discrete tokens corresponding to the inputs’ quantized version. Formally, , where such that and is the size of the vocabulary. After quantization one can either operate on the original discrete sequences (duped) or collapse repeated units (e.g., ), we refer to such sequences as “deduped”. Working with the deduped sequences simplifies modeling long sequences, however, the tempo information is lost.
2 Units to Speech
Converting a sequence of units to audio is akin to the Text-to-Speech (TTS) problem, where we consider the discrete units as “pseudo-text”. This can be solved by adopting a standard TTS architecture. For instance, Lakhotia et al. (2021) trained a Tacotron2 model Shen et al. (2018) to perform units to mel-spectrogram conversion followed by a WaveGlow Prenger et al. (2019) neural vocoder for time-domain reconstruction.
Formally, to reconstruct a time-domain speech signal from a sequence of discrete units, we define the composition as, where is a mel-spectrogram estimation module (e.g., Tacotron2), and is a phase vocoder module responsible for time-domain synthesis (e.g., WaveGlow). The input sequence can be either the original sequence or its deduped version.
Interestingly, one can simplify the synthesis process when working with the duped unit sequences. As we have a direct mapping between the duped discrete unit sequence to the time domain signal (e.g., each unit corresponds to a 20ms window) one can remove , and directly feed to . This was successfully done in Polyak et al. (2021) for speech resynthesis using the HiFi-GAN neural vocoder Kong et al. (2020). Alternatively, as suggested by Kreuk et al. (2021); Lee et al. (2021b) one can train a unit duration prediction model and use the predicted durations to inflate the sequence and feed the discrete sequence directly to .
3 Unit to Units
Equipped with the models to encode spoken language into discrete unit sequences and convert them back to speech samples, one can conveniently use the common Natural Language Processing (NLP) architectures to model spoken language.
Consider to be a sequence modeling function that gets as input a discrete unit sequence and outputs another discrete units sequence, denoted as . Generally, can represent different generations, depending on the modeling task. For instance, Lakhotia et al. (2021); Kharitonov et al. (2021a) set to be a Transformer language model and trained a generative spoken language model. Similarly, Kreuk et al. (2021) set to be a sequence-to-sequence model, hence can cast the emotion conversion problem as a translation task.Examples are provided at speechbot.github.io/.
Library Overview
In this section, we present the textless-lib library, intending to simplify future research on textless spoken language modeling. Additionally, the proposed package will remove the main barrier of processing and synthesizing speech, which requires domain expertise, for other language researchers (e.g., NLP researchers) who are interested in modeling spoken language, analyzing the learned representations, etc.
To support the above, it is essential to provide the main building blocks described in Section 2, together with pre-trained models, with minimal coupling between them (a list of the supported pre-trained models can be seen on Table 1). This will allow researchers to flexibly use the provided pre-trained building blocks as well as develop new building blocks and use them anywhere in their pipeline. We decided to exclude both U2U models as well as evaluation metrics from the core functionality of the library as we believe these models should be an example usage. There are plenty of ways to evaluate the overall pipeline Lakhotia et al. (2021); Dunbar et al. (2019, 2020); Nguyen et al. (2020) as well as different ways to model the “pseudo-text” units Shi et al. (2021); Kharitonov et al. (2021a); Polyak et al. (2021); Kreuk et al. (2021); Lee et al. (2021a), hence including them as an integral part of textless-lib will make the library over complicated and hard to use.
The pipeline presented in Figure 1 hints a straightforward way to decouple elements of the library into two principal blocks: (i) encoding speech; and (ii) decoding speech, with the only inter-dependence being the format of the data in-between (e.g., vocabulary size). Such interfaces enable interesting mix-and-match combinations as well as conducting research on each component independently. We firstly present those two interfaces, then we discuss helpers for dataloading.
Encoders and Vocoders. We denote the encoders as SpeechEncoder. These modules encompass all steps required to represent raw audio as discrete unit sequences (i.e., pseudo-text units and, optionally duration and pitch streams).
SpeechEncoder obtains a dense vector representation from a given self-supervised model, discretizes the dense representation into units, extracts pitch, aligns it with the unit streams, and potentially, applies run-length encoding with per-frame pitch averaging. See Fig. 2 for a visual description.
For each sub-model, a user might choose to use a pre-trained model or provide a custom torch.nn.Module module instead. An example of the former is demonstrated in lines 7-12 in Figure 3, in which a HuBERT model and a corresponding k-means codebook with a pre-defined (i.e., vocabulary size) are automatically retrieved.
Conversely, vocoders take as input a discretized sequence and convert it back to the audio domain. As with SpeechEncoder, we can retrieve a pre-trained model by setting the expected input specification (model, quantizer, and the size of the codebook), see Figure 4 lines 17-21.
Datasets, Dataloaders, and Preprocessing. Apart from encoders and vocoders, in the textless-lib we provide several components aimed to simplify frequent data loading use-cases. First, we provide a set of standard datasets (e.g., LibriSpeech) wrapped to produce quantized representations (see Fig. 3 lines 14-15). Those datasets are implemented via a QuantizeDataset wrapper which can be used to wrap any map-style PyTorch dataset, containing raw waveform data.
The QuantizeDataset runs an instance of a dense representation model, which can be computationally heavy (e.g., the HuBERT-base model has 7 convolutional layers and 12 Transformer layers). Unfortunately, such heavy preprocessing can starve the training loop. Hence, we provide two possible solutions: (i) as part of the textless-lib we provide a way to spread QuantizeDataset and DataLoader preprocessing workers (each with its copy of a dense model) across multiple GPUs, hence potentially balancing training and preprocessing across different devices; (ii) in cases where on-the-fly preprocessing is not required (e.g., there is no randomized data augmentation Kharitonov et al. (2021b)), an alternative is to preprocess the entire dataset in advance. textless-lib provides a tool for preprocessing arbitrary sets of audio files into a stream of pseudo-unit tokens and, optionally, streams of per-frame tempo and F0 values, aligned to the token stream. The tool uses multi-GPU and multi-node parallelism to speed up the process.
2 Pre-trained Models
As part of textless-lib we provide several pre-trained models that proved to work best in prior work Lakhotia et al. (2021); Polyak et al. (2021). In future, we will maintain the list of the models to be aligned with state-of-the-art.
Dense representations. We support two dense representation models: (i) HuBERT base-960h model Hsu et al. (2021) trained on LibriSpeech 960h dataset, with a framerate of 50 Hz; (ii) Contrastive Predictive Coding (CPC) model Rivière and Dupoux (2020); Oord et al. (2018) trained on the 6K hours subset from LibriLight Kahn et al. (2020) with a framerate of 100 Hz. Both models provided the best overall performance according to Lakhotia et al. (2021); Polyak et al. (2021).
Pitch extraction. Following Polyak et al. (2021) we support F0 extraction using the YAAPT pitch extraction algorithm Kasi and Zahorian (2002). We plan to include other F0 extraction models, e.g. CREPE Kim et al. (2018).
Quantizers. With the textless-lib we provide several pre-trained quantization functions for both HuBERT and CPC dense models using a vocabulary sizes . For the quantization function, we trained a k-means algorithm using the “dev-clean” part in the LibriSpeech dataset Panayotov et al. (2015).
Pitch normalization. Following Kharitonov et al. (2021a), we applied per-speaker pitch normalization to reduce inter-speaker variability. For single speaker datasets, we do not perform F0 normalization and the span of pitch values is preserved. Under the textless-lib we provide two pitch-normalization methods: per-speaker and prefix-based. In the per-speaker normalization, we assume the mean F0 value per speaker is known in advance. While in the prefix-based normalization method a part of the audio is used to calculate the mean pitch. Those two options provide useful trade-offs. In the first case, we need to have a closed set of speakers but have a better precision while in the second we sacrifice quality but gain flexibility.
Vocoder. In the initial release of the library, we provide Tacotron2 as a mel-spectrogram estimation module (i.e., the function) followed by WaveGlow Prenger et al. (2019) neural vocoder (i.e., the function) as used by Lakhotia et al. (2021).WaveGlow is used as a part of TacotronVocoder. Both Tacotron2 and WaveGlow were trained on LJ speech Ito and Johnson (2017). These operate on deduplicated pseudo-unit streams with vocabulary sizes of 50, 100, and 200. In a follow-up release, we aim to include HiFi-GAN-based vocoders similarly to Polyak et al. (2021); Kharitonov et al. (2021a). We found those to generate better audio quality with higher computational performance. However, as described in Section 2, the main drawback of dropping and directly feeding the discrete units to is the need for a unit duration prediction model. We plan to include such models as well in the next release.
Examples
Alongside the core functionality of the library, we provide a set of illustrative examples. The goal of these examples is two-fold: (a) to illustrate the usage of particular components of the library, and (b) to serve as a starter code for a particular type of application. For instance, a probing example (Section 4.1) can be adapted for better studying used representations, while discrete resynthesis (Section 4.2) could provide a starter code for an application operating on units (e.g., language modeling or a high-compression speech codec).
A vibrant area of research studies properties of “universal” pre-trained representations, such as GLoVE Pennington et al. (2014) and BERT Devlin et al. (2018). Examples span from probing for linguistic properties Adi et al. (2017b); Ettinger et al. (2016); Adi et al. (2017a); Conneau et al. (2018); Hewitt and Manning (2019) to discovering biases Bolukbasi et al. (2016); Caliskan et al. (2017).
In contrast, widely used pre-trained representations produced by HuBERT Hsu et al. (2021) and wav2vec 2.0 Baevski et al. (2020) are relatively understudied. Few existing works include (van Niekerk et al., 2021; Higy et al., 2021).
We believe our library can provide a convenient tool for research in this area. Hence, as the first example, we include a probing experiment similar to the one proposed in (van Niekerk et al., 2021; Adi et al., 2019). We study whether the extracted representations contain speaker-specific information. In this example, we experiment with quantized and continuous representations provided by CPC and HuBERT. We randomly split LibriSpeech dev-clean utterances into train/test (90%/10%) setsWe have to create a new split as the standard one has disjoint sets of speakers, making this experiment impossible. and train a two-layer Transformer for 5 epochs to predict a speaker’s anonymized identifier, based on an utterance they produced. From the results reported in Table 2 we see that the continuous representations allow identifying speaker on hold-out utterances. In contrast, the quantization adds some speaker-invariance, justifying its use.
2 Speech Resynthesis
The next example is the discrete speech resynthesis, i.e., the speech audio deduplicated units speech audio pipeline. Fig. 4 illustrates how simple its implementation is with textless-lib.
3 Speech Continuation
Finally, we include a textless-lib re-implementation of the full GSLM speech continuation pipeline Lakhotia et al. (2021), as depicted in Figure 1. Table 4 presents ASR transcripts of three different continuations of the same prompt, generated using different random seeds. We use a large wav2vec 2.0 model, trained on LibriSpeech-960h with CTC loss. Its decoder uses the standard KenLM 4-gram language model.
Discussion and Future Work
We introduced textless-lib, a Pytorch library aimed to advance research in textless modeling of spoken language, by simplifying textless processing and synthesizing spoken language. We described the main building blocks used to preprocess, quantize, and synthesize speech. To demonstrate the usability of the library, we provided three usage examples related to (i) representation probing, (ii) speech compression, and (iii) speech continuation. The proposed library greatly simplifies research in the textless spoken language processing, hence we believe it will be a handful not only for speech researchers but to the entire NLP community.
As a future work for textless-lib we envision improving performance of the existing building blocks, adding new example tasks (e.g., translation), extending the set of provided pre-trained models, and introducing the possibility of training the different components.