Downloads · 30 days
7
5% of all-time downloads
Siki-77/imdb_roberta_large
imdb_roberta_large is a text classification model from Siki-77. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
should probably proofread and complete it, then remove this comment. --
Downloads · 30 days
7
5% of all-time downloads
All-time downloads
140
Public
Parameters
355M
2.8 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.4 GB · 100%
From the Hugging Face model README
This model is a fine-tuned version of roberta-large on an unknown dataset. It achieves the following results on the evaluation set:
Train and Test Code
from datasets import load_dataset
imdb = load_dataset("imdb")
import numpy as np
from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer
import torch
from transformers import AutoTokenizer
from transformers import DataCollatorWithPadding
from transformers import EarlyStoppingCallback
import evaluate
# model_name = 'xlnet-large-cased'
model_name = 'roberta-large'
id2label = {0: "NEGATIVE", 1: "POSITIVE"}
label2id = {"NEGATIVE": 0, "POSITIVE": 1}
def compute_metrics(eval_pred):
predictions, labels = eval_pred
predictions = np.argmax(predictions, axis=1)
return accuracy.compute(predictions=predictions, references=labels)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def preprocess_function(examples):
return tokenizer(examples["text"], truncation=True)
tokenized_imdb = imdb.map(preprocess_function, batched=True)
data_collator = DataCollatorWithPadding(tokenizer=tokenizer)
accuracy = evaluate.load("accuracy")
model = AutoModelForSequenceClassification.from_pretrained(
model_name, num_labels=2, id2label=id2label, label2id=label2id
)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
bts = 8
accumulated_step = 2
training_args = TrainingArguments(
output_dir=f"5imdb_{model_name.replace('-','_')}",
learning_rate=2e-5,
per_device_train_batch_size=bts,
per_device_eval_batch_size=bts,
num_train_epochs=2,
weight_decay=0.01,
evaluation_strategy="epoch",
save_strategy="epoch",
load_best_model_at_end=True,
push_to_hub=True,
gradient_accumulation_steps=accumulated_step,
)
# 创建 EarlyStoppingCallback 回调
early_stopping = EarlyStoppingCallback(early_stopping_patience=3)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=tokenized_imdb["train"],
eval_dataset=tokenized_imdb["test"],
tokenizer=tokenizer,
data_collator=data_collator,
compute_metrics=compute_metrics,
callbacks=[early_stopping],
)
trainer.train()
More information needed
More information needed
The following hyperparameters were used during training:
| Training Loss | Epoch | Step | Validation Loss | Accuracy |
|---|---|---|---|---|
| 0.1732 | 1.0 | 1562 | 0.1323 | 0.9574 |
| 0.0978 | 2.0 | 3124 | 0.1728 | 0.9627 |