Instructions to use devanasokan/bert-lyrics-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use devanasokan/bert-lyrics-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="devanasokan/bert-lyrics-classifier")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("devanasokan/bert-lyrics-classifier") model = AutoModelForSequenceClassification.from_pretrained("devanasokan/bert-lyrics-classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 6,819 Bytes
3a3329e 900a3e2 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 3a3329e 0f4a650 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | ---
library_name: transformers
license: mit
datasets:
- devanasokan/song-appropriateness
metrics:
- accuracy
base_model:
- google-bert/bert-base-uncased
pipeline_tag: text-classification
---
<!-- Provide a quick summary of what the model is/does. -->
# bert-lyrics-classifier
`bert-lyrics-classifier` is a fine-tuned [`bert-base-uncased`](https://huggingface.co/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`](https://huggingface.co/bert-base-uncased)
### Model Sources
- **Repository:** [devanasokan/devanasokan_fyp](https://github.com/lemonmelonn/devanasokan_fyp)
- **Dataset:** [devanasokan/lyrics-appropriateness-dataset](https://huggingface.co/datasets/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 children
- `LABEL_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](#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](https://github.com/lemonmelonn/devanasokan_fyp/blob/main/checklist.md) 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
```python
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:
```python
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`](https://huggingface.co/datasets/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](https://optuna.org/) (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.
<!-- TODO: add a comparison table with the RNN/LSTM/DistilBERT scores if you want the full comparison visible here -->
## Environmental Impact
<!-- TODO: fill in if you tracked this, e.g. via the ML CO2 impact calculator (https://mlco2.github.io/impact#compute) -->
- **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:
```bibtex
@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
|