Downloads · 30 days
8
7% of all-time downloads
sumitp76/distilroberta-base-goodreads-genres
distilroberta-base-goodreads-genres is a text classification model from sumitp76. 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.
This model is a fine-tuned version of distilroberta-base for Goodreads book review / genre classification. It is designed to classify book-related text, such as book reviews, descriptions, or summaries, into genre cat…
Downloads · 30 days
8
7% of all-time downloads
All-time downloads
117
Public
Parameters
82.1M
329 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors329 MB · 99%
From the Hugging Face model README
This model is a fine-tuned version of distilroberta-base for Goodreads book review / genre classification. It is designed to classify book-related text, such as book reviews, descriptions, or summaries, into genre categories.
The model was developed as part of an MLOps assignment using Hugging Face Transformers, Kaggle Notebook, Hugging Face Hub, and Weights & Biases for experiment tracking.
distilroberta-base-goodreads-genresdistilroberta-baseThe training was performed in a Kaggle Notebook.
Kaggle Notebook:
https://www.kaggle.com/code/sumitpiitj/gr-book-review/edit
Install the required Python libraries:
pip install transformers
pip install datasets
pip install evaluate
pip install accelerate
pip install huggingface_hub
pip install wandb
pip install scikit-learn
pip install pandas
pip install numpy
pip install torch
In Kaggle, many packages may already be installed. If needed, install missing packages inside a notebook cell:
!pip install transformers datasets evaluate accelerate huggingface_hub wandb scikit-learn
To push the model to Hugging Face Hub, create a Hugging Face access token with Write permission.
In Kaggle:
Go to Add-ons Open Secrets Add your Hugging Face token Save it using the name:
HF_TOKEN
Then load it in the notebook:
from kaggle_secrets import UserSecretsClient
from huggingface_hub import login
user_secrets = UserSecretsClient()
HF_TOKEN = user_secrets.get_secret("HF_TOKEN")
login(token=HF_TOKEN)
Log in to Weights & Biases:
import wandb
wandb.login()
Initialize a W&B run:
wandb.init(
project="mlops-assignment2",
name="distilroberta-base-goodreads-genres"
)
W&B dashboard:
https://wandb.ai/sumit-k-pal-76-iitj/mlops-assignment2/table?nw=nwusersumitkpal76
The model was trained using Hugging Face Trainer.
General training flow:
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments
model_name = "distilroberta-base"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(
model_name,
num_labels=num_labels
)
Tokenize the dataset:
def tokenize_function(examples):
return tokenizer(
examples["text"],
padding="max_length",
truncation=True
)
tokenized_dataset = dataset.map(tokenize_function, batched=True)
Train using Trainer:
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
tokenizer=tokenizer,
compute_metrics=compute_metrics
)
trainer.train()
After training, evaluate the model:
results = trainer.evaluate()
print(results)
repo_id = "sumitp76/distilroberta-base-goodreads-genres"
model.push_to_hub(repo_id, token=HF_TOKEN)
tokenizer.push_to_hub(repo_id, token=HF_TOKEN)
Model link:
https://huggingface.co/sumitp76/distilroberta-base-goodreads-genres
You can use the model directly with the Hugging Face pipeline.
from transformers import pipeline
classifier = pipeline(
"text-classification",
model="sumitp76/distilroberta-base-goodreads-genres"
)
text = "A young wizard discovers his magical powers and enters a hidden world of adventure."
result = classifier(text)
print(result)
The model was trained on Kaggle Notebook.
Platform: Kaggle Notebook link: https://www.kaggle.com/code/sumitpiitj/gr-book-review/edit Framework: Hugging Face Transformers Experiment tracking: Weights & Biases Model hosting: Hugging Face Hub
The base model used was:
distilroberta-base
distilroberta-base is a smaller and faster version of RoBERTa. It is suitable for text classification tasks where a balance between performance and efficiency is required.
The general preprocessing steps included:
Update the values below according to the final notebook settings:
| Parameter | Value |
|---|---|
| Base model | distilroberta-base |
| Task | Text Classification |
| Optimizer | AdamW |
| Loss function | Cross-entropy loss |
| Training/Eval Batch size | 16/32 |
| Learning rate | 2e-5 |
| Number of epochs | 6 |
| Max sequence length | 256 |
| Evaluation strategy | steps |
| Metric | Score |
|---|---|
| Accuracy | 0.61583 |
| F1 Score | 0.61632 |
| Eval Loss | 2.66787 |
Kaggle Notebook: https://www.kaggle.com/code/sumitpiitj/gr-book-review/edit Hugging Face model: https://huggingface.co/sumitp76/distilroberta-base-goodreads-genres W&B dashboard: https://wandb.ai/sumit-k-pal-76-iitj/mlops-assignment2/table?nw=nwusersumitkpal76