Cognitive Distortion Detection in Journal Entries
JournalWise is a project that explores detecting cognitive distortions in user-generated text, such as journal entries. Cognitive distortions are recurring, biased ways of thinking that can reinforce negative thoughts, emotions, and behaviors.
By combining NLP preprocessing, data augmentation, and machine learning models, this notebook builds a model to classify distorted thinking patterns. I have also deployed the model with FastAPI and created a UI with streamlit.
Cognitive distortions are irrational thought patterns that alter how people perceive themselves, others, or the world. They can fuel stress, anxiety, and depression by making situations seem worse or more negative than they really are.
This project classifies journal entries into one of the following five distortion types, or none if no distortion applies.
-
Catastrophizing
When individuals imagine the worst possible outcome, even if it’s highly unlikely.
➡️ “If I forget one detail in my presentation, my whole career will be ruined.” -
Overgeneralization
Drawing broad, sweeping conclusions based on limited evidence.
➡️ “One person ignored me; therefore, nobody likes me.” -
Mind Reading
Assuming you know what others are thinking or feeling, without concrete evidence.
➡️ “She didn’t text back, so she must be angry at me.” -
Personalization
Blaming yourself (or unfairly blaming someone else) for events outside of personal control.
➡️ “My team lost because I didn’t work hard enough.” -
Emotional Reasoning
Believing that because you feel something, it must automatically be true.
➡️ “I feel like a failure, so I must be one.” -
None
If a journal entry does not fit into any of the above categories, the model returns: ➡️ none
- Scrapes text data related to mental health / journal entries from Reddit using the RedditAPI
- Labels text data using rule based methods and LLMs
- Preprocesses and cleans text data using NLTK
- Performs exploratory data analysis (EDA)
- Implements a baseline Logistic Regression Moddel model to classify cognitive distortions
- Handles data imbalance with data augmentation techniques using nlpaug
- Implements SVM model to classify cognitive distortions
- Deploys ML model with FastAPI and UI is built with Streamlit
- Uses Gemini API to reframe thoughts positively
