The problem
Depression classification from social media posts using BERT is a text-classification project that reads the language of a post — word choice, tone, sleep and withdrawal references, hopelessness markers — and predicts whether the post shows language patterns associated with depression. People often write about sleepless nights, exhaustion and feeling disconnected, yet reading thousands of posts by hand is slow and inconsistent. Keyword lists alone miss this signal because the same word means different things in different sentences: "tired after a great run" and "tired of being alive" share a word but not a meaning. BERT solves that by reading every word in the context of the whole sentence, so the model learns patterns of expression rather than matching a fixed word list. The result turns raw social-media text into a structured, explainable signal for researchers, while staying honest about its limits: it detects language patterns, it never diagnoses a person.
9,210 diagnosed and 107,274 control users' posts from the RSDD dataset.
Follow the working sequence
How it works
Depression classification from social media posts using BERT works end to end in six stages. First, posts from the RSDD Reddit dataset are collected and cleaned: URLs, usernames and markup are stripped, and posts are truncated to BERT's 512-token window. Second, each post is tokenized with the BERT WordPiece tokenizer and framed by [CLS] and [SEP] tokens. Third, the pre-trained BERT-base model is fine-tuned on the labelled posts with a two-class classification head, using class weights to handle the imbalance between diagnosed and control users. Fourth, the trained model is evaluated once on a held-out test split with precision, recall, F1 and a confusion matrix. Fifth, the saved model is wired into a web demo that tokenizes a typed post exactly the same way and returns the class probabilities. Sixth, the demo highlights the words that most influenced the score, so the decision can be explained rather than just asserted.
- RSDD posts are loaded and cleaned: URLs, usernames and markup are removed, and each post is truncated to the 512-token BERT input window.
- Posts are tokenized with the BERT WordPiece tokenizer (approximately 30,522-entry vocabulary) and framed with [CLS] and [SEP] tokens.
- BERT-base uncased is fine-tuned with a two-class softmax head on the [CLS] vector, using class weights because control users outnumber diagnosed users by roughly 12 to 1.
- Training uses a train/validation/test split with early stopping on validation F1, and the best checkpoint is saved.
- The held-out test split is evaluated once: precision, recall, F1-score and a confusion matrix are generated for the report.
- In the web demo, a typed or sample post is tokenized identically to training data and passed through the saved model, which returns per-class probabilities and a word-influence highlight.
Tech stack:
-
Python 3, PyTorch, Hugging Face Transformers
-
BERT-base uncased (google-bert/bert-base-uncased)
-
RSDD dataset (Yates et al., EMNLP 2017)
-
Jupyter Notebook (training & evaluation)
-
scikit-learn (metrics & confusion matrix)
-
HTML, CSS & JavaScript (classification demo)
-
Pandas & NumPy (data preparation)
-
Dataset: RSDD (Reddit Self-reported Depression Diagnosis, Yates et al., EMNLP 2017) — 9,210 users who self-reported a depression diagnosis and 107,274 matched control users, 116,484 users in total, drawn from Reddit posts published between 2006 and 2016. A selected subset of the dataset is used for this implementation, with a documented train/validation/test split.
-
Task: Binary text classification; input = one English social-media post (up to 512 WordPiece tokens), output = probability distribution over two classes (depressive-language indicators / no indication).
-
Model: BERT-base uncased — 12 Transformer encoder layers, 768 hidden units, 12 attention heads, approximately 110 million parameters — fine-tuned with a linear classification head on the [CLS] representation; WordPiece tokenizer with an approximately 30,522-entry vocabulary.
-
Metrics: Precision, recall, F1-score and confusion matrix on the held-out test split, reported per class. Final performance depends on the dataset, train/test split, preprocessing, class weighting and training conditions; no accuracy figure is claimed as measured until the training run is executed for the order.
| Parameter | Value |
|---|---|
| Input format | One English social-media post, up to 512 WordPiece tokens (design target) |
| Classes | 2 (depressive-language indicators / no indication) |
| Dataset size | 116,484 users in total: 9,210 diagnosed + 107,274 control (RSDD, Yates et al. 2017) |
| Model parameters | Approximately 110 million (BERT-base, datasheet value) |
| Model architecture | 12 layers, 768 hidden units, 12 attention heads (datasheet values) |
| Training time | Approximately 2–4 hours on a single GPU (expected, subset-dependent) |
| Inference | Approximately 40–80 ms per post on GPU (expected); approximately 150–300 ms per post on CPU (expected) |
| Demo | Single-file web app, runs offline after download (design target) |
Project features
Depression classification from social media posts using BERT ships four core capabilities: a fine-tuned BERT-base classifier that scores any English post for depressive-language indicators, a live web demo that classifies typed or sample posts with confidence and per-class scores, a word-influence view that shows which words pushed the score in either direction, and a full evaluation pack with precision, recall, F1 and a confusion matrix. Around those sit a documented training pipeline on the RSDD dataset, a sample-post browser for repeatable demonstrations, and a clear ethics and limitations note that keeps the project honest in the viva. Optional additions and future-scope items are labelled separately below so nothing is oversold. The training notebook records every decision — the split, the class weights, the learning rate and the early-stopping rule — so the student can defend the build in the viva instead of quoting a tutorial.
- [Fine-tuned BERT-base classifier] BERT-base uncased (12 layers, 768 hidden units, approximately 110 million parameters) fine-tuned for binary text classification, with a two-class softmax head over the [CLS] representation. Implemented.
- [Live classification web demo] Paste any English post, or pick from six labelled sample posts, and see the predicted class with model confidence and per-class probability scores. Implemented.
- [Word-influence highlight] The demo shades the words that pushed the score toward or away from the depressive class, giving a concrete talking point for how attention-style context weighting works. Implemented.
- [Sample-post browser] Six clearly labelled sample posts written for demonstration — not real users' data — each with a reference label and demo confidence, so the viva demonstration is repeatable. Implemented.
- [Evaluation pack] Precision, recall, F1-score and a confusion matrix computed on the held-out test split, with class-imbalance handling documented. Implemented.
- [Training notebook] Data loading, cleaning, tokenization with the BERT WordPiece tokenizer, class-weighted fine-tuning, and evaluation in one reproducible Jupyter notebook. Implemented.
- [Optional: multi-post user timeline] Aggregating several posts from one user into a single timeline-level score can be added on request; it is not part of the base single-post classifier. Optional customization.
- [Future scope: multilingual posts] Extending the classifier to Hinglish or other Indian-language posts with a multilingual BERT checkpoint is possible future work and is not included in the base project. Future scope.
What is included
- Complete training & evaluation Jupyter notebook
- Fine-tuned BERT model files with the tokenization pipeline
- Live classification web demo with sample-post browser and word-influence view
- Precision, recall, F1-score and confusion-matrix report
- Project report PDF (background, BERT theory, dataset ethics, methodology, results)
- PPT presentation for final review
- Viva Q&A preparation document (BERT attention, fine-tuning, class imbalance, ethics)
Limitations & prerequisites
- This is an academic prototype for language-pattern research: it is not a diagnostic or clinical tool and must never be presented as one.
- Labels come from self-reported diagnoses on Reddit, so the model learns how people write about depression, not a clinical ground truth.
- The classifier reads one post at a time; a single post cannot capture a person's mental state, and sarcasm, song lyrics or quoted text can mislead it.
- RSDD posts span 2006–2016, so slang and platform language from recent years may be under-represented.
- Performance is reported per class on the held-out split only; no accuracy figure is claimed before the training run is executed for the order.
- Anyone in distress should contact a professional: Tele-MANAS, India's free 24×7 tele mental-health helpline, at 14416 (verified via the Ministry of Health and Family Welfare, October 2026).
- The demo in the browser uses a lightweight keyword-and-context heuristic as a stand-in for the fine-tuned BERT model; the delivered model is the real fine-tuned BERT checkpoint.
Frequently Asked Questions
Which dataset is used and why?
The RSDD dataset (Reddit Self-reported Depression Diagnosis, Yates et al., EMNLP 2017) is used: 9,210 users who self-reported a depression diagnosis and 107,274 matched control users, drawn from Reddit posts between 2006 and 2016, because its labels come from explicit self-reported diagnoses verified by annotators. It is the standard benchmark for this task, and its size supports fine-tuning a transformer. A documented subset is used for training, with the split recorded in the notebook.
Which model is used?
BERT-base uncased, fine-tuned for binary text classification, is used: 12 Transformer encoder layers, 768 hidden units, 12 attention heads and approximately 110 million parameters, with a two-class softmax head added on the [CLS] representation, and the model is trained with class weights because control users outnumber diagnosed users by roughly twelve to one. BERT is chosen because its bidirectional self-attention reads each word in the context of the whole sentence, which matters when the same word carries different meaning in different posts.
Can this project diagnose depression?
No — this project classifies language patterns in a single social-media post and cannot diagnose depression, assess a person, or substitute for professional mental-health care in any way, because a post is a fragment of language, not a clinical assessment. The report states this limit explicitly, and the demo carries the same warning. Anyone in distress should contact a professional — in India, Tele-MANAS is free and available 24×7 at 14416.
Is the accuracy guaranteed?
No accuracy figure is guaranteed or claimed, because final performance depends on the dataset subset, train/test split, preprocessing, class weighting and training conditions used in the built-to-order training run, and the report documents the actual precision, recall and F1 achieved on the held-out test split instead. This honesty is itself a strong viva point: the project reports measured results, not promised ones.
Can the demo classify my own posts?
Yes — the web demo accepts any typed English post and returns its predicted class with confidence and per-class scores, alongside six labelled sample posts for repeatable demonstrations, and typed posts are processed only inside the browser demo, never stored or sent anywhere. The demonstration stays private by design. Note that the browser demo uses a lightweight heuristic as a stand-in; the delivered model is the fine-tuned BERT checkpoint.
Is this project suitable for a final-year project?
Yes — for Computer Science, IT and AI & Machine Learning programs, because it demonstrates transformer fine-tuning, dataset ethics, class-imbalance handling and rigorous evaluation in one coherent build, and its limitations are documented honestly, which gives students genuine, defensible material for viva questions rather than inflated claims. The project suits students comfortable with Python and NLP basics, and the report explains BERT attention and fine-tuning in viva-ready language.
Components & software requirements
- Python 3, PyTorch, Hugging Face Transformers
- BERT-base uncased (google-bert/bert-base-uncased)
- RSDD dataset (Yates et al., EMNLP 2017)
- Jupyter Notebook (training & evaluation)
- scikit-learn (metrics & confusion matrix)
- HTML, CSS & JavaScript (classification demo)
- Pandas & NumPy (data preparation)
Delivery information
Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.
Support terms
Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.
Download free synopsis (PDF)
Enter your name and WhatsApp number — the synopsis PDF downloads immediately. We may send occasional project updates on WhatsApp; no spam.