
<!-- 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 Tiny for SST2

This model is a fine-tuned version of [M-FAC/bert-tiny-finetuned-sst2](https://huggingface.co/M-FAC/bert-tiny-finetuned-sst2) on the sst2 dataset.
It achieves the following results on the evaluation set:
- Loss: 0.4771
- Accuracy: 0.8280

## Usage Example

```python
from transformers import BertTokenizer, BertForSequenceClassification, TrainingArguments, Trainer, DataCollatorWithPadding
import datasets

model = BertForSequenceClassification.from_pretrained('VityaVitalich/bert-tiny-sst2')
tokenizer = BertTokenizer.from_pretrained('VityaVitalich/bert-tiny-sst2')

def create_data(tokenizer):
  train_set = datasets.load_dataset('sst2', split='train').remove_columns(['idx'])
  val_set = datasets.load_dataset('sst2', split='validation').remove_columns(['idx'])

  def tokenize_func(examples):
      return tokenizer(examples["sentence"], max_length=128, padding='max_length', truncation=True)

  encoded_dataset_train = train_set.map(tokenize_func, batched=True)
  encoded_dataset_test = val_set.map(tokenize_func, batched=True)
  data_collator = DataCollatorWithPadding(tokenizer)
  return encoded_dataset_train, encoded_dataset_test, data_collator

encoded_dataset_train, encoded_dataset_test, data_collator = create_data(tokenizer)

training_args = TrainingArguments(
    output_dir='./results',
    learning_rate=3e-5,
    per_device_train_batch_size=128,
    per_device_eval_batch_size=128,
    load_best_model_at_end=True,
    num_train_epochs=5,
    weight_decay=0.1,
    fp16=True,
    fp16_full_eval=True,
    evaluation_strategy="epoch",
    seed=42,
    save_strategy = "epoch",
    save_total_limit=5,
    logging_strategy="epoch",
    report_to="all",
)


trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=encoded_dataset_train,
    eval_dataset=encoded_dataset_test,
    data_collator=data_collator,
    compute_metrics=compute_metrics,
)

trainer.evaluate(encoded_dataset_test)
```


## Training procedure

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 3e-05
- train_batch_size: 128
- eval_batch_size: 128
- seed: 42
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- num_epochs: 5

### Training results

| Training Loss | Epoch | Step | Validation Loss | Accuracy |
|:-------------:|:-----:|:----:|:---------------:|:--------:|
| 0.2313        | 1.0   | 527  | 0.4771          | 0.8280   |
| 0.2057        | 2.0   | 1054 | 0.4937          | 0.8257   |
| 0.1949        | 3.0   | 1581 | 0.5121          | 0.8177   |
| 0.1904        | 4.0   | 2108 | 0.5100          | 0.8200   |
| 0.1879        | 5.0   | 2635 | 0.5137          | 0.8211   |


### Framework versions

- Transformers 4.34.0.dev0
- Pytorch 2.0.1+cu117
- Datasets 2.14.5
- Tokenizers 0.14.0

{"tags": ["generated_from_trainer"], "datasets": ["sst2"], "metrics": ["accuracy"], "base_model": "M-FAC/bert-tiny-finetuned-sst2", "model-index": [{"name": "results", "results": [{"task": {"type": "text-classification", "name": "Text Classification"}, "dataset": {"name": "sst2", "type": "sst2", "config": "default", "split": "validation", "args": "default"}, "metrics": [{"type": "accuracy", "value": 0.8279816513761468, "name": "Accuracy"}]}]}]}
transformers pytorch bert text-classification generated_from_trainer dataset:sst2 base_model:M-FAC/bert-tiny-finetuned-sst2 model-index autotrain_compatible endpoints_compatible region:us