json_schema
genlm.eval.domains.json_schema
JSONSchemaBenchDataset
Bases: Dataset[JSONSchemaBenchInstance]
Dataset for JSON evaluation using the JSONSchemaBench dataset.
Source code in genlm/eval/domains/json_schema/dataset.py
__init__(schemas, tasks, unique_ids)
Initialize the dataset with a list of regex patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list[str]
|
The JSON schemas to evaluate. |
required |
tasks
|
list[str]
|
The task name for each schema. |
required |
unique_ids
|
list[int]
|
The unique id for each schema. |
required |
Source code in genlm/eval/domains/json_schema/dataset.py
from_tasks(tasks, split='val')
classmethod
Load tasks from a list of tasks in the JSONSchemaBench dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks
|
list[Task]
|
The tasks to evaluate. |
required |
split
|
str
|
The split to load. Defaults to "val". |
'val'
|
Returns:
| Type | Description |
|---|---|
JSONSchemaBenchDataset
|
Dataset initialized with schemas from the tasks. |
Source code in genlm/eval/domains/json_schema/dataset.py
__iter__()
Iterate over JSON schemas.
Returns:
| Type | Description |
|---|---|
Iterator[JSONSchemaBenchInstance]
|
Iterator over JSON schema instances. |
Source code in genlm/eval/domains/json_schema/dataset.py
schema
property
Get the schema class for this dataset.
Returns:
| Type | Description |
|---|---|
type[JSONSchemaBenchInstance]
|
The Pydantic model class for JSON schema instances. |
JSONSchemaBenchInstance
JSONSchemaBenchEvaluator
Bases: Evaluator[JSONSchemaBenchInstance]
Evaluator for JSON schema.
Source code in genlm/eval/domains/json_schema/evaluator.py
evaluate_sample(instance, response)
Evaluate if a response is valid against the JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
JSONSchemaBenchInstance
|
The JSON schema instance being evaluated. |
required |
response
|
str
|
The model's response text. |
required |
Returns:
| Type | Description |
|---|---|
EvaluationResult
|
Evaluation result for whether the response is valid against the JSON schema. |
Source code in genlm/eval/domains/json_schema/evaluator.py
default_prompt_formatter(tokenizer, instance, use_chat_format=True, system_prompt=DEFAULT_SYSTEM_PROMPT)
Default prompt formatter for JSON Schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
Tokenizer
|
The tokenizer to use. |
required |
instance
|
JSONSchemaInstance
|
The instance to format. |
required |
use_chat_format
|
bool
|
Whether to use chat format. |
True
|
system_prompt
|
str
|
The system prompt to use. |
DEFAULT_SYSTEM_PROMPT
|
Returns:
| Type | Description |
|---|---|
list[int]
|
The prompt ids. |