Instructions to use roberthsu2003/for_multiple_choice with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use roberthsu2003/for_multiple_choice with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMultipleChoice tokenizer = AutoTokenizer.from_pretrained("roberthsu2003/for_multiple_choice") model = AutoModelForMultipleChoice.from_pretrained("roberthsu2003/for_multiple_choice", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files24 unmodified lines25262728293031323324 unmodified lines- Loss: 1.3109- Accuracy: 0.5962## Model descriptionMore information needed## Intended uses & limitations24 unmodified lines2526272829303132333435363738394041424344454647484950515253545556575859606162636465666724 unmodified lines- Loss: 1.3109- Accuracy: 0.5962## 模型的使用from typing import Anyimport torchclass MultipleChoicePipeline:def __init__(self, model, tokenizer) -> None:self.model = modelself.tokenizer = tokenizerself.device = model.devicedef preprocess(self, context, question, choices):cs, qcs = [], []for choice in choices:cs.append(context)qcs.append(question + " " + choice)return tokenizer(cs, qcs, truncation="only_first", max_length=256, return_tensors="pt")def predict(self, inputs):inputs = {k: v.unsqueeze(0).to(self.device) for k, v in inputs.items()}return self.model(**inputs).logitsdef postprocess(self, logits, choices):predition = torch.argmax(logits, dim=-1).cpu().item()return choices[predition]def __call__(self, context, question, choices) -> Any:inputs = self.preprocess(context,question,choices)logits = self.predict(inputs)result = self.postprocess(logits, choices)return resultif __name__ == "__main__":pipe = MultipleChoicePipeline(model, tokenizer)result1 = pipe("國堂在台北上班","國堂在哪裏上班?",['台北','台中'])print(result1)## Intended uses & limitations
README.md+37-3