Skip to main content

Machine learning audio prediction experiments based on templates

Project description

Nkululeko

status

Nkululeko is a software to detect speaker characteristics by machine learning experiments with a high-level interface. The idea is to have a framework (based on e.g. sklearn and torch) that can be used to rapidly and automatically analyse audio data and explore machine learning models based on that data.

Some abilities that Nkululeko provides: combines acoustic features and machine learning models (including feature selection and features concatenation); performs data exploration, selection and visualization the results; finetuning; ensemble learning models; soft labeling (predicting labels with pre-trained model); and inference the model on a test set.

Nkululeko orchestrates data loading, feature extraction, and model training, allowing you to specify your experiment in a configuration file. The framework handles the process from raw data to trained model and evaluation, making it easy to run machine learning experiments without directly coding in Python.

Who is this for?

Nkululeko is for speech processing learners, researchers and ML practitioners focused on speaker characteristics, e.g., emotion, age, gender, or disorder detection.

Installation

Nkululeko requires Python 3.10 or higher with the following build status:

Python 3.11
Python 3.12
Python 3.13

Create and activate a virtual Python environment and simply install Nkululeko:

# using python venv
python -m venv .env
source .env/bin/activate  # specify OS versions, add a separate line for Windows users 
pip install nkululeko
# using uv in development mode
uv venv --python 3.12
source .venv/bin/activate
uv pip install -e .
# or run directly using uv run after cloning
uv run python -m nkululeko.nkululeko --config examples/exp_polish_tree.ini

Optional Dependencies

Nkululeko supports optional dependencies through extras:

# Install with PyTorch support
pip install nkululeko[torch]

# Install with CPU-only PyTorch
pip install nkululeko[torch-cpu]

# Install with TensorFlow support
pip install nkululeko[tensorflow]

# Install all optional dependencies
pip install nkululeko[all]

Manual Installation Options

You can also install dependencies manually:

PyTorch Installation

For CPU-only installation (recommended for most users):

pip install torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 --index-url https://download.pytorch.org/whl/cpu

For GPU support (cuda 12.6):

pip install torch torchvision torchaudio

Some functionalities require extra packages to be installed, which we didn't include automatically:

  • For spotlight adapter:
    pip install PyYAML  # Install PyYAML first to avoid dependency issues
    pip install nkululeko[spotlight]
    

Some examples for ini-files (which you use to control nkululeko) are in the examples folder.

Documentation

The documentation, along with extensions of installation, usage, INI file format, and examples, can be found nkululeko.readthedocs.io.

Usage

ini-file values

Basically, you specify your experiment in an "ini" file (e.g. experiment.ini) and then call one of the Nkululeko interfaces to run the experiment like this:

python -m nkululeko.nkululeko --config experiment.ini

A basic configuration looks like this:

[EXP]
root = ./
name = exp_emodb
[DATA]
databases = ['emodb']
emodb = ./emodb/
emodb.split_strategy = speaker_split
target = emotion
labels = ['anger', 'boredom', 'disgust', 'fear']
[FEATS]
type = ['praat']
[MODEL]
type = svm
[EXPL]
model = tree
plot_tree = True

Read the Hello World example for initial usage with Emo-DB dataset.

Here is an overview of the interfaces/modules:

All of them take --config <my_config.ini> as an argument.

Hello World example

  • NEW: Here's a Google colab that runs this example out-of-the-box, and here is the same with Kaggle
  • I made a video to show you how to do this on Windows
  • Set up Python on your computer, version >= 3.8
  • Open a terminal/command line/console window
  • Test python by typing python, python should start with version >3 (NOT 2!). You can leave the Python Interpreter by typing exit()
  • Create a folder on your computer for this example, let's call it nkulu_work
  • Get a copy of the Berlin emodb in audformat and unpack inside the folder you just created (nkulu_work)
  • Make sure the folder is called "emodb" and does contain the database files directly (not box-in-a-box)
  • Also, in the nkulu_work folder:
    • Create a Python environment
      • python -m venv venv
    • Then, activate it:
      • under Linux / mac
        • source venv/bin/activate
      • under Windows
        • venv\Scripts\activate.bat
      • if that worked, you should see a (venv) in front of your prompt
    • Install the required packages in your environment
      • pip install nkululeko
      • Repeat until all error messages vanish (or fix them, or try to ignore them)...
  • Now you should have two folders in your nkulu_work folder:
    • emodb and venv
  • Download a copy of the file exp_emodb.ini to the current working directory (nkulu_work)
  • Run the demo
    • python -m nkululeko.nkululeko --config exp_emodb.ini
  • Find the results in the newly created folder exp_emodb
    • Inspect exp_emodb/images/run_0/emodb_xgb_os_0_000_cnf.png
    • This is the main result of your experiment: a confusion matrix for the emodb emotional categories
  • Inspect and play around with the demo configuration file that defined your experiment, then re-run.
  • There are many ways to experiment with different classifiers and acoustic feature sets, all described here

Features

The framework is targeted at the speech domain and supports experiments where different classifiers are combined with different feature extractors.

  • Classifiers: Naive Bayes, KNN, Tree, XGBoost, SVM, MLP
  • Feature extractors: Praat, Opensmile, openXBOW BoAW, TRILL embeddings, Wav2vec2 embeddings, audModel embeddings, ...
  • Feature scaling
  • Label encoding
  • Binning (continuous to categorical)
  • Online demo interface for trained models
  • Visualization: confusion matrix, feature importance, feature distribution, epoch progression, t-SNE plot, data distribution, bias checking, uncertainty estimation

Here's a rough UML-like sketch of the framework (and here's the real one done with pyreverse). sketch

Currently, the following linear classifiers are implemented (integrated from sklearn):

  • SVM, SVR, XGB, XGR, Tree, Tree_regressor, KNN, KNN_regressor, NaiveBayes, GMM and the following ANNs (artificial neural networks)
  • MLP (multi-layer perceptron), CNN (convolutional neural network)

For visualization, besides confusion matrix, feature importance, feature distribution, t-SNE plot, data distribution (just names a few), Nkululeko can also be used for bias checking, uncertainty estimation, and epoch progression.

Bias checking

In some cases, you might wonder if there's bias in your data. You can try to detect this with automatically estimated speech properties by visualizing the correlation of target labels and predicted labels.

Uncertainty

Nkululeko estimates the uncertainty of model decisions (only for classifiers) with entropy over the class probabilities or logits per sample.

Here's an animation that shows the progress of classification done with nkululeko.

News

There's Felix blog with tutorials below:

License

Nkululeko can be used under the MIT license.

Contributing

Contributions are welcome and encouraged. To learn more about how to contribute to nkululeko, please refer to the Contributing guidelines.

Citation

If you use Nkululeko, please cite the paper:

F. Burkhardt and B. Tris Atmaja, (2025). Nkululeko 1.0: A Python package to predict speaker characteristics with a high-level interface. Journal of Open Source Software, 10(115), 8049, https://doi.org/10.21105/joss.08049

@article{Burkhardt2025, doi = {10.21105/joss.08049}, url = {https://doi.org/10.21105/joss.08049}, year = {2025}, publisher = {The Open Journal}, volume = {10}, number = {115}, pages = {8049}, author = {Burkhardt, Felix and Atmaja, Bagus Tris}, title = {Nkululeko 1.0: A Python package to predict speaker characteristics with a high-level interface}, journal = {Journal of Open Source Software} } 

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nkululeko-1.3.4.tar.gz (37.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nkululeko-1.3.4-py3-none-any.whl (340.2 kB view details)

Uploaded Python 3

File details

Details for the file nkululeko-1.3.4.tar.gz.

File metadata

  • Download URL: nkululeko-1.3.4.tar.gz
  • Upload date:
  • Size: 37.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for nkululeko-1.3.4.tar.gz
Algorithm Hash digest
SHA256 79778b95a2b4feda8f1f966d1821cf530eba8c19d55532331e0c4e85ce4bf863
MD5 d7b697b5a06b86692269123054b86b02
BLAKE2b-256 21e05f62c9cd1c3195d84a6776682a048883727542c2871c6a75892f2d16a12d

See more details on using hashes here.

File details

Details for the file nkululeko-1.3.4-py3-none-any.whl.

File metadata

  • Download URL: nkululeko-1.3.4-py3-none-any.whl
  • Upload date:
  • Size: 340.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for nkululeko-1.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c38c3938c87017ed91e02f4473e6e546d7b7dcdadda473d551ed7907cb7a5945
MD5 d8b541feed6a941de6b06cb27f652256
BLAKE2b-256 c74ba1def90ab83bc2baa76f0e0476aa5a5006030a33b4372f65c16da0ad1291

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page