hubert large speech emotion recognition russian dusha finetuned
简介
核心亮点
- 专注俄语语音情感识别,捕捉细微情绪波动
- 基于 HuBERT-Large 架构,特征提取能力强
- 适用于智能客服、心理分析等音频分类场景
- 采用 Apache-2.0 协议,商业集成灵活便捷
使用方法
# 安装 Hugging Face transformers
pip install transformers torch
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned")
tokenizer = AutoTokenizer.from_pretrained("xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned")
Hugging Face 下载
我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。
操作指引:在下载前,请先通过如下命令安装 huggingface_hub:
pip install -U huggingface_hub
命令行下载
下载完整模型库
huggingface-cli download xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned
下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned config.json --local-dir ./dir
SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned')
Git 下载
请确保 lfs 已经被正确安装
git lfs install
git clone https://huggingface.co/xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned
如果您希望跳过 lfs 大文件下载,可以使用如下命令
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned
模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。
PyTorch / Transformers 使用
安装 Transformers
pip install -U transformers torch
模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned')
tokenizer = AutoTokenizer.from_pretrained('xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned')
完整文档
---
language:
- ru
tags:
- SER
- speech
- audio
- russian
license: apache-2.0
pipeline_tag: audio-classification
base_model: facebook/hubert-large-ls960-ft
datasets:
- xbgoose/dusha
---
HuBERT fine-tuned on DUSHA dataset for speech emotion recognition in russian language
The pre-trained model is this one - facebook/hubert-large-ls960-ft
The DUSHA dataset used can be found here
Fine-tuning
Fine-tuned in Google Colab using Pro account with A100 GPU
Freezed all layers exept projector, classifier and all 24 HubertEncoderLayerStableLayerNorm layers
Used half of the train dataset
Training parameters
- 2 epochs
- train batch size = 8
- eval batch size = 8
- gradient accumulation steps = 4
- learning rate = 5e-5 without warm up and decay
Metrics
Achieved
- accuracy = 0.86
- balanced = 0.76
- macro f1 score = 0.81
on test set, improving accucary and f1 score compared to dataset baseline
Usage
from transformers import HubertForSequenceClassification, Wav2Vec2FeatureExtractor
import torchaudio
import torch
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained("facebook/hubert-large-ls960-ft")
model = HubertForSequenceClassification.from_pretrained("xbgoose/hubert-speech-emotion-recognition-russian-dusha-finetuned")
num2emotion = {0: 'neutral', 1: 'angry', 2: 'positive', 3: 'sad', 4: 'other'}
filepath = "path/to/audio.wav"
waveform, sample_rate = torchaudio.load(filepath, normalize=True)
transform = torchaudio.transforms.Resample(sample_rate, 16000)
waveform = transform(waveform)
inputs = feature_extractor(
waveform,
sampling_rate=feature_extractor.sampling_rate,
return_tensors="pt",
padding=True,
max_length=16000 * 10,
truncation=True
)
logits = model(inputs['input_values'][0]).logits
predictions = torch.argmax(logits, dim=-1)
predicted_emotion = num2emotion[predictions.numpy()[0]]
print(predicted_emotion)