Transform Your Thoughts: Unveiling ThoughtCoach, the App that Reframes Your Mindset

response

See the open source Github repo

Try the Online demo

Introduction

Today, I am open-sourcing a recent project of mine called ThoughtCoach, a free application designed to positively reshape the way we think. In a world where mental wellness is often challenged by stress, negativity, and uncertainty, ThoughtCoach emerges as a beacon of hope. Harnessing the immense potential of Artificial Intelligence, this app helps individuals reframe potentially negative thought patterns into empowering and constructive mindsets. Whether you are someone seeking to improve your mental resilience, a developer intrigued by the applications of AI to “for good” causes, ThoughtCoach might be of interest to you. In this blog post, we will dive into the conception, features and future for ThoughtCoach.

A brief introduction to the ThoughtCoach App

In today’s fast-paced world, mental well-being is an area that demands attention and care. With the advent of technology, there are new avenues to explore in mental health support. One such exploration is my ThoughtCoach app, currently a prototype designed to serve as a tool for helping individuals recognize and manage negative thought patterns using artificial intelligence.

Having personal experience with Cognitive Behavioural Therapy, through personal therapy and via books, especially the great work of Dr David Burn’s books such as Feeling Good and Feeling Great. I have found many of the exercises suggested within of great help to working on my own thinking patterns.

response

The importance of catching and reframing negative thought patterns

Catching and reframing negative thought patterns is a critical component of mental health and well-being. Negative thoughts, if left unchecked, can significantly affect various aspects of our lives:

The Conception of ThoughtCoach

As an engineer, I like systems and processes. The idea of recognising Cognitive Distortions in my own thoughts, exploring the evidence that supports the thoughts. By challenging those thoughts, and reframing them to be more balanced I personally have found great relief.

What are Cognitive Distortions?

Cognitive distortions are biased or irrational ways of thinking that can contribute to negative emotions and behaviors. These distortions often reinforce negative thoughts or emotions and can exacerbate mental health issues such as anxiety and depression. Cognitive distortions can be automatic and are often based on inaccurate perceptions of reality. Here are some common types of cognitive distortions:

  1. All-or-Nothing Thinking (Black-and-White Thinking): This involves seeing things in only two categories (e.g., good or bad, success or failure) without acknowledging any middle ground or shades of gray.

  2. Overgeneralization: This is when you make broad conclusions based on a single event or piece of evidence. For example, if something goes wrong once, you might think it will always go wrong.

  3. Mental Filter (Selective Abstraction): Focusing exclusively on the negative aspects of a situation while ignoring any positive elements.

  4. Disqualifying the Positive: Rejecting positive experiences or achievements by insisting they don’t count for some reason or another.

  5. Jumping to Conclusions: Making negative interpretations even though there are no definite facts that convincingly support the conclusion. This can be divided into mind-reading (assuming the thoughts and intentions of others) and fortune-telling (predicting events will turn out badly).

  6. Magnification (Catastrophizing) and Minimization: Exaggerating the significance of negative events or emotions (magnification) while downplaying the significance of positive ones (minimization).

  7. Emotional Reasoning: Believing that because you feel a certain way, it must be true. For example, if you feel unlikable, you believe that nobody likes you.

  8. Should Statements: Using “should,” “ought to,” or “must” statements can create unrealistic expectations or standards for yourself or others, leading to frustration and disappointment.

  9. Labeling and Mislabeling: Attaching a label to oneself or others based on a single event or behavior (e.g., calling yourself a “loser” because you didn’t win a competition).

  10. Personalization: Taking responsibility for events outside of your control and blaming yourself for the negative actions or emotions of others.

  11. Blaming: The opposite of personalization, blaming involves attributing all responsibility for negative events or feelings to others instead of recognizing one’s role in the situation.

Recognizing and challenging cognitive distortions is often a key component of cognitive-behavioral therapy (CBT), which is a common treatment for anxiety, depression, and other mental health disorders. By learning to identify these distortions, individuals can work on replacing them with more realistic and balanced thoughts, leading to improved emotional well-being.

The Idea and Inspiration Behind ThoughtCoach

For a while, I wanted to try to build an application that can 1. Detect cognitive distortions in text (such as a journal) and 2. Help to offer possible reframing of these thoughts. I have had limited success in finding good datasets to train classifiers. The advent of LLMs such as GPT-4 reignited my interest in this, as these models come with an extensive knowledge base and natural language processing capabilities that can potentially be leveraged to accurately identify cognitive distortions and generate insightful alternatives for reframing thoughts. With the advancements in AI and the sheer linguistic prowess of GPT-4, the prospect of creating an impactful tool for mental health has become more tangible and exciting.

Addressing a Need: How ThoughtCoach could fill a Gap in Mental Health Resources

How ThoughtCoach Could Fill a Gap in Mental Health Resources

The landscape of mental health has evolved, but there still exist substantial gaps that need to be addressed. Accessibility, availability, and immediacy are among the most pressing concerns. ThoughtCoach, with its AI-driven approach to identifying and reframing negative thought patterns, could serve as a pivotal tool in bridging some of these gaps.

Immediate Assistance

One of the most significant challenges individuals face when struggling with mental health is the immediate need for assistance. When someone experiences a surge of negative thoughts or anxiety, it’s often impractical to have immediate access to a therapist. Scheduling a session usually takes time, and there’s a growing demand for mental health services which often leads to long waiting lists. This is where ThoughtCoach can come in handy. Being a web app, it provides users with the ability to seek guidance in real-time. While it’s not a replacement for professional therapy, it can offer immediate relief and strategies to manage negative thoughts until professional help can be obtained.

Accessibility and Cost-Effectiveness

Access to mental health care is not always affordable or geographically accessible. The costs associated with private therapy can be prohibitive for many individuals. ThoughtCoach, on the other hand, can provide a more accessible and cost-effective alternative for people who might not otherwise have the means or opportunity to seek professional help. Its AI-powered capabilities are designed to emulate certain aspects of cognitive-behavioral therapy, such as identifying cognitive distortions and offering suggestions for reframing.

Reducing Stigma

In many societies, there is still stigma attached to seeking mental health support. Some individuals may be hesitant to see a therapist due to societal perceptions. ThoughtCoach provides a private and anonymous way for individuals to start addressing their mental health concerns without the fear of judgment.

Supplementary Support

ThoughtCoach can also be used as supplementary support alongside traditional therapy. It can be a beneficial tool for individuals to practice skills they have learned in therapy or to monitor and manage their thoughts between sessions.

Note on Limitations

While ThoughtCoach can play an important role in filling gaps in mental health resources, it’s essential to recognize that it’s not a substitute for professional mental health care, especially for severe mental health issues. It can, however, serve as a highly beneficial tool for immediate assistance, ongoing self-monitoring, and as an entry point for those who might not otherwise seek help.

ThoughtCoach, therefore, represents a promising step in leveraging technology to address some of the challenges and barriers in mental health care, making support more immediate, accessible, and widespread. We must be aware that LLMs can provide incorrect or biased information.

How ThoughtCoach Works

ThoughtCoach is a serverless application using SST. It is hosted on AWS using Lambda functions and Cloudfront. The frontend is a Next.js application and the API endpoints are written in Node.js making use of Langchain.js.

The backend makes use of the Output parsers functionality in Langchain using the Zod library to enforce structured response from GPT4, which can be used directly in the frontend React components.

This approach is very flexible and ensures guardrails on the response. Here is the Zod schema for the response from the API:

StructuredOutputParser.fromZodSchema(
  z.object({
    reframe: z
      .string()
      .describe(
        "A healthier thought about the story and event that I can tell myself, which is more balanced and without cognitive distortions"
      ),
    advice: z
      .string()
      .describe(
        "What steps can I take to learn healthier thought patterns around this event"
      ),
    distortions: z.record(
      z
        .enum([
          "All-or-Nothing Thinking",
          "Overgeneralization",
          "Filtering",
          "Disqualifying the Positive",
          "Jumping to Conclusions",
          "Mind Reading",
          "Fortune Telling",
          "Magnification and Minimization",
          "Emotional Reasoning",
          "Should Statements",
          "Labeling and Mislabeling",
          "Personalization",
          "Blaming",
          "Fallacy of Change",
        ])
        .describe(
          "the name of the cognitive distortion detected in the thought"
        ),
      z
        .object({
          spans: z
            .array(z.string().describe("a vertabim span of the input thought"))
            .describe(
              "all the incidences of this cognitive distortions in the thought"
            ),
          info: z.string().describe("A description of what this distortion is"),
          reframe: z
            .string()
            .describe(
              "A way this thought can be reframed with respect to this distortion into a healthier balanced perspective"
            ),
          confidence: z
            .number()
            .describe(
              "how confident between 0 and 100 of the presence of this distortion"
            ),
        })
        .describe("each cognitive distortion at play in the input thought")
    ),
  })
);

Treading a fineline

Initial feedback from users pointed out that the application was overeager to make suggestions when the user’s thoughts were either perfectly justified or entirely unrelated to a therapeutic context. We certainly don’t want to patronise users, or worse gaslight them into thinking balanced thoughts are distorted.

To ameliorate this situation, a first check is performed to classify the input as either balanced, distorted or invalid. If the thought is balanced or invalid, a separate message informs the user of that.

response response

Opensource and The Future of ThoughtCoach

I’ve open-sourced ThoughtCoach because I want it to be transparent and allow for community-driven development and innovation. Open sourcing enables the following:

  1. Collective Enhancement: By allowing developers and experts from around the world to access the code, ThoughtCoach can benefit from a diverse set of skills and knowledge. The community can contribute by fixing bugs, improving algorithms, and adding new features.

  2. Transparency and Trust: Mental health is a sensitive domain. By open-sourcing ThoughtCoach, users and experts can scrutinize the code and understand how the app works. This transparency builds trust, as users can be confident that the app handles their data responsibly and performs the functions it claims.

  3. Adaptability: Other developers can adapt ThoughtCoach for specific use cases or integrate it into broader mental health platforms. This adaptability ensures that ThoughtCoach’s benefits can reach a wider audience and cater to various needs.

  4. Accelerated Development: Open-source projects often develop at a faster pace than closed projects due to the number of contributors. This can be particularly beneficial for an app like ThoughtCoach, where timely advancements can have a significant impact on mental health support.

  5. Educational Resource: For students and professionals seeking to learn more about AI and mental health, ThoughtCoach serves as a real-world project that they can study, learn from, and contribute to. This educational aspect can foster innovation and inspire new approaches to mental health technology.

  6. Cross-Disciplinary Collaboration: Open sourcing ThoughtCoach can encourage collaborations between AI experts, psychologists, therapists, and researchers. Such cross-disciplinary collaboration is essential for creating an app that is technologically sound and psychologically effective.

  7. Global Reach and Localization: With a global community of contributors, ThoughtCoach can be localized to different languages and cultures, making it more accessible and relevant to non-English speaking populations.

By open-sourcing ThoughtCoach, I am inviting collaboration, innovation, and scrutiny, all of which are essential for the evolution and efficacy of an application that aims to have a positive impact on mental health. Through the collective effort, ThoughtCoach has the potential to become not just an app, but a movement towards accessible and effective mental health support.

I’d love to have contributions or suggestions from you, so please create an issue or a PR if you want to join in!