Skip to content

Commit aebe5be

Browse files
committed
update tutorials
1 parent a334229 commit aebe5be

16 files changed

+916
-792
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ to install the necessary dependencies. You might need to install [pipx](https://
3636

3737
## Usage
3838

39-
To get started right away, take a look at our [getting started notebook](https://github.com/finitearth/promptolution/blob/main/notebooks/getting_started.ipynb).
39+
To get started right away, take a look at our [getting started notebook](https://github.com/finitearth/promptolution/blob/main/tutorials/getting_started.ipynb) and our [other demos and tutorials](https://github.com/finitearth/promptolution/blob/main/tutorials).
4040
For more details, a comprehensive **documentation** with API reference is availabe at https://finitearth.github.io/promptolution/.
4141

4242
### Featured Optimizers

notebooks/llm_as_judge_tutorial.ipynb

Lines changed: 0 additions & 467 deletions
This file was deleted.

notebooks/reward_task_tutorial.ipynb

Lines changed: 0 additions & 297 deletions
This file was deleted.

promptolution/tasks/base_task.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ def _collect_results_from_cache(
147147
return scores if not return_seq else (scores, seqs)
148148

149149
@abstractmethod
150-
def _single_evaluate(self, x: np.ndarray, y: np.ndarray, pred: np.ndarray) -> float:
151-
"""Abstract method to calculate the score for a single prediction.
150+
def _evaluate(self, xs: np.ndarray, ys: np.ndarray, preds: np.ndarray) -> List[float]:
151+
"""Abstract method to calculate the score for a predictions.
152152
153153
This method should be implemented by subclasses based on their specific evaluation logic.
154154
"""
@@ -183,10 +183,9 @@ def evaluate(
183183

184184
if return_seq:
185185
preds, seqs = preds
186-
186+
scores = self._evaluate(xs_to_evaluate, ys_to_evaluate, preds)
187187
for i, cache_key in enumerate(batches):
188-
x, y, y_pred = xs_to_evaluate[i], ys_to_evaluate[i], preds[i]
189-
self.eval_cache[cache_key] = self._single_evaluate(x, y, y_pred)
188+
self.eval_cache[cache_key] = scores[i]
190189

191190
if return_seq:
192191
self.seq_cache[cache_key] = seqs[i]

promptolution/tasks/classification_tasks.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pandas as pd
66
from sklearn.metrics import accuracy_score
77

8-
from typing import TYPE_CHECKING, Callable, Literal
8+
from typing import TYPE_CHECKING, Callable, List, Literal
99

1010
from promptolution.tasks.base_task import BaseTask
1111

@@ -65,6 +65,9 @@ def __init__(
6565
self.ys = df[self.y_column].str.lower().values # Ensure y values are lowercase for consistent comparison
6666
self.classes = np.unique(self.ys)
6767

68-
def _single_evaluate(self, x: np.ndarray, y: np.ndarray, pred: np.ndarray) -> float:
68+
def _evaluate(self, xs: np.ndarray, ys: np.ndarray, preds: np.ndarray) -> List[float]:
6969
"""Calculate the score for a single prediction."""
70-
return self.metric([y], [pred])
70+
scores = []
71+
for pred, y in zip(preds, ys):
72+
scores.append(self.metric([y], [pred]))
73+
return scores

0 commit comments

Comments
 (0)