Home

Awesome

<p align="center"> <a href="https://ludwig.ai"> <img src="https://github.com/ludwig-ai/ludwig-docs/raw/master/docs/images/ludwig_hero_smaller.jpg" height="150"> </a> </p> <div align="center">

Declarative deep learning framework built for scale and efficiency.

PyPI version Discord DockerHub Downloads License X

</div>

[!IMPORTANT] Our community has moved to Discord -- please join us there!

πŸ“– What is Ludwig?

Ludwig is a low-code framework for building custom AI models like LLMs and other deep neural networks.

Key features:

Ludwig is hosted by the Linux Foundation AI & Data.

img

πŸ’Ύ Installation

Install from PyPi. Be aware that Ludwig requires Python 3.8+.

pip install ludwig

Or install with all optional dependencies:

pip install ludwig[full]

Please see contributing for more detailed installation instructions.

πŸš‚ Getting Started

Want to take a quick peak at some of the Ludwig 0.8 features? Check out this Colab Notebook πŸš€ Open In Colab

Looking to fine-tune Llama-2 or Mistral? Check out these notebooks:

  1. Fine-Tune Llama-2-7b: Open In Colab
  2. Fine-Tune Llama-2-13b: Open In Colab
  3. Fine-Tune Mistral-7b: Open In Colab

For a full tutorial, check out the official getting started guide, or take a look at end-to-end Examples.

Large Language Model Fine-Tuning

Open In Colab

Let's fine-tune a pretrained LLaMA-2-7b large language model to follow instructions like a chatbot ("instruction tuning").

Prerequisites

Running

We'll use the Stanford Alpaca dataset, which will be formatted as a table-like file that looks like this:

instructioninputoutput
Give three tips for staying healthy.1.Eat a balanced diet and make sure to include...
Arrange the items given below in the order to ...cake, me, eatingI eating cake.
Write an introductory paragraph about a famous...Michelle ObamaMichelle Obama is an inspirational woman who r...
.........

Create a YAML config file named model.yaml with the following:

model_type: llm
base_model: meta-llama/Llama-2-7b-hf

quantization:
  bits: 4

adapter:
  type: lora

prompt:
  template: |
    Below is an instruction that describes a task, paired with an input that may provide further context.
    Write a response that appropriately completes the request.

    ### Instruction:
    {instruction}

    ### Input:
    {input}

    ### Response:

input_features:
  - name: prompt
    type: text

output_features:
  - name: output
    type: text

trainer:
  type: finetune
  learning_rate: 0.0001
  batch_size: 1
  gradient_accumulation_steps: 16
  epochs: 3
  learning_rate_scheduler:
    decay: cosine
    warmup_fraction: 0.01

preprocessing:
  sample_ratio: 0.1

backend:
  type: local

And now let's train the model:

export HUGGING_FACE_HUB_TOKEN = "<api_token>"

ludwig train --config model.yaml --dataset "ludwig://alpaca"

Supervised ML

Let's build a neural network that predicts whether a given movie critic's review on Rotten Tomatoes was positive or negative.

Our dataset will be a CSV file that looks like this:

movie_titlecontent_ratinggenresruntimetop_criticreview_contentrecommended
Deliver Us from EvilRAction & Adventure, Horror117.0TRUEDirector Scott Derrickson and his co-writer, Paul Harris Boardman, deliver a routine procedural with unremarkable frights.0
BarbaraPG-13Art House & International, Drama105.0FALSESomehow, in this stirring narrative, Barbara manages to keep hold of her principles, and her humanity and courage, and battles to save a dissident teenage girl whose life the Communists are trying to destroy.1
Horrible BossesRComedy98.0FALSEThese bosses cannot justify either murder or lasting comic memories, fatally compromising a farce that could have been great but ends up merely mediocre.0
.....................

Download a sample of the dataset from here.

wget https://ludwig.ai/latest/data/rotten_tomatoes.csv

Next create a YAML config file named model.yaml with the following:

input_features:
  - name: genres
    type: set
    preprocessing:
      tokenizer: comma
  - name: content_rating
    type: category
  - name: top_critic
    type: binary
  - name: runtime
    type: number
  - name: review_content
    type: text
    encoder:
      type: embed
output_features:
  - name: recommended
    type: binary

That's it! Now let's train the model:

ludwig train --config model.yaml --dataset rotten_tomatoes.csv

Happy modeling

Try applying Ludwig to your data. Reach out on Discord if you have any questions.

❓ Why you should use Ludwig

πŸ“š Tutorials

πŸ”¬ Example Use Cases

πŸ’‘ More Information

Read our publications on Ludwig, declarative ML, and Ludwig’s SoTA benchmarks.

Learn more about how Ludwig works, how to get started, and work through more examples.

If you are interested in contributing, have questions, comments, or thoughts to share, or if you just want to be in the know, please consider joining our Community Discord and follow us on X!

🀝 Join the community to build Ludwig with us

Ludwig is an actively managed open-source project that relies on contributions from folks just like you. Consider joining the active group of Ludwig contributors to make Ludwig an even more accessible and feature rich framework for everyone to use!

<a href="https://github.com/ludwig-ai/ludwig/graphs/contributors"> <img src="https://contrib.rocks/image?repo=ludwig-ai/ludwig" /> </a><br/>

Star History

Star History Chart

πŸ‘‹ Getting Involved