File size: 1,480 Bytes
5fa1a76 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
Instantiate a pipeline for audio classification with your model, and pass your audio file to it: from transformers import pipeline classifier = pipeline("audio-classification", model="stevhliu/my_awesome_minds_model") classifier(audio_file) [ {'score': 0.09766869246959686, 'label': 'cash_deposit'}, {'score': 0.07998877018690109, 'label': 'app_error'}, {'score': 0.0781070664525032, 'label': 'joint_account'}, {'score': 0.07667109370231628, 'label': 'pay_bill'}, {'score': 0.0755252093076706, 'label': 'balance'} ] You can also manually replicate the results of the pipeline if you'd like: Load a feature extractor to preprocess the audio file and return the input as PyTorch tensors: from transformers import AutoFeatureExtractor feature_extractor = AutoFeatureExtractor.from_pretrained("stevhliu/my_awesome_minds_model") inputs = feature_extractor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt") Pass your inputs to the model and return the logits: from transformers import AutoModelForAudioClassification model = AutoModelForAudioClassification.from_pretrained("stevhliu/my_awesome_minds_model") with torch.no_grad(): logits = model(**inputs).logits Get the class with the highest probability, and use the model's id2label mapping to convert it to a label: import torch predicted_class_ids = torch.argmax(logits).item() predicted_label = model.config.id2label[predicted_class_ids] predicted_label 'cash_deposit' |