bert-lyrics-classifier
bert-lyrics-classifier is a fine-tuned bert-base-uncased model that classifies individual song lyric verses as SAFE or UNSAFE for children, enabling verse-level (rather than whole-song) content moderation.
It was developed as part of a Final Year Project at Asia Pacific University: "Implementing a Machine Learning Based Approach for Classifying Song Lyrics Appropriateness for Children." The model powers LyricLens, a Spotify-connected dashboard that surfaces which parts of a song may not be appropriate for young listeners.
Model Details
Model Description
Most existing content filters (e.g. the Spotify "explicit" tag) label an entire song as appropriate or not, which misses the fact that a single song can contain both safe and unsafe verses. This model instead classifies lyrics at the verse level, allowing more granular moderation.
- Developed by: Devan Asokan
- Model type: Fine-tuned BERT for binary sequence classification
- Language(s): English
- License: MIT
- Finetuned from model:
bert-base-uncased
Model Sources
- Repository: devanasokan/devanasokan_fyp
- Dataset: devanasokan/lyrics-appropriateness-dataset
- Demo: LyricLens dashboard (see project repository)
Uses
Direct Use
The model takes a single verse of song lyrics as input and predicts whether it is:
LABEL_0— SAFE: appropriate for childrenLABEL_1— UNSAFE: not appropriate for children
It is intended to be used as one component of a larger content-moderation pipeline (e.g. flagging specific verses within a song for parental review), not as a sole, fully automated gatekeeping decision.
Out-of-Scope Use
- Not intended for languages other than English (verses are filtered to English before classification upstream).
- Not intended as a substitute for human judgment in high-stakes moderation decisions.
- Not evaluated on song lyrics outside the genre/style distribution of the training data (see Training Data).
Bias, Risks, and Limitations
- The training labels were generated with LLM-assisted annotation rather than exclusively human review, so label noise from the annotating model may be present.
- "Appropriateness" is a subjective, culturally variable judgment; the model reflects the definitions and prompt used during annotation, not a universal standard.
- Long or ambiguous verses (e.g. long choruses, code-switched lyrics) may be classified less reliably — see the project checklist for known open issues.
- As with any classifier, false negatives (unsafe content marked safe) are possible; this model should not be relied on as the only safeguard for children's content exposure.
Recommendations
Users should treat predictions as a decision-support signal rather than a final verdict, and periodically spot-check outputs against the source lyrics before relying on the classification in a downstream product.
How to Get Started with the Model
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
repo_id = "devanasokan/bert-lyrics-classifier"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
model = AutoModelForSequenceClassification.from_pretrained(repo_id)
verse = "Dancing in the sunshine with my friends all day long"
inputs = tokenizer(verse, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
logits = model(**inputs).logits
predicted_class_id = torch.argmax(logits, dim=-1).item()
labels = {0: "SAFE", 1: "UNSAFE"}
print(labels[predicted_class_id])
Or with the pipeline API:
from transformers import pipeline
classifier = pipeline("text-classification", model="devanasokan/bert-lyrics-classifier")
classifier("Dancing in the sunshine with my friends all day long")
Training Details
Training Data
The model was trained on devanasokan/lyrics-appropriateness-dataset: song lyrics collected via the Spotify and Genius APIs, split into verses, and labelled SAFE / UNSAFE with LLM-assisted annotation, followed by cleaning and language filtering (English only). Labels were mapped as SAFE → 0, UNSAFE → 1.
The dataset was split 80/10/10 into train/validation/test sets.
Training Procedure
Hyperparameters were tuned with Optuna (TPE sampler) over learning rate, per-device batch size, and weight decay, optimizing validation accuracy across 10 trials with early stopping.
Training Hyperparameters (best trial)
- Base model:
bert-base-uncased - Learning rate: 2e-5
- Batch size: 8
- Weight decay: 0.01
- Epochs: 3
- Precision: fp32
- Seed: 42 (fixed for reproducibility, including deterministic CUDA algorithms)
Evaluation
Testing Data
Held-out test split (10% of the labelled verse dataset), from the same collection/annotation pipeline as the training data.
Metrics
Accuracy, precision, recall, and F1-score (weighted for the UNSAFE class) were used to evaluate classification performance.
Results
| Metric | Score |
|---|---|
| Accuracy | 0.8925 |
| Precision | 0.8918 |
| Recall | 0.8934 |
| F1-score | 0.8926 |
This BERT model was compared against RNN, LSTM, and DistilBERT baselines trained on the same dataset; BERT was selected for deployment based on overall performance.
Environmental Impact
- Hardware Type: [NVIDIA GeForce RTX 4060]
- Hours used: [9]
- Cloud Provider: [More Information Needed]
Citation
If you use this model, please cite the associated Final Year Project:
@misc{asokan2026lyriclens,
author = {Asokan, Devan},
title = {Implementing a Machine Learning Based Approach for Classifying Song Lyrics Appropriateness for Children},
year = {2026},
publisher = {Asia Pacific University},
howpublished = {\url{https://github.com/lemonmelonn/devanasokan_fyp}}
}
Model Card Author
Devan Asokan