Skip to content

Commit fd30d94

Browse files
authored
chore: remove deprecated ground_truths (#2402)
1 parent ba8a1cc commit fd30d94

File tree

3 files changed

+5
-31
lines changed

3 files changed

+5
-31
lines changed

docs/howtos/integrations/_opik.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ dataset = fiqa_eval["baseline"].select(range(3))
208208
dataset = dataset.map(
209209
lambda x: {
210210
"user_input": x["question"],
211-
"reference": x["ground_truths"][0],
211+
"reference": x["ground_truth"],
212212
"retrieved_contexts": x["contexts"],
213213
}
214214
)

docs/howtos/integrations/opik.ipynb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,7 @@
260260
{
261261
"cell_type": "markdown",
262262
"metadata": {},
263-
"source": [
264-
"#### Evaluating datasets\n",
265-
"\n",
266-
"If you looking at evaluating a dataset, you can use the Ragas `evaluate` function. When using this function, the Ragas library will compute the metrics on all the rows of the dataset and return a summary of the results.\n",
267-
"\n",
268-
"You can use the OpikTracer callback to log the results of the evaluation to the Opik platform. For this we will configure the OpikTracer"
269-
]
263+
"source": "from datasets import load_dataset\n\nfrom ragas import evaluate\nfrom ragas.metrics import answer_relevancy, context_precision, faithfulness\n\nfiqa_eval = load_dataset(\"explodinggradients/fiqa\", \"ragas_eval\")\n\n# Reformat the dataset to match the schema expected by the Ragas evaluate function\ndataset = fiqa_eval[\"baseline\"].select(range(3))\n\ndataset = dataset.map(\n lambda x: {\n \"user_input\": x[\"question\"],\n \"reference\": x[\"ground_truth\"],\n \"retrieved_contexts\": x[\"contexts\"],\n }\n)\n\nopik_tracer_eval = OpikTracer(tags=[\"ragas_eval\"], metadata={\"evaluation_run\": True})\n\nresult = evaluate(\n dataset,\n metrics=[context_precision, faithfulness, answer_relevancy],\n callbacks=[opik_tracer_eval],\n)\n\nprint(result)"
270264
},
271265
{
272266
"cell_type": "code",
@@ -309,7 +303,7 @@
309303
"dataset = dataset.map(\n",
310304
" lambda x: {\n",
311305
" \"user_input\": x[\"question\"],\n",
312-
" \"reference\": x[\"ground_truths\"][0],\n",
306+
" \"reference\": x[\"ground_truth\"],\n",
313307
" \"retrieved_contexts\": x[\"contexts\"],\n",
314308
" }\n",
315309
")\n",
@@ -347,4 +341,4 @@
347341
},
348342
"nbformat": 4,
349343
"nbformat_minor": 2
350-
}
344+
}

src/ragas/validation.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import typing as t
55

6-
from datasets import Dataset, Sequence
6+
from datasets import Dataset
77

88
from ragas.dataset_schema import EvaluationDataset, MultiTurnSample, SingleTurnSample
99
from ragas.metrics.base import Metric, MetricType, MultiTurnMetric, SingleTurnMetric
@@ -20,26 +20,6 @@ def remap_column_names(dataset: Dataset, column_map: dict[str, str]) -> Dataset:
2020
return dataset.rename_columns(inverse_column_map)
2121

2222

23-
def handle_deprecated_ground_truths(ds: Dataset) -> Dataset:
24-
if "ground_truths" in ds.features and "ground_truth" not in ds.features:
25-
column_names = "ground_truths"
26-
if (
27-
isinstance(ds.features[column_names], Sequence)
28-
and ds.features[column_names].feature.dtype == "string"
29-
):
30-
logger.warning(
31-
"passing column names as 'ground_truths' is deprecated and will be removed in the next version, please use 'ground_truth' instead. Note that `ground_truth` should be of type string and not Sequence[string] like `ground_truths`"
32-
)
33-
gt = [gt[0] for gt in ds["ground_truths"]]
34-
ds = ds.add_column(
35-
"ground_truth",
36-
gt,
37-
new_fingerprint=ds._fingerprint
38-
+ "a", # adding random to fingerprint to avoid caching
39-
)
40-
return ds
41-
42-
4323
def get_supported_metric_type(ds: EvaluationDataset):
4424
"""
4525
get the supported metric type for the given dataset

0 commit comments

Comments
 (0)