Views
No views yet
1from datasets import load_dataset
2from transformers import pipeline
3
4dataset = load_dataset("anton-l/superb_demo", "ks", split="test")
5
6classifier = pipeline("audio-classification", model="superb/wav2vec2-base-superb-ks")
7labels = classifier(dataset[0]["file"], top_k=5)1import torch
2from datasets import load_dataset
3from transformers import Wav2Vec2ForSequenceClassification, Wav2Vec2FeatureExtractor
4from torchaudio.sox_effects import apply_effects_file
5
6effects = [["channels", "1"], ["rate", "16000"], ["gain", "-3.0"]]
7def map_to_array(example):
8 speech, _ = apply_effects_file(example["file"], effects)
9 example["speech"] = speech.squeeze(0).numpy()
10 return example
11
12# load a demo dataset and read audio files
13dataset = load_dataset("anton-l/superb_demo", "ks", split="test")
14dataset = dataset.map(map_to_array)
15
16model = Wav2Vec2ForSequenceClassification.from_pretrained("superb/wav2vec2-base-superb-ks")
17feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained("superb/wav2vec2-base-superb-ks")
18
19# compute attention masks and normalize the waveform if needed
20inputs = feature_extractor(dataset[:4]["speech"], sampling_rate=16000, padding=True, return_tensors="pt")
21
22logits = model(**inputs).logits
23predicted_ids = torch.argmax(logits, dim=-1)
24labels = [model.config.id2label[_id] for _id in predicted_ids.tolist()]| s3prl | transformers | |
|---|---|---|
| test | 0.9623 | 0.9643 |
1@article{yang2021superb,
2 title={SUPERB: Speech processing Universal PERformance Benchmark},
3 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},
4 journal={arXiv preprint arXiv:2105.01051},
5 year={2021}
6}