Giter Site home page Giter Site logo

deep-spin / speech-continuous-attention Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 1.0 196 KB

Speech Classification using Continuous Attention Mechanisms

License: MIT License

Python 100.00%
speech-classification continuous-attention continuous-softmax continuous-sparsemax

speech-continuous-attention's Introduction

speech-continuous-attention

Speech Classification with Continuous Attention Mechanisms.

This is the code for speech classification experiments of the paper:

which builds upon:

The code is based on the following speechbrain recipes:

We provide scripts for UrbanSound8k only. The datasets should be placed in the data/ folder.

Installation

First, install the spcdist library to get support for sparse continuous distributions:

pip3 install git+https://github.com/deep-spin/sparse_continuous_distributions#egg=spcdist

Then install other requirements via:

pip3 install -r requirements.txt

Run 10-fold

Valdiating and testing on fold 1:

# discrete-attention models
for max_act in "softmax", "entmax1333", "entmax15", "sparsemax"
do
    mkdir "results/urbansound8k_discrete_${max_act}"
    python3 urbansound8k_train.py hparams/urbansound8k_acrnn.yaml \
        --train_fold_nums=[2, 3, 4, 5, 6, 7, 8, 9, 10] \
        --valid_fold_nums=[1] \
        --test_fold_nums=[1] \
        --attn_domain discrete \
        --attn_max_activation ${max_act} \
        --output_folder=results/urbansound8k_discrete_${max_act}/fold_1 \
        --device=cuda:0
done

# continuous-attention models
for max_act in "softmax", "triweight", "biweight", "sparsemax"
do
    mkdir "results/urbansound8k_continuous_${max_act}"
    python3 urbansound8k_train.py hparams/urbansound8k_acrnn.yaml \
        --train_fold_nums=[2, 3, 4, 5, 6, 7, 8, 9, 10] \
        --valid_fold_nums=[1] \
        --test_fold_nums=[1] \
        --attn_domain continuous \
        --attn_max_activation ${max_act} \
        --output_folder=results/urbansound8k_continuous_${max_act}/fold_1 \
        --device=cuda:0 
done

Do the same for the other folds and average in the end to get the final results as in the paper. See the config files in the hparams folder for more information.

Save and plot attention maps

First, save the spectrograms:

mkdir -p specs/urbansound8k_continuous_sparsemax
python3 urbansound8k_save_specs.py hparams/urbansound8k_acrnn.yaml \
    --train_fold_nums=[2, 3, 4, 5, 6, 7, 8, 9, 10] \
    --valid_fold_nums=[1] \
    --test_fold_nums=[1] \
    --attn_domain continuous \
    --attn_max_activation sparsemax \
    --output_folder=results/urbansound8k_continuous_sparsemax/fold_1 \
    --device=cpu \
    --attn_num_samples 50 \
    --spec_dname specs/urbansound8k_continuous_sparsemax/

And then save the attention maps:

mkdir saved_attentions
python3 urbansound8k_save_attentions.py hparams/urbansound8k_acrnn.yaml \
    --train_fold_nums=[2, 3, 4, 5, 6, 7, 8, 9, 10] \
    --valid_fold_nums=[1] \
    --test_fold_nums=[1] \
    --attn_domain continuous \
    --attn_max_activation sparsemax \
    --output_folder=results/urbansound8k_continuous_sparsemax/fold_1 \
    --device=cuda:2 \
    --attn_num_samples 200 \
    --attn_fname saved_attentions/urbansound8k_continuous_sparsemax.csv

For plotting attention densities you can follow the step-by-step instructions in this notebook: https://colab.research.google.com/drive/1Ce51VB_rgmNmxB5lggRSUDZ__-zu-Xov?usp=sharing

Citation

If you use this codebase, or otherwise found our work valuable, please cite:

todo

speech-continuous-attention's People

Contributors

mtreviso avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.