Download validate.py from unitxt/data: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/datasets/unitxt/data/resolve/175f6e2aa0fa60b211efee6eec0f334080d771ae/validate.py
- Command line
-
hf download hf://datasets/unitxt/data@175f6e2aa0fa60b211efee6eec0f334080d771ae/validate.py
-
curl -L -o validate.py https://huggingface.co/datasets/unitxt/data/resolve/175f6e2aa0fa60b211efee6eec0f334080d771ae/validate.py
1.33 kB
| from abc import ABC | |
| from dataclasses import field | |
| from typing import Any, Dict | |
| from datasets import Dataset, Features, Sequence, Value | |
| from .operator import StreamInstanceOperator | |
| class Validator(ABC): | |
| pass | |
| class ValidateSchema(Validator, StreamInstanceOperator): | |
| schema: Features = None | |
| def verify(self): | |
| assert isinstance(self.schema, Features), "Schema must be an instance of Features" | |
| assert self.schema is not None, "Schema must be specified" | |
| def verify_first_instance(self, instance): | |
| for field in self.standart_fields: | |
| assert field in instance, f'Field "{field}" is missing in the first instance' | |
| def process(self, instance: Dict[str, Any], stream_name: str = None) -> Dict[str, Any]: | |
| return instance | |
| class StandardSchema(Features): | |
| def __init__(self): | |
| super().__init__( | |
| { | |
| "source": Value("string"), | |
| "target": Value("string"), | |
| "references": Sequence(Value("string")), | |
| "metrics": Sequence(Value("string")), | |
| "parser": Value("string"), | |
| # 'group': Value('string'), | |
| # 'guidance': Value('string'), | |
| } | |
| ) | |
| class ValidateStandartSchema: | |
| schema: Features = field(default_factory=StandardSchema) | |