Instructions to use BashirRP/llm_judge2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use BashirRP/llm_judge2 with PEFT:
from peft import PeftModel from transformers import AutoModelForSequenceClassification base_model = AutoModelForSequenceClassification.from_pretrained("roberta-large") model = PeftModel.from_pretrained(base_model, "BashirRP/llm_judge2") - Notebooks
- Google Colab
- Kaggle
Download handler.py from BashirRP/llm_judge2: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/BashirRP/llm_judge2/resolve/main/handler.py
- Command line
-
hf download hf://BashirRP/llm_judge2/handler.py
-
curl -L -o handler.py https://huggingface.co/BashirRP/llm_judge2/resolve/main/handler.py
1.29 kB
| from typing import Dict, List, Any | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| class EndpointHandler: | |
| def __init__(self, | |
| path="" | |
| ): | |
| # Preload all the elements you are going to need at inference. | |
| # pseudo: | |
| self.model = AutoModelForSequenceClassification.from_pretrained(path) | |
| self.tokenizer = AutoTokenizer.from_pretrained("roberta-large", padding_side='right') | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| input_dict = data.pop("inputs", data) | |
| self.model.eval() | |
| input = self.tokenizer(input_dict['answer'], | |
| input_dict['source'], | |
| truncation=True, | |
| max_length=None, | |
| return_tensors="pt" | |
| ) | |
| # input.to(device) | |
| # with torch.no_grad(): | |
| # output = model(**input) | |
| output = model(**input) | |
| prediction = output.logits.argmax(dim=-1) | |
| #smax = nn.Softmax(dim=1) | |
| #score = smax(output.logits) | |
| return [{ | |
| "label": prediction.item(), | |
| #"score": score[0][0].item() | |
| } | |
| ] | |