Download inference.py from unitxt/data: direct link, hf CLI and curl.
- Browser
- Download file 775 Bytes
-
https://huggingface.co/datasets/unitxt/data/resolve/2428ddb00a447bcbc9d98ded720fd6a4fe40b9d1/inference.py
- Command line
-
hf download hf://datasets/unitxt/data@2428ddb00a447bcbc9d98ded720fd6a4fe40b9d1/inference.py
-
curl -L -o inference.py https://huggingface.co/datasets/unitxt/data/resolve/2428ddb00a447bcbc9d98ded720fd6a4fe40b9d1/inference.py
775 Bytes
| import abc | |
| from .artifact import Artifact | |
| class InferenceEngine(abc.ABC, Artifact): | |
| """Abstract base class for inference.""" | |
| def infer(self, dataset): | |
| """Perform inference on the input dataset.""" | |
| pass | |
| class HFPipelineBasedInferenceEngine(Artifact): | |
| """Abstract base class for inference.""" | |
| model_name: str | |
| max_new_tokens: int | |
| def prepare(self): | |
| from transformers import pipeline | |
| self.model = pipeline(model=self.model_name) | |
| def infer(self, dataset): | |
| return [ | |
| output["generated_text"] | |
| for output in self.model( | |
| [instance["source"] for instance in dataset], | |
| max_new_tokens=self.max_new_tokens, | |
| ) | |
| ] | |