π» This is the official implementation of paper Cognivia: An AI Therapist for Evidence-Based Cognitive Behavioral Therapy.
Cognivia (or βε―θβ in Chinese) is an evidence-based artificial intelligence therapist for cognitive behavioral therapy (CBT) that integrates automatic cognitive distortion identification and rational response generation.
Qi Chen, Siria Xiyueyao Luo, Xuejiao Zhao*
** Southwest Petroleum University Β | Β University of Groningen Β |Β Nanyang Technological University**
* Corresponding author
- [2026.02.01] We release github repository of Cognivia. πͺ Have a tryοΌ
Figure 1: The overall framework of Cognivia.
The pipeline of our model is shown in Fig. 1, which consists of three stages:
- (1) CBT Expert Seed Curation: Curate CBT literatures to form high quality CBT Cognitive Triplet Dataset as reference seed.
- (2) CBT Cognitive Triplet Dataset Augmentation: Multi-stage prompting and structured generation to augment mental health questions from PsyQA dataset to generate Augmented CBT Cognitive Triplet Dataset.
- (3) Task-oriented LoRA Fine-tuning: Fine-tuning large language models by Augmented CBT Cognitive Triplet Dataset to obtain Cognivia for cognitive distortion identification and rational response generation.
- CBT Cognitive Triplet Dataset: Our work is based on authoritative texts that are widely regarded as core paradigms and standard references in CBT. Using these resources, we curate a high-quality seed cognitive triplet dataset of representative CBT questionβanswer pairs and corresponding rational response. The seed dataset is constructed based on established theoretical frameworks and clinical guidelines, which is why we refer to our approach as evidence-based. The form of this CBT Cognitive Triplet Dataset:
{"Thought": "...", "Cognitive Distortion": "...", "Rational Response": "..."}- Augmented CBT Cognitive Triplet Dataset: This dataset is based on PsyQA, a large-scale psychological question-answering dataset collected from publicly accessible online mental health forums. PsyQA consists of anonymized user-generated questionβanswer pairs related to psychological concerns as the following form:
{"Question": "...", "Answer": "..."}
For each question ππ in PsyQA, we employ the DeepSeek and GPT-5 Mini with two-stage data preprocessing to construct the Augmented CBT Cognitive Triplet Dataset with 9,437 samples:
From the original PsyQA dataset (~22K samples), we selected 9,437 question samples exhibiting cognitive distortions through a designed prompt-based filtering process. We use an expert-designed prompt_1 to identify the corresponding cognitive distortion ππ.
Model: DeepSeek
Prompt: filter_prompt.txt (Prompt1 Version 2)β
Script: identify_distortion.py
We use GPT-5 Mini with prompt_2 to generate a corresponding rational response ππ.
Model: GPT-5 Mini
Prompt: response_prompt.txt (Prompt2 Version 3)
Script: generate_response.py
The form of this Augmented CBT Cognitive Triplet Dataset:
{"Thought": "...", "Cognitive Distortion": "...", "Rational Response": "..."}The code structure and corresponding comments of this repository are as follows:
Cognivia/
βββ Cognivia.py # Main entry script for running Cognivia
βββ prompts
β βββ filter_prompt.txt # Prompt_1 of CBT Cognitive Triplet Dataset Augmentation (Cognitive Distortion Labelling)
β βββ response_prompt.txt # Prompt_2 of CBT Cognitive Triplet Dataset Augmentation (Rational Response Generation)
β
βββ data/
β βββ CBT_Cognitive_Triplet_Dataset.xlsx # CBT Cognitive Triplet Dataset curated from CBT Literatures
β
βββ src/
β βββ evaluation_with_8_dimensions.py # Custom 8-dimension quality evaluation
β βββ evaluation_with_NLP.py # NLP-based evaluation methods
β βββ fine-tuned_model_generate.py # Generate responses using fine-tuned model
β βββ identify_distortion.py # Identify cognitive distortions
β βββ generate_response.py # Generate rational responses
β
βββ materials/ # Figures & assets for the paper
βββ README.md # Project introduction and usage
βββ LICENCE.txt # Licence information
βββ requirements.txt # Python dependencies
git clone https://github.com/SNOWTEAM2023/Cognivia.git
cd Cognivia
pip install -r requirements.txtTo use your own OpenAI, DeepSeek, or SiliconFlow API tokens, replace the placeholders with your actual tokens. The relevant sections in the code have been left blank for this purpose.
# Replace with your OpenAI API token
api_key = "your_openai_api"
# Replace with your DeepSeek API token
api_key = "your_deepseek_api"
# Replace with your SiliconFlow API token
api_key = "your_siliconflow_api"The relevant sections in the code have been left blank to ensure the correct path is used.
# Replace with your path to the preprocessed dataset.
psyqa_path = os.path.join(current_dir, "questions.xlsx")Once the paths and tokens have been updated, run this file to get Augmented CBT Cognitive Triplet Dataset :
identify_distortion.py && generate_response.pyTo meet the training requirements of the model, we transformed the data in the Augmented CBT Cognitive Triplet Dataset into the following format:
{"user": "...", "assistant": "..."}We fine-tuned Qwen2.5-7B-Instruct using LoRA on SiliconFlow. The model is accessible via API with ID [ft:LoRA/Qwen/Qwen2.5-7B-Instruct:d50jhbk50mis73di8n5g:gpt5_mini:udjarjexxlodpjueztat-ckpt_step_625]. You can try it out with the code I've included below.
from openai import OpenAI
# Replace with your SiliconFlow API token
api_key = "your_siliconflow_api"
client = OpenAI(
api_key=api_key,
base_url="https://api.siliconflow.cn/v1"
)
FINE_TUNED_MODEL_ID = "ft:LoRA/Qwen/Qwen2.5-7B-Instruct:d50jhbk50mis73di8n5g:gpt5_mini:udjarjexxlodpjueztat-ckpt_step_62"
# Replace with your question
test_user_input = ("Is my career short-lived? Feeling lost about the future.")
response = client.chat.completions.create(
model=FINE_TUNED_MODEL_ID,
messages=[
{
"role": "system",
"content": """You are a cognitive behavioral therapy (CBT) psychologist.
First, identify the type of cognitive distortion exhibited in the statement,
and then provide a response containing the following five paragraphs, separated by blank lines:
1.Empathy and Validation
2.Cognitive Distortion Analysis
3.Reflective Questions
4.CBT Exercise Recommendation
5.Encouragement and Next Steps.
If it does not contain a cognitive distortion (e.g., casual conversation, general questions, or statements without distortions),
switch to a natural, supportive conversation mode. Respond in a warm, counselor-like tone without analyzing distortions or following the five-paragraph structure.
"""
},
{
"role": "user",
"content": test_user_input
}
],
temperature=0.2,
max_tokens=300
)
print("\n--- Model Analysis Results ---\n")
print(response.choices[0].message.content)The relevant sections in the code have been left blank to ensure the correct path is used.
# Replace with your path to test dataset
INPUT_FILE = os.path.join(current_dir, "test.xlsx")
file2_path = os.path.join(current_dir, "test.xlsx")Our work shows that Cognivia performs particularly well on CBT tasks, you can use the following for evaluation.
fine-tuned_model_generate.py && (evaluation_with_NLP.py & evaluation_with_8_dimensions.py &)This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. Commercial use is prohibited without a separate license agreement with the author.


