language: zh
datasets:
- superb
tags:
- 语音
- 音频
- hubert
- 音频分类
license: apache-2.0
widget:
- example_title: 语音指令 "down"
src: https://cdn-media.huggingface.co/speech_samples/keyword_spotting_down.wav
- example_title: 语音指令 "go"
src: https://cdn-media.huggingface.co/speech_samples/keyword_spotting_go.wav
Hubert-Large 关键词检测模型
模型描述
此模型为S3PRL的Hubert在SUPERB关键词检测任务上的移植版本。
基础模型采用hubert-large-ll60k,该模型基于16kHz采样的语音音频进行预训练。使用时请确保输入语音同样以16kHz采样。
更多信息请参考SUPERB:语音处理通用性能基准
任务与数据集说明
关键词检测(KS)通过将语音片段分类至预定义的词汇集合,实现预设关键词的识别。该任务通常在设备端实时执行,因此准确性、模型体积和推理速度均为关键指标。SUPERB采用广泛使用的语音指令数据集v1.0,包含10个关键词类别、1个静音类别及1个未知类别(用于误报检测)。
原始模型训练与评估方法详见S3PRL下游任务说明。
使用示例
可通过音频分类流水线调用:
from datasets import load_dataset
from transformers import pipeline
dataset = load_dataset("anton-l/superb_demo", "ks", split="test")
classifier = pipeline("audio-classification", model="superb/hubert-large-superb-ks")
labels = classifier(dataset[0]["file"], top_k=5)
或直接调用模型:
import torch
from datasets import load_dataset
from transformers import HubertForSequenceClassification, Wav2Vec2FeatureExtractor
from torchaudio.sox_effects import apply_effects_file
effects = [["channels", "1"], ["rate", "16000"], ["gain", "-3.0"]]
def map_to_array(example):
speech, _ = apply_effects_file(example["file"], effects)
example["speech"] = speech.squeeze(0).numpy()
return example
dataset = load_dataset("anton-l/superb_demo", "ks", split="test")
dataset = dataset.map(map_to_array)
model = HubertForSequenceClassification.from_pretrained("superb/hubert-large-superb-ks")
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained("superb/hubert-large-superb-ks")
inputs = feature_extractor(dataset[:4]["speech"], sampling_rate=16000, padding=True, return_tensors="pt")
logits = model(**inputs).logits
predicted_ids = torch.argmax(logits, dim=-1)
labels = [model.config.id2label[_id] for _id in predicted_ids.tolist()]
评估结果
评估指标为准确率。
|
s3prl |
transformers |
测试集 |
0.9529 |
0.9532 |
BibTeX引用信息
@article{yang2021superb,
title={SUPERB: Speech processing Universal PERformance Benchmark},
author={Yang, Shu-wen and Chi, Po-Han and Chuang, Yung-Sung and Lai, Cheng-I Jeff and Lakhotia, Kushal and Lin, Yist Y and Liu, Andy T and Shi, Jiatong and Chang, Xuankai and Lin, Guan-Ting and others},
journal={arXiv preprint arXiv:2105.01051},
year={2021}
}