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
|
Download README.md from roberthsu2003/for_multiple_choice: direct link, hf CLI and curl.
- Browser
- Download file 3.33 kB
-
https://huggingface.co/roberthsu2003/for_multiple_choice/resolve/main/README.md
- Command line
-
hf download hf://roberthsu2003/for_multiple_choice/README.md
-
curl -L -o README.md https://huggingface.co/roberthsu2003/for_multiple_choice/resolve/main/README.md
3.33 kB
| library_name: transformers | |
| base_model: google-bert/bert-base-chinese | |
| tags: | |
| - generated_from_trainer | |
| metrics: | |
| - accuracy | |
| model-index: | |
| - name: for_multiple_choice | |
| results: [] | |
| license: apache-2.0 | |
| datasets: | |
| - roberthsu2003/for_Multiple_Choice | |
| language: | |
| - zh | |
| <!-- This model card has been generated automatically according to the information the Trainer had access to. You | |
| should probably proofread and complete it, then remove this comment. --> | |
| # for_multiple_choice | |
| This model is a fine-tuned version of [google-bert/bert-base-chinese](https://huggingface.co/google-bert/bert-base-chinese) on an unknown dataset. | |
| It achieves the following results on the evaluation set: | |
| - Loss: 1.3109 | |
| - Accuracy: 0.5962 | |
| ## 模型的使用 | |
| from transformers import AutoTokenizer, AutoModelForMultipleChoice | |
| from typing import Any | |
| import torch | |
| tokenizer = AutoTokenizer.from_pretrained('roberthsu2003/for_multiple_choice') | |
| model = AutoModelForMultipleChoice.from_pretrained('roberthsu2003/for_multiple_choice') | |
| from typing import Any | |
| import torch | |
| class MultipleChoicePipeline: | |
| def __init__(self, model, tokenizer) -> None: | |
| self.model = model | |
| self.tokenizer = tokenizer | |
| self.device = model.device | |
| def 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).logits | |
| def 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 result | |
| if __name__ == "__main__": | |
| pipe = MultipleChoicePipeline(model, tokenizer) | |
| result1 = pipe("男:你今天晚上有時間嗎?我們一起去看電影吧? 女:你喜歡恐怖片和愛情片,但是我喜歡喜劇片","女的最喜歡哪種電影?",["恐怖片","愛情片","喜劇片","科幻片"]) | |
| print(result1) | |
| ``` | |
| ## Intended uses & limitations | |
| More information needed | |
| ## Training and evaluation data | |
| More information needed | |
| ## Training procedure | |
| ### Training hyperparameters | |
| The following hyperparameters were used during training: | |
| - learning_rate: 5e-05 | |
| - train_batch_size: 16 | |
| - eval_batch_size: 16 | |
| - seed: 42 | |
| - optimizer: Use OptimizerNames.ADAMW_TORCH with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments | |
| - lr_scheduler_type: linear | |
| - num_epochs: 3 | |
| - mixed_precision_training: Native AMP | |
| ### Training results | |
| | Training Loss | Epoch | Step | Validation Loss | Accuracy | | |
| |:-------------:|:-----:|:----:|:---------------:|:--------:| | |
| | 0.9816 | 1.0 | 366 | 0.9955 | 0.5814 | | |
| | 0.7299 | 2.0 | 732 | 1.0239 | 0.5918 | | |
| | 0.3452 | 3.0 | 1098 | 1.3109 | 0.5962 | | |
| ### Framework versions | |
| - Transformers 4.50.2 | |
| - Pytorch 2.6.0+cu124 | |
| - Datasets 3.5.0 | |
| - Tokenizers 0.21.1 |