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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- mental-health
|
| 7 |
+
- text-generation
|
| 8 |
+
- conversational-ai
|
| 9 |
+
- gpt2
|
| 10 |
+
pipeline_tag: text-generation
|
| 11 |
+
base_model: openai-community/gpt2
|
| 12 |
+
|
| 13 |
+
# GPT-2 (Fine-Tuned for MindPadi)
|
| 14 |
+
|
| 15 |
+
This is a fine-tuned version of GPT-2 for the **MindPadi** mental health chatbot. It has been adapted to generate empathetic, therapeutic, and contextually relevant responses for mental health support. It is the primary generative model used in long-form conversation and therapy-related dialogue management in MindPadi.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
## π§ Model Summary
|
| 20 |
+
|
| 21 |
+
- **Model Type:** GPT-2 (12-layer transformer)
|
| 22 |
+
- **Parameters:** ~124M
|
| 23 |
+
- **Fine-Tuned For:** Empathetic and supportive text generation
|
| 24 |
+
- **Used In:** `app/chatbot/fusion_bot.py`
|
| 25 |
+
- **Architecture:** Decoder-only transformer (causal LM)
|
| 26 |
+
- **Framework:** Hugging Face Transformers + PyTorch
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
## π§Ύ Intended Use
|
| 31 |
+
|
| 32 |
+
### βοΈ Primary Use Cases
|
| 33 |
+
- Generating thoughtful, compassionate responses in mental health conversations
|
| 34 |
+
- Completing sentences in a therapy dialogue setting
|
| 35 |
+
- Supporting GPTFusion workflows in MindPadi backend
|
| 36 |
+
|
| 37 |
+
### π« Not Recommended For
|
| 38 |
+
- Clinical diagnoses or medical decisions
|
| 39 |
+
- Domains outside mental health (e.g., finance, legal)
|
| 40 |
+
- Multilingual generation (trained on English only)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
## ποΈββοΈ Training Details
|
| 45 |
+
|
| 46 |
+
- **Base Model:** `gpt2` from Hugging Face
|
| 47 |
+
- **Fine-Tuning Script:** `training/finetune_gpt2_pipeline.py`
|
| 48 |
+
- **Datasets:** Mental health dialogue datasets (e.g., therapy transcripts, Reddit mental health subreddits)
|
| 49 |
+
- Location: `training/datasets/finetuned/`
|
| 50 |
+
- **Preprocessing:**
|
| 51 |
+
- Cleaned for profanity, PII, and formatting noise
|
| 52 |
+
- Converted to conversation format: `User: ... Assistant: ...`
|
| 53 |
+
|
| 54 |
+
### Hyperparameters
|
| 55 |
+
- Epochs: 3β5
|
| 56 |
+
- Batch Size: 4β8
|
| 57 |
+
- Learning Rate: 5e-5
|
| 58 |
+
- Warmup Steps: 200
|
| 59 |
+
- Optimizer: AdamW
|
| 60 |
+
|
| 61 |
+
### Hardware
|
| 62 |
+
- NVIDIA RTX 2080 / A100 / equivalent (local or cloud)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
## π Evaluation
|
| 67 |
+
|
| 68 |
+
- **Evaluation Script:** `training/evaluate_model.py`
|
| 69 |
+
- **Metrics:**
|
| 70 |
+
- Perplexity: Reduced ~20% compared to base GPT-2
|
| 71 |
+
- BLEU Score: Improved ~12% in test responses
|
| 72 |
+
- Human Evaluation: Higher relevance and emotional alignment in blind tests
|
| 73 |
+
- **Examples:** Available in `logs/training.log` and test dialogues
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
## π Files
|
| 78 |
+
|
| 79 |
+
| File | Purpose |
|
| 80 |
+
|------|---------|
|
| 81 |
+
| `config.json` | Model architecture |
|
| 82 |
+
| `pytorch_model.bin` or `model.safetensors` | Fine-tuned weights |
|
| 83 |
+
| `tokenizer.json`, `vocab.json`, `merges.txt` | Tokenizer and BPE merge rules |
|
| 84 |
+
| `checkpoint-*/` | Intermediate training checkpoints (optional) |
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
## π¬ Example Usage
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 92 |
+
|
| 93 |
+
model = GPT2LMHeadModel.from_pretrained("mindpadi/gpt2")
|
| 94 |
+
tokenizer = GPT2Tokenizer.from_pretrained("mindpadi/gpt2")
|
| 95 |
+
|
| 96 |
+
prompt = "User: I feel hopeless and tired.\nAssistant:"
|
| 97 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 98 |
+
outputs = model.generate(**inputs, max_length=100, do_sample=True)
|
| 99 |
+
|
| 100 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 101 |
+
````
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
## π§ Integration in MindPadi
|
| 106 |
+
|
| 107 |
+
This model is integrated into:
|
| 108 |
+
|
| 109 |
+
* `app/chatbot/fusion_bot.py`: Primary text generator
|
| 110 |
+
* `app/chatbot/gpt_router.py`: Fusion routing between GPT-2 and DistilGPT2
|
| 111 |
+
* `app/chatbot/core.py`: Chat interface logic
|
| 112 |
+
* LangGraph workflows: Via GPTFusionRouter nodes
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
## β οΈ Limitations
|
| 117 |
+
|
| 118 |
+
* **Bias:** May carry biases from internet pretraining or mental health corpora
|
| 119 |
+
* **Language:** English-only
|
| 120 |
+
* **Token Limit:** \~1024 tokens context window
|
| 121 |
+
* **Sensitivity:** May generate inappropriate responses if inputs are adversarial or out-of-distribution
|
| 122 |
+
* **Non-Determinism:** Sampling may produce varied outputs even for the same input
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
## π Ethical Considerations
|
| 127 |
+
|
| 128 |
+
* Not intended for crisis response or as a substitute for professional help
|
| 129 |
+
* Includes guardrails to detect emergency keywords (e.g., "suicide", "abuse")
|
| 130 |
+
* Should always inform users they are interacting with AI (see `chat_interface.py`)
|
| 131 |
+
* Responses are not clinically validated; user discretion advised
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
## π§ͺ Deployment
|
| 136 |
+
|
| 137 |
+
You can deploy this model via Hugging Face Inference Endpoints for GPU-powered responses.
|
| 138 |
+
|
| 139 |
+
```python
|
| 140 |
+
import requests
|
| 141 |
+
|
| 142 |
+
api_url = "https://<your-endpoint>.hf.space"
|
| 143 |
+
headers = {"Authorization": f"Bearer <your-token>", "Content-Type": "application/json"}
|
| 144 |
+
|
| 145 |
+
payload = {"inputs": "User: I feel anxious.\nAssistant:"}
|
| 146 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
| 147 |
+
print(response.json())
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
## π License
|
| 153 |
+
|
| 154 |
+
MIT License β Free for commercial and non-commercial use with attribution.
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
## π¬ Contact
|
| 159 |
+
|
| 160 |
+
* **Project:** [MindPadi AI Chatbot](https://huggingface.co/mindpadi)
|
| 161 |
+
* **Maintainer:** MindPadi Team
|
| 162 |
+
* **Email:** \[[you@example.com](mailto:you@example.com)]
|
| 163 |
+
* **GitHub:** \[github.com/mindpadi/mindpadi]
|
| 164 |
+
|
| 165 |
+
*Last updated: May 2025*
|