A multimodal AI that understands internet memes to detect underlying signs of anxiety and depression.
Jupyter Notebook
1
48 commits
updated Feb 3, 2026
The dataset has 8 categories
Lack of Interest
Self-Harm
Feeling Down
Concentration Problem
Lack of Energy
Sleeping Disorder
Low Self-Esteem
Eating Disorder
The dataset has 8 categories
Nervousness
Lack of Worry Control
Excessive Worry
Restlessness
Difficulty Relaxing
Impending Doom
Irritatbily
Unknown
Ignore the below Unknown images in the anxiety dataset: TR-2027, TR-2094, TR-212
Model for Depression (Multi-Label Classification)
Model for Anxiety (Single-Label Classification)
Overleaf document link: Overleaf
Common document (docs) link: Docs
Paper: Figurative-cum-Commonsense Knowledge Infusion for Multimodal Mental Health Meme Classification
The baseline implementation focuses on leveraging OCR text extracted from memes and using BERT embeddings for classification. The models were trained and evaluated using the following setup:
bert-base-uncased) with a classification head.BCEWithLogitsLoss).5e-50.90.9991e-81e-20.2165121.010best_model.pt) saved based on validation Macro F1 score.last_model.pt) saved after the final epoch.training_logs.csv) with epoch-wise metrics.test_report.txt).bert-base-uncased) with a classification head.5e-50.90.9991e-81e-20.2165121.010best_model.pt) saved based on validation Macro F1 score.last_model.pt) saved after the final epoch.training_logs.csv) with epoch-wise metrics.test_report.txt).OCR Text:
bert-base-uncased) with a maximum sequence length of 512.BERT Embeddings:
bert-base-uncased) are fine-tuned for both tasks.Training and Evaluation:
10 epochs using the AdamW optimizer and a constant learning rate scheduler.Outputs:
best_model.pt and last_model.pt) are saved in the respective output directories.training_logs.csv) and test evaluation results (test_report.txt) are saved for analysis.Summary of Metrics:
55.27%62.36%0.1067Explanation:
The depression task achieved similar performance to paper, with a Macro F1 Score of 55.27%, indicating balanced performance across all categories. The Weighted F1 Score of 62.36% reflects better performance on more frequent categories.
The Hamming Loss of 0.1067 suggests that the model makes relatively few errors in its predictions, which is expected for a multi-label classification task.
The training process shows consistent improvement in both Macro F1 and Weighted F1 scores across epochs, as seen in the training logs.
Compared to the paper's reported metrics (Macro F1 Score: 58.16%, Weighted F1 Score: 57.12%), the model's Weighted F1 Score surpasses the paper's results, while the Macro F1 Score is slightly lower, indicating room for improvement in balancing performance across all categories.
A training loss vs. epochs graph is available for visualization:

A F1 Scores vs. epochs graph is available for visualization:

A Validation Hamming Loss vs. epochs graph is available for visualization:

Summary of Metrics:
55.37%47.46%55.48%0.4463Class-wise Performance:
| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| Difficulty Relaxing | 71.43% | 63.73% | 67.36% | 102 |
| Excessive Worry | 46.85% | 56.52% | 51.23% | 92 |
| Impending Doom | 65.06% | 51.43% | 57.45% | 105 |
| Irritability | 46.43% | 35.14% | 40.00% | 37 |
| Lack of Worry Control | 57.30% | 54.26% | 55.74% | 94 |
| Nervousness | 60.17% | 66.98% | 63.39% | 106 |
| Restlessness | 41.67% | 47.83% | 44.53% | 115 |
| Unknown Anxiety | 0.00% | 0.00% | 0.00% | 1 |
Explanation:
The model achieved similar performance to paper on the anxiety task, with an overall accuracy of 55.37%. The Macro F1 Score of 47.46% indicates that the model's performance is not uniform across all classes, as it gives equal weight to each class regardless of its size. The Weighted F1 Score of 55.48% reflects better performance on larger classes like "Nervousness."
The Hamming Loss of 0.4463 suggests that the model makes errors in nearly half of the predictions, which is expected given the complexity of the task.
Class-wise, the model performed best on "Nervousness" with an F1-Score of 63.39%, while "Irritability" had the lowest F1-Score of 40.00%, indicating room for improvement in handling smaller or more ambiguous classes.
Compared to the paper's reported metrics (Macro F1 Score: 62.99%, Weighted F1 Score: 63.06%), the model's performance is lower, highlighting the need for further optimization to match or exceed the baseline results.
Additionally, we have included two extra classes, Irritability and Unknown Anxiety, which were not present in the paper. This may have contributed to the differences in performance metrics.
A training loss vs. epochs graph is available for visualization:

A F1 Scores vs. epochs graph is available for visualization:

A Validatioin Hamming Loss vs. epochs graph is available for visualization:


HyCore_M3Net (Hybrid Core Multimodal Mental Health Network) is a novel multimodal architecture specifically designed for mental health meme classification. The model combines:
The architecture follows this flow:
To run HyCore_M3Net, you'll need the following dependencies:
# Basic Libraries
pip install numpy pandas matplotlib tqdm
# Deep Learning
pip install torch torchvision
# Hugging Face Transformers and Models
pip install transformers==4.35.0 sentence-transformers==2.2.2
# Retrieval Components
pip install faiss-gpu # Use faiss-cpu for CPU-only environments
# Data Processing and Evaluation
pip install scikit-learn
pip install --no-cache-dir
torch==2.1.2
transformers==4.38.2
accelerate==0.28.0
sentence-transformers==2.7.0
faiss-cpu==1.8.0
scikit-learn==1.3.2
pandas==2.1.4
numpy==1.26.3
matplotlib==3.8.2
tqdm==4.66.2
Pillow==10.2.0
To run the HyCore_M3Net model from the terminal:
# Navigate to the project directory
cd mental-health-meme-classification
# Run for depression (multi-label) task
python src/shared/HyCore_M3Net.py
# To run for anxiety (single-label) task, edit the script
# Change line ~1187 from:
# dataset = 'depression'
# To:
# dataset = 'anxiety'
# Then run:
python src/shared/HyCore_M3Net.py
The model contains several configurable parameters:
MAX_LEN_LXMERT: Maximum token length for OCR text (default: 80)MAX_LEN_BART: Maximum token length for reasoning text (default: 512)BATCH_SIZE: Batch size for training (default: 8)NUM_EPOCHS: Number of training epochs (default: 10)LEARNING_RATE: Learning rate (default: 2e-5)NUM_ENSEMBLE_MODELS: Number of models for ensemble (default: 3)RETRIEVAL_K: Number of similar examples to retrieve for RAG (default: 3)These can be modified in the script to optimize performance based on your computational resources.
The model produces:
HyCore_M3Net leverages region-level visual information rather than just global image features. The model uses Detectron2 (with Faster R-CNN) to extract these region features:
The extracted features are stored in PyTorch (.pt) files as dictionaries with the following structure:
region_features = {
"image_id_1": {
"features": torch.tensor(...), # Shape: (num_boxes, 2048)
"boxes": torch.tensor(...) # Shape: (num_boxes, 4) - normalized coordinates
},
"image_id_2": {
# Same structure for each image
},
# ... more images
}
Each image entry contains:
Region Features (features):
(num_boxes, feature_dimension)num_boxes is the number of regions detected (typically 36-100)feature_dimension is 2048 for LXMERT compatibilityBounding Box Coordinates (boxes):
(num_boxes, 4)[x_min/W, y_min/H, x_max/W, y_max/H]This region-level approach allows the model to perform fine-grained visual reasoning about specific elements in memes, rather than just considering the image as a whole, significantly improving performance for mental health classification tasks.
Anxiety Output

Depression Output


Your project implements a sophisticated knowledge fusion approach for analyzing mental health memes, particularly those related to anxiety and depression. Let me explain how you're extracting and combining different types of features to create a comprehensive representation for RAG (Retrieval-Augmented Generation) during training.
Your system extracts three distinct types of information from each meme:
OCR Text (Textual Content)
Figurative Reasoning (Semantic Understanding)
Visual Features (Image Content)
You create a unified representation through concatenation:
Knowledge Fusion DB = [OCR Embedding | Figurative Reasoning Embedding | Image Embedding]
This results in a 3072-dimensional vector (3 × 1024) for each meme, containing complementary information from all three modalities.
Your code includes several sophisticated elements:
The resulting knowledge-fused embeddings serve as a comprehensive database for retrieval-augmented generation:
This approach is particularly valuable for meme analysis because:
By integrating OCR text, figurative reasoning, and visual features into a unified representation, your system creates a rich knowledge base that captures both the explicit and implicit meanings of mental health memes, enabling more nuanced analysis and generation.
For each training, we have preprocessed the features and figurative reasoning into the dataset directory. The embeddings generated by the embeddings_extractor.py, then tok_k_rag_extractor.py generates the top k embeddings and store the csv into the dataset. Then rag_trainer.py trains the model on that dataset.


Pipeline flow for the inference. Technical Architecture The system combines multiple technologies:
Frontend: Streamlit web application
Text Extraction: EasyOCR
Reasoning Engine: Hyperbolic API (Qwen 2.5 VL 7B model)
Classification Models: Fine-tuned transformer models for depression and anxiety analysis
Inference Pipeline: Seamless flow from image upload to symptom detection
Usage
Upload a meme image using the sidebar
Select the desired analysis type (Depression or Anxiety)
The system will automatically perform OCR, reasoning, and classification
Review the results in the main panel

Run the application by: streamlit run mental-health-meme-classification/src/inference/web_ui.py
Ensure that model paths are correctly configured
A multimodal AI that understands internet memes to detect underlying signs of anxiety and depression.
Jupyter Notebook
1
48 commits
updated Feb 3, 2026
The dataset has 8 categories
Lack of Interest
Self-Harm
Feeling Down
Concentration Problem
Lack of Energy
Sleeping Disorder
Low Self-Esteem
Eating Disorder
The dataset has 8 categories
Nervousness
Lack of Worry Control
Excessive Worry
Restlessness
Difficulty Relaxing
Impending Doom
Irritatbily
Unknown
Ignore the below Unknown images in the anxiety dataset: TR-2027, TR-2094, TR-212
Model for Depression (Multi-Label Classification)
Model for Anxiety (Single-Label Classification)
Overleaf document link: Overleaf
Common document (docs) link: Docs
Paper: Figurative-cum-Commonsense Knowledge Infusion for Multimodal Mental Health Meme Classification
The baseline implementation focuses on leveraging OCR text extracted from memes and using BERT embeddings for classification. The models were trained and evaluated using the following setup:
bert-base-uncased) with a classification head.BCEWithLogitsLoss).5e-50.90.9991e-81e-20.2165121.010best_model.pt) saved based on validation Macro F1 score.last_model.pt) saved after the final epoch.training_logs.csv) with epoch-wise metrics.test_report.txt).bert-base-uncased) with a classification head.5e-50.90.9991e-81e-20.2165121.010best_model.pt) saved based on validation Macro F1 score.last_model.pt) saved after the final epoch.training_logs.csv) with epoch-wise metrics.test_report.txt).OCR Text:
bert-base-uncased) with a maximum sequence length of 512.BERT Embeddings:
bert-base-uncased) are fine-tuned for both tasks.Training and Evaluation:
10 epochs using the AdamW optimizer and a constant learning rate scheduler.Outputs:
best_model.pt and last_model.pt) are saved in the respective output directories.training_logs.csv) and test evaluation results (test_report.txt) are saved for analysis.Summary of Metrics:
55.27%62.36%0.1067Explanation:
The depression task achieved similar performance to paper, with a Macro F1 Score of 55.27%, indicating balanced performance across all categories. The Weighted F1 Score of 62.36% reflects better performance on more frequent categories.
The Hamming Loss of 0.1067 suggests that the model makes relatively few errors in its predictions, which is expected for a multi-label classification task.
The training process shows consistent improvement in both Macro F1 and Weighted F1 scores across epochs, as seen in the training logs.
Compared to the paper's reported metrics (Macro F1 Score: 58.16%, Weighted F1 Score: 57.12%), the model's Weighted F1 Score surpasses the paper's results, while the Macro F1 Score is slightly lower, indicating room for improvement in balancing performance across all categories.
A training loss vs. epochs graph is available for visualization:

A F1 Scores vs. epochs graph is available for visualization:

A Validation Hamming Loss vs. epochs graph is available for visualization:

Summary of Metrics:
55.37%47.46%55.48%0.4463Class-wise Performance:
| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| Difficulty Relaxing | 71.43% | 63.73% | 67.36% | 102 |
| Excessive Worry | 46.85% | 56.52% | 51.23% | 92 |
| Impending Doom | 65.06% | 51.43% | 57.45% | 105 |
| Irritability | 46.43% | 35.14% | 40.00% | 37 |
| Lack of Worry Control | 57.30% | 54.26% | 55.74% | 94 |
| Nervousness | 60.17% | 66.98% | 63.39% | 106 |
| Restlessness | 41.67% | 47.83% | 44.53% | 115 |
| Unknown Anxiety | 0.00% | 0.00% | 0.00% | 1 |
Explanation:
The model achieved similar performance to paper on the anxiety task, with an overall accuracy of 55.37%. The Macro F1 Score of 47.46% indicates that the model's performance is not uniform across all classes, as it gives equal weight to each class regardless of its size. The Weighted F1 Score of 55.48% reflects better performance on larger classes like "Nervousness."
The Hamming Loss of 0.4463 suggests that the model makes errors in nearly half of the predictions, which is expected given the complexity of the task.
Class-wise, the model performed best on "Nervousness" with an F1-Score of 63.39%, while "Irritability" had the lowest F1-Score of 40.00%, indicating room for improvement in handling smaller or more ambiguous classes.
Compared to the paper's reported metrics (Macro F1 Score: 62.99%, Weighted F1 Score: 63.06%), the model's performance is lower, highlighting the need for further optimization to match or exceed the baseline results.
Additionally, we have included two extra classes, Irritability and Unknown Anxiety, which were not present in the paper. This may have contributed to the differences in performance metrics.
A training loss vs. epochs graph is available for visualization:

A F1 Scores vs. epochs graph is available for visualization:

A Validatioin Hamming Loss vs. epochs graph is available for visualization:


HyCore_M3Net (Hybrid Core Multimodal Mental Health Network) is a novel multimodal architecture specifically designed for mental health meme classification. The model combines:
The architecture follows this flow:
To run HyCore_M3Net, you'll need the following dependencies:
# Basic Libraries
pip install numpy pandas matplotlib tqdm
# Deep Learning
pip install torch torchvision
# Hugging Face Transformers and Models
pip install transformers==4.35.0 sentence-transformers==2.2.2
# Retrieval Components
pip install faiss-gpu # Use faiss-cpu for CPU-only environments
# Data Processing and Evaluation
pip install scikit-learn
pip install --no-cache-dir
torch==2.1.2
transformers==4.38.2
accelerate==0.28.0
sentence-transformers==2.7.0
faiss-cpu==1.8.0
scikit-learn==1.3.2
pandas==2.1.4
numpy==1.26.3
matplotlib==3.8.2
tqdm==4.66.2
Pillow==10.2.0
To run the HyCore_M3Net model from the terminal:
# Navigate to the project directory
cd mental-health-meme-classification
# Run for depression (multi-label) task
python src/shared/HyCore_M3Net.py
# To run for anxiety (single-label) task, edit the script
# Change line ~1187 from:
# dataset = 'depression'
# To:
# dataset = 'anxiety'
# Then run:
python src/shared/HyCore_M3Net.py
The model contains several configurable parameters:
MAX_LEN_LXMERT: Maximum token length for OCR text (default: 80)MAX_LEN_BART: Maximum token length for reasoning text (default: 512)BATCH_SIZE: Batch size for training (default: 8)NUM_EPOCHS: Number of training epochs (default: 10)LEARNING_RATE: Learning rate (default: 2e-5)NUM_ENSEMBLE_MODELS: Number of models for ensemble (default: 3)RETRIEVAL_K: Number of similar examples to retrieve for RAG (default: 3)These can be modified in the script to optimize performance based on your computational resources.
The model produces:
HyCore_M3Net leverages region-level visual information rather than just global image features. The model uses Detectron2 (with Faster R-CNN) to extract these region features:
The extracted features are stored in PyTorch (.pt) files as dictionaries with the following structure:
region_features = {
"image_id_1": {
"features": torch.tensor(...), # Shape: (num_boxes, 2048)
"boxes": torch.tensor(...) # Shape: (num_boxes, 4) - normalized coordinates
},
"image_id_2": {
# Same structure for each image
},
# ... more images
}
Each image entry contains:
Region Features (features):
(num_boxes, feature_dimension)num_boxes is the number of regions detected (typically 36-100)feature_dimension is 2048 for LXMERT compatibilityBounding Box Coordinates (boxes):
(num_boxes, 4)[x_min/W, y_min/H, x_max/W, y_max/H]This region-level approach allows the model to perform fine-grained visual reasoning about specific elements in memes, rather than just considering the image as a whole, significantly improving performance for mental health classification tasks.
Anxiety Output

Depression Output


Your project implements a sophisticated knowledge fusion approach for analyzing mental health memes, particularly those related to anxiety and depression. Let me explain how you're extracting and combining different types of features to create a comprehensive representation for RAG (Retrieval-Augmented Generation) during training.
Your system extracts three distinct types of information from each meme:
OCR Text (Textual Content)
Figurative Reasoning (Semantic Understanding)
Visual Features (Image Content)
You create a unified representation through concatenation:
Knowledge Fusion DB = [OCR Embedding | Figurative Reasoning Embedding | Image Embedding]
This results in a 3072-dimensional vector (3 × 1024) for each meme, containing complementary information from all three modalities.
Your code includes several sophisticated elements:
The resulting knowledge-fused embeddings serve as a comprehensive database for retrieval-augmented generation:
This approach is particularly valuable for meme analysis because:
By integrating OCR text, figurative reasoning, and visual features into a unified representation, your system creates a rich knowledge base that captures both the explicit and implicit meanings of mental health memes, enabling more nuanced analysis and generation.
For each training, we have preprocessed the features and figurative reasoning into the dataset directory. The embeddings generated by the embeddings_extractor.py, then tok_k_rag_extractor.py generates the top k embeddings and store the csv into the dataset. Then rag_trainer.py trains the model on that dataset.


Pipeline flow for the inference. Technical Architecture The system combines multiple technologies:
Frontend: Streamlit web application
Text Extraction: EasyOCR
Reasoning Engine: Hyperbolic API (Qwen 2.5 VL 7B model)
Classification Models: Fine-tuned transformer models for depression and anxiety analysis
Inference Pipeline: Seamless flow from image upload to symptom detection
Usage
Upload a meme image using the sidebar
Select the desired analysis type (Depression or Anxiety)
The system will automatically perform OCR, reasoning, and classification
Review the results in the main panel

Run the application by: streamlit run mental-health-meme-classification/src/inference/web_ui.py
Ensure that model paths are correctly configured