模型:

superb/hubert-base-superb-ks

英文

Hubert-Base基于关键词检测

模型描述

这是 S3PRL's Hubert for the SUPERB Keyword Spotting task 的移植版。

基础模型是 hubert-base-ls960 ,该模型在16kHz采样的语音音频上进行了预训练。使用该模型时,请确保语音输入也是以16kHz进行采样。

更多信息请参阅 SUPERB: Speech processing Universal PERformance Benchmark

任务和数据集描述

关键词检测(Keyword Spotting, KS)通过将话语分类为预定义的一组词来检测预注册的关键词。该任务通常在设备上执行,以获得快速的响应时间。因此,准确性、模型大小和推理时间都至关重要。SUPERB使用广泛使用的 Speech Commands dataset v1.0 执行此任务。该数据集包含十个关键词类别、一个静音类别和一个未知类别以包括误报。

有关原始模型的训练和评估说明,请参阅 S3PRL downstream task 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

# load a demo dataset and read audio files
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")

# compute attention masks and normalize the waveform if needed
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
test 0.9630 0.9672

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}
}