nicholasKluge's picture
Update README.md
e8aed20 verified
metadata
license: apache-2.0
datasets:
  - christykoh/imdb_pt
language:
  - pt
metrics:
  - accuracy
library_name: transformers
pipeline_tag: text-classification
tags:
  - sentiment-analysis
widget:
  - text: Esqueceram de mim 2 é um dos melhores filmes de natal de todos os tempos.
    example_title: Exemplo
  - text: Esqueceram de mim 2 é o pior filme da franquia inteira.
    example_title: Exemplo

TeenyTinyLlama-460m-IMDB

TeenyTinyLlama is a pair of small foundational models trained in Brazilian Portuguese.

This repository contains a version of TeenyTinyLlama-460m (TeenyTinyLlama-460m-IMDB) fine-tuned on the the IMDB dataset.

Details

  • Number of Epochs: 3
  • Batch size: 16
  • Optimizer: torch.optim.AdamW (learning_rate = 4e-5, epsilon = 1e-8)
  • GPU: 1 NVIDIA A100-SXM4-40GB

Usage

Using transformers.pipeline:

from transformers import pipeline

text = "Esqueceram de mim 2 é um dos melhores filmes de natal de todos os tempos."

classifier = pipeline("text-classification", model="nicholasKluge/TeenyTinyLlama-460m-IMDB")
classifier(text)

# >>> [{'label': 'POSITIVE', 'score': 0.9971244931221008}]

Reproducing

To reproduce the fine-tuning process, use the following code snippet:

# IMDB
! pip install transformers datasets evaluate accelerate -q

import evaluate
import numpy as np
from datasets import load_dataset
from transformers import AutoTokenizer, DataCollatorWithPadding
from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer

# Load the task
dataset = load_dataset("christykoh/imdb_pt")

# Create a `ModelForSequenceClassification`
model = AutoModelForSequenceClassification.from_pretrained(
    "nicholasKluge/TeenyTinyLlama-460m", 
    num_labels=2, 
    id2label={0: "NEGATIVE", 1: "POSITIVE"}, 
    label2id={"NEGATIVE": 0, "POSITIVE": 1}
)

tokenizer = AutoTokenizer.from_pretrained("nicholasKluge/TeenyTinyLlama-460m")

# Preprocess the dataset
def preprocess_function(examples):
    return tokenizer(examples["text"], truncation=True, max_length=256)

dataset_tokenized = dataset.map(preprocess_function, batched=True)

# Create a simple data collactor
data_collator = DataCollatorWithPadding(tokenizer=tokenizer)

# Use accuracy as an evaluation metric
accuracy = evaluate.load("accuracy")

# Function to compute accuracy
def compute_metrics(eval_pred):
    predictions, labels = eval_pred
    predictions = np.argmax(predictions, axis=1)
    return accuracy.compute(predictions=predictions, references=labels)

# Define training arguments
training_args = TrainingArguments(
    output_dir="checkpoints",
    learning_rate=4e-5,
    per_device_train_batch_size=16,
    per_device_eval_batch_size=16,
    num_train_epochs=3,
    weight_decay=0.01,
    evaluation_strategy="epoch",
    save_strategy="epoch",
    load_best_model_at_end=True,
    push_to_hub=True,
    hub_token="your_token_here",
    hub_model_id="username/model-name-imdb"
)

# Define the Trainer
trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=dataset_tokenized["train"],
    eval_dataset=dataset_tokenized["test"],
    tokenizer=tokenizer,
    data_collator=data_collator,
    compute_metrics=compute_metrics,
)

# Train!
trainer.train()

Fine-Tuning Comparisons

Cite as 🤗


@misc{nicholas22llama,
  doi = {10.5281/zenodo.6989727},
  url = {https://huggingface.co/nicholasKluge/TeenyTinyLlama-460m},
  author = {Nicholas Kluge Corrêa},
  title = {TeenyTinyLlama},
  year = {2023},
  publisher = {HuggingFace},
  journal = {HuggingFace repository},
}

Funding

This repository was built as part of the RAIES (Rede de Inteligência Artificial Ética e Segura) initiative, a project supported by FAPERGS - (Fundação de Amparo à Pesquisa do Estado do Rio Grande do Sul), Brazil.

License

TeenyTinyLlama-460m-IMDB is licensed under the Apache License, Version 2.0. See the LICENSE file for more details.