api
| CLASS | DESCRIPTION |
|---|---|
BaseEvaluationBuilder |
Abstract mutable builder for creating evaluation requests. |
JsonlEvaluationBuilder |
Concrete builder for JSONL-based evaluations. |
| FUNCTION | DESCRIPTION |
|---|---|
metric |
Create a generic metric spec using a metric's name. |
count_characters |
Create a metric spec for counting the number of characters in the evaluated text. |
count_tokens |
Create a metric spec for counting the number of tokens in the evaluated text. |
count_encodings |
Create a metric spec for counting the number of model-specific encodings in a text. |
json_format |
Create a metric spec for validating JSON output format. |
Classes
BaseEvaluationBuilder
BaseEvaluationBuilder(*, catalog: type[Catalog] = MetricsCatalog)
flowchart TD
evallm.application.api.BaseEvaluationBuilder[BaseEvaluationBuilder]
click evallm.application.api.BaseEvaluationBuilder href "" "evallm.application.api.BaseEvaluationBuilder"
Abstract mutable builder for creating evaluation requests.
| METHOD | DESCRIPTION |
|---|---|
use |
Attach a single metric spec and return the same builder instance. |
build_dataset |
Build the dataset spec for the concrete builder. |
build_request |
Build the canonical evaluation request. |
build_evaluator |
Build an evaluator from the current builder state. |
run |
Lazily execute evaluation and yield individual results. |
from_request |
Rebuild a concrete builder from a canonical request. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
catalog |
Immutable catalog used for metric resolution. |
metrics |
Immutable view of attached metric specs.
TYPE:
|
Source code in src/evallm/application/api.py
Attributes
catalog
property
metrics
property
metrics: tuple[MetricSpec, ...]
Immutable view of attached metric specs.
| RETURNS | DESCRIPTION |
|---|---|
tuple[MetricSpec, ...]
|
tuple[MetricSpec, ...]: Tuple of currently attached metric specs. |
Functions
use
use(metric_spec: MetricSpec) -> Self
Attach a single metric spec and return the same builder instance.
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The mutated builder instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
DuplicateMetricResultKeyError
|
If attaching the metric would cause a final result-key collision. |
Source code in src/evallm/application/api.py
build_dataset
abstractmethod
build_request
build_request() -> EvaluationRequest
Build the canonical evaluation request.
| RETURNS | DESCRIPTION |
|---|---|
EvaluationRequest
|
Canonical request assembled from current builder state.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no metrics are attached. |
Source code in src/evallm/application/api.py
build_evaluator
build_evaluator() -> Evaluator
Build an evaluator from the current builder state.
| RETURNS | DESCRIPTION |
|---|---|
Evaluator
|
Evaluator configured with the built request and catalog.
TYPE:
|
Source code in src/evallm/application/api.py
run
run() -> Iterator[EvaluationResult]
Lazily execute evaluation and yield individual results.
| YIELDS | DESCRIPTION |
|---|---|
EvaluationResult
|
Per-record evaluation result.
TYPE::
|
from_request
abstractmethod
classmethod
from_request(
request: EvaluationRequest, *, catalog: type[Catalog] = MetricsCatalog
) -> Self
Rebuild a concrete builder from a canonical request.
Source code in src/evallm/application/api.py
JsonlEvaluationBuilder
JsonlEvaluationBuilder(
input_file: str | PathLike[str],
*,
text_key: str,
record_id_key: str = "#IDX#",
catalog: type[Catalog] = MetricsCatalog,
)
flowchart TD
evallm.application.api.JsonlEvaluationBuilder[JsonlEvaluationBuilder]
evallm.application.api.BaseEvaluationBuilder[BaseEvaluationBuilder]
evallm.application.api.BaseEvaluationBuilder --> evallm.application.api.JsonlEvaluationBuilder
click evallm.application.api.JsonlEvaluationBuilder href "" "evallm.application.api.JsonlEvaluationBuilder"
click evallm.application.api.BaseEvaluationBuilder href "" "evallm.application.api.BaseEvaluationBuilder"
Concrete builder for JSONL-based evaluations.
-
API Reference
evallmapplication
| METHOD | DESCRIPTION |
|---|---|
build_dataset |
Build a JSONL dataset spec from the builder state. |
from_request |
Rebuild a JSONL builder from an existing request. |
use |
Attach a single metric spec and return the same builder instance. |
build_request |
Build the canonical evaluation request. |
build_evaluator |
Build an evaluator from the current builder state. |
run |
Lazily execute evaluation and yield individual results. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
input_file |
Input JSONL dataset path.
TYPE:
|
text_key |
Key of the field containing text to evaluate in each JSONL record.
TYPE:
|
record_id_key |
Key of the field containing record ids.
TYPE:
|
catalog |
Immutable catalog used for metric resolution. |
metrics |
Immutable view of attached metric specs.
TYPE:
|
Source code in src/evallm/application/api.py
Attributes
input_file
property
input_file: Path
Input JSONL dataset path.
| RETURNS | DESCRIPTION |
|---|---|
Path
|
The input JSONL dataset as a normalized path.
TYPE:
|
text_key
property
text_key: str
Key of the field containing text to evaluate in each JSONL record.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The field's name.
TYPE:
|
record_id_key
property
record_id_key: str
Key of the field containing record ids.
| RETURNS | DESCRIPTION |
|---|---|
str
|
str | Literal["#IDX#"]: The field's name or the reserved literal "#IDX#" if record ids aren't present and should instead be auto-generated as 0-based indices. |
catalog
property
metrics
property
metrics: tuple[MetricSpec, ...]
Immutable view of attached metric specs.
| RETURNS | DESCRIPTION |
|---|---|
tuple[MetricSpec, ...]
|
tuple[MetricSpec, ...]: Tuple of currently attached metric specs. |
Functions
build_dataset
build_dataset() -> JsonlDatasetSpec
Build a JSONL dataset spec from the builder state.
| RETURNS | DESCRIPTION |
|---|---|
JsonlDatasetSpec
|
JSONL dataset spec built from current builder fields.
TYPE:
|
Source code in src/evallm/application/api.py
from_request
classmethod
from_request(
request: EvaluationRequest, *, catalog: type[Catalog] = MetricsCatalog
) -> JsonlEvaluationBuilder
Rebuild a JSONL builder from an existing request.
| RETURNS | DESCRIPTION |
|---|---|
JsonlEvaluationBuilder
|
Builder reconstructed from the provided request.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/evallm/application/api.py
use
use(metric_spec: MetricSpec) -> Self
Attach a single metric spec and return the same builder instance.
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The mutated builder instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
DuplicateMetricResultKeyError
|
If attaching the metric would cause a final result-key collision. |
Source code in src/evallm/application/api.py
build_request
build_request() -> EvaluationRequest
Build the canonical evaluation request.
| RETURNS | DESCRIPTION |
|---|---|
EvaluationRequest
|
Canonical request assembled from current builder state.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no metrics are attached. |
Source code in src/evallm/application/api.py
build_evaluator
build_evaluator() -> Evaluator
Build an evaluator from the current builder state.
| RETURNS | DESCRIPTION |
|---|---|
Evaluator
|
Evaluator configured with the built request and catalog.
TYPE:
|
Source code in src/evallm/application/api.py
run
run() -> Iterator[EvaluationResult]
Lazily execute evaluation and yield individual results.
| YIELDS | DESCRIPTION |
|---|---|
EvaluationResult
|
Per-record evaluation result.
TYPE::
|
Functions
metric
metric(
name: str,
*,
config: Mapping[str, JsonValue] | None = None,
result_key: str | None = None,
) -> MetricSpec
Create a generic metric spec using a metric's name.
Warning
This function only performs syntactic validation so as to create canonical
MetricSpec objects. It does not guarantee the existence of the metric's
name in the catalog, nor does it validate the provided config against the
metric's config schema.
See also
MetricSpec.resolve_metric(catalog)for runtime resolution and validation of metric specs against a catalog.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the metric as registered in the catalog.
TYPE:
|
config
|
Optional config dict for the
metric. (see also:
|
result_key
|
Optional explicit result key for the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
Canonical metric specification.
TYPE:
|
Source code in src/evallm/application/api.py
count_characters
count_characters(*, result_key: str | None = None) -> MetricSpec
Create a metric spec for counting the number of characters in the evaluated text.
| PARAMETER | DESCRIPTION |
|---|---|
result_key
|
Optional explicit result key for the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
Character-count metric specification.
TYPE:
|
Source code in src/evallm/application/api.py
count_tokens
count_tokens(
*,
segmentation: Literal["whitespace", "wordpunct"] = "whitespace",
result_key: str | None = None,
) -> MetricSpec
Create a metric spec for counting the number of tokens in the evaluated text.
| PARAMETER | DESCRIPTION |
|---|---|
segmentation
|
Tokenization
method to use. Defaults to "whitespace". (see also:
TYPE:
|
result_key
|
Optional explicit result key for the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
Token-count metric specification.
TYPE:
|
Source code in src/evallm/application/api.py
count_encodings
count_encodings(
model: str, *, hf_token: str | None = None, result_key: str | None = None
) -> MetricSpec
Create a metric spec for counting the number of model-specific encodings in a text.
This metric allows for specifying any
HuggingFace model to use for segmenting the text into encodings.Counting encodings
The 'hf-tokenizers' extra of evaLLM must be installed to use this metric, as
it relies on the HuggingFace tokenizers library for encoding text.
Install it with:
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The name of a HuggingFace model that provides a pretrained tokenizer, which will be used to segment the text into model-specific encodings.
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
hf_token |
User access token for HuggingFace.
This is only required when specifying a
gated model to use for
encoding. Note that you can also set the
TYPE:
|
result_key |
Optional explicit result key for the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
Encoding-count metric specification.
TYPE:
|
Source code in src/evallm/application/api.py
json_format
json_format(
expected_schema: Mapping[str, Any] | str,
*,
check_formats: bool = False,
result_key: str | None = None,
) -> MetricSpec
Create a metric spec for validating JSON output format.
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
JSON-format validation metric specification.
TYPE:
|