|
|
--- |
|
|
license: apache-2.0 |
|
|
base_model: bert-base-uncased |
|
|
tags: |
|
|
- generated_from_trainer |
|
|
metrics: |
|
|
- accuracy |
|
|
model-index: |
|
|
- name: Bert-Lab4 |
|
|
results: [] |
|
|
--- |
|
|
|
|
|
<!-- 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. --> |
|
|
|
|
|
# Bert-Lab4 |
|
|
|
|
|
This model is a fine-tuned version of [bert-base-uncased](https://huggingface.co/bert-base-uncased) on an unknown dataset. |
|
|
It achieves the following results on the evaluation set: |
|
|
- Loss: 0.5647 |
|
|
- Accuracy: 0.73 |
|
|
|
|
|
## Model description |
|
|
|
|
|
More information needed |
|
|
|
|
|
## Intended uses & limitations |
|
|
|
|
|
More information needed |
|
|
|
|
|
## Training and evaluation data |
|
|
|
|
|
We use 100 data from the glue/sst2, since we train on Colab. |
|
|
https://drive.google.com/file/d/1Ej0-bDkfXmlNPynypS-xDbEEGK9hI06l/view?usp=sharing |
|
|
|
|
|
## How to use |
|
|
|
|
|
```python |
|
|
from datasets import load_dataset |
|
|
from transformers import AutoTokenizer, DataCollatorWithPadding |
|
|
|
|
|
raw_datasets = load_dataset("glue", "sst2") |
|
|
checkpoint = "ChiJuiChen/Bert-Lab4" |
|
|
tokenizer = AutoTokenizer.from_pretrained(checkpoint) |
|
|
|
|
|
|
|
|
def tokenize_function(example): |
|
|
return tokenizer(example["sentence"], truncation=True) |
|
|
|
|
|
|
|
|
tokenized_datasets = raw_datasets.map(tokenize_function, batched=True) |
|
|
|
|
|
small_train_dataset = tokenized_datasets["train"].shuffle(seed=42).select(range(100)) |
|
|
small_eval_dataset = tokenized_datasets["validation"].shuffle(seed=42).select(range(100)) |
|
|
|
|
|
data_collator = DataCollatorWithPadding(tokenizer=tokenizer) |
|
|
|
|
|
from transformers import TrainingArguments |
|
|
|
|
|
training_args = TrainingArguments(output_dir="ChiJuiChen/Bert-Lab4", |
|
|
evaluation_strategy="epoch", |
|
|
hub_model_id="ChiJuiChen/Bert-Lab4") |
|
|
|
|
|
from transformers import AutoModelForSequenceClassification |
|
|
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2) |
|
|
|
|
|
from transformers import Trainer |
|
|
trainer = Trainer( |
|
|
model, |
|
|
training_args, |
|
|
train_dataset=small_train_dataset, # if using cpu |
|
|
eval_dataset=small_eval_dataset, # if using cpu |
|
|
data_collator=data_collator, |
|
|
tokenizer=tokenizer, |
|
|
compute_metrics=compute_metrics, |
|
|
) |
|
|
|
|
|
# Evaluation |
|
|
predictions = trainer.predict(small_eval_dataset) |
|
|
print(predictions.predictions.shape, predictions.label_ids.shape) |
|
|
preds = np.argmax(predictions.predictions, axis=-1) |
|
|
|
|
|
import evaluate |
|
|
metric = evaluate.load("glue", "sst2") |
|
|
metric.compute(predictions=preds, references=predictions.label_ids) |
|
|
``` |
|
|
## Training procedure |
|
|
|
|
|
### Training hyperparameters |
|
|
|
|
|
The following hyperparameters were used during training: |
|
|
- learning_rate: 5e-05 |
|
|
- train_batch_size: 8 |
|
|
- eval_batch_size: 8 |
|
|
- seed: 42 |
|
|
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08 |
|
|
- lr_scheduler_type: linear |
|
|
- num_epochs: 3.0 |
|
|
|
|
|
### Training results |
|
|
|
|
|
| Training Loss | Epoch | Step | Validation Loss | Accuracy | |
|
|
|:-------------:|:-----:|:----:|:---------------:|:--------:| |
|
|
| No log | 1.0 | 13 | 0.6383 | 0.59 | |
|
|
| No log | 2.0 | 26 | 0.5867 | 0.71 | |
|
|
| No log | 3.0 | 39 | 0.5647 | 0.73 | |
|
|
|
|
|
|
|
|
### Framework versions |
|
|
|
|
|
- Transformers 4.38.2 |
|
|
- Pytorch 2.2.1+cu121 |
|
|
- Datasets 2.18.0 |
|
|
- Tokenizers 0.15.2 |
|
|
|