Model

DistilBERT Book Genre Classifier

A transformer-based model fine-tuned to classify Goodreads reviews into eight distinct genres.

Key Features Model: DistilBERT (Transformer-based) Dataset: Goodreads book reviews Output: 8 genre categories Task: Multi-class text classification

Model Description

This model is a specialized text classification tool designed to bridge the gap between subjective reader feedback and structured metadata. By fine-tuning the DistilBERT architecture a lighter, faster version of the original BERT model—this classifier can interpret the nuance, tone, and vocabulary used in Goodreads reviews to predict a book's genre. Unlike traditional keyword matching, this model uses deep learning to understand the context of a review. It can distinguish between the "thrilling" elements of a mystery and the "breathless" excitement found in a romance. This makes it an ideal solution for organizing large digital libraries, enhancing recommendation engines, or helping authors understand how their work is being perceived by specific audiences.

Supported Genres

The model categorizes reviews into the following eight

Label Genre 0 Children 1 Comics & Graphic 2 Fantasy & Paranormal 3 History & Biography 4 Mystery, Thriller & Crime 5 Poetry 6 Romance 7 Young Adult

Training Configuration

Parameter Value
Base Model distilbert-base-cased
Epochs 3
Train Batch Size 16
Eval Batch Size 32
Learning Rate 3e-5
Warmup Steps 100
Weight Decay 0.01
Max Sequence Length 512
Training Samples 6,400
Test Samples 1,600
Platform Kaggle (GPU T4 x2)
Experiment Tracking Weights & Biases

Training Results

Epoch Training Loss Validation Loss Accuracy F1
1 2.543057 2.389233 0.583125 0.582607
2 1.955018 2.249788 0.603750 0.605045
3 1.433714 2.274478 0.608750 0.611895

Final Evaluation Metrics

Metric Score
Accuracy 0.608750
F1 Score 0.611895
Eval Loss 2.274478

Installation

Install the required libraries:

pip install transformers torch

Quick Inference

Use the Hugging Face pipeline API:

from huggingface_hub import login

# Login to HuggingFace using token from Kaggle Secrets
login(token=HF_TOKEN)
print("Logged in to HuggingFace!")


HF_USERNAME = "Rashmii30"
REPO_NAME = "distilbert-goodreads-genres"
HF_REPO = f"{HF_USERNAME}/{REPO_NAME}"

# Push model weights to HuggingFace Hub
print("Pushing model to HuggingFace Hub...")
model.push_to_hub(HF_REPO)
print("Model pushed successfully!")

# Push tokenizer to same repository
print("Pushing tokenizer to HuggingFace Hub...")
tokenizer.push_to_hub(HF_REPO)
print("Tokenizer pushed successfully!")

# Log the HuggingFace URL to W&B run summary
wandb.run.summary["huggingface_model"] = f"https://huggingface.co/{HF_REPO}"
print(f"HuggingFace model URL logged to W&B!")
print(f"Your model is live at: https://huggingface.co/{HF_REPO}")

Dataset

The model was trained using the UCSD Book Graph / Goodreads Reviews Dataset, which contains large-scale Goodreads book reviews across multiple genres.

8 genres were selected

2,000 reviews sampled per genre

Stratified train-test split:

 800 training samples per genre
 200 test samples per genre
 

Project Highlights

Fine-tuned transformer-based NLP classifier GPU training on Kaggle Experiment tracking using Weights & Biases Hugging Face model deployment Reproducible MLOps workflow

Technologies Used

Python PyTorch Hugging Face Transformers Dataset Weights & Biases Kaggle Notebooks

Author

Name: Rashmi Kumari Roll Number: G25AIT2083

Model Repository

Hugging Face Model Repository

Downloads last month
1
Safetensors
Model size
65.8M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support