语言: 中文
数据集:
- superb
标签:
- 语音
- 音频
- hubert
- 音频分类
许可证: apache-2.0
小部件:
- 示例标题: 语音命令 "down"
来源: https://cdn-media.huggingface.co/speech_samples/keyword_spotting_down.wav
- 示例标题: 语音命令 "go"
来源: https://cdn-media.huggingface.co/speech_samples/keyword_spotting_go.wav
基于Hubert的关键词识别模型
模型描述
此模型为S3PRL的Hubert模型在SUPERB关键词识别任务上的移植版本。
基础模型为hubert-base-ls960,该模型基于16kHz采样的语音音频进行预训练。使用时请确保输入语音同样以16kHz采样。
更多信息请参考SUPERB: 语音处理通用性能基准
任务与数据集说明
关键词识别(KS)通过将语音片段分类为预定义的词汇集合,检测预先注册的关键词。该任务通常在设备端执行以实现快速响应,因此准确率、模型大小和推理时间都至关重要。SUPERB使用广泛应用的语音命令数据集v1.0,包含10个关键词类别、1个静音类别和1个未知类别(用于处理误报)。
原始模型的训练和评估说明请参考S3PRL下游任务README。
使用示例
可通过音频分类管道使用模型:
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-base-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-base-superb-ks")
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained("superb/hubert-base-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.9630 |
0.9672 |
BibTeX条目及引用信息
@article{yang2021superb,
title={SUPERB: 语音处理通用性能基准},
author={杨书文, 纪柏涵, 庄永松, 赖正一, 拉科蒂亚·库沙尔, 林逸, 刘安迪, 石家同, 常轩凯, 林冠廷等},
journal={arXiv预印本 arXiv:2105.01051},
year={2021}
}