https://github.com/bagustris/soxan

https://github.com/bagustris/soxan

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (5.6%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: bagustris
  • License: apache-2.0
  • Language: Python
  • Default Branch: master
  • Size: 36.1 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Created almost 5 years ago · Last pushed over 4 years ago
Metadata Files
Readme License

README.md

Soxan

This repository consists of models, scripts, and notebooks that help you to use all the benefits of Wav2Vec 2.0 and HUBERT in your research. In the following, I'll show you how to train speech tasks in your dataset and how to use the pretrained models.

How to train

I'm just at the beginning of all the possible speech tasks. To start, we continue the training script with the speech emotion recognition problem.

Training - CMD

bash python3 run_wav2vec_clf.py \ --pooling_mode="mean" \ --model_name_or_path="lighteternal/wav2vec2-large-xlsr-53-greek" \ --model_mode="wav2vec" \ # or you can use hubert --output_dir=/path/to/output \ --cache_dir=/path/to/cache/ \ --train_file=/path/to/train.csv \ --validation_file=/path/to/dev.csv \ --test_file=/path/to/test.csv \ --per_device_train_batch_size=4 \ --per_device_eval_batch_size=4 \ --gradient_accumulation_steps=2 \ --learning_rate=1e-4 \ --num_train_epochs=5.0 \ --evaluation_strategy="steps"\ --save_steps=100 \ --eval_steps=100 \ --logging_steps=100 \ --save_total_limit=2 \ --do_eval \ --do_train \ --fp16 \ --freeze_feature_extractor

Prediction

```python import torch import torch.nn as nn import torch.nn.functional as F import torchaudio from transformers import AutoConfig, Wav2Vec2FeatureExtractor from src.models import Wav2Vec2ForSpeechClassification, HubertForSpeechClassification

modelnameor_path = "path/to/your-pretrained-model"

device = torch.device("cuda" if torch.cuda.isavailable() else "cpu") config = AutoConfig.frompretrained(modelnameorpath) featureextractor = Wav2Vec2FeatureExtractor.frompretrained(modelnameorpath) samplingrate = featureextractor.sampling_rate

for wav2vec

model = Wav2Vec2ForSpeechClassification.frompretrained(modelnameorpath).to(device)

for hubert

model = HubertForSpeechClassification.frompretrained(modelnameorpath).to(device)

def speechfiletoarrayfn(path, samplingrate): speecharray, samplingrate = torchaudio.load(path) resampler = torchaudio.transforms.Resample(samplingrate, samplingrate) speech = resampler(speecharray).squeeze().numpy() return speech

def predict(path, samplingrate): speech = speechfiletoarrayfn(path, samplingrate) inputs = featureextractor(speech, samplingrate=samplingrate, returntensors="pt", padding=True) inputs = {key: inputs[key].to(device) for key in inputs}

with torch.no_grad():
    logits = model(**inputs).logits

scores = F.softmax(logits, dim=1).detach().cpu().numpy()[0]
outputs = [{"Emotion": config.id2label[i], "Score": f"{round(score * 100, 3):.1f}%"} for i, score in
           enumerate(scores)]
return outputs

path = "/path/to/disgust.wav" outputs = predict(path, sampling_rate)
```

Output:

bash [ {'Emotion': 'anger', 'Score': '0.0%'}, {'Emotion': 'disgust', 'Score': '99.2%'}, {'Emotion': 'fear', 'Score': '0.1%'}, {'Emotion': 'happiness', 'Score': '0.3%'}, {'Emotion': 'sadness', 'Score': '0.5%'} ]

Demos

https://huggingface.co/Bagus/wav2vec2-xlsr-greek-speech-emotion-recognition

Owner

  • Name: Bagus Tris Atmaja
  • Login: bagustris
  • Kind: user
  • Location: Tsukuba
  • Company: AIST

Researcher @aistairc @VibrasticLab

GitHub Events

Total
Last Year

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 4
  • Total Committers: 1
  • Avg Commits per committer: 4.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
B Atmaja b****a@a****p 4
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels