for_multiple_choice

This model is a fine-tuned version of 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
Downloads last month
-
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for roberthsu2003/for_multiple_choice

Finetuned
(228)
this model

Dataset used to train roberthsu2003/for_multiple_choice