模型:

superb/wav2vec2-base-superb-ks

英文

Wav2Vec2-Base 关键词识别模型

模型描述

这是一个移植的版本 S3PRL's Wav2Vec2 for the SUPERB Keyword Spotting task

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

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

任务和数据集描述

关键词识别(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/wav2vec2-base-superb-ks")
labels = classifier(dataset[0]["file"], top_k=5)

或者直接使用该模型:

import torch
from datasets import load_dataset
from transformers import Wav2Vec2ForSequenceClassification, 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 = Wav2Vec2ForSequenceClassification.from_pretrained("superb/wav2vec2-base-superb-ks")
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained("superb/wav2vec2-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.9623 0.9643

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