Evaluating Opik’s Moderation Metric
For this guide we will be evaluating the Moderation metric included in the LLM Evaluation SDK which will showcase both how to use the evaluation
functionality in the platform as well as the quality of the Moderation metric included in the SDK.
Creating an account on Comet.com
Comet provides a hosted version of the Opik platform, simply create an account and grab you API Key.
You can also run the Opik platform locally, see the installation guide for more information.
Preparing our environment
First, we will configure the OpenAI API key and download a reference moderation dataset.
We will be using the OpenAI Moderation API Release dataset which according to this blog post GPT-4o detects 60% of hallucinations. The first step will be to create a dataset in the platform so we can keep track of the results of the evaluation.
Since the insert methods in the SDK deduplicates items, we can insert 50 items and if the items already exist, Opik will automatically remove them.
Evaluating the moderation metric
In order to evaluate the performance of the Opik moderation metric, we will define:
- Evaluation task: Our evaluation task will use the data in the Dataset to return a moderation score computed using the Opik moderation metric.
- Scoring metric: We will use the
Equals
metric to check if the moderation score computed matches the expected output.
By defining the evaluation task in this way, we will be able to understand how well Opik’s moderation metric is able to detect moderation violations in the dataset.
We can use the Opik SDK to compute a moderation score for each item in the dataset:
We are able to detect ~85% of moderation violations, this can be improved further by providing some additional examples to the model. We can view a breakdown of the results in the Opik UI: