Wav2Vec2ASRBundle¶
- class torchaudio.pipelines.Wav2Vec2ASRBundle[原始碼]¶
資料類別,將關聯資訊捆綁在一起,以使用預訓練的
Wav2Vec2Model
。此類別提供用於實例化預訓練模型以及檢索預訓練權重和要與模型一起使用的其他資訊的必要介面。
Torchaudio 函式庫實例化此類別的物件,每個物件代表不同的預訓練模型。 客戶端程式碼應透過這些實例存取預訓練模型。
請參閱以下用法和可用值。
- 範例 - ASR
>>> import torchaudio >>> >>> bundle = torchaudio.pipelines.HUBERT_ASR_LARGE >>> >>> # Build the model and load pretrained weight. >>> model = bundle.get_model() Downloading: 100%|███████████████████████████████| 1.18G/1.18G [00:17<00:00, 73.8MB/s] >>> >>> # Check the corresponding labels of the output. >>> labels = bundle.get_labels() >>> print(labels) ('-', '|', 'E', 'T', 'A', 'O', 'N', 'I', 'H', 'S', 'R', 'D', 'L', 'U', 'M', 'W', 'C', 'F', 'G', 'Y', 'P', 'B', 'V', 'K', "'", 'X', 'J', 'Q', 'Z') >>> >>> # Resample audio to the expected sampling rate >>> waveform = torchaudio.functional.resample(waveform, sample_rate, bundle.sample_rate) >>> >>> # Infer the label probability distribution >>> emissions, _ = model(waveform) >>> >>> # Pass emission to decoder >>> # `ctc_decode` is for illustration purpose only >>> transcripts = ctc_decode(emissions, labels)
- 使用
Wav2Vec2ASRBundle
的教學
屬性¶
sample_rate¶
方法¶
get_labels¶
- Wav2Vec2ASRBundle.get_labels(*, blank: str = '-') Tuple[str, ...] [source]¶
輸出類別標籤。
第一個是空白符記,並且可以自訂。
- 參數:
blank (str, optional) – 空白符記。(預設值:
'-'
)- 回傳:
對於在 ASR 上進行微調的模型,回傳表示輸出類別標籤的字串 tuple。
- 回傳類型:
Tuple[str, …]
- 範例
>>> from torchaudio.pipelines import HUBERT_ASR_LARGE as bundle >>> bundle.get_labels() ('-', '|', 'E', 'T', 'A', 'O', 'N', 'I', 'H', 'S', 'R', 'D', 'L', 'U', 'M', 'W', 'C', 'F', 'G', 'Y', 'P', 'B', 'V', 'K', "'", 'X', 'J', 'Q', 'Z')
get_model¶
- Wav2Vec2ASRBundle.get_model(*, dl_kwargs=None) Module ¶
建構模型並載入預訓練權重。
權重檔案會從網際網路下載,並使用
torch.hub.load_state_dict_from_url()
進行快取。- 參數:
dl_kwargs (關鍵字引數的字典) – 傳遞給
torch.hub.load_state_dict_from_url()
。- 回傳:
Wav2Vec2Model
的變體。對於下面列出的模型,會在輸入上執行額外的層歸一化。
對於所有其他模型,會回傳
Wav2Vec2Model
實例。WAV2VEC2_LARGE_LV60K
WAV2VEC2_ASR_LARGE_LV60K_10M
WAV2VEC2_ASR_LARGE_LV60K_100H
WAV2VEC2_ASR_LARGE_LV60K_960H
WAV2VEC2_XLSR53
WAV2VEC2_XLSR_300M
WAV2VEC2_XLSR_1B
WAV2VEC2_XLSR_2B
HUBERT_LARGE
HUBERT_XLARGE
HUBERT_ASR_LARGE
HUBERT_ASR_XLARGE
WAVLM_LARGE