Skip to content

Commit

Permalink
[Evals] Update JSON validator to use match check (openai#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-openai committed Apr 15, 2023
1 parent 3d70c4d commit a6fe832
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions evals/elsuite/basic/json_validator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import json
from typing import Any

import numpy as np

import evals
import evals.metrics
import evals.record
from evals.api import CompletionFn

Expand All @@ -22,12 +21,10 @@ def __init__(
completion_fns: list[CompletionFn],
samples_jsonl: str,
*args,
max_tokens: int = 500,
**kwargs,
):
super().__init__(completion_fns, *args, **kwargs)
assert len(completion_fns) == 1, "JsonValidator only supports one completion fn"
self.max_tokens = max_tokens
self.samples_jsonl = samples_jsonl

def eval_sample(self, sample: Any, *_):
Expand All @@ -37,12 +34,12 @@ def eval_sample(self, sample: Any, *_):
temperature=0.0,
)
sampled = result.get_completions()[0]
return evals.record.record_metrics(
is_valid_json=is_valid_json(sampled),
)
return evals.record.record_match(is_valid_json(sampled), expected=None, picked=sampled)

def run(self, recorder):
samples = self.get_samples()
self.eval_all_samples(recorder, samples)
metrics = recorder.get_metrics()
return {"num_valid_json": np.mean([m["is_valid_json"] for m in metrics])}
events = recorder.get_events("match")
return {
"accuracy": evals.metrics.get_accuracy(events),
}

0 comments on commit a6fe832

Please sign in to comment.