Skip to content

Commit 896626a

Browse files
authored
feat: added ragas_score and fixed dependency and ci issues (#36)
* ci fixes * add src directory file structure * update pyproject * fix _version.py * fix linting and type issues * fix dependencies * fix annotation bug * added ragas score
1 parent 322bd13 commit 896626a

File tree

15 files changed

+46
-94
lines changed

15 files changed

+46
-94
lines changed

β€Ž.gitignoreβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,4 @@ ragas/_version.py
164164
experiments/**/data
165165
experiments/**/storage
166166
**/fil-result/
167+
src/ragas/_version.py

β€ŽMakefileβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ format: ## Running code formatter: black and isort
88
@echo "(isort) Ordering imports..."
99
@isort .
1010
@echo "(black) Formatting codebase..."
11-
@black --config pyproject.toml ragas tests examples
11+
@black --config pyproject.toml src tests examples experiments
1212
@echo "(black) Formatting stubs..."
13-
@find ragas -name "*.pyi" ! -name "*_pb2*" -exec black --pyi --config pyproject.toml {} \;
13+
@find src -name "*.pyi" ! -name "*_pb2*" -exec black --pyi --config pyproject.toml {} \;
1414
@echo "(ruff) Running fix only..."
15-
@ruff check ragas examples tests --fix-only
15+
@ruff check src examples tests --fix-only
1616
lint: ## Running lint checker: ruff
1717
@echo "(ruff) Linting development project..."
18-
@ruff check ragas examples tests
18+
@ruff check src examples tests
1919
type: ## Running type checker: pyright
2020
@echo "(pyright) Typechecking codebase..."
21-
@pyright ragas
21+
@pyright src
2222
clean: ## Clean all generated files
2323
@echo "Cleaning all generated files..."
2424
@cd $(GIT_ROOT)/docs && make clean

β€Žpyproject.tomlβ€Ž

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
[project]
22
name = "ragas"
33
dependencies = [
4-
"Levenshtein",
5-
"rouge-score",
64
"numpy",
75
"transformers",
86
"sentence-transformers",
9-
"nltk",
107
"datasets",
11-
"spacy<4.0.0,>=3.0.0",
128
"protobuf<=3.20.0",
9+
"backoff",
10+
"openai",
1311
]
1412
dynamic = ["version", "readme"]
1513

14+
[tool.setuptools]
15+
package-dir = {"" = "src"}
16+
1617
[tool.setuptools.dynamic]
1718
readme = {file = ["README.md"], content-type = "text/plain"}
1819

1920
[build-system]
2021
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
2122
build-backend = "setuptools.build_meta"
23+
2224
[tool.setuptools_scm]
23-
write_to = "ragas/_version.py"
25+
write_to = "src/ragas/_version.py"
File renamed without changes.

β€Žragas/evaluation.pyβ€Ž renamed to β€Žsrc/ragas/evaluation.pyβ€Ž

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from __future__ import annotations
22

3-
import typing as t
43
from dataclasses import dataclass
54
from enum import Enum
65

76
import numpy as np
87
from datasets import Dataset, concatenate_datasets
9-
from tqdm import tqdm
108

119
from ragas.metrics.base import Metric
1210

@@ -44,19 +42,24 @@ def evaluate(
4442
[m.init_model() for m in metrics]
4543

4644
scores = []
47-
for metric in tqdm(metrics):
45+
for metric in metrics:
4846
scores.append(metric.score(dataset).select_columns(metric.name))
4947

50-
return Result(concatenate_datasets(scores))
48+
return Result(concatenate_datasets(scores, axis=1))
5149

5250

5351
@dataclass
5452
class Result(dict):
5553
scores: Dataset
5654

5755
def __post_init__(self):
56+
values = []
5857
for cn in self.scores.column_names:
59-
self[cn] = np.mean(self.scores[cn])
58+
value = np.mean(self.scores[cn])
59+
self[cn] = value
60+
values.append(value)
61+
62+
self["ragas_score"] = len(values) / np.sum(1.0 / np.array(values))
6063

6164
def describe(self):
6265
description = {}
File renamed without changes.
File renamed without changes.

β€Žragas/metrics/answer_relevance.pyβ€Ž renamed to β€Žsrc/ragas/metrics/answer_relevance.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def predict(
121121
) -> npt.NDArray[np.float64]:
122122
predictions = []
123123
dataloader = DataLoader(
124-
sentences, batch_size=batch_size, collate_fn=self.collate_fn
124+
sentences, batch_size=batch_size, collate_fn=self.collate_fn # type: ignore
125125
)
126126

127127
if show_progress:

β€Žragas/metrics/base.pyβ€Ž renamed to β€Žsrc/ragas/metrics/base.pyβ€Ž

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ def get_batches(self, dataset_size: int):
4747
range(i, i + self.batch_size)
4848
for i in range(0, self.batch_size * num_batches, self.batch_size)
4949
]
50-
batches.append(
51-
range(self.batch_size * num_batches, self.batch_size * num_batches + tail)
52-
)
50+
if tail != 0:
51+
batches.append(
52+
range(
53+
self.batch_size * num_batches, self.batch_size * num_batches + tail
54+
)
55+
)
5356

5457
return batches

0 commit comments

Comments
Β (0)