Instructions to use LA1512/PubMed-fine-tune with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LA1512/PubMed-fine-tune with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("LA1512/PubMed-fine-tune") model = AutoModelForSeq2SeqLM.from_pretrained("LA1512/PubMed-fine-tune") - Notebooks
- Google Colab
- Kaggle
| from typing import Dict, List, Any | |
| from transformers import pipeline, AutoTokenizer, BartForConditionalGeneration | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| self.model = BartForConditionalGeneration.from_pretrained(path) | |
| self.tokenizer = AutoTokenizer(path) | |
| def __call__(self, data: str) -> str: | |
| """ | |
| data args: | |
| inputs (:obj: `str`) | |
| date (:obj: `str`) | |
| Return: | |
| A :obj:`list` | `dict`: will be serialized and returned | |
| """ | |
| # get inputs | |
| text_tokenized = self.tokenizer( | |
| [data], padding="max_length", truncation=True, max_length=1024,return_tensors='pt') | |
| prediction_token = self.model.generate(text_tokenized["input_ids"], max_length = 256, num_beams = 6) | |
| prediction_summary = self.tokenizer.decode(prediction_token[0][2:-1:1]) | |
| return prediction_summary |