HuBERT 사전학습·파인튜닝·디코딩 실습
HuBERT 사전학습·파인튜닝·디코딩
fairseq 저장소의 examples/hubert 디렉터리는 HuBERT를 처음부터 사전학습(pre-train)하고, CTC 손실로 파인튜닝하며, 세 가지 방식으로 디코딩하는 전체 레시피를 담고 있어요. 이 페이지는 그 핵심 명령어를 따라가는 실습 흐름이에요.
출처: https://github.com/facebookresearch/fairseq/blob/main/examples/hubert/README.md
사전학습·파인튜닝 모델 목록
| 모델 | 사전학습 데이터 | 파인튜닝 데이터 | 다운로드 |
|---|---|---|---|
| HuBERT Base (~95M params) | Librispeech 960 hr | 없음 (사전학습만) | hubert_base_ls960.pt |
| HuBERT Large (~316M params) | Libri-Light 60k hr | 없음 | hubert_large_ll60k.pt |
| HuBERT Extra Large (~1B params) | Libri-Light 60k hr | 없음 | hubert_xtralarge_ll60k.pt |
| HuBERT Large | Libri-Light 60k hr | Librispeech 960 hr | hubert_large_ll60k_finetune_ls960.pt |
| HuBERT Extra Large | Libri-Light 60k hr | Librispeech 960 hr | hubert_xtralarge_ll60k_finetune_ls960.pt |
모델 불러오기
ckpt_path = "/path/to/the/checkpoint.pt"
models, cfg, task = fairseq.checkpoint_utils.load_model_ensemble_and_task([ckpt_path])
model = models[0]
데이터 준비
./simple_kmeans 단계를 따라 다음 파일을 만든다:
{train,valid}.tsv— 파형 목록{train,valid}.km— 프레임 정렬 의사 레이블(pseudo label)dict.km.txt— 더미 사전
label_rate는 클러스터링에 쓴 피처 프레임 레이트와 같아야 해요. MFCC 피처는 기본 100Hz, HuBERT 피처는 50Hz예요.
사전학습 (Pre-train)
{train,valid}.tsv가 /path/to/data, {train,valid}.km이 /path/to/labels에 있고 레이블 레이트가 100Hz라고 할 때, base 모델(12 레이어 transformer)을 학습하려면:
$ python fairseq_cli/hydra_train.py --config-dir /path/to/fairseq-py/examples/hubert/config/pretrain --config-name hubert_base_librispeech task.data=/path/to/data task.label_dir=/path/to/labels task.labels='["km"]' model.label_rate=100
CTC 손실로 파인튜닝 (Fine-tune)
$ python fairseq_cli/hydra_train.py --config-dir /path/to/fairseq-py/examples/hubert/config/finetune --config-name base_10h task.data=/path/to/data task.label_dir=/path/to/trans model.w2v_path=/path/to/checkpoint
디코딩 (Decode)
Viterbi 방식은 언어 모델 없이 greedy 디코딩을 해요. 디코딩 결과는 /path/to/experiment/directory/decode/viterbi/test에 저장돼요.
$ python examples/speech_recognition/new/infer.py --config-dir /path/to/fairseq-py/examples/hubert/config/decode --config-name infer_viterbi task.data=/path/to/data task.normalize=[true|false] decoding.exp_dir=/path/to/experiment/directory common_eval.path=/path/to/checkpoint
dataset.gen_subset=test
KenLM(arpa 포맷 n-gram LM) 디코딩은 --config-name infer_kenlm을, Fairseq 신경망 LM 디코딩은 infer_fsqlm을 쓰고 발음 사전·LM 경로를 지정해요. 빔 크기 500으로 탐색하려면 decoding.decoder.beam=500처럼 붙이면 돼요.