File size: 3,326 Bytes
79408bd 2396239 79408bd feacdc9 8bdd32b feacdc9 8bdd32b feacdc9 8bdd32b 863ad34 79408bd 2396239 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
---
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 |