模型概述
模型特點
模型能力
使用案例
🚀 大規模多語言語音(MMS) - 微調後的自動語音識別 - FL102
本檢查點是一個針對多語言自動語音識別(ASR)進行微調的模型,是Facebook 大規模多語言語音項目 的一部分。該檢查點基於 Wav2Vec2架構,並利用適配器模型來轉錄100多種語言。此檢查點包含 10億個參數,是在 Fleurs 的102種語言上,從 facebook/mms-1b 微調而來。
🚀 快速開始
安裝依賴庫
本MMS檢查點可與 Transformers 配合使用,以轉錄1107種不同語言的音頻。首先,我們需要安裝 transformers
和其他一些庫:
pip install torch accelerate torchaudio datasets
pip install --upgrade transformers
⚠️ 重要提示
要使用MMS,你需要至少安裝
transformers >= 4.30
版本。如果 PyPI 上還沒有4.30
版本,請確保從源代碼安裝transformers
:
pip install git+https://github.com/huggingface/transformers.git
加載音頻樣本
接下來,我們通過 datasets
加載一些音頻樣本。請確保音頻數據的採樣率為16000 kHz。
from datasets import load_dataset, Audio
# 英語
stream_data = load_dataset("mozilla-foundation/common_voice_13_0", "en", split="test", streaming=True)
stream_data = stream_data.cast_column("audio", Audio(sampling_rate=16000))
en_sample = next(iter(stream_data))["audio"]["array"]
# 法語
stream_data = load_dataset("mozilla-foundation/common_voice_13_0", "fr", split="test", streaming=True)
stream_data = stream_data.cast_column("audio", Audio(sampling_rate=16000))
fr_sample = next(iter(stream_data))["audio"]["array"]
加載模型和處理器
from transformers import Wav2Vec2ForCTC, AutoProcessor
import torch
model_id = "facebook/mms-1b-fl102"
processor = AutoProcessor.from_pretrained(model_id)
model = Wav2Vec2ForCTC.from_pretrained(model_id)
處理音頻數據並轉錄
現在,我們處理音頻數據,將處理後的音頻數據傳入模型,並轉錄模型輸出,就像我們通常對 facebook/wav2vec2-base-960h 等Wav2Vec2模型所做的那樣。
inputs = processor(en_sample, sampling_rate=16_000, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs).logits
ids = torch.argmax(outputs, dim=-1)[0]
transcription = processor.decode(ids)
# 'joe keton disapproved of films and buster also had reservations about the media'
切換語言適配器
我們可以將同一模型保留在內存中,並通過為模型調用便捷的 load_adapter()
函數,為分詞器調用 set_target_lang()
函數,簡單地切換語言適配器。我們將目標語言作為輸入傳入 - 法語為 "fra"。
processor.tokenizer.set_target_lang("fra")
model.load_adapter("fra")
inputs = processor(fr_sample, sampling_rate=16_000, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs).logits
ids = torch.argmax(outputs, dim=-1)[0]
transcription = processor.decode(ids)
# "ce dernier est volé tout au long de l'histoire romaine"
同樣,我們可以為所有其他支持的語言切換語言。你可以查看:
processor.tokenizer.vocab.keys()
更多詳細信息,請查看 官方文檔。
✨ 主要特性
- 多語言支持:該模型支持102種語言,可廣泛應用於不同語言的語音識別場景。
- 基於Wav2Vec2架構:利用先進的Wav2Vec2架構,結合適配器模型,實現高效的多語言轉錄。
📦 安裝指南
pip install torch accelerate torchaudio datasets
pip install --upgrade transformers
若 transformers
版本未達到 4.30
,可從源代碼安裝:
pip install git+https://github.com/huggingface/transformers.git
💻 使用示例
基礎用法
from datasets import load_dataset, Audio
from transformers import Wav2Vec2ForCTC, AutoProcessor
import torch
# 加載英語音頻樣本
stream_data = load_dataset("mozilla-foundation/common_voice_13_0", "en", split="test", streaming=True)
stream_data = stream_data.cast_column("audio", Audio(sampling_rate=16000))
en_sample = next(iter(stream_data))["audio"]["array"]
# 加載模型和處理器
model_id = "facebook/mms-1b-fl102"
processor = AutoProcessor.from_pretrained(model_id)
model = Wav2Vec2ForCTC.from_pretrained(model_id)
# 處理音頻數據並轉錄
inputs = processor(en_sample, sampling_rate=16_000, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs).logits
ids = torch.argmax(outputs, dim=-1)[0]
transcription = processor.decode(ids)
print(transcription)
高級用法
# 加載法語音頻樣本
stream_data = load_dataset("mozilla-foundation/common_voice_13_0", "fr", split="test", streaming=True)
stream_data = stream_data.cast_column("audio", Audio(sampling_rate=16000))
fr_sample = next(iter(stream_data))["audio"]["array"]
# 切換語言適配器
processor.tokenizer.set_target_lang("fra")
model.load_adapter("fra")
# 處理法語音頻數據並轉錄
inputs = processor(fr_sample, sampling_rate=16_000, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs).logits
ids = torch.argmax(outputs, dim=-1)[0]
transcription = processor.decode(ids)
print(transcription)
📚 詳細文檔
你可以在以下鏈接找到更多詳細信息:
🔧 技術細節
模型信息
屬性 | 詳情 |
---|---|
模型類型 | 多語言自動語音識別模型 |
開發者 | Vineel Pratap等人 |
支持語言 | 100多種語言,見 支持的語言 |
許可證 | CC - BY - NC 4.0許可證 |
參數數量 | 10億 |
音頻採樣率 | 16000 kHz |
引用方式 | @article{pratap2023mms, title={Scaling Speech Technology to 1,000+ Languages}, author={Vineel Pratap and Andros Tjandra and Bowen Shi and Paden Tomasello and Arun Babu and Sayani Kundu and Ali Elkahky and Zhaoheng Ni and Apoorv Vyas and Maryam Fazel - Zarandi and Alexei Baevski and Yossi Adi and Xiaohui Zhang and Wei - Ning Hsu and Alexis Conneau and Michael Auli}, journal={arXiv}, year={2023} } |
支持的語言
此模型支持102種語言。點擊以下內容可展開查看此檢查點支持的所有語言的 ISO 639 - 3代碼。你可以在 MMS語言覆蓋概述 中找到有關這些語言及其ISO 649 - 3代碼的更多詳細信息。
點擊展開
- afr
- amh
- ara
- asm
- ast
- azj-script_latin
- bel
- ben
- bos
- bul
- cat
- ceb
- ces
- ckb
- cmn-script_simplified
- cym
- dan
- deu
- ell
- eng
- est
- fas
- fin
- fra
- ful
- gle
- glg
- guj
- hau
- heb
- hin
- hrv
- hun
- hye
- ibo
- ind
- isl
- ita
- jav
- jpn
- kam
- kan
- kat
- kaz
- kea
- khm
- kir
- kor
- lao
- lav
- lin
- lit
- ltz
- lug
- luo
- mal
- mar
- mkd
- mlt
- mon
- mri
- mya
- nld
- nob
- npi
- nso
- nya
- oci
- orm
- ory
- pan
- pol
- por
- pus
- ron
- rus
- slk
- slv
- sna
- snd
- som
- spa
- srp-script_latin
- swe
- swh
- tam
- tel
- tgk
- tgl
- tha
- tur
- ukr
- umb
- urd-script_arabic
- uzb-script_latin
- vie
- wol
- xho
- yor
- yue-script_traditional
- zlm
- zul
📄 許可證
本模型使用CC - BY - NC 4.0許可證。



