Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions superpipe/grid_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def run(self, df: pd.DataFrame, output_dir=None, verbose=False, styled=True):
result = {
**GridSearch._flatten_params_dict(params),
'score': self.pipeline.score,
'lables': self.pipeline.labels,
'Confusion_matrix': self.pipeline.cm,
'input_cost': self.pipeline.statistics.input_cost,
'output_cost': self.pipeline.statistics.output_cost,
'total_latency': self.pipeline.statistics.total_latency,
Expand Down
8 changes: 8 additions & 0 deletions superpipe/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from prettytable import PrettyTable
from superpipe.steps import Step, LLMStep, LLMStructuredStep, LLMStructuredCompositeStep
from superpipe.config import is_dev, studio_enabled
from sklearn.metrics import confusion_matrix


@dataclass
class PipelineStatistics:
score: Optional[float] = None
cm = None
input_tokens: dict = field(default_factory=lambda: defaultdict(int))
output_tokens: dict = field(default_factory=lambda: defaultdict(int))
input_cost: float = 0.0
Expand Down Expand Up @@ -68,6 +70,8 @@ def __init__(self,
self.output_fields = output_fields or steps[-1].output_fields()
self.data = None
self.score = None
self.labels = None
self.cm = None
self.name = name or self.__class__.__name__
self.statistics = PipelineStatistics()

Expand Down Expand Up @@ -138,6 +142,10 @@ def evaluate(self, evaluation_fn=None):
results = self.data.apply(lambda row: evaluation_fn(row), axis=1)
self.data[f"__{evaluation_fn.__name__}__"] = results
self.score = results.sum() / len(results)
labels = self.data.label.str.lower()
predicts = self.data.predict.str.lower()
self.labels = sorted(list(set(labels).union(predicts)))
self.cm = confusion_matrix(labels, predicts)
return self.score

def _aggregate_statistics(self, data: Union[pd.DataFrame, Dict]):
Expand Down