Instructions to use yjmsvma/flant5-clause-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yjmsvma/flant5-clause-classifier with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("yjmsvma/flant5-clause-classifier") model = AutoModelForSeq2SeqLM.from_pretrained("yjmsvma/flant5-clause-classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from yjmsvma/flant5-clause-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/yjmsvma/flant5-clause-classifier/resolve/main/handler.py
- Command line
-
hf download hf://yjmsvma/flant5-clause-classifier/handler.py
-
curl -L -o handler.py https://huggingface.co/yjmsvma/flant5-clause-classifier/resolve/main/handler.py
1.16 kB
| from typing import Dict, List, Any | |
| from transformers import AutoModelForSeq2SeqLM, AutoTokenizer | |
| import torch | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| # load model and processor from path | |
| self.model = AutoModelForSeq2SeqLM.from_pretrained(path, device_map="auto") | |
| self.tokenizer = AutoTokenizer.from_pretrained(path) | |
| def __call__(self, data: Dict[str, Any]) -> Dict[str, str]: | |
| """ | |
| Args: | |
| data (:dict:): | |
| The payload with the text prompt and generation parameters. | |
| """ | |
| # process input | |
| inputs = data.pop("inputs", data) | |
| parameters = data.pop("parameters", None) | |
| # preprocess | |
| input_ids = self.tokenizer(inputs, return_tensors="pt").input_ids | |
| # pass inputs with all kwargs in data | |
| if parameters is not None: | |
| outputs = self.model.generate(input_ids, **parameters) | |
| else: | |
| outputs = self.model.generate(input_ids) | |
| # postprocess the prediction | |
| prediction = self.tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return [{"generated_text": prediction}] |