Uber’s Ludwig v0.2: New features and Improvements

Uber released a new version of Ludwig with new features as well as some improvements to old once. If you don’t already know Uber’s Ludwig is a machine learning toolbox aimed at opening the world of machine learning to none-coders by providing a simple interface to create deep neural networks for lots of different applications.

I already covered the basics of Uber’s Ludwig in two other articles. I released the first one right after the release of Uber’s Ludwig in February 2019. It covers the core principles and basics of Uber’s Ludwig. In the second article, I covered how to use Uber’s Ludwig for tabular, image and text data.

Ludwig 0.2

The newest version of Uber’s Ludwig expands its feature-set with a series of new features aimed at improving the overall workflow of Ludwig as well as adding some preprocessing techniques which were missing in the old release.

If you want to know about all the changes in detail check out the official article on the release of Ludwig 0.2. At a high level, here a the most important changes:

  • Comet.ml Integration: Comet.ml is a tool that lets users track their machine learning code, experiments, and results. Ludwig 0.2 integrates with Comet.ml to allow us to compare experiments, manage changes, track results and tune hyperparameter
  • BERT Encoder: BERT is a language encoding model based on the Transformer architecture for encoding textual data that is trained on a large corpus of textual data in a self-supervised way. Ludwig 0.2 added BERT to their list of available text encoders to allow for use cases where the supervised data is small but the performance requirements are high. Using it is as simple as downloading some pre-trained weights and added bert as the encoder.
  • Audio/Speech features: One of the big additions to Ludwig are their newly available audio features that make it possible to work with audio data in Ludwig. The audio features include model architectures like a RNN as well as common audio preprocessing techniques like a Fast Fourier transformation.
  • H3 Features: Ludwig 0.2 also adds support for geographic features based on the H3 spatial index created and open-sourced by Uber in 2018. The H3 spatial index can be used by using the following config
  • Date Features: Ludwig also added support for date features. This allows users to input date-time features that will be automatically subdivided into components (year, month, day, day of the week, day of the year, hour, minute, and second).
  • Model Serving: Probably the most important addition to Uber’s Ludwig is the ability to directly deploy Ludwig models as REST-APIs. This makes it incredibly easy to quickly prototype a model and push it to production.

Additionally, the team behind Uber’s Ludwig has added features to Ludwigs Visualization API, added the newest spaCy text preprocessing methods and made other small improvements to the library.

 Working with Audio/Speech features

Ludwig 0.2 makes it incredibly easy to work with audio data. Whilst with other libraries you need to have extensive knowledge about audio preprocessings and what models are best for working with audio data Ludwig allows you to work with audio data by only specifying the audio tag.

Using this feature we can easily build an audio classification model. I used the Audio Cats and Dogs data-set which is freely available on Kaggle

For this data-set we first on need to create a csv file containing a column with the file paths and another column with the class of the audio file. This can be done using a simple Python script.

import pandas as pd
import itertools
import argparse


def create_csv(filename, save_path):
    df = pd.read_csv(filename)
    df_new = pd.DataFrame()
    df_new['filename'] = list(itertools.chain(df['train_cat'].values, df['train_dog'].values))
    df_new.dropna(inplace=True)
    df_new['class'] = df_new['filename'].map(lambda x: x.split('_')[0])
    df_new['filename'] = df_new['filename'].map(lambda x: 'cats_dogs/'+x)
    df_new = df_new.sample(frac=1).reset_index(drop=True)
    df_new.to_csv(save_path, index=None)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Create csv to use with Uber Ludwig')
    parser.add_argument('-f', '--filename', type=str, default='train_test_split.csv', help="Path to Audio cat and Dog csv")
    parser.add_argument('-s', '--save_path', type=str, default='data.csv', help='Save path')
    args = parser.parse_args()
    create_csv(args.filename, args.save_path)

After executing this script we are ready to create our model_definition.yaml file. As an input, we will have the audio feature which can be specified as shown above. As an output, we will either have a cat or dog so we can use a binary or category type.

input_features:
  -
    name: filename
    type: audio
    encoder: rnn
    cell_type: lstm
    preprocessing:
      features: fft
    in_memory: False

output_features:
  -
    name: class
    type: category

training:
    batch_size: 4

This can now be trained using Ludwig’s train command.

ludwig train --data_csv data.csv --model_definition_file model_definition.yaml

Serve Ludwig Model

Probably the biggest addition to Ludwig is their adaption of the FastAPI library to spawn a REST server that can be queried to obtain predictions. 

To serve a trained model using Ludwig you need to run the serve command.

ludwig serve --model_path <path-to-model>

After serving the model you can make requests using services like curl.

curl http://0.0.0.0:8000/predict -X POST -F '<feature>=<feature-value>'

Conclusion

Ludwig v0.2 brings a lot of new features to the table that really extend the usefulness of the toolbox. Using Ludwig you can now build complex audio classification systems, work with date and geographic features as well as use Comet.ml to compare experiments, manage changes, track results and tune hyperparameter.

That’s all from this article. If you have any questions or just want to chat with me feel free to leave a comment below or contact me on social media. If you want to get continuous updates about my blog make sure to follow me on Medium and join my newsletter.