Google Colab
colab.research.google.com
- Upload a dataset of examples containing articles and human-written reference summaries to Phoenix
- Define an experiment task that summarizes a news article
- Devise evaluators for length and ROUGE score
- Run experiments to iterate on your prompt template and to compare the summaries produced by different LLMs
Install Dependencies and Import Libraries
Install requirements and import libraries.Launch Phoenix
Launch Phoenix and follow the instructions in the cell output to open the Phoenix UI.Instrument Your Application
Create Your Dataset
Download your data from HuggingFace and inspect a random sample of ten rows. This dataset contains news articles and human-written summaries that we will use as a reference against which to compare our LLM generated summaries. Upload the data as a dataset in Phoenix and follow the link in the cell output to inspect the individual examples of the dataset. Later in the notebook, you will run experiments over this dataset in order to iteratively improve your summarization application.Define Your Experiment Task
A task is a callable that maps the input of a dataset example to an output by invoking a chain, query engine, or LLM. An experiment maps a task across all the examples in a dataset and optionally executes evaluators to grade the task outputs. You’ll start by defining your task, which in this case, invokes OpenAI. First, set your OpenAI API key if it is not already present as an environment variable.functools.partial to derive your first task, which is a callable that takes in an example and returns an output. Test out your task by invoking it on the test example.
Define Your Evaluators
Evaluators take the output of a task (in this case, a string) and grade it, often with the help of an LLM. In your case, you will create ROUGE score evaluators to compare the LLM-generated summaries with the human reference summaries you uploaded as part of your dataset. There are several variants of ROUGE, but we’ll use ROUGE-1 for simplicity:- ROUGE-1 precision is the proportion of overlapping tokens (present in both reference and generated summaries) that are present in the generated summary (number of overlapping tokens / number of tokens in the generated summary)
- ROUGE-1 recall is the proportion of overlapping tokens that are present in the reference summary (number of overlapping tokens / number of tokens in the reference summary)
- ROUGE-1 F1 score is the harmonic mean of precision and recall, providing a single number that balances these two scores.
rouge and tiktoken).
Run Experiments and Iterate on Your Prompt Template
Run your first experiment and follow the link in the cell output to inspect the task outputs (generated summaries) and evaluations.num_tokens has indeed increased, but the generated summaries are still far more verbose than the reference summaries.
Instead of just instructing the LLM to produce concise summaries, let’s use a few-shot prompt to show it examples of articles and good summaries. The cell below includes a few articles and reference summaries in an updated prompt template.
Compare With Another Model (Optional)
Now that you have a prompt template that is performing reasonably well, you can compare the performance of other models on this particular task. Anthropic’s Claude is notable for producing concise and to-the-point output. First, enter your Anthropic API key if it is not already present.Synopsis and Next Steps
Congrats! In this tutorial, you have:- Created a Phoenix dataset
- Defined an experimental task and custom evaluators
- Iteratively improved a prompt template to produce more concise summaries with balanced ROUGE-1 precision and recall

