Back to Tensorzero

Example: Dynamic In-Context Learning (DICL)

examples/optimization/dicl/README.md

2026.4.1937 B
Original Source

Example: Dynamic In-Context Learning (DICL)

This example shows how to use the dynamic in-context learning (DICL) optimization workflow to improve the performance of a variant.

For this example, we'll tackle a SMS spam classification task based on the SMS spam dataset.

In the dicl.ipynb Jupyter notebook, we will:

  1. Load the spam dataset
  2. Convert it to the TensorZero format
  3. Store the converted datapoints in TensorZero
  4. Query the stored datapoints back
  5. Launch the DICL optimization workflow
  6. Compare the baseline and the DICL variants

The variant optimized with DICL materially outperforms the baseline variant.

Setup

  1. Set the OPENAI_API_KEY environment variable.
  2. Install the Python dependencies. We recommend using uv:
bash
uv sync
  1. Launch TensorZero:
    bash
    docker compose up