Views
No views yet
1from datasets import load_dataset
2from transformers import pipeline
3
4dataset = load_dataset("anton-l/superb_demo", "si", split="test")
5
6classifier = pipeline("audio-classification", model="superb/hubert-base-superb-sid")
7labels = classifier(dataset[0]["file"], top_k=5)1import torch
2import librosa
3from datasets import load_dataset
4from transformers import HubertForSequenceClassification, Wav2Vec2FeatureExtractor
5
6def map_to_array(example):
7 speech, _ = librosa.load(example["file"], sr=16000, mono=True)
8 example["speech"] = speech
9 return example
10
11# load a demo dataset and read audio files
12dataset = load_dataset("anton-l/superb_demo", "si", split="test")
13dataset = dataset.map(map_to_array)
14
15model = HubertForSequenceClassification.from_pretrained("superb/hubert-base-superb-sid")
16feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained("superb/hubert-base-superb-sid")
17
18# compute attention masks and normalize the waveform if needed
19inputs = feature_extractor(dataset[:2]["speech"], sampling_rate=16000, padding=True, return_tensors="pt")
20
21logits = model(**inputs).logits
22predicted_ids = torch.argmax(logits, dim=-1)
23labels = [model.config.id2label[_id] for _id in predicted_ids.tolist()]| s3prl | transformers | |
|---|---|---|
| test | 0.8142 | 0.8071 |
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}