Instructions to use DhaneshV/T2FPipeline with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DhaneshV/T2FPipeline with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("DhaneshV/T2FPipeline") model = AutoModelForSeq2SeqLM.from_pretrained("DhaneshV/T2FPipeline", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download testing.py from DhaneshV/T2FPipeline: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/DhaneshV/T2FPipeline/resolve/main/testing.py
- Command line
-
hf download hf://DhaneshV/T2FPipeline/testing.py
-
curl -L -o testing.py https://huggingface.co/DhaneshV/T2FPipeline/resolve/main/testing.py
1.44 kB
| from transformers import Pipeline | |
| import torch | |
| class DeclarativePipeline(Pipeline): | |
| def _sanitize_parameters(self, **kwargs): | |
| preprocess_kwargs = {} | |
| return preprocess_kwargs, {}, {} | |
| def preprocess(self, inputs): | |
| question = inputs.split("#")[0] | |
| answer = inputs.split("#")[1] | |
| return self.tokenizer( | |
| question, | |
| answer, | |
| add_special_tokens=True, | |
| max_length=512, | |
| padding='max_length', | |
| truncation='only_first', | |
| return_attention_mask=True, | |
| return_tensors=self.framework | |
| ) | |
| def _forward(self, model_inputs): | |
| self.model.eval() | |
| with torch.no_grad(): | |
| generate_ids = self.model.generate( | |
| input_ids=model_inputs["input_ids"], | |
| attention_mask=model_inputs["attention_mask"], | |
| max_length=128, | |
| num_beams=4, | |
| num_return_sequences=1, | |
| no_repeat_ngram_size=2, | |
| early_stopping=True, | |
| ) | |
| return generate_ids | |
| def postprocess(self, model_outputs): | |
| preds = [ | |
| self.tokenizer.decode(gen_id, | |
| skip_special_tokens=True, | |
| clean_up_tokenization_spaces=True) | |
| for gen_id in model_outputs | |
| ] | |
| return "".join(preds) | |