evalr.hf¶
Hugging Face datasets: publishing, pinning and importing (the [hf] extra).
The Hugging Face Hub holds published and pinned datasets (ADR-0003). HfDatasetStore adapts it
to the DatasetStore port (ADR-0006), with a dataset card per save; import_dataset reads any
dataset on the Hub at a pinned commit.
See The Hugging Face Hub.
The store¶
HfDatasetStore
¶
Saves datasets to the Hugging Face Hub, and loads them from it at a revision.
The Hub's calls are synchronous, so they run in a worker thread.
Use the Hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api
|
HubApi | None
|
The Hub's client; |
None
|
private
|
bool
|
Create new dataset repositories as private. |
True
|
save
async
¶
Commit the dataset's examples and card to the repository of its name.
Returns:
| Type | Description |
|---|---|
str
|
The commit's hash. |
load
async
¶
load(
name: str,
/,
*,
input_type: type[InputT],
verdict_type: type[VerdictT],
revision: str | None = None,
) -> Dataset[InputT, VerdictT]
Read a dataset at a revision: a commit hash, a branch or a tag; the latest by default.
Raises:
| Type | Description |
|---|---|
DatasetNotFound
|
The Hub has no such repository, revision, or examples file. |
ValidationError
|
The examples are not of these types. |
HubApi
¶
Bases: Protocol
The parts of huggingface_hub.HfApi the store uses.
create_repo
¶
create_repo(
repo_id: str,
*,
private: bool | None = None,
repo_type: str | None = None,
exist_ok: bool = False,
) -> object
Create a repository, or do nothing if it exists and exist_ok.
create_commit
¶
create_commit(
repo_id: str,
operations: Iterable[CommitOperationAdd],
*,
commit_message: str,
repo_type: str | None = None,
) -> CommitInfo
Commit files to a repository.
Pinning and importing¶
resolve_revision
¶
Pin a branch or tag of a dataset repository to its commit hash.
Raises:
| Type | Description |
|---|---|
DatasetNotFound
|
The Hub has no such repository or revision. |
ValueError
|
The Hub reported no commit hash. |
pinned
¶
Whether a revision is a full commit hash, which always names the same data.
COMMIT
module-attribute
¶
A full commit hash: the only revision that always names the same data.
import_dataset
async
¶
import_dataset(
path: str,
*,
revision: str,
input_type: type[InputT],
verdict_type: type[VerdictT],
to_example: Callable[
[dict[str, Any]], Example[InputT, VerdictT]
]
| None = None,
name: str | None = None,
description: str = "",
split: str = "train",
cache_dir: str | None = None,
token: str | bool | None = None,
) -> Dataset[InputT, VerdictT]
Load a dataset from the Hub (or a local directory) with datasets, as examples.
Only a full commit hash names the same data every time, so nothing else is accepted: pin
a branch or tag first with resolve_revision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The dataset's repository ( |
required |
revision
|
str
|
The commit to load. |
required |
input_type
|
type[InputT]
|
The Pydantic model of the examples' inputs. |
required |
verdict_type
|
type[VerdictT]
|
The Pydantic model of the examples' verdicts. |
required |
to_example
|
Callable[[dict[str, Any]], Example[InputT, VerdictT]] | None
|
Turns a row into an example; rows are read as evalr's records by default. |
None
|
name
|
str | None
|
The dataset's name; the path by default. |
None
|
description
|
str
|
What the dataset holds. |
''
|
split
|
str
|
The split to load. |
'train'
|
cache_dir
|
str | None
|
Where |
None
|
token
|
str | bool | None
|
A Hugging Face token, for private datasets. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The revision is not a full commit hash. |
Dataset cards¶
dataset_card
¶
The README of a dataset on the Hub: metadata for evalr and the Hub, and a description.
The metadata points the Hub's viewer and datasets.load_dataset at the examples, and
records the types, the description and the content hash under evalr.
read_card
¶
What a card records under evalr; empty for a card evalr did not write.
DATA_FILE
module-attribute
¶
Where a dataset's examples are, one JSON record to a line.