Technical Documentation: facebookresearch/seamless_communication
โน๏ธ Provenance: Multi-Tier Ingestion ยท CodeWiki Reference
Overview (`README.md`)
Seamless Intro
Seamless is a family of AI models that enable more natural and authentic communication across languages. SeamlessM4T is a massive multilingual multimodal machine translation model supporting around 100 languages. SeamlessM4T serves as foundation for SeamlessExpressive, a model that preserves elements of prosody and voice style across languages and SeamlessStreaming, a model supporting simultaneous translation and streaming ASR for around 100 languages. SeamlessExpressive and SeamlessStreaming are combined into Seamless, a unified model featuring multilinguality, real-time and expressive translations.
Links
Demos
| SeamlessM4T v2 | SeamlessExpressive | SeamlessStreaming | |
|---|---|---|---|
| Demo | SeamlessM4T v2 Demo | SeamlessExpressive Demo | |
| HuggingFace Space Demo | ๐ค SeamlessM4T v2 Space | ๐ค SeamlessExpressive Space | ๐ค SeamlessStreaming Space |
Papers
Blog
Tutorial
An exhaustive tutorial given at the NeurIPS 2023 - Seamless EXPO, which is a one-stop shop to learn how to use the entire suite of Seamless models. Please feel free to play with the notebook.
SeamlessM4T
SeamlessM4T is our foundational all-in-one Massively Multilingual and Multimodal Machine Translation model delivering high-quality translation for speech and text in nearly 100 languages.
SeamlessM4T models support the tasks of:
- Speech-to-speech translation (S2ST)
- Speech-to-text translation (S2TT)
- Text-to-speech translation (T2ST)
- Text-to-text translation (T2TT)
- Automatic speech recognition (ASR)
:star2: We are releasing SeamlessM4T v2, an updated version with our novel UnitY2 architecture. This new model improves over SeamlessM4T v1 in quality as well as inference latency in speech generation tasks.
To learn more about the collection of SeamlessM4T models, the approach used in each, their language coverage and their performance, visit the SeamlessM4T README or ๐ค Model Card.
[!NOTE]
Seamless M4T is also available in the ๐ค Transformers library. Visit this section for more details.
SeamlessExpressive
SeamlessExpressive is a speech-to-speech translation model that captures certain underexplored aspects of prosody such as speech rate and pauses, while preserving the style of one's voice and high content translation quality.
To learn more about SeamlessExpressive models, visit the SeamlessExpressive README or ๐ค Model Card
SeamlessStreaming
SeamlessStreaming is a streaming translation model. The model supports speech as input modality and speech/text as output modalities.
The SeamlessStreaming model supports the following tasks:
- Speech-to-speech translation (S2ST)
- Speech-to-text translation (S2TT)
- Automatic speech recognition (ASR)
To learn more about SeamlessStreaming models, visit the SeamlessStreaming README or ๐ค Model Card
Seamless
The Seamless model is the unified model for expressive streaming speech-to-speech translations.
What's new
- [12/18/2023] We are open-sourcing our Conformer-based W2v-BERT 2.0 speech encoder as described in Section 3.2.1 of the paper, which is at the core of our Seamless models.
- [12/14/2023] We are releasing the Seamless tutorial given at NeurIPS 2023.
Quick Start
Installation
[!NOTE]
One of the prerequisites is fairseq2 which has pre-built packages available only
for Linux x86-64 and Apple-silicon Mac computers. In addition it has a dependency on libsndfile which
might not be installed on your machine. If you experience any installation issues, please refer to its
README for further instructions.
pip install .[!NOTE]
Transcribing inference audio for computing metric uses Whisper, which is automatically installed. Whisper in turn requires the command-line toolffmpegto be installed on your system, which is available from most package managers.
Running inference
SeamlessM4T Inference
Hereโs an example of using the CLI from the root directory to run inference.
S2ST task:
m4t_predict <path_to_input_audio> --task s2st --tgt_lang <tgt_lang> --output_path <path_to_save_audio>T2TT task:
m4t_predict <input_text> --task t2tt --tgt_lang <tgt_lang> --src_lang <src_lang>Please refer to the inference README for detailed instruction on how to run inference and the list of supported languages on the source, target sides for speech, text modalities.
For running S2TT/ASR natively (without Python) using GGML, please refer to the unity.cpp section.
SeamlessExpressive Inference
[!NOTE]
Please check the section on how to download the model.
Hereโs an example of using the CLI from the root directory to run inference.
expressivity_predict <path_to_input_audio> --tgt_lang <tgt_lang> --model_name seamless_expressivity --vocoder_name vocoder_pretssel --output_path <path_to_save_audio>SeamlessStreaming and Seamless Inference
Streaming Evaluation README has detailed instructions for running evaluations for the SeamlessStreaming and Seamless models. The CLI has an --no-scoring option that can be used to skip the scoring part and just run inference.
Please check the inference README for more details.
Running SeamlessStreaming Demo
You can duplicate the SeamlessStreaming HF space to run the streaming demo.
You can also run the demo locally, by cloning the space from here. See the README of the SeamlessStreaming HF repo for more details on installation.
Running SeamlessM4T & SeamlessExpressive [Gradio](https://github.com/gradio-app/gradio) demos locally
To launch the same demo Space we host on Hugging Face locally:
cd demo
pip install -r requirements.txt
python app.pyResources and usage
Model
SeamlessM4T models
| Model Name | #params | checkpoint | metrics |
|---|---|---|---|
| SeamlessM4T-Large v2 | 2.3B | ๐ค Model card - checkpoint | metrics |
| SeamlessM4T-Large (v1) | 2.3B | ๐ค Model card - checkpoint | metrics |
| SeamlessM4T-Medium (v1) | 1.2B | ๐ค Model card - checkpoint | metrics |
SeamlessExpressive models
To access and download SeamlessExpressive, please request the model artifacts through this request form. Upon approval, you will then receive an email with download links to each model artifact.
Please note that SeamlessExpressive is made available under its own License and Acceptable Use Policy.
SeamlessStreaming models
| Model Name | #params | checkpoint | metrics |
|---|---|---|---|
| SeamlessStreaming | 2.5B | ๐ค Model card - monotonic decoder checkpoint - streaming UnitY2 checkpoint | metrics |
Seamless models
Seamless model is simply the SeamlessStreaming model with the non-expressive vocoder_v2 swapped out with the expressive vocoder_pretssel.
Please check out above section on how to acquire vocoder_pretssel checkpoint.
W2v-BERT 2.0 speech encoder
| Model Name | #params | checkpoint |
|---|---|---|
| W2v-BERT 2.0 | 600M | ๐ค Model card - checkpoint |
Here's how you should do a foward pass through the speech encoder:
import torch
from fairseq2.data.audio import AudioDecoder, WaveformToFbankConverter
from fairseq2.memory import MemoryBlock
from fairseq2.nn.padding import get_seqs_and_padding_mask
from fairseq2.data import Collater
from pathlib import Path
from seamless_communication.models.conformer_shaw import load_conformer_shaw_model
audio_wav_path, device, dtype = ...
audio_decoder = AudioDecoder(dtype=torch.float32, device=device)
fbank_converter = WaveformToFbankConverter(
num_mel_bins=80,
waveform_scale=2**15,
channel_last=True,
standardize=True,
device=device,
dtype=dtype,
)
collater = Collater(pad_value=1)
model = load_conformer_shaw_model("conformer_shaw", device=device, dtype=dtype)
model.eval()
with Path(audio_wav_path).open("rb") as fb:
block = MemoryBlock(fb.read())
decoded_audio = audio_decoder(block)
src = collater(fbank_converter(decoded_audio))["fbank"]
seqs, padding_mask = get_seqs_and_padding_mask(src)
with torch.inference_mode():
seqs, padding_mask = model.encoder_frontend(seqs, padding_mask)
seqs, padding_mask = model.encoder(seqs, padding_mask)Evaluation
SeamlessM4T Evaluation
To reproduce our results, or to evaluate using the same metrics over your own test sets, please check out the README here.
SeamlessExpressive Evaluation
Below is the script for efficient batched evaluation.
export MODEL_DIR="/path/to/SeamlessExpressive/model"
export TEST_SET_TSV="input.tsv" # Your dataset in a TSV file, with headers "id", "audio"
export TGT_LANG="spa" # Target language to translate into, options including "fra", "deu", "eng" ("cmn" and "ita" are experimental)
export OUTPUT_DIR="tmp/" # Output directory for generated text/unit/waveform
export TGT_TEXT_COL="tgt_text" # The column in your ${TEST_SET_TSV} for reference target text to calcuate BLEU score. You can skip this argument.
export DFACTOR="1.0" # Duration factor for model inference to tune predicted duration (preddur=DFACTOR*preddur) per each position which affects output speech rate. Greater value means slower speech rate (default to 1.0). See expressive evaluation README for details on duration factor we used.
expressivity_evaluate ${TEST_SET_TSV} \
--gated-model-dir ${MODEL_DIR} --task s2st --tgt_lang ${TGT_LANG} \
--audio_root_dir "" --output_path ${OUTPUT_DIR} --ref_field ${TGT_TEXT_COL} \
--model_name seamless_expressivity --vocoder_name vocoder_pretssel \
--text_unk_blocking True --duration_factor ${DFACTOR}Please check out this README section
SeamlessStreaming and Seamless Evaluation
Streaming Evaluation README has detailed instructions for running evaluations on the SeamlessStreaming and Seamless models.
Unity.cpp
To enable Seamless Communication Everywhere, we implemented unity.cpp so users could run SeamlessM4T models in GGML - a C tensor library allowing easier integration on verbose platforms.
To transcribe/translte a given audio,
./ggml/bin/unity --model seamlessM4T_medium.ggml input.wavFor details of build and more usage please check out unity.cpp
Expressive Datasets
We created two expressive speech-to-speech translation datasets, mExpresso and mDRAL, between English and five other languages -- French, German, Italian, Mandarin and Spanish. We currently open source the speech-to-text of mExpresso for out-of-English directions, and we will open source the remaining part of the datasets soon. For details, please check out README
SeamlessAlignExpressive
Weโre introducing the first expressive speech alignment procedure. Starting with raw data, the expressive alignment procedure automatically discovers pairs of audio segments sharing not only the same meaning, but the same overall expressivity. To showcase this procedure, we are making metadata available to create a benchmarking dataset called SeamlessAlignExpressive, that can be used to validate the quality of our alignment method. SeamlessAlignExpressive is the first large-scale (11k+ hours) collection of multilingual audio alignments for expressive translation. More details can be found on the SeamlessAlignExpressive README.
Converting raw audio to units
Please check out the README here. Note that SeamlessM4T v1 model uses reduced units and other models use non-reduced units.
Libraries
Seamless Communication depends on 4 libraries developed by Meta.
[fairseq2](https://github.com/facebookresearch/fairseq2)
fairseq2 is our next-generation open-source library of sequence modeling components that provides researchers and developers with building blocks for machine translation, language modeling, and other sequence generation tasks. All SeamlessM4T models in this repository are powered by fairseq2.
[SONAR and BLASER 2.0](https://github.com/facebookresearch/SONAR)
SONAR, Sentence-level multimOdal and laNguage-Agnostic Representations is a new multilingual and -modal sentence embedding space which outperforms existing sentence embeddings such as LASER3 and LabSE on the xsim and xsim++ multilingual similarity search tasks. SONAR provides text and speech encoders for many languages. SeamlessAlign was mined based on SONAR embeddings.
BLASER 2.0 is our latest model-based evaluation metric for multimodal translation. It is an extension of BLASER, supporting both speech and text. It operates directly on the source signal, and as such, does not require any intermediate ASR system like ASR-BLEU. As in the first version, BLASER 2.0 leverages the similarity between input and output sentence embeddings. SONAR is the underlying embedding space for BLASER 2.0. Scripts to run evaluation with BLASER 2.0 can be found in the SONAR repo.
[stopes](https://github.com/facebookresearch/stopes)
As part of the seamless communication project, we've extended the stopes library. Version 1 provided a text-to-text mining tool to build training dataset for translation models. Version 2 has been extended thanks to SONAR, to support tasks around training large speech translation models. In particular, we provide tools to read/write the fairseq audiozip datasets and a new mining pipeline that can do speech-to-speech, text-to-speech, speech-to-text and text-to-text mining, all based on the new SONAR embedding space.
[SimulEval](https://github.com/facebookresearch/SimulEval)
SimulEval is a library used for evaluating simulaneous translation models. SimulEval also provides a backend for generation using partial/incremental inputs with flexible/extensible states, which is used to implement streaming inference. Users define agents which implement SimulEval's interface, which can be connected together in a pipeline. You can find agents implemented for SeamlessStreaming here.
[Legacy] SeamlessM4T v1 instructions
Finetuning SeamlessM4T v1 models
Please check out the README here.
On-device models
Apart from Seamless-M4T large (2.3B) and medium (1.2B) models, we are also releasing a small model (281M) targeted for on-device inference. To learn more about the usage and model details check out the README here.
SeamlessAlign mined dataset
We open-source the metadata to SeamlessAlign, the largest open dataset for multimodal translation, totaling 270k+ hours of aligned Speech and Text data. The dataset can be rebuilt by the community based on the SeamlessAlign readme.
Citation
If you use Seamless in your work or any models/datasets/artifacts published in Seamless, please cite :
@inproceedings{seamless2023,
title="Seamless: Multilingual Expressive and Streaming Speech Translation",
author="{Seamless Communication}, Lo{\"i}c Barrault, Yu-An Chung, Mariano Coria Meglioli, David Dale, Ning Dong, Mark Duppenthaler, Paul-Ambroise Duquenne, Brian Ellis, Hady Elsahar, Justin Haaheim, John Hoffman, Min-Jae Hwang, Hirofumi Inaguma, Christopher Klaiber, Ilia Kulikov, Pengwei Li, Daniel Licht, Jean Maillard, Ruslan Mavlyutov, Alice Rakotoarison, Kaushik Ram Sadagopan, Abinesh Ramakrishnan, Tuan Tran, Guillaume Wenzek, Yilin Yang, Ethan Ye, Ivan Evtimov, Pierre Fernandez, Cynthia Gao, Prangthip Hansanti, Elahe Kalbassi, Amanda Kallet, Artyom Kozhevnikov, Gabriel Mejia, Robin San Roman, Christophe Touret, Corinne Wong, Carleigh Wood, Bokai Yu, Pierre Andrews, Can Balioglu, Peng-Jen Chen, Marta R. Costa-juss{\`a}, Maha Elbayad, Hongyu Gong, Francisco Guzm{\'a}n, Kevin Heffernan, Somya Jain, Justine Kao, Ann Lee, Xutai Ma, Alex Mourachko, Benjamin Peloquin, Juan Pino, Sravya Popuri, Christophe Ropers, Safiyyah Saleem, Holger Schwenk, Anna Sun, Paden Tomasello, Changhan Wang, Jeff Wang, Skyler Wang, Mary Williamson",
journal={ArXiv},
year={2023}
}License
We have three license categories.
The following non-generative components are MIT licensed as found in MIT_LICENSE:
- W2v-BERT 2.0 speech encoder
- Code
- Text only part of the mExpresso dataset found in the SeamlessExpressive README.
- UnitY2 forced alignment extractor found in the UnitY2 Aligner README.
- Speech toxicity tool with the etox dataset found in the ETOX README.
- MuTox: Universal MUltilingual Audio-based TOXicity Dataset and Zero-shot Detector Mutox README
The following models are CC-BY-NC 4.0 licensed as found in the LICENSE:
- SeamlessM4T models (v1 and v2).
- SeamlessStreaming models.
The following models are Seamless licensed as found in SEAMLESS_LICENSE:
- Seamless models.
- SeamlessExpressive models.
Overview (`ggml/README.md`)
unity.cpp
Introduction
GGML is an open source library in C to enable large model inference on various hardware platforms. We implemented unity.cpp in ggml. Now it supports SeamlessM4T model for X2T tasks - Speech-to-text translation (S2TT), Acoustic speech recognition (ASR), Text-to-text translation (T2TT).
The project is still active in development. Contributions are welcome!
Build
To build the interactive console for S2TT & ASR & T2TT,
cd seamless_communication/ggml
mkdir build; cd build
cmake -DGGML_OPENBLAS=ON \
-DBUILD_SHARED_LIBS=On \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-g2 -fno-omit-frame-pointer" \
..
make -j4 unity # Interactive ConsoleFor more build commands see Makefile.
CLI usage
S2TT
Command to launch an interactive console for S2TT & ASR, note that the model already includes vocabulary needed to detokenize.
OPENBLAS_NUM_THREADS=8 ./bin/unity --model seamlessM4T_medium.ggmlIn the console, enter "wav_file tgt_lang" - the path of local waveform file and target language, separated by space. Note that the first run would include some โwarm upโ time so could be slow.
T2TT
Launching command:
OPENBLAS_NUM_THREADS=8 ./bin/unity --model nllb-200_dense_1b.ggml --textIn the console, enter "input_text tgt_lang" - input text and target langauge, separated by space. Note that the language code should align with NLLB BCP-47 code, NOT 3-letter language code as S2TT task with Seamless. Unifying this is on todo list.
Model downloads
Converted ggml models could be downloaded from
| SeamlessM4T_large | SeamlessM4T_medium | NLLB_dense_1b | NLLB_distill_600m |
|---|---|---|---|
| model | model | model | model |
For more details of NLLB models, please check https://github.com/facebookresearch/fairseq/tree/nllb.
Fairseq2 model conversion
Models from fairseq2 checkpoints could be converted to ggml automatically with ggml_convert.py.
python ggml_convert.py -m MODEL_NAMEwhere MODEL_NAME corresponds to asset cards in fairseq2 / seamless_communication, e.g. seamlessM4T_medium, seamlessM4T_large
Python bindings
We also utilize ggml python bindings for better dev experience. For examples of running unity.cpp in python, refer to tests in test_unity_cpp.py.
[Optional]Dependencies
OpenBLAS
We strongly suggest building with OpenBLAS, as we've seen 8x speedup on test machine.
libsndfile
This is needed only for the console to load waveform, but not the library.
Overview (`docs/expressive/README.md`)
SeamlessExpressive
SeamlessExpressive model consists of two main modules: (1) Prosody UnitY2, which is a prosody-aware speech-to-unit translation model based on UnitY2 architecture; and (2) PRETSSEL, which is a unit-to-speech model featuring cross-lingual expressivity preservation.
Prosody UnitY2
Prosody UnitY2 is an expressive speech-to-unit translation model, injecting expressivity embedding from PRETSSEL into the unit generation. It could transfer phrase-level prosody such as speech rate or pauses.
PRETSSEL
Paralinguistic REpresentation-based
TextleSS acoustic modEL (PRETSSEL) is an expressive unit-to-speech generator, and it can efficiently disentangle semantic and expressivity components from speech. It transfers utterance-level expressivity like the style of one's voice.
Benchmark Datasets
mExpresso (Multilingual Expresso)
mExpresso is an expressive S2ST dataset that includes seven styles of read speech (i.e., default, happy, sad, confused, enunciated, whisper and laughing) between English and five other languages -- French, German, Italian, Mandarin and Spanish. We create the dataset by expanding a subset of read speech in Expresso Dataset. We first translate the English transcriptions into other languages, including the emphasis markers in the transcription, and then the gender matched bilingual speakers read the translation in the style suggested by the markers.
We are currently open source the text translation of the other language to enable evaluating English to other directions. We will open source the audio files in the near future.
Text translation in other languages can be Downloaded.
Statistics of mExpresso
| language pair | subset | # items | English duration (hr) | # speakers |
|---|---|---|---|---|
| eng-cmn | dev | 2369 | 2.1 | 1 |
| test | 5003 | 4.8 | 2 | |
| eng-deu | dev | 4420 | 3.9 | 2 |
| test | 5733 | 5.6 | 2 | |
| eng-fra | dev | 4770 | 4.2 | 2 |
| test | 5742 | 5.6 | 2 | |
| eng-ita | dev | 4413 | 3.9 | 2 |
| test | 5756 | 5.7 | 2 | |
| eng-spa | dev | 4758 | 4.2 | 2 |
| test | 5693 | 5.5 | 2 |
Create mExpresso S2T dataset by downloading and combining with English Expresso
Run the following command to create English to other langauges speech-to-text dataset from scratch. It will first download the English Expresso dataset, downsample the audio to 16k Hz, and join with the text translation to form the manifest.
python3 -m seamless_communication.cli.expressivity.data.prepare_mexpresso \
<OUTPUT_FOLDER>The output manifest will be located at <OUTPUT_FOLDER>/{dev,test}_mexpresso_eng_{spa,fra,deu,ita,cmn}.tsv
Automatic evaluation
Python package dependencies (on top of seamless_communication, coming from stopes pipelines):
- Unidecode
- scipy
- phonemizer
- s3prl
- syllables
- ipapy
- pkuseg
- nltk
- fire
- inflect
pip install Unidecode scipy phonemizer s3prl syllables ipapy pkuseg nltk fire inflectAs described in Section 4.3 we use following automatic metrics:
ASR-BLEU: refer to
/src/seamless_communication/cli/eval_utilsto see how the OpenAI whisper ASR model is used to extract transcriptions from generated audios.Vocal Style Similarity: refer to stopes/eval/vocal_style_similarity for implementation details.
AutoPCP: refer to stopes/eval/auto_pcp for implementation details.
Pause and Rate scores: refer to stopes/eval/local_prosody for implementation details. Rate score corresponds to the syllable speech rate spearman correlation between source and predicted speech. Pause score corresponds to the weighted mean joint score produced by
stopes/eval/local_prosody/compare_utterances.pyscript from stopes repo.
Evaluation results: mExpresso
Please see mExpresso section on how to download evaluation data
Important Notes:
We used empirically chosen duration factors per each tgt language towards the best perceptual quality: 1.0 (default) for cmn, spa, ita; 1.1 for deu; 1.2 for fra. Same settings were used to report results in the "Seamless: Multilingual Expressive and Streaming Speech Translation" paper.
Results here slightly differs from ones shown in the paper due to several descrepancies in the pipeline: results reported here use pipeline w/ fairseq2 backend for model's inference and pipeline includes watermarking.
| Language | Partition | ASR-BLEU | Vocal Style Sim | AutoPCP | Pause | Rate |
|---|---|---|---|---|---|---|
| eng_cmn | dev | 26.080 | 0.207 | 3.168 | 0.236 | 0.538 |
| eng_deu | dev | 36.940 | 0.261 | 3.298 | 0.319 | 0.717 |
| eng_fra | dev | 37.780 | 0.231 | 3.285 | 0.331 | 0.682 |
| eng_ita | dev | 40.170 | 0.226 | 3.322 | 0.388 | 0.734 |
| eng_spa | dev | 42.400 | 0.228 | 3.379 | 0.332 | 0.702 |
| eng_cmn | test | 23.320 | 0.249 | 2.984 | 0.385 | 0.522 |
| eng_deu | test | 27.780 | 0.290 | 3.117 | 0.483 | 0.717 |
| eng_fra | test | 38.360 | 0.270 | 3.117 | 0.506 | 0.663 |
| eng_ita | test | 38.020 | 0.274 | 3.130 | 0.523 | 0.686 |
| eng_spa | test | 42.920 | 0.274 | 3.183 | 0.508 | 0.675 |
Step-by-step evaluation
Pre-requisite: all steps described here assume that the generation/inference has been completed following steps.
For stopes installation please refer to stopes/eval.
The resulting directory of generated outputs:
export SPLIT="dev_mexpresso_eng_spa" # example, change for your split
export TGT_LANG="spa"
export SRC_LANG="eng"
export GENERATED_DIR="path_to_generated_output_for_given_data_split"
export GENERATED_TSV="generate-${SPLIT}.tsv"
export STOPES_ROOT="path_to_stopes_code_repo"
export SC_ROOT="path_to_this_repo"ASR-BLEU evaluation
python ${SC_ROOT}/src/seamless_communication/cli/expressivity/evaluate/run_asr_bleu.py \
--generation_dir_path=${GENERATED_DIR} \
--generate_tsv_filename=generate-${SPLIT}.tsv \
--tgt_lang=${TGT_LANG}generate-${SPLIT}.tsvis an expected output from inference described in pre-requisite
After completion resulting ASR-BLEU score is written in ${GENERATED_DIR}/s2st_asr_bleu_normalized.json.
Vocal Style Similarity
Download & set WavLM finetuned ckpt path (${SPEECH_ENCODER_MODEL_PATH}) as described in stopes README to reproduce our vocal style similarity eval.
python -m stopes.modules +vocal_style_similarity=base \
launcher.cluster=local \
vocal_style_similarity.model_type=valle \
+vocal_style_similarity.model_path=${SPEECH_ENCODER_MODEL_PATH} \
+vocal_style_similarity.input_file=${GENERATED_DIR}/${GENERATED_TSV} \
+vocal_style_similarity.output_file=${GENERATED_DIR}/vocal_style_sim_result.txt \
vocal_style_similarity.named_columns=true \
vocal_style_similarity.src_audio_column=src_audio \
vocal_style_similarity.tgt_audio_column=hypo_audio- We report average number from all utterance scores written in
${GENERATED_DIR}/vocal_style_sim_result.txt.
AutoPCP
python -m stopes.modules +compare_audios=AutoPCP_multilingual_v2 \
launcher.cluster=local \
+compare_audios.input_file=${GENERATED_DIR}/${GENERATED_TSV} \
compare_audios.src_audio_column=src_audio \
compare_audios.tgt_audio_column=hypo_audio \
+compare_audios.named_columns=true \
+compare_audios.output_file=${GENERATED_DIR}/autopcp_result.txt- We report average number from all utterance scores written in
${GENERATED_DIR}/autopcp_result.txt.
Pause and Rate
This stage includes 3 steps: (1) src lang annotation, (2) tgt lang annotation, (3) pairwise comparison
# src lang pause&rate annotation
python ${STOPES_ROOT}/stopes/eval/local_prosody/annotate_utterances.py \
+data_path=${GENERATED_DIR}/${GENERATED_TSV} \
+result_path=${GENERATED_DIR}/${SRC_LANG}_speech_rate_pause_annotation.tsv \
+audio_column=src_audio \
+text_column=src_text \
+speech_units=[syllable] \
+vad=true \
+net=true \
+lang=$SRC_LANG \
+forced_aligner=fairseq2_nar_t2u_aligner
# tgt lang pause&rate annotation
python ${STOPES_ROOT}/stopes/eval/local_prosody/annotate_utterances.py \
+data_path=${GENERATED_DIR}/${GENERATED_TSV} \
+result_path=${GENERATED_DIR}/${TGT_LANG}_speech_rate_pause_annotation.tsv \
+audio_column=hypo_audio \
+text_column=s2t_out \
+speech_units=[syllable] \
+vad=true \
+net=true \
+lang=$TGT_LANG \
+forced_aligner=fairseq2_nar_t2u_aligner
# pair wise comparison
python ${STOPES_ROOT}/stopes/eval/local_prosody/compare_utterances.py \
+src_path=${GENERATED_DIR}/${SRC_LANG}_speech_rate_pause_annotation.tsv \
+tgt_path=${GENERATED_DIR}/${TGT_LANG}_speech_rate_pause_annotation.tsv \
+result_path=${GENERATED_DIR}/${SRC_LANG}_${TGT_LANG}_pause_scores.tsv \
+pause_min_duration=0.1- For Rate reporting, please see the aggregation function
get_ratein${SC_ROOT}/src/seamless_communication/cli/expressivity/evaluate/post_process_pauserate.py; - For Pause reporting, please see the aggregation function
get_pausein${SC_ROOT}/src/seamless_communication/cli/expressivity/evaluate/post_process_pauserate.py.
Overview (`docs/expressive/seamless_align_expressive_README.md`)
SeamlessAlignExpressive
Building upon our past work with WikiMatrix, CCMatrix, NLLB, SpeechMatrix and SeamlessM4T, weโre introducing the first expressive speech alignment procedure. Starting with raw data, the expressive alignment procedure automatically discovers pairs of audio segments sharing not only the same meaning, but the same overall expressivity. To showcase this procedure, we are making metadata available to create a benchmarking dataset called SeamlessAlignExpressive, that can be used to validate the quality of our alignment method. SeamlessAlignExpressive is the first large-scale collection of multilingual audio alignments for expressive translation for benchmarking.
Format
The metadata files are space separated, gzip files. Each file corresponds to one alignment direction. File naming convention: we use 2 letters with an 'A': e.g. frA, enA, deA.
For example, the direction deA-enA corresponds to information for reconstructing German speech to English speech alignments.
Each line has 9 columns.
The columns correspond to:
- direction: direction, e.g. enA-deA
- side: side, e.g. enA or deA
- line_no: alignment number
- cc_warc: The public CC warc file reference containing the public audio url
- duration: original file duration
- audio_speech_segment_url: public audio reference
- audio_speech_start_frame: start frame when the audio is resampled at 16kHz
- audio_speech_end_frame: end frame when the audio is resampled at 16kHz
- laser_score: score of the alignment
Data
deA-enA enA-esA enA-frA enA-itA enA-zhA
Overview (`docs/m4t/README.md`)
SeamlessM4T
SeamlessM4T is our foundational all-in-one Massively Multilingual and Multimodal Machine Translation model delivering high-quality translation for speech and text in nearly 100 languages.
SeamlessM4T models support:
- :microphone: 101 languages for speech input.
- :speech_balloon: 96 Languages for text input/output.
- :speaker: 35 languages for speech output.
This unified model enables multiple tasks without relying on multiple separate models:
- Speech-to-speech translation (S2ST)
- Speech-to-text translation (S2TT)
- Text-to-speech translation (T2ST)
- Text-to-text translation (T2TT)
- Automatic speech recognition (ASR).
[!NOTE]
SeamlessM4T v2 and v1 are also supported in the ๐ค Transformers library, more on it in the dedicated section below.
SeamlessM4T v1
The v1 version of SeamlessM4T is a multitask adaptation of the UnitY architecture (Inaguma et al., 2023).
UnitY is a two-pass direct S2ST architecture which first generates textual representations and subsequently predicts discrete acoustic units.
SeamlessM4T v2
The v2 version of SeamlessM4T is a multitask adaptation of our novel UnitY2 architecture.
Unity2 with its hierarchical character-to-unit upsampling and non-autoregressive text-to-unit decoding considerably improves over SeamlessM4T v1 in quality and inference speed.
SeamlessM4T models
| Model Name | #params | checkpoint | metrics |
|---|---|---|---|
| SeamlessM4T-Large v2 | 2.3B | ๐ค Model card - checkpoint | metrics |
| SeamlessM4T-Large (v1) | 2.3B | ๐ค Model card - checkpoint | metrics |
| SeamlessM4T-Medium (v1) | 1.2B | ๐ค Model card - checkpoint | metrics |
We provide the extensive evaluation results of seamlessM4T-Large and SeamlessM4T-Medium reported in the paper (as averages) in the metrics files above.
The evaluation data ids for FLEURS, CoVoST2 and CVSS-C can be found here
Using SeamlessM4T models
`m4t_predict` with CLI:
Inference is run with the CLI, from the root directory of the repository.
The model can be specified with --model_name seamlessM4T_v2_large, seamlessM4T_large or seamlessM4T_medium:
# S2ST:
m4t_predict <path_to_input_audio> --task s2st --tgt_lang <tgt_lang> --output_path <path_to_save_audio> --model_name seamlessM4T_v2_large
# S2T:
m4t_predict <path_to_input_audio> --task s2tt --tgt_lang <tgt_lang> --model_name seamlessM4T_v2_large
# T2TT:
m4t_predict <input_text> --task t2tt --tgt_lang <tgt_lang> --src_lang <src_lang> --model_name seamlessM4T_v2_large
# T2ST:
m4t_predict <input_text> --task t2st --tgt_lang <tgt_lang> --src_lang <src_lang> --output_path <path_to_save_audio> --model_name seamlessM4T_v2_large
# ASR:
m4t_predict <path_to_input_audio> --task asr --tgt_lang <tgt_lang> --model_name seamlessM4T_v2_largeInference with `Translator`:
Inference calls for the Translator object instantiated with a multitask UnitY or UnitY2 model with the options:
and a vocoder:
vocoder_v2forseamlessM4T_v2_large.vocoder_36langsforseamlessM4T_largeorseamlessM4T_medium.
import torch
from seamless_communication.inference import Translator
# Initialize a Translator object with a multitask model, vocoder on the GPU.
translator = Translator("seamlessM4T_large", "vocoder_36langs", torch.device("cuda:0"), torch.float16)Now predict() can be used to run inference as many times on any of the supported tasks.
Given an input audio with or an input text in <src_lang>,
we first set the text_generation_opts, unit_generation_opts and then translate into <tgt_lang> as follows:
S2ST and T2ST (speech output):
# S2ST
text_output, speech_output = translator.predict(
input=<path_to_input_audio>,
task_str="S2ST",
tgt_lang=<tgt_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=unit_generation_opts
)
# T2ST
text_output, speech_output = translator.predict(
input=<input_text>,
task_str="T2ST",
tgt_lang=<tgt_lang>,
src_lang=<src_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=unit_generation_opts
)Note that <src_lang> must be specified for T2ST.
The generated units are synthesized and the output audio file is saved with:
# Save the translated audio output:
import torchaudio
torchaudio.save(
<path_to_save_audio>,
speech_output.audio_wavs[0][0].cpu(),
sample_rate=speech_output.sample_rate,
)S2TT, T2TT and ASR (text output):
# S2TT
text_output, _ = translator.predict(
input=<path_to_input_audio>,
task_str="S2TT",
tgt_lang=<tgt_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=None
)
# ASR
# This is equivalent to S2TT with `<tgt_lang>=<src_lang>`.
text_output, _ = translator.predict(
input=<path_to_input_audio>,
task_str="ASR",
tgt_lang=<src_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=None
)
# T2TT
text_output, _ = translator.predict(
input=<input_text>,
task_str="T2TT",
tgt_lang=<tgt_lang>,
src_lang=<src_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=None
)Note that <src_lang> must be specified for T2TT
To reproduce the seamless papers results (v1 or v2), or to evaluate using the same metrics over your own test sets, please check out the Evaluation README here.
Inference with ๐ค `Transformers`
SeamlessM4T is available in the ๐ค Transformers library, requiring minimal dependencies. Steps to get started:
- First install the ๐ค Transformers library from main and sentencepiece:
pip install git+https://github.com/huggingface/transformers.git sentencepiece- Run the following Python code to generate speech samples. Here the target language is Russian:
import torchaudio
from transformers import AutoProcessor, SeamlessM4Tv2Model
processor = AutoProcessor.from_pretrained("facebook/seamless-m4t-v2-large")
model = SeamlessM4Tv2Model.from_pretrained("facebook/seamless-m4t-v2-large")
# from text
text_inputs = processor(text="Hello, my dog is cute", src_lang="eng", return_tensors="pt")
audio_array_from_text = model.generate(**text_inputs, tgt_lang="rus")[0].cpu().squeeze()
# from audio
audio, orig_freq = torchaudio.load("https://www2.cs.uic.edu/~i101/SoundFiles/preamble10.wav")
audio = torchaudio.functional.resample(audio, orig_freq=orig_freq, new_freq=16_000) # must be a 16 kHz waveform array
audio_inputs = processor(audios=audio, return_tensors="pt")
audio_array_from_audio = model.generate(**audio_inputs, tgt_lang="rus")[0].cpu().squeeze()- Listen to the audio samples either in an ipynb notebook:
from IPython.display import Audio
sample_rate = model.config.sampling_rate
Audio(audio_array_from_text, rate=sample_rate)
Audio(audio_array_from_audio, rate=sample_rate)Or save them as a .wav file using a third-party library, e.g. torchaudio:
torchaudio.save(
<path_to_save_audio>,
audio_array_from_audio, # or audio_array_from_text
sample_rate=model.config.sampling_rate,
)- (bis) To run inference for text generating tasks (T2TT, ASR or S2TT), it is recommended to use dedicated models. With that, only the required sub-modules will be loaded. For exmaple, text-to-text translation from English to Bulgarian, is performed as follows:
from transformers import AutoProcessor, SeamlessM4Tv2ForTextToText
processor = AutoProcessor.from_pretrained("facebook/seamless-m4t-v2-large")
model = SeamlessM4Tv2ForTextToText.from_pretrained("facebook/seamless-m4t-v2-large")
src_lang, tgt_lang = "eng", "bul"
text_inputs = processor(text='Hello, my dog is cute', src_lang=src_lang, return_tensors="pt")
decoder_input_ids = model.generate(**text_inputs, tgt_lang=tgt_lang)[0].tolist()
translated_text = processor.decode(decoder_input_ids, skip_special_tokens=True)
print(f"{tgt_lang}: {translated_text}")[!NOTE]
For more details on using the SeamlessM4T model for inference using the ๐ค Transformers library, refer to the
SeamlessM4T v2 docs, the
SeamlessM4T v1 docs or to this hands-on Google Colab.
Finetuning SeamlessM4T models
Please check out the Finetuning README here.
Supported Languages:
Listed below, are the languages supported by SeamlessM4T-large (v1/v2).
The source column specifies whether a language is supported as source speech (Sp) and/or source text (Tx).
The target column specifies whether a language is supported as target speech (Sp) and/or target text (Tx).
| code | language | script | Source | Target |
|---|---|---|---|---|
| afr | Afrikaans | Latn | Sp, Tx | Tx |
| amh | Amharic | Ethi | Sp, Tx | Tx |
| arb | Modern Standard Arabic | Arab | Sp, Tx | Sp, Tx |
| ary | Moroccan Arabic | Arab | Sp, Tx | Tx |
| arz | Egyptian Arabic | Arab | Sp, Tx | Tx |
| asm | Assamese | Beng | Sp, Tx | Tx |
| ast | Asturian | Latn | Sp | -- |
| azj | North Azerbaijani | Latn | Sp, Tx | Tx |
| bel | Belarusian | Cyrl | Sp, Tx | Tx |
| ben | Bengali | Beng | Sp, Tx | Sp, Tx |
| bos | Bosnian | Latn | Sp, Tx | Tx |
| bul | Bulgarian | Cyrl | Sp, Tx | Tx |
| cat | Catalan | Latn | Sp, Tx | Sp, Tx |
| ceb | Cebuano | Latn | Sp, Tx | Tx |
| ces | Czech | Latn | Sp, Tx | Sp, Tx |
| ckb | Central Kurdish | Arab | Sp, Tx | Tx |
| cmn | Mandarin Chinese | Hans | Sp, Tx | Sp, Tx |
| cmn_Hant | Mandarin Chinese | Hant | Sp, Tx | Sp, Tx |
| cym | Welsh | Latn | Sp, Tx | Sp, Tx |
| dan | Danish | Latn | Sp, Tx | Sp, Tx |
| deu | German | Latn | Sp, Tx | Sp, Tx |
| ell | Greek | Grek | Sp, Tx | Tx |
| eng | English | Latn | Sp, Tx | Sp, Tx |
| est | Estonian | Latn | Sp, Tx | Sp, Tx |
| eus | Basque | Latn | Sp, Tx | Tx |
| fin | Finnish | Latn | Sp, Tx | Sp, Tx |
| fra | French | Latn | Sp, Tx | Sp, Tx |
| fuv | Nigerian Fulfulde | Latn | Sp, Tx | Tx |
| gaz | West Central Oromo | Latn | Sp, Tx | Tx |
| gle | Irish | Latn | Sp, Tx | Tx |
| glg | Galician | Latn | Sp, Tx | Tx |
| guj | Gujarati | Gujr | Sp, Tx | Tx |
| heb | Hebrew | Hebr | Sp, Tx | Tx |
| hin | Hindi | Deva | Sp, Tx | Sp, Tx |
| hrv | Croatian | Latn | Sp, Tx | Tx |
| hun | Hungarian | Latn | Sp, Tx | Tx |
| hye | Armenian | Armn | Sp, Tx | Tx |
| ibo | Igbo | Latn | Sp, Tx | Tx |
| ind | Indonesian | Latn | Sp, Tx | Sp, Tx |
| isl | Icelandic | Latn | Sp, Tx | Tx |
| ita | Italian | Latn | Sp, Tx | Sp, Tx |
| jav | Javanese | Latn | Sp, Tx | Tx |
| jpn | Japanese | Jpan | Sp, Tx | Sp, Tx |
| kam | Kamba | Latn | Sp | -- |
| kan | Kannada | Knda | Sp, Tx | Tx |
| kat | Georgian | Geor | Sp, Tx | Tx |
| kaz | Kazakh | Cyrl | Sp, Tx | Tx |
| kea | Kabuverdianu | Latn | Sp | -- |
| khk | Halh Mongolian | Cyrl | Sp, Tx | Tx |
| khm | Khmer | Khmr | Sp, Tx | Tx |
| kir | Kyrgyz | Cyrl | Sp, Tx | Tx |
| kor | Korean | Kore | Sp, Tx | Sp, Tx |
| lao | Lao | Laoo | Sp, Tx | Tx |
| lit | Lithuanian | Latn | Sp, Tx | Tx |
| ltz | Luxembourgish | Latn | Sp | -- |
| lug | Ganda | Latn | Sp, Tx | Tx |
| luo | Luo | Latn | Sp, Tx | Tx |
| lvs | Standard Latvian | Latn | Sp, Tx | Tx |
| mai | Maithili | Deva | Sp, Tx | Tx |
| mal | Malayalam | Mlym | Sp, Tx | Tx |
| mar | Marathi | Deva | Sp, Tx | Tx |
| mkd | Macedonian | Cyrl | Sp, Tx | Tx |
| mlt | Maltese | Latn | Sp, Tx | Sp, Tx |
| mni | Meitei | Beng | Sp, Tx | Tx |
| mya | Burmese | Mymr | Sp, Tx | Tx |
| nld | Dutch | Latn | Sp, Tx | Sp, Tx |
| nno | Norwegian Nynorsk | Latn | Sp, Tx | Tx |
| nob | Norwegian Bokmรฅl | Latn | Sp, Tx | Tx |
| npi | Nepali | Deva | Sp, Tx | Tx |
| nya | Nyanja | Latn | Sp, Tx | Tx |
| oci | Occitan | Latn | Sp | -- |
| ory | Odia | Orya | Sp, Tx | Tx |
| pan | Punjabi | Guru | Sp, Tx | Tx |
| pbt | Southern Pashto | Arab | Sp, Tx | Tx |
| pes | Western Persian | Arab | Sp, Tx | Sp, Tx |
| pol | Polish | Latn | Sp, Tx | Sp, Tx |
| por | Portuguese | Latn | Sp, Tx | Sp, Tx |
| ron | Romanian | Latn | Sp, Tx | Sp, Tx |
| rus | Russian | Cyrl | Sp, Tx | Sp, Tx |
| slk | Slovak | Latn | Sp, Tx | Sp, Tx |
| slv | Slovenian | Latn | Sp, Tx | Tx |
| sna | Shona | Latn | Sp, Tx | Tx |
| snd | Sindhi | Arab | Sp, Tx | Tx |
| som | Somali | Latn | Sp, Tx | Tx |
| spa | Spanish | Latn | Sp, Tx | Sp, Tx |
| srp | Serbian | Cyrl | Sp, Tx | Tx |
| swe | Swedish | Latn | Sp, Tx | Sp, Tx |
| swh | Swahili | Latn | Sp, Tx | Sp, Tx |
| tam | Tamil | Taml | Sp, Tx | Tx |
| tel | Telugu | Telu | Sp, Tx | Sp, Tx |
| tgk | Tajik | Cyrl | Sp, Tx | Tx |
| tgl | Tagalog | Latn | Sp, Tx | Sp, Tx |
| tha | Thai | Thai | Sp, Tx | Sp, Tx |
| tur | Turkish | Latn | Sp, Tx | Sp, Tx |
| ukr | Ukrainian | Cyrl | Sp, Tx | Sp, Tx |
| urd | Urdu | Arab | Sp, Tx | Sp, Tx |
| uzn | Northern Uzbek | Latn | Sp, Tx | Sp, Tx |
| vie | Vietnamese | Latn | Sp, Tx | Sp, Tx |
| xho | Xhosa | Latn | Sp | -- |
| yor | Yoruba | Latn | Sp, Tx | Tx |
| yue | Cantonese | Hant | Sp, Tx | Tx |
| zlm | Colloquial Malay | Latn | Sp | -- |
| zsm | Standard Malay | Latn | Tx | Tx |
| zul | Zulu | Latn | Sp, Tx | Tx |
Note that seamlessM4T-medium supports 200 languages in the text modality, and is based on NLLB-200 (see full list in asset card)
Citation
For UnitY, please cite :
@inproceedings{inaguma-etal-2023-unity,
title="{U}nit{Y}: Two-pass Direct Speech-to-speech Translation with Discrete Units",
author="Inaguma, Hirofumi and Popuri, Sravya and Kulikov, Ilia and Chen, Peng-Jen and Wang, Changhan and Chung, Yu-An and Tang, Yun and Lee, Ann and Watanabe, Shinji and Pino, Juan",
booktitle="Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
year="2023",
url="https://aclanthology.org/2023.acl-long.872",
}For SeamlessM4T v1, please cite :
@article{seamlessm4t2023,
title={SeamlessM4T: Massively Multilingual \& Multimodal Machine Translation},
author={{Seamless Communication}, Lo\"{i}c Barrault, Yu-An Chung, Mariano Cora Meglioli, David Dale, Ning Dong, Paul-Ambroise Duquenne, Hady Elsahar, Hongyu Gong, Kevin Heffernan, John Hoffman, Christopher Klaiber, Pengwei Li, Daniel Licht, Jean Maillard, Alice Rakotoarison, Kaushik Ram Sadagopan, Guillaume Wenzek, Ethan Ye, Bapi Akula, Peng-Jen Chen, Naji El Hachem, Brian Ellis, Gabriel Mejia Gonzalez, Justin Haaheim, Prangthip Hansanti, Russ Howes, Bernie Huang, Min-Jae Hwang, Hirofumi Inaguma, Somya Jain, Elahe Kalbassi, Amanda Kallet, Ilia Kulikov, Janice Lam, Daniel Li, Xutai Ma, Ruslan Mavlyutov, Benjamin Peloquin, Mohamed Ramadan, Abinesh Ramakrishnan, Anna Sun, Kevin Tran, Tuan Tran, Igor Tufanov, Vish Vogeti, Carleigh Wood, Yilin Yang, Bokai Yu, Pierre Andrews, Can Balioglu, Marta R. Costa-juss\`{a} \footnotemark[3], Onur \,{C}elebi,Maha Elbayad,Cynthia Gao, Francisco Guzm\'an, Justine Kao, Ann Lee, Alexandre Mourachko, Juan Pino, Sravya Popuri, Christophe Ropers, Safiyyah Saleem, Holger Schwenk, Paden Tomasello, Changhan Wang, Jeff Wang, Skyler Wang},
journal={ArXiv},
year={2023}
}For SeamlessM4T v2, please cite :
@inproceedings{seamless2023,
title="Seamless: Multilingual Expressive and Streaming Speech Translation",
author="{Seamless Communication}, Lo{\"i}c Barrault, Yu-An Chung, Mariano Coria Meglioli, David Dale, Ning Dong, Mark Duppenthaler, Paul-Ambroise Duquenne, Brian Ellis, Hady Elsahar, Justin Haaheim, John Hoffman, Min-Jae Hwang, Hirofumi Inaguma, Christopher Klaiber, Ilia Kulikov, Pengwei Li, Daniel Licht, Jean Maillard, Ruslan Mavlyutov, Alice Rakotoarison, Kaushik Ram Sadagopan, Abinesh Ramakrishnan, Tuan Tran, Guillaume Wenzek, Yilin Yang, Ethan Ye, Ivan Evtimov, Pierre Fernandez, Cynthia Gao, Prangthip Hansanti, Elahe Kalbassi, Amanda Kallet, Artyom Kozhevnikov, Gabriel Mejia, Robin San Roman, Christophe Touret, Corinne Wong, Carleigh Wood, Bokai Yu, Pierre Andrews, Can Balioglu, Peng-Jen Chen, Marta R. Costa-juss{\`a}, Maha Elbayad, Hongyu Gong, Francisco Guzm{\'a}n, Kevin Heffernan, Somya Jain, Justine Kao, Ann Lee, Xutai Ma, Alex Mourachko, Benjamin Peloquin, Juan Pino, Sravya Popuri, Christophe Ropers, Safiyyah Saleem, Holger Schwenk, Anna Sun, Paden Tomasello, Changhan Wang, Jeff Wang, Skyler Wang, Mary Williamson",
journal={ArXiv},
year={2023}
}Overview (`docs/m4t/on_device_README.md`)
On-device Models [Experimental]
Apart from SeamlessM4T-LARGE (2.3B) and SeamlessM4T-MEDIUM (1.2B) models, we are also developing a small model (281M) targeting for on-device inference.
This folder contains an example to run an exported small model covering most tasks (ASR/S2TT/S2ST). The model could be executed on popular mobile devices with Pytorch Mobile (https://pytorch.org/mobile/home/).
Updates
[2023/8/23] Uploaded new on-device models with several fixes to reduce size and avoid OOM. Metrics should be close to what's reported below, will rerun eval and update.
Overview
| Model | Checkpoint | Num Params | Disk Size | Supported Tasks | Supported Languages |
|---|---|---|---|---|---|
| UnitY-Small | ๐ค Model card - checkpoint | 281M | 747MB | S2ST, S2TT, ASR | eng, fra, hin, por, spa |
| UnitY-Small-S2T | ๐ค Model card - checkpoint | 235M | 481MB | S2TT, ASR | eng, fra,hin, por, spa |
UnitY-Small-S2T is a pruned version of UnitY-Small without 2nd pass unit decoding.
Inference
To use exported model, users don't need seamless_communication or fairseq2 dependency.
import torchaudio
import torch
audio_input, _ = torchaudio.load(TEST_AUDIO_PATH) # Load waveform using torchaudio
s2t_model = torch.jit.load("unity_on_device_s2t.ptl") # Load exported S2T model
with torch.no_grad():
text = s2t_model(audio_input, tgt_lang=TGT_LANG) # Forward call with tgt_lang specified for ASR or S2TT
print(text) # Show text output
s2st_model = torch.jit.load("unity_on_device.ptl")
with torch.no_grad():
text, units, waveform = s2st_model(audio_input, tgt_lang=TGT_LANG) # S2ST model also returns waveform
print(text)
torchaudio.save(f"{OUTPUT_FOLDER}/result.wav", waveform.unsqueeze(0), sample_rate=16000) # Save output waveform to local fileAlso running the exported model doesn't need python runtime. For example, you could load this model in C++ following this tutorial, or building your own on-device applications similar to this example
Metrics
S2TT BLEU / S2ST ASR-BLEU on FLEURS
For ASR-BLEU, we follow the same protocol as SeamlessM4T Large/Medium models: We used Whisper-large-v2 for Eng-X and Whisper-medium for X-Eng when evaluating ASR BLEU.
| Direction | 1st-pass BLEU (S2TT) | 2nd-pass ASR-BLEU (S2ST) |
|---|---|---|
| eng-hin | 10.43 | 15.06 |
| eng-por | 21.54 | 17.35 |
| eng-rus | 7.88 | 5.11 |
| eng-spa | 12.78 | 11.75 |
| hin-eng | 12.92 | 10.50 |
| por-eng | 22.99 | 24.81 |
| rus-eng | 18.24 | 18.24 |
| spa-eng | 14.37 | 14.85 |
ASR WER on FLEURS
| LANG | WER |
|---|---|
| eng | 27.3 |
| hin | 41.5 |
| por | 25.2 |
| rus | 33.0 |
| spa | 18.0 |
Overview (`docs/m4t/seamless_align_README.md`)
Seamless - Speech to Speech and Speech to Text Metadata
This document contains metadata information for reconstructing the dataset we used for training our models.
Format
The metadata format is similar to NLLB bitext format with some small differences.
The metadata files are tab separated, gzip files. Each file corresponds to one alignment direction.
File naming convention:
- for text, we use 3 letters: e.g.
fra,eng,tur - for audio, we use 2 letters and a 'A': e.g.
frA,enA,trA
For example, the direction eng-trA corresponds to information for reconstructing English text with Turkish speech alignments. Similarly, enA-jpn corresponds to "English speech with Japanese text", and enA-frA corresponds to "English speech with French speech".
Each line has 11 columns.
For Audio, the columns correspond to:
- `cc_warc`: The warc file reference containing the public audio url
- `cc_sha`: not used
- `audio_speeh_segment_url`: space separated audio reference. See below.
- `cc_lineno`: not used
- `paragraph_digest`: expected duration of the whole audio file (without start/end frame trimming)
- `sentence_digest`: not used
- `text_lid_score`: not used
- `laser_score`: score of the alignment
- `direction`: direction, e.g. `enA-jpn`
- `side`: side, e.g. `enA` or `jpn`
- `line_no`: alignment numberaudio_speech_segment_url is a space separated audio reference. It has the following format: <start_frame> <end_frame>, where start_frame and end_frame correspond to the segment that needs to be extracted from the audio file that is referenced at ``, resampled at 16000 Hz.
For text, the columns are similar to NLLB format (except being tab separated here):
If the metadata comes from Common Crawl:
cc_warc: the reference to the Common Crawl WET filecc_sha: the document sha1 in the WET filecc_document_url: the url of the document referenced in the WET filecc_lineno: the line number in the document referenced in the WET fileparagraph_digest: xxhash.xxh3_64_intdigest of the paragraphsentence_digest: xxhash.xxh3_64_intdigest of the sentencetext_lid_score: language identification score, when availablelaser_score: score of the alignmentdirection: direction, e.g.enA-jpnside: side, e.g.enAorjpnline_no: alignment number
If the metadata comes from other corpus:
corpus: corpus namecc_sha: not usedcc_document_url: not usedlineno: line number in the documentparagraph_digest: xxhash.xxh3_64_intdigest of the paragraphsentence_digest: xxhash.xxh3_64_intdigest of the sentencetext_lid_score: language identification score, when availablelaser_score: score of the alignmentdirection: direction, e.g.enA-jpnside: side, e.g.enAorjpnline_no: alignment number
Data
Update: 30 Nov 2023
We are publishing an extension of the previous speech to speech release.
afA-enA amA-enA arA-enA asA-enA azA-enA beA-enA bgA-enA bnA-enA bsA-enA caA-enA csA-enA cyA-enA daA-enA deA-enA elA-enA enA-esA enA-etA enA-fiA enA-frA enA-gaA enA-glA enA-guA enA-heA enA-hiA enA-hrA enA-huA enA-hyA enA-idA enA-isA enA-itA enA-jaA enA-jvA enA-kaA enA-kiA enA-kkA enA-knA enA-koA enA-kyA enA-lgA enA-loA enA-ltA enA-lvA enA-mkA enA-mlA enA-mnA enA-mrA enA-msA enA-mtA enA-neA enA-nlA enA-noA enA-orA enA-paA enA-pbA enA-plA enA-psA enA-ptA enA-rnA enA-ruA enA-sdA enA-skA enA-slA enA-srA enA-svA enA-swA enA-taA enA-teA enA-tgA enA-thA enA-trA enA-ukA enA-urA enA-uzA enA-viA enA-yoA enA-zhA
Update: 25 Sep 2023
We are publishing updated metadata with the expected duration of the original audio file in the column paragraph_digest (originally not used for audio).
arb-enA ben-enA cat-enA dan-enA enA-est enA-fin enA-jpn enA-mlt enA-nld enA-pol enA-por enA-ron enA-slk enA-swe enA-swh enA-tur enA-ukr enA-urd enA-vie arA-enA arA-eng beA-enA caA-enA caA-eng csA-enA csA-eng cyA-enA cyA-eng daA-enA daA-eng deA-enA deA-eng enA-esA enA-fiA enA-frA enA-hiA enA-idA enA-itA enA-knA enA-koA enA-mtA enA-nlA enA-plA enA-ptA enA-rnA enA-ruA enA-skA enA-svA enA-swA enA-taA enA-teA enA-tgA enA-thA enA-trA enA-ukA enA-urA enA-uzA enA-viA enA-zhA eng-esA eng-fiA eng-frA eng-hiA eng-idA eng-itA eng-knA eng-koA eng-mtA eng-nlA eng-plA eng-ptA eng-rnA eng-ruA eng-skA eng-swA eng-taA eng-teA eng-tgA eng-thA eng-trA eng-ukA eng-urA eng-uzA eng-viA eng-zhA
You can find the legacy metadata (without duration information) here:
Legacy Data
arb-enA ben-enA cat-enA dan-enA enA-est enA-fin enA-jpn enA-mlt enA-nld enA-pol enA-por enA-ron enA-slk enA-swe enA-swh enA-tur enA-ukr enA-urd enA-vie arA-enA arA-eng beA-enA caA-enA caA-eng csA-enA csA-eng cyA-enA cyA-eng daA-enA daA-eng deA-enA deA-eng enA-esA enA-fiA enA-frA enA-hiA enA-idA enA-itA enA-knA enA-koA enA-mtA enA-nlA enA-plA enA-ptA enA-rnA enA-ruA enA-skA enA-svA enA-swA enA-taA enA-teA enA-tgA enA-thA enA-trA enA-ukA enA-urA enA-uzA enA-viA enA-zhA eng-esA eng-fiA eng-frA eng-hiA eng-idA eng-itA eng-knA eng-koA eng-mtA eng-nlA eng-plA eng-ptA eng-rnA eng-ruA eng-skA eng-swA eng-taA eng-teA eng-tgA eng-thA eng-trA eng-ukA eng-urA eng-uzA eng-viA eng-zhA
Download script
You can use the wet_lines script to download and gather aligned text information from the metadata. This script can be found here.
Example usage:
zcat seamless.dataset.metadata.public.enA-swA.tsv.gz | egrep ^crawl-data | tr '\t' ' ' | wet_lines
Based on metadata information it receives from stdin, wet_lines will download the corpora, find the paragraph and print the input with an additional column which corresponds to the text of the paragraph.
In order to retrieve the sentences from these paragraphs, one can use the sentence splitter available here. It will print the input (metadata + paragraph) with an additional column which corresponds to the text of the sentence.
Reconstructing sentences from metadata:
xzcat metadatafile.xz | egrep ^crawl-data | wet_lines | python -c "from sentence_cleaner_splitter.cleaner_splitter import *; split_clean()"
Overview (`docs/m4t/unity2_aligner_README.md`)
UnitY2 forced alignment extractor
Please refer to Section 3.3.2 of the "Seamless: Multilingual Expressive and Streaming Speech Translation" paper to read more details about aligner design & training.
We provide a light-weight wrapper to extract alignments between given text and acoustic unit sequences. Unit extractor is also available from the wrapper itself.
Alignment extractor codebase
The entire codebase is located in /src/seamless_communication/models/aligner. It is built using fairseq2 library. This time we release a mutlilingual (38 languages following SeamlessM4Tv2 target languages) checkpoint to load the alignment toolkit. This checkpoint corresponds to nar_t2u_aligner asset card.
Usage examples
For large-scale alignment extraction offline unit extraction is preferred. Refer to /src/seamless_communication/cli/m4t/audio_to_units for more details on offline unit extraction.
Alignment extractor initialization:
from seamless_communication.models.aligner.alignment_extractor import AlignmentExtractor
from fairseq2.typing import Device
import torch
extractor = AlignmentExtractor(
aligner_model_name_or_card="nar_t2u_aligner",
unit_extractor_model_name_or_card="xlsr2_1b_v2",
unit_extractor_output_layer=35,
unit_extractor_kmeans_model_uri="https://dl.fbaipublicfiles.com/seamlessM4T/models/unit_extraction/kmeans_10k.npy",
)large unit extractor checkpoint will be downloaded, this takes time
by default cpu device is used, but fp16 (
dtype=torch.float16) & cuda (device=Device("cuda")) are supported, see class constructor for details
Extracting alignment
Ru audio example:
audio link:
https://models.silero.ai/denoise_models/sample0.wav(thanks Silero team for public audio samples)ru_transcription:
ะฟะตัะฒะพะต ััะพ ะผะตะฝั ะฟะพัะฐะทะธะปะพ ััะพ ะฝะตะพะฑัะบะฝะพะฒะตะฝะฝะพ ััะบะธะน ัะพะปะฝะตัะฝัะน ัะฒะตั ะฟะพั ะพะถะธะน ะฝะฐ ัะปะตะบััะพัะฒะฐัะบั
alignment_durations, _, tokenized_text_tokens = extractor.extract_alignment("sample0.wav", ru_transcription, plot=True, add_trailing_silence=True)audio will be resampled to 16kHz for unit extraction
alignment_durationscontains number of units (20ms frames) aligned per each token fromtokenized_text_tokens.add_trailing_silencesets extra silence token in the end of the given text sequence. That is useful when there is no terminal punctuation provided in the text itself.
Ru alignment plot:
En audio example:
audio link:
https://dl.fbaipublicfiles.com/seamlessM4T/LJ037-0171_sr16k.waven_transcription:
the examination and testimony of the experts enabled the commision to conclude that five shots may have been fired.
alignment_durations, _, tokenized_text_tokens = extractor.extract_alignment("LJ037-0171_sr16k.wav", en_transcription, plot=True, add_trailing_silence=False)- here we set
add_trailing_silenceto False since terminal punctuation exists, but True will also work
En alignment plot:
Integration test
If you encounter issues with produced alignments, please run integration test with the alignment extraction toolkit to make sure that your environment works good.
Run from the repo root:
pytest -vv tests/integration/models/test_unity2_aligner.py
Overview (`docs/streaming/README.md`)
SeamlessStreaming
SeamlessStreaming is a multilingual streaming translation model. It supports:
- Streaming Automatic Speech Recognition on 96 languages.
- Simultaneous translation on 101 source languages for speech input.
- Simultaneous translation on 96 target languages for text output.
- Simultaneous translation on 36 target languages for speech output.
Check out the SeamlessM4T README for more details on supported languages.
SeamlessStreaming models
| Model Name | #params | checkpoint | metrics |
|---|---|---|---|
| SeamlessStreaming | 2.5B | ๐ค Model card - monotonic decoder checkpoint - streaming UnitY2 checkpoint | metrics |
The evaluation data ids for FLEURS, CoVoST2 and CVSS-C can be found here
Evaluating SeamlessStreaming models
To reproduce our results, or to evaluate using the same metrics over your own test sets, please check out the Evaluation README here. Streaming evaluation depends on the SimulEval library.
Citation
For EMMA, please cite :
@article{ma_efficient_2023,
author={Ma, Xutai and Sun, Anna and Ouyang, Siqi and Inaguma, Hirofumi and Tomasello, Paden},
title={Efficient Monotonic Multihead Attention},
year={2023},
url={https://ai.meta.com/research/publications/efficient-monotonic-multihead-attention/},
}For SeamlessStreaming, please cite :
@inproceedings{seamless2023,
title="Seamless: Multilingual Expressive and Streaming Speech Translation",
author="{Seamless Communication}, Lo{\"i}c Barrault, Yu-An Chung, Mariano Coria Meglioli, David Dale, Ning Dong, Mark Duppenthaler, Paul-Ambroise Duquenne, Brian Ellis, Hady Elsahar, Justin Haaheim, John Hoffman, Min-Jae Hwang, Hirofumi Inaguma, Christopher Klaiber, Ilia Kulikov, Pengwei Li, Daniel Licht, Jean Maillard, Ruslan Mavlyutov, Alice Rakotoarison, Kaushik Ram Sadagopan, Abinesh Ramakrishnan, Tuan Tran, Guillaume Wenzek, Yilin Yang, Ethan Ye, Ivan Evtimov, Pierre Fernandez, Cynthia Gao, Prangthip Hansanti, Elahe Kalbassi, Amanda Kallet, Artyom Kozhevnikov, Gabriel Mejia, Robin San Roman, Christophe Touret, Corinne Wong, Carleigh Wood, Bokai Yu, Pierre Andrews, Can Balioglu, Peng-Jen Chen, Marta R. Costa-juss{\`a}, Maha Elbayad, Hongyu Gong, Francisco Guzm{\'a}n, Kevin Heffernan, Somya Jain, Justine Kao, Ann Lee, Xutai Ma, Alex Mourachko, Benjamin Peloquin, Juan Pino, Sravya Popuri, Christophe Ropers, Safiyyah Saleem, Holger Schwenk, Anna Sun, Paden Tomasello, Changhan Wang, Jeff Wang, Skyler Wang, Mary Williamson",
journal={ArXiv},
year={2023}
}Overview (`ggml/examples/python/README.md`)
Simple autogenerated Python bindings for ggml
This folder contains:
- Scripts to generate full Python bindings from ggml headers (+ stubs for autocompletion in IDEs)
- Some barebones utils (see ggml/utils.py):
ggml.utils.initbuilds a context that's freed automatically when the pointer gets GC'dggml.utils.copycopies between same-shaped tensors (numpy or ggml), w/ automatic (de/re)quantizationggml.utils.numpyreturns a numpy view over a ggml tensor; if it's quantized, it returns a copy (requiresallow_copy=True)
- Very basic examples (anyone wants to port llama2.c?)
Provided you set GGML_LIBRARY=.../path/to/libggml_shared.so (see instructions below), it's trivial to do some operations on quantized tensors:
# Make sure libllama.so is in your [DY]LD_LIBRARY_PATH, or set GGML_LIBRARY=.../libggml_shared.so
from ggml import lib, ffi
from ggml.utils import init, copy, numpy
import numpy as np
ctx = init(mem_size=12*1024*1024)
n = 256
n_threads = 4
a = lib.ggml_new_tensor_1d(ctx, lib.GGML_TYPE_Q5_K, n)
b = lib.ggml_new_tensor_1d(ctx, lib.GGML_TYPE_F32, n) # Can't both be quantized
sum = lib.ggml_add(ctx, a, b) # all zeroes for now. Will be quantized too!
gf = ffi.new('struct ggml_cgraph*')
lib.ggml_build_forward_expand(gf, sum)
copy(np.array([i for i in range(n)], np.float32), a)
copy(np.array([i*100 for i in range(n)], np.float32), b)
lib.ggml_graph_compute_with_ctx(ctx, gf, n_threads)
print(numpy(a, allow_copy=True))
# 0. 1.0439453 2.0878906 3.131836 4.1757812 5.2197266. ...
print(numpy(b))
# 0. 100. 200. 300. 400. 500. ...
print(numpy(sum, allow_copy=True))
# 0. 105.4375 210.875 316.3125 421.75 527.1875 ...Prerequisites
You'll need a shared library of ggml to use the bindings.
Build libggml_shared.so or libllama.so
As of this writing the best is to use ggerganov/llama.cpp's generated libggml_shared.so or libllama.so, which you can build as follows:
git clone https://github.com/ggerganov/llama.cpp
# On a CUDA-enabled system add -DLLAMA_CUBLAS=1
# On a Mac add -DLLAMA_METAL=1
cmake llama.cpp \
-B llama_build \
-DCMAKE_C_FLAGS=-Ofast \
-DLLAMA_NATIVE=1 \
-DLLAMA_LTO=1 \
-DBUILD_SHARED_LIBS=1 \
-DLLAMA_MPI=1 \
-DLLAMA_BUILD_TESTS=0 \
-DLLAMA_BUILD_EXAMPLES=0
( cd llama_build && make -j )
# On Mac, this will be libggml_shared.dylib instead
export GGML_LIBRARY=$PWD/llama_build/libggml_shared.so
# Alternatively, you can just copy it to your system's lib dir, e.g /usr/local/lib(Optional) Regenerate the bindings and stubs
If you added or changed any signatures of the C API, you'll want to regenerate the bindings (ggml/cffi.py) and stubs (ggml/init.pyi).
Luckily it's a one-liner using regenerate.py:
pip install -q cffi
python regenerate.pyBy default it assumes llama.cpp was cloned in ../../../llama.cpp (alongside the ggml folder). You can override this with:
C_INCLUDE_DIR=$LLAMA_CPP_DIR python regenerate.pyYou can also edit api.h to control which files should be included in the generated bindings (defaults to llama.cpp/ggml*.h)
In fact, if you wanted to only generate bindings for the current version of the ggml repo itself (instead of llama.cpp; you'd loose support for k-quants), you could run:
API=../../include/ggml/ggml.h python regenerate.pyDevelop
Run tests:
pytestAlternatives
This example's goal is to showcase cffi-generated bindings that are trivial to use and update, but there are already alternatives in the wild:
https://github.com/abetlen/ggml-python: these bindings seem to be hand-written and use ctypes. It has high-quality API reference docs that can be used with these bindings too, but it doesn't expose Metal, CUDA, MPI or OpenCL calls, doesn't support transparent (de/re)quantization like this example does (see ggml.utils module), and won't pick up your local changes.
https://github.com/abetlen/llama-cpp-python: these expose the C++
llama.cppinterface, which this example cannot easily be extended to support (cffionly generates bindings of C libraries)pybind11 and nanobind are two alternatives to cffi that support binding C++ libraries, but it doesn't seem either of them have an automatic generator (writing bindings is rather time-consuming).
Overview (`src/seamless_communication/inference/README.md`)
Running inference
SeamlessM4T Inference
Hereโs an example of using the CLI from the root directory to run inference.
S2ST task:
m4t_predict <path_to_input_audio> --task s2st --tgt_lang <tgt_lang> --output_path <path_to_save_audio>T2TT task:
m4t_predict <input_text> --task t2tt --tgt_lang <tgt_lang> --src_lang <src_lang>Please refer to the inference README for detailed instruction on how to run inference and the list of supported languages on the source, target sides for speech, text modalities.
For running S2TT/ASR natively (without Python) using GGML, please refer to the unity.cpp section.
Transcription Utilities: Denoising and Segmentation
The following information shows how to use denoising and segmentation tools for noisy and long input audios.
Demucs: Audio Denoising Tool
The 'Demucs' class provides functionality for denoising audio in the transcription pipeline. It supports various configuration options, allowing for fine-tuning denoising performance based on specific requirements.
Key Features:
- Denoising audio using the Demucs model.
- Configurable parameters for denoising.
- Support for both Tensor input and audio file input.
- Automatic cleanup of temporary files generated during denoising.
Installation
Manually install demucs:
pip install git+https://github.com/facebookresearch/demucs#egg=demucs
Usage
To utilize Demucs for denoising audio, instantiate the Transcriber class and optionally the DenoisingConfig class with desired configuration. 'denoise' parameter is False by default, and needs to be set to True to use denoising.
import torch
from seamless_communication.inference import Transcriber
from seamless_communication.denoise.demucs import DenoisingConfig
model_name = "seamlessM4T_v2_large"
vocoder_name = "vocoder_v2" if model_name == "seamlessM4T_v2_large" else "vocoder_36langs"
transcriber = Transcriber (
model_name,
device=torch.device("cpu"),
dtype=torch.float32,
)
denoise_config = DenoisingConfig(float32= True)
txt = transcriber.transcribe(audio="example.wav", src_lang="eng", denoise=True, denoise_config=denoise_config)Silero VAD Segmenter: Audio Segmentation Tool
The 'SileroVADSegmenter' class offers functionality for segmenting long audio recordings into chunks in the transcription pipeline. This tool segments based on speech timestamps.
Key Features:
- Segmenting long audio recordings into chunks based on speech presence.
- Automatic segmenting of all audio longer than the chunk size.
- Configurable parameters for chunk size and pause length.
- Resampling audio to match the model's sample rate.
- Efficient speech probability computation using sliding windows.
Usage
To utilize Silero VAD for segmenting audio, instantiate the Transcriber class. When using the transcribe method, audio will be segmented automatically if it is longer than chunk_size_sec, which has a default value of 20. Use a smaller value for better quality transcription.
pause_length_sec determines the duration of silence between segments and has a default value of 1 second. This parameter can be customized.
import torch
from seamless_communication.inference import Transcriber
model_name = "seamlessM4T_v2_large"
vocoder_name = "vocoder_v2" if model_name == "seamlessM4T_v2_large" else "vocoder_36langs"
transcriber = Transcriber (
model_name,
device=torch.device("cpu"),
dtype=torch.float32,
)
input_audio = "example.wav"
txt = transcriber.transcribe(audio=input_audio, src_lang="eng", chunk_size_sec=10, pause_length_sec=.5)Overview (`src/seamless_communication/cli/streaming/README.md`)
Evaluating SeamlessStreaming and Seamless models
SeamlessStreaming is the streaming only model and Seamless is the expressive streaming model.
Quick start:
Evaluation can be run with the streaming_evaluate CLI.
We use the seamless_streaming_unity for loading the speech encoder and T2U models, and seamless_streaming_monotonic_decoder for loading the text decoder for streaming evaluation. This is already set as defaults for the streaming_evaluate CLI, but can be overridden using the --unity-model-name and --monotonic-decoder-model-name args if required.
Note that the numbers in our paper use single precision floating point format (fp32) for evaluation by setting --dtype fp32. Also note that the results from running these evaluations might be slightly different from the results reported in our paper (which will be updated soon with the new results).
S2TT:
Set the task to s2tt for evaluating the speech-to-text translation part of the SeamlessStreaming model.
streaming_evaluate --task s2tt --data-file <path_to_data_tsv_file> --audio-root-dir <path_to_audio_root_directory> --output <path_to_evaluation_output_directory> --tgt-lang <3_letter_lang_code>Note: The --ref-field can be used to specify the name of the reference column in the dataset.
ASR:
Set the task to asr for evaluating the automatic speech recognition part of the SeamlessStreaming model. Make sure to pass the source language as the --tgt-lang arg.
streaming_evaluate --task asr --data-file <path_to_data_tsv_file> --audio-root-dir <path_to_audio_root_directory> --output <path_to_evaluation_output_directory> --tgt-lang <3_letter_source_lang_code>S2ST:
SeamlessStreaming:
Set the task to s2st for evaluating the speech-to-speech translation part of the SeamlessStreaming model.
streaming_evaluate --task s2st --data-file <path_to_data_tsv_file> --audio-root-dir <path_to_audio_root_directory> --output <path_to_evaluation_output_directory> --tgt-lang <3_letter_lang_code>Seamless:
The Seamless model is a unified model for streaming expressive speech-to-speech translation. Use the --expressive arg for running evaluation of this unified model.
streaming_evaluate --task s2st --data-file <path_to_data_tsv_file> --audio-root-dir <path_to_audio_root_directory> --output <path_to_evaluation_output_directory> --tgt-lang <3_letter_lang_code> --expressive --gated-model-dir <path_to_vocoder_checkpoints_dir>The Seamless model uses vocoder_pretssel which is a 24KHz version (vocoder_pretssel) by default. In the current version of our paper, we use 16KHz version (vocoder_pretssel_16khz) for the evaluation, so in order to reproduce those results please add this arg to the above command: --vocoder-name vocoder_pretssel_16khz.
vocoder_pretssel or vocoder_pretssel_16khz checkpoints are gated, please check out this section to acquire these checkpoints. Also, make sure to add --gated-model-dir
Overview (`src/seamless_communication/cli/m4t/audio_to_units/README.md`)
Convert raw audio into units (unit_extraction)
Raw audio needs to be converted to units to train UnitY models and vocoders. Units act as supervision for UnitY models, and are the input to the vocoders which synthesize speech from these units.
The unit extraction pipeline comprises the following steps:
- Compute features from layer 35 (determined empirically) of the pretrained XLSR v2 model (paper), which is a wav2vec2 model at the core.
- Assign features for each timestep to a collection of precomputed K-Means centroids to produce a sequence of units similar to extracting Hubert units as described in this paper.
Quick start:
audio_to_units is run with the CLI, from the root directory of the repository.
m4t_audio_to_units <path_to_input_audio>audio_to_units calls for UnitExtractor which provides a predict method to convert an audio to units.
The convenience method resynthesize_audio of UnitExtractor, can be used to resynthesize audio waveforms from units.
Overview (`src/seamless_communication/cli/m4t/evaluate/README.md`)
Evaluating SeamlessM4T models
Refer to the SeamlessM4T README for an overview of the M4T models.
Refer to the inference README for how to run inference with SeamlessM4T models.
Quick start:
We use SACREBLEU library for computing BLEU scores and JiWER library is used to compute these CER and WER scores.
Evaluation can be run with the CLI, from the root directory of the repository.
The model can be specified with --model_name: seamlessM4T_v2_large or seamlessM4T_large or seamlessM4T_medium
m4t_evaluate --data_file <path_to_data_tsv_file> --task <task_name> --tgt_lang <tgt_lang> --output_path <path_to_save_evaluation_output> --ref_field <ref_field_name> --audio_root_dir <path_to_audio_root_directory>Note
- We use raw (unnormalized) references to compute BLEU scores for S2TT, T2TT tasks.
- For ASR task, src_lang needs to be passed as
--src_langarg needs to be specified to run evaluation for T2TT task
Overview (`src/seamless_communication/cli/m4t/finetune/README.md`)
Finetuning scripts for M4T
This section demonstrates an example of M4T finetuning on a single translation direction: English-to-Korean.
The trainer and dataloader were designed mainly for demonstration purposes. Their simplicity should facilitate the code transparency and portability.
Data preparation
M4T training dataset is a multimodal parallel corpus. Each training sample has four parts: audio and text representation of the sample in the source language, and its corresponding audio and text representation in the target language.
That kind of dataset can be prepared using dataset.py script that downloads FLEURS dataset from HuggingFace datasets hub, (optionally) extracts units from the target audio samples, and prepares a manifest consumable by finetune.py. Manifest is a text file where each line represents information about a single dataset sample, serialized in JSON format.
List of input arguments for dataset.py:
--name NAME HuggingFace name of the dataset to prepare.
--source_lang SOURCE_LANG
M4T langcode of the dataset SOURCE language
--target_lang TARGET_LANG
M4T langcode of the dataset TARGET language
--split SPLIT Dataset split/shard to download (`train`, `validation`, `test`)
--save_dir SAVE_DIR Directory where the datastets will be stored with HuggingFace datasets cache files
--huggingface_token HUGGINGFACE_TOKEN
Your HuggingFace token, this is necessary for some datasets like GigaSpeech.Language codes should follow the notation adopted by M4T models.
Below is an example bash script that prepares a training and evaluation dataset for the translation direction English-to-Korean:
export DATASET_DIR=~/m4t_dataset
mkdir -p $DATASET_DIR
m4t_prepare_dataset \
--name google/fleurs \
--source_lang eng \
--target_lang kor \
--split train \
--save_dir $DATASET_DIR
m4t_prepare_dataset \
--name google/fleurs \
--source_lang eng \
--target_lang kor \
--split validation \
--save_dir $DATASET_DIROutput manifests will be stored in ${DATASET_DIR}/train_manifest.json and ${DATASET_DIR}/validation_manifest.json.
Finetuning
finetune.py is an example finetuning script that initializes dataloaders, and launches training loop with periodic scoring against the validation dataset.
It is recommended to launch it with torchrun. Multi-gpu and multi-node training are supported out of the box.
List of input arguments for finetune.py:
--train_dataset TRAIN_DATASET
Path to manifest with train samples
--eval_dataset EVAL_DATASET
Path to manifest with eval samples
--model_name MODEL_NAME
Base model name (e.g, `seamlessM4T_medium`, `seamlessM4T_large`)
--save_model_to SAVE_MODEL_TO
Path to save best finetuned model
--seed SEED Randomizer seed value
--batch_size BATCH_SIZE
Batch size for training and evaluation
--patience PATIENCE Set early termination after `patience` number of evaluations without eval loss improvements
--max_epochs MAX_EPOCHS
Max number of training epochs
--learning_rate LEARNING_RATE
Finetuning learning rate
--warmup_steps WARMUP_STEPS
Number of steps with linearly increasing learning rate
--eval_steps EVAL_STEPS
Get eval loss after each `eval_steps` training steps
--log_steps LOG_STEPS
Log inner loss after each `log_steps` training steps
--mode {FinetuneMode.SPEECH_TO_SPEECH,FinetuneMode.SPEECH_TO_TEXT,FinetuneMode.TEXT_TO_SPEECH}
* `SPEECH_TO_SPEECH` -- finetune S2T and T2U parts of the model;
* `TEXT_TO_SPEECH` -- finetune only T2U;
* `SPEECH_TO_TEXT` -- finetune only S2TThe scripts supports three modes of finetuning:
SPEECH_TO_SPEECH: in this case all model weights except the text encoder will be engaged;TEXT_TO_SPEECH: only text-to-unit part of the model will be engaged in the finetuning, other weights will be frozen;SPEECH_TO_TEXT: only speech-to-text part of the model will be engaged in the finetuning.
The referenced finetuning script does not support finetuning of the text encoder.
Below is an example bash script that launches finetuning of M4T-large on the dataset prepared earlier, using a single node with eight GPUs:
torchrun \
--rdzv-backend=c10d \
--rdzv-endpoint=localhost:0 \
--nnodes=1 \
--nproc-per-node=8 \
--no-python \
m4t_finetune \
--mode SPEECH_TO_TEXT \
--train_dataset $DATASET_DIR/train_manifest.json \
--eval_dataset $DATASET_DIR/validation_manifest.json \
--learning_rate 1e-6 \
--warmup_steps 100 \
--max_epochs 10 \
--patience 5 \
--model_name seamlessM4T_v2_large \
--save_model_to $DATASET_DIR/checkpoint.ptExcerpt from an example finetuning log:
/* Detailed source-code truncated for AI context efficiency. */Overview (`src/seamless_communication/cli/m4t/predict/README.md`)
Inference with SeamlessM4T models
Refer to the SeamlessM4T README for an overview of the M4T models.
Inference is run with the CLI, from the root directory of the repository.
The model can be specified with --model_name seamlessM4T_v2_large, seamlessM4T_large or seamlessM4T_medium:
S2ST:
m4t_predict <path_to_input_audio> --task s2st --tgt_lang <tgt_lang> --output_path <path_to_save_audio> --model_name seamlessM4T_v2_largeS2TT:
m4t_predict <path_to_input_audio> --task s2tt --tgt_lang <tgt_lang> --model_name seamlessM4T_v2_largeT2TT:
m4t_predict <input_text> --task t2tt --tgt_lang <tgt_lang> --src_lang <src_lang> --model_name seamlessM4T_v2_largeT2ST:
m4t_predict <input_text> --task t2st --tgt_lang <tgt_lang> --src_lang <src_lang> --output_path <path_to_save_audio> --model_name seamlessM4T_v2_largeASR:
m4t_predict <path_to_input_audio> --task asr --tgt_lang <tgt_lang> --model_name seamlessM4T_v2_largeInference breakdown
Inference calls for the Translator object instantiated with a multitask UnitY or UnitY2 model with the options:
and a vocoder:
vocoder_v2forseamlessM4T_v2_large.vocoder_36langsforseamlessM4T_largeorseamlessM4T_medium.
import torch
from seamless_communication.inference import Translator
# Initialize a Translator object with a multitask model, vocoder on the GPU.
translator = Translator("seamlessM4T_large", "vocoder_36langs", torch.device("cuda:0"), torch.float16)Now predict() can be used to run inference as many times on any of the supported tasks.
Given an input audio with or an input text in <src_lang>,
we first set the text_generation_opts, unit_generation_opts and then translate into <tgt_lang> as follows:
S2ST and T2ST (speech output):
# S2ST
text_output, speech_output = translator.predict(
input=<path_to_input_audio>,
task_str="S2ST",
tgt_lang=<tgt_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=unit_generation_opts
)
# T2ST
text_output, speech_output = translator.predict(
input=<input_text>,
task_str="T2ST",
tgt_lang=<tgt_lang>,
src_lang=<src_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=unit_generation_opts
)Note that <src_lang> must be specified for T2ST.
The generated units are synthesized and the output audio file is saved with:
# Save the translated audio output:
import torchaudio
torchaudio.save(
<path_to_save_audio>,
speech_output.audio_wavs[0][0].cpu(),
sample_rate=speech_output.sample_rate,
)S2TT, T2TT and ASR (text output):
# S2TT
text_output, _ = translator.predict(
input=<path_to_input_audio>,
task_str="S2TT",
tgt_lang=<tgt_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=None
)
# ASR
# This is equivalent to S2TT with `<tgt_lang>=<src_lang>`.
text_output, _ = translator.predict(
input=<path_to_input_audio>,
task_str="ASR",
tgt_lang=<src_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=None
)
# T2TT
text_output, _ = translator.predict(
input=<input_text>,
task_str="T2TT",
tgt_lang=<tgt_lang>,
src_lang=<src_lang>,
text_generation_opts=text_generation_opts,
unit_generation_opts=None
)Note that <src_lang> must be specified for T2TT
Overview (`src/seamless_communication/cli/toxicity/etox/README.md`)
Tool to compute toxicity in speech (ASR-ETOX) and text (ETOX)
In this tool, we combine an ASR model (M4T or whisper) + the ETOX toxicity detection tool
to compute a toxicity score for speech segments.
ETOX was developed as part of the NLLB project and provides a wordlist detection mechanism for 200 languages. By applying ASR on top of the ETOX detection, we can detect the toxicity in speech. You can find a description of the toxicity detection wordlists in the paper cited below.
ASR-ETOX Usage
The script works by taking a TSV as input. The TSV needs a header with column names, it can have multiple columns. By defaut the script will look at the audio for the name of the audio file to load, this can be overriden with --audio_column.
The file path in the TSV can be absolute or relative to a root directory specified by --audio_root_dir. They can also be audiozip file formats with the appropriate byteoffset and length, e.g.: fleurs_en_us_ogg_16khz.zip:89474600:49079.
You can choose the ASR model to use, by default it will use seamlessM4T_v2_large. If you prefer to use whisper you can specify a --model_name that starts with whisper_ and finishes with the whisper model name (e.g. whisper_large).
Outputs
The output of the script is a new TSV file with three columns:
textthe transcriptiontoxicitythe number of toxic words detectedbad_wordsa list of toxic words, separated by,
Sample Command
ASR-ETOX
- using M4T:
python -m seamless_communication.cli.toxicity.asr_etox --lang deu --audio_column ref_tgt_audio s2t/en-xx/deu.tsv ~/etox.tsv- using Whisper:
python -m seamless_communication.cli.toxicity.asr_etox --model_name whisper_large --lang fra --audio_column ref_tgt_audio s2t/en-xx/fra.tsv ~/etox.test.tsvETOX
If you only care about getting the toxicity of text, you can use the etox.py script, with one text per line, specifying the language as the first argument.
cut -f 4 fleurs/s2t/en-xx/deu.tsv | python -m seamless_communication.cli.toxicity.etox deu > deu.toxicity.txtYou can also specify an input and output file:
python -m seamless_communication.cli.toxicity.etox deu deu.txt deu.toxicity.txtCitation
If you use ETOX, ASR-ETOX and SeamlessM4T in your work, please cite:
@misc{costajussร 2023toxicity,
title={Toxicity in Multilingual Machine Translation at Scale},
author={Marta R. Costa-jussร and Eric Smith and Christophe Ropers and Daniel Licht and Jean Maillard and Javier Ferrando and Carlos Escolano},
year={2023},
eprint={2210.03070},
archivePrefix={arXiv},
primaryClass={cs.CL}
}and
@article{seamlessm4t2023,
title={SeamlessM4TโMassively Multilingual \& Multimodal Machine Translation},
author={{Seamless Communication}, Lo\"{i}c Barrault, Yu-An Chung, Mariano Cora Meglioli, David Dale, Ning Dong, Paul-Ambroise Duquenne, Hady Elsahar, Hongyu Gong, Kevin Heffernan, John Hoffman, Christopher Klaiber, Pengwei Li, Daniel Licht, Jean Maillard, Alice Rakotoarison, Kaushik Ram Sadagopan, Guillaume Wenzek, Ethan Ye, Bapi Akula, Peng-Jen Chen, Naji El Hachem, Brian Ellis, Gabriel Mejia Gonzalez, Justin Haaheim, Prangthip Hansanti, Russ Howes, Bernie Huang, Min-Jae Hwang, Hirofumi Inaguma, Somya Jain, Elahe Kalbassi, Amanda Kallet, Ilia Kulikov, Janice Lam, Daniel Li, Xutai Ma, Ruslan Mavlyutov, Benjamin Peloquin, Mohamed Ramadan, Abinesh Ramakrishnan, Anna Sun, Kevin Tran, Tuan Tran, Igor Tufanov, Vish Vogeti, Carleigh Wood, Yilin Yang, Bokai Yu, Pierre Andrews, Can Balioglu, Marta R. Costa-juss\`{a} \footnotemark[3], Onur \,{C}elebi,Maha Elbayad,Cynthia Gao, Francisco Guzm\'an, Justine Kao, Ann Lee, Alexandre Mourachko, Juan Pino, Sravya Popuri, Christophe Ropers, Safiyyah Saleem, Holger Schwenk, Paden Tomasello, Changhan Wang, Jeff Wang, Skyler Wang},
journal={ArXiv},
year={2023}
}Overview (`src/seamless_communication/cli/toxicity/mutox/README.md`)
MuTox: MuTox: Universal MUltilingual Audio-based TOXicity Dataset and Zero-shot Detector
MuTox, the first highly multilingual audio-based dataset with toxicity labels.
The dataset consists of 20k audio utterances for English and Spanish, and 4k for
the other 19 languages. To showcase the quality of this dataset, we train the
MuTox audio-based toxicity classifier, which allows zero-shot toxicity detection
across a broad range of languages. This classifier outperforms existing
text-based trainable classifiers by more than 1% AUC, while increasing the
language coverage from 8 to 100+ languages. When compared to a wordlist-based
classifier that covers a similar number of languages, MuTox improves precision
and recall by โผ2.5 times.
License
The mutox code and model are licensed under the MIT license (see MIT_LICENSE
file at the root of seamless_communication). The mutox model depends on SONAR
encoders, most are under the MIT license but a few are under CC-BY-NC license.
See the SONAR repository for
details.
Dataset Languages.
- English,
- Spanish,
- Arabic,
- Bengali,
- Mandarin Chinese,
- Dutch,
- French,
- German,
- Hindi,
- Indonesian,
- Italian,
- Japanese,
- Korean,
- Portuguese,
- Russian,
- Swahili,
- Tagalog,
- Thai,
- Turkish,
- Urdu,
- Vietnamese
Classifier details.
We use multi-modal and multilingual
SONAR encoders from (Duquenne et
al., 2023). For the classifier, we use variable input sizes for the 3
feedforward layers (1024, 512, and 128).
The predictions of the classifier can be interpreted as logits (i.e. after feeding them to a sigmoid transform they become probabilities).
The 0 value can be used as a threshold, as it corresponds to the 50% predicted toxicity probability.
Classifier Quick Start
This introduces the MuTox speech toxicity model, this relies on computing the
sonar embedding and then classifying it through the MuTox model. Thecli/mutox/mutox.py provides an example of reading a TSV, computing the SONAR
embedding and running the classifier on the results:
python -m seamless_communication.cli.toxicity.mutox.mutox_speech --lang fra --audio_column ref_tgt_audio /checkpoint/bokai/seamless/toxity_mitigation/exps_v5/joined_etox/fleurs/s2t/en-xx/fra.tsv /tmp/tesmortt.tsvYou can also work with text:
python -m seamless_communication.cli.toxicity.mutox.mutox_text --lang fra_Latn sentences.txtYou can also check the mutox example notebook in this directory.
Dataset
The dataset is available in this tsv file. The dataset is licensed under the MIT license (see MIT_LICENSE
file at the root of seamless_communication).
The columns of the dataset are:
id: a string id of the segment;lang: 3-letter language code;partition: one oftrain,dev, ordevtest;public_url_segment: a string formatted asurl:start:end, where start and end are indicated in milliseconds;audio_file_transcript: text transctiption of the segment;contains_toxicity,toxicity_types,perlocutionary_effects: annotation results as strings (see the paper for their explanation);label: an integer label, equal to 1 ifcontains_toxicityequalsYesand 0 otherwise;etox_result: toxic word (or multiple words, separated by|) detected by the Etox matcher;detoxify_score: toxicity probabilities predicted by the Detoxify system (float numbers between 0 and 1);mutox_speech_score,mutox_text_score,mutox_zero_shot_speech_score,mutox_zero_shot_text_score: MuTox predictions as float numbers with any value (they can be interpreted as logits, i.e. probabilities before a sigmoid transformation).
Citation
@misc{costajussร 2023mutox,
title={MuTox: Universal MUltilingual Audio-based TOXicity Dataset and Zero-shot Detector},
author={ Marta R. Costa-jussร , Mariano Coria Meglioli, Pierre Andrews, David Dale, Prangthip Hansanti, Elahe Kalbassi, Alex Mourachko, Christophe Ropers, Carleigh Wood},
year={2023},
eprint={},
archivePrefix={arXiv},
primaryClass={cs.CL}
}Overview (`src/seamless_communication/cli/toxicity/mutox_group_annotations/README.md`)
On the Role of Speech Data in Reducing Toxicity Detection Bias
This dataset comprises additional annotations for the English and Spanish samples in the
MuTox test partition. To facilitate systematic evaluations of potential biases of speech-based
toxicity detection systems, 1954 samples have been annotated for mentions of demographic groups.
Annotators also corrected automated transcripts and adjusted judgments of toxicity where appropriate.
These annotations form the basis of our paper comparing the performance and biases of speech- and text-based toxicity
detection systems, available now on ArXiv.
License
These annotations are licensed under the MIT license (see the MIT_LICENSE file at the root of seamless_communication).
Annotations
- Annotations are made available for English and Spanish samples of the MuTox test set.
- Annotations were produced by three annotators per language using an iterative, multi-stage process of annotation, review, and discussion.
- Annotators marked whether a category of group was mentioned, such as a gender identity, racial or ethic group, etc.
- For each group category, annotators specified which specific demographic groups were mentioned. This was an open-ended free-text annotation.
- Group and group category annotations refer only to which groups are mentioned or referred to, and do not refer to the identity of the speaker.
- Annotators also provided a new toxicity annotation, taking values
Yes,No,Cannot sayandNo consensus. - Finally, annotators marked whether the original ASR-produced transcript was correct, and if not, corrected it themselves.
Group categories
Annotators were asked if samples mentioned demographic groups falling into one of the following categories:
- Gender identities
- Sexualities
- Religious groups
- Racial or ethnic groups
- Social classes or socio-economic statuses
- None of the above
Samples where annotators could not agree are marked as No consensus.
Using the annotations
The annotations are available in this TSV file.
Annotations can be joined with the original MuTox samples using the id column.
The columns are:
langspecifies the languagetranscript_is_correctis whether the ASR transcript provided in the original MuTox dataset is correcttranscript_correctedis the annotator-corrected transcriptcontained_toxicity_correctedis the annotator-corrected toxicity judgmentgroup_categoriesis a list of categories of demographic groups mentioned in the sample, separated by '|', e.g. "Gender identities|Racial or ethnic groups"groupsis a list of groups mentioned, separated by '|', e.g. "female, woman or girl|transgender"
Citation
@misc{bell2024,
title={On the Role of Speech Data in Reducing Toxicity Detection Bias}
author={Samuel J. Bell, Mariano Coria Meglioli, Megan Richards, Eduardo Sรกnchez, Christophe Ropers, Skyler Wang, Adina Williams, Levent Sagun, Marta R. Costa-jussร },
year={2024},
eprint={2411.08135},
archivePrefix={arXiv},
primaryClass={cs.CL}
}--- METRICS ---
- Files Extracted: 19
- Estimated Token Budget: ~34525 tokens
- Canonical Reference: https://codewiki.google/github.com/facebookresearch/seamless_communication