scdong commited on
Commit
bd30f7c
·
verified ·
1 Parent(s): b03ee16

Upload 10 files

Browse files
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Base image
2
+ FROM python:3.10-slim
3
+
4
+ # System dependencies
5
+ RUN apt-get update && apt-get install -y \
6
+ build-essential \
7
+ cmake \
8
+ git \
9
+ curl \
10
+ ninja-build \
11
+ libopenblas-dev \
12
+ && apt-get clean
13
+
14
+ # Set working directory
15
+ WORKDIR /app
16
+
17
+ # Copy requirements and install
18
+ COPY requirements.txt .
19
+ RUN pip install --upgrade pip && \
20
+ pip install --no-cache-dir --prefer-binary -r requirements.txt
21
+
22
+ # Copy the rest of the app
23
+ COPY . .
24
+
25
+ # Run the app
26
+ CMD ["streamlit", "run", "app_local.py", "--server.port=8501", "--server.address=0.0.0.0"]
Flan-T5_on_Kaggle_Dataset.ipynb ADDED
@@ -0,0 +1,859 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "01991402-68d2-4cfb-9b3a-22f170ccf74b",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Build a smart assistant to help mental health counselors respond thoughtfully to patients. "
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "markdown",
13
+ "id": "f643f217-faf3-4b5a-9f14-63b898a4d7b8",
14
+ "metadata": {},
15
+ "source": [
16
+ "## The Mental Health Chatbot (Multi-Turn with LLM + Classifier) works in **two steps**:\n",
17
+ "\n",
18
+ "1. **Understanding the situation**: When you describe a patient's issue, the system uses a machine learning model to figure out what kind of response might be most helpful—like giving advice, validating feelings, asking a follow-up question, or sharing some mental health information.\n",
19
+ "\n",
20
+ "2. **Generating a helpful reply**: After the system decides what type of response is appropriate, it asks a language model (Flan-T5) to write a suggestion based on that need. For example, if the model thinks the user needs validation, it will ask the LLM to generate an empathetic and supportive response.\n",
21
+ "\n"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "markdown",
26
+ "id": "0cae93e4-7e58-4497-8047-4a069bc7a6c6",
27
+ "metadata": {},
28
+ "source": [
29
+ "## This following python code does:\n",
30
+ "- Classifies user messages into response types (advice, validation, information, question)\n",
31
+ "- Uses a language model (Flan-T5) to generate counselor-like responses\n",
32
+ "- Maintains a limited conversation history\n",
33
+ "- Allows exporting conversation history to a JSON file"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "markdown",
38
+ "id": "d29686fa-8db3-4447-9970-da864a96dc64",
39
+ "metadata": {},
40
+ "source": [
41
+ "### Load Required Libraries"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 1,
47
+ "id": "8375290a-0034-4050-af72-c76183020bec",
48
+ "metadata": {},
49
+ "outputs": [
50
+ {
51
+ "name": "stderr",
52
+ "output_type": "stream",
53
+ "text": [
54
+ "/Users/Pi/miniconda3/envs/myenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
55
+ " from .autonotebook import tqdm as notebook_tqdm\n"
56
+ ]
57
+ }
58
+ ],
59
+ "source": [
60
+ "import json\n",
61
+ "import pandas as pd\n",
62
+ "import numpy as np\n",
63
+ "import matplotlib.pyplot as plt\n",
64
+ "import seaborn as sns\n",
65
+ "from sklearn.model_selection import train_test_split\n",
66
+ "from sklearn.feature_extraction.text import TfidfVectorizer\n",
67
+ "from sklearn.preprocessing import LabelEncoder\n",
68
+ "from xgboost import XGBClassifier\n",
69
+ "from transformers import pipeline"
70
+ ]
71
+ },
72
+ {
73
+ "cell_type": "markdown",
74
+ "id": "c15554b4-d47f-4052-a18d-a51742065fc4",
75
+ "metadata": {},
76
+ "source": [
77
+ "### Load and Label Dataset "
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": 2,
83
+ "id": "dbb763bb-eaa1-45ce-ad03-3d6bb300c4e4",
84
+ "metadata": {},
85
+ "outputs": [],
86
+ "source": [
87
+ "df = pd.read_csv(\"dataset/Kaggle_Mental_Health_Conversations_train.csv\")\n",
88
+ "df = df[['Context', 'Response']].dropna().copy()\n",
89
+ "\n",
90
+ "keywords_to_labels = {\n",
91
+ " 'advice': ['try', 'should', 'suggest', 'recommend'],\n",
92
+ " 'validation': ['understand', 'feel', 'valid', 'normal'],\n",
93
+ " 'information': ['cause', 'often', 'disorder', 'symptom'],\n",
94
+ " 'question': ['how', 'what', 'why', 'have you']\n",
95
+ "}\n",
96
+ "\n",
97
+ "def auto_label_response(response):\n",
98
+ " response = response.lower()\n",
99
+ " for label, keywords in keywords_to_labels.items():\n",
100
+ " if any(word in response for word in keywords):\n",
101
+ " return label\n",
102
+ " return 'information'\n",
103
+ "\n",
104
+ "df['response_type'] = df['Response'].apply(auto_label_response)\n",
105
+ "\n"
106
+ ]
107
+ },
108
+ {
109
+ "cell_type": "markdown",
110
+ "id": "3cc76163-b688-49b1-a5ab-3f991e6a790b",
111
+ "metadata": {},
112
+ "source": [
113
+ "### Train on Combined Context + Response"
114
+ ]
115
+ },
116
+ {
117
+ "cell_type": "code",
118
+ "execution_count": 3,
119
+ "id": "5aff7aff-7756-4c28-9424-9a9963580883",
120
+ "metadata": {},
121
+ "outputs": [
122
+ {
123
+ "name": "stderr",
124
+ "output_type": "stream",
125
+ "text": [
126
+ "/Users/Pi/miniconda3/envs/myenv/lib/python3.10/site-packages/xgboost/training.py:183: UserWarning: [22:52:39] WARNING: /Users/runner/work/xgboost/xgboost/src/learner.cc:738: \n",
127
+ "Parameters: { \"use_label_encoder\" } are not used.\n",
128
+ "\n",
129
+ " bst.update(dtrain, iteration=i, fobj=obj)\n"
130
+ ]
131
+ },
132
+ {
133
+ "data": {
134
+ "text/html": [
135
+ "<style>#sk-container-id-1 {\n",
136
+ " /* Definition of color scheme common for light and dark mode */\n",
137
+ " --sklearn-color-text: #000;\n",
138
+ " --sklearn-color-text-muted: #666;\n",
139
+ " --sklearn-color-line: gray;\n",
140
+ " /* Definition of color scheme for unfitted estimators */\n",
141
+ " --sklearn-color-unfitted-level-0: #fff5e6;\n",
142
+ " --sklearn-color-unfitted-level-1: #f6e4d2;\n",
143
+ " --sklearn-color-unfitted-level-2: #ffe0b3;\n",
144
+ " --sklearn-color-unfitted-level-3: chocolate;\n",
145
+ " /* Definition of color scheme for fitted estimators */\n",
146
+ " --sklearn-color-fitted-level-0: #f0f8ff;\n",
147
+ " --sklearn-color-fitted-level-1: #d4ebff;\n",
148
+ " --sklearn-color-fitted-level-2: #b3dbfd;\n",
149
+ " --sklearn-color-fitted-level-3: cornflowerblue;\n",
150
+ "\n",
151
+ " /* Specific color for light theme */\n",
152
+ " --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
153
+ " --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
154
+ " --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
155
+ " --sklearn-color-icon: #696969;\n",
156
+ "\n",
157
+ " @media (prefers-color-scheme: dark) {\n",
158
+ " /* Redefinition of color scheme for dark theme */\n",
159
+ " --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
160
+ " --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
161
+ " --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
162
+ " --sklearn-color-icon: #878787;\n",
163
+ " }\n",
164
+ "}\n",
165
+ "\n",
166
+ "#sk-container-id-1 {\n",
167
+ " color: var(--sklearn-color-text);\n",
168
+ "}\n",
169
+ "\n",
170
+ "#sk-container-id-1 pre {\n",
171
+ " padding: 0;\n",
172
+ "}\n",
173
+ "\n",
174
+ "#sk-container-id-1 input.sk-hidden--visually {\n",
175
+ " border: 0;\n",
176
+ " clip: rect(1px 1px 1px 1px);\n",
177
+ " clip: rect(1px, 1px, 1px, 1px);\n",
178
+ " height: 1px;\n",
179
+ " margin: -1px;\n",
180
+ " overflow: hidden;\n",
181
+ " padding: 0;\n",
182
+ " position: absolute;\n",
183
+ " width: 1px;\n",
184
+ "}\n",
185
+ "\n",
186
+ "#sk-container-id-1 div.sk-dashed-wrapped {\n",
187
+ " border: 1px dashed var(--sklearn-color-line);\n",
188
+ " margin: 0 0.4em 0.5em 0.4em;\n",
189
+ " box-sizing: border-box;\n",
190
+ " padding-bottom: 0.4em;\n",
191
+ " background-color: var(--sklearn-color-background);\n",
192
+ "}\n",
193
+ "\n",
194
+ "#sk-container-id-1 div.sk-container {\n",
195
+ " /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
196
+ " but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
197
+ " so we also need the `!important` here to be able to override the\n",
198
+ " default hidden behavior on the sphinx rendered scikit-learn.org.\n",
199
+ " See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
200
+ " display: inline-block !important;\n",
201
+ " position: relative;\n",
202
+ "}\n",
203
+ "\n",
204
+ "#sk-container-id-1 div.sk-text-repr-fallback {\n",
205
+ " display: none;\n",
206
+ "}\n",
207
+ "\n",
208
+ "div.sk-parallel-item,\n",
209
+ "div.sk-serial,\n",
210
+ "div.sk-item {\n",
211
+ " /* draw centered vertical line to link estimators */\n",
212
+ " background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
213
+ " background-size: 2px 100%;\n",
214
+ " background-repeat: no-repeat;\n",
215
+ " background-position: center center;\n",
216
+ "}\n",
217
+ "\n",
218
+ "/* Parallel-specific style estimator block */\n",
219
+ "\n",
220
+ "#sk-container-id-1 div.sk-parallel-item::after {\n",
221
+ " content: \"\";\n",
222
+ " width: 100%;\n",
223
+ " border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
224
+ " flex-grow: 1;\n",
225
+ "}\n",
226
+ "\n",
227
+ "#sk-container-id-1 div.sk-parallel {\n",
228
+ " display: flex;\n",
229
+ " align-items: stretch;\n",
230
+ " justify-content: center;\n",
231
+ " background-color: var(--sklearn-color-background);\n",
232
+ " position: relative;\n",
233
+ "}\n",
234
+ "\n",
235
+ "#sk-container-id-1 div.sk-parallel-item {\n",
236
+ " display: flex;\n",
237
+ " flex-direction: column;\n",
238
+ "}\n",
239
+ "\n",
240
+ "#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
241
+ " align-self: flex-end;\n",
242
+ " width: 50%;\n",
243
+ "}\n",
244
+ "\n",
245
+ "#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
246
+ " align-self: flex-start;\n",
247
+ " width: 50%;\n",
248
+ "}\n",
249
+ "\n",
250
+ "#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
251
+ " width: 0;\n",
252
+ "}\n",
253
+ "\n",
254
+ "/* Serial-specific style estimator block */\n",
255
+ "\n",
256
+ "#sk-container-id-1 div.sk-serial {\n",
257
+ " display: flex;\n",
258
+ " flex-direction: column;\n",
259
+ " align-items: center;\n",
260
+ " background-color: var(--sklearn-color-background);\n",
261
+ " padding-right: 1em;\n",
262
+ " padding-left: 1em;\n",
263
+ "}\n",
264
+ "\n",
265
+ "\n",
266
+ "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
267
+ "clickable and can be expanded/collapsed.\n",
268
+ "- Pipeline and ColumnTransformer use this feature and define the default style\n",
269
+ "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
270
+ "*/\n",
271
+ "\n",
272
+ "/* Pipeline and ColumnTransformer style (default) */\n",
273
+ "\n",
274
+ "#sk-container-id-1 div.sk-toggleable {\n",
275
+ " /* Default theme specific background. It is overwritten whether we have a\n",
276
+ " specific estimator or a Pipeline/ColumnTransformer */\n",
277
+ " background-color: var(--sklearn-color-background);\n",
278
+ "}\n",
279
+ "\n",
280
+ "/* Toggleable label */\n",
281
+ "#sk-container-id-1 label.sk-toggleable__label {\n",
282
+ " cursor: pointer;\n",
283
+ " display: flex;\n",
284
+ " width: 100%;\n",
285
+ " margin-bottom: 0;\n",
286
+ " padding: 0.5em;\n",
287
+ " box-sizing: border-box;\n",
288
+ " text-align: center;\n",
289
+ " align-items: start;\n",
290
+ " justify-content: space-between;\n",
291
+ " gap: 0.5em;\n",
292
+ "}\n",
293
+ "\n",
294
+ "#sk-container-id-1 label.sk-toggleable__label .caption {\n",
295
+ " font-size: 0.6rem;\n",
296
+ " font-weight: lighter;\n",
297
+ " color: var(--sklearn-color-text-muted);\n",
298
+ "}\n",
299
+ "\n",
300
+ "#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
301
+ " /* Arrow on the left of the label */\n",
302
+ " content: \"▸\";\n",
303
+ " float: left;\n",
304
+ " margin-right: 0.25em;\n",
305
+ " color: var(--sklearn-color-icon);\n",
306
+ "}\n",
307
+ "\n",
308
+ "#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
309
+ " color: var(--sklearn-color-text);\n",
310
+ "}\n",
311
+ "\n",
312
+ "/* Toggleable content - dropdown */\n",
313
+ "\n",
314
+ "#sk-container-id-1 div.sk-toggleable__content {\n",
315
+ " max-height: 0;\n",
316
+ " max-width: 0;\n",
317
+ " overflow: hidden;\n",
318
+ " text-align: left;\n",
319
+ " /* unfitted */\n",
320
+ " background-color: var(--sklearn-color-unfitted-level-0);\n",
321
+ "}\n",
322
+ "\n",
323
+ "#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
324
+ " /* fitted */\n",
325
+ " background-color: var(--sklearn-color-fitted-level-0);\n",
326
+ "}\n",
327
+ "\n",
328
+ "#sk-container-id-1 div.sk-toggleable__content pre {\n",
329
+ " margin: 0.2em;\n",
330
+ " border-radius: 0.25em;\n",
331
+ " color: var(--sklearn-color-text);\n",
332
+ " /* unfitted */\n",
333
+ " background-color: var(--sklearn-color-unfitted-level-0);\n",
334
+ "}\n",
335
+ "\n",
336
+ "#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
337
+ " /* unfitted */\n",
338
+ " background-color: var(--sklearn-color-fitted-level-0);\n",
339
+ "}\n",
340
+ "\n",
341
+ "#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
342
+ " /* Expand drop-down */\n",
343
+ " max-height: 200px;\n",
344
+ " max-width: 100%;\n",
345
+ " overflow: auto;\n",
346
+ "}\n",
347
+ "\n",
348
+ "#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
349
+ " content: \"▾\";\n",
350
+ "}\n",
351
+ "\n",
352
+ "/* Pipeline/ColumnTransformer-specific style */\n",
353
+ "\n",
354
+ "#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
355
+ " color: var(--sklearn-color-text);\n",
356
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
357
+ "}\n",
358
+ "\n",
359
+ "#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
360
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
361
+ "}\n",
362
+ "\n",
363
+ "/* Estimator-specific style */\n",
364
+ "\n",
365
+ "/* Colorize estimator box */\n",
366
+ "#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
367
+ " /* unfitted */\n",
368
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
369
+ "}\n",
370
+ "\n",
371
+ "#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
372
+ " /* fitted */\n",
373
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
374
+ "}\n",
375
+ "\n",
376
+ "#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
377
+ "#sk-container-id-1 div.sk-label label {\n",
378
+ " /* The background is the default theme color */\n",
379
+ " color: var(--sklearn-color-text-on-default-background);\n",
380
+ "}\n",
381
+ "\n",
382
+ "/* On hover, darken the color of the background */\n",
383
+ "#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
384
+ " color: var(--sklearn-color-text);\n",
385
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
386
+ "}\n",
387
+ "\n",
388
+ "/* Label box, darken color on hover, fitted */\n",
389
+ "#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
390
+ " color: var(--sklearn-color-text);\n",
391
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
392
+ "}\n",
393
+ "\n",
394
+ "/* Estimator label */\n",
395
+ "\n",
396
+ "#sk-container-id-1 div.sk-label label {\n",
397
+ " font-family: monospace;\n",
398
+ " font-weight: bold;\n",
399
+ " display: inline-block;\n",
400
+ " line-height: 1.2em;\n",
401
+ "}\n",
402
+ "\n",
403
+ "#sk-container-id-1 div.sk-label-container {\n",
404
+ " text-align: center;\n",
405
+ "}\n",
406
+ "\n",
407
+ "/* Estimator-specific */\n",
408
+ "#sk-container-id-1 div.sk-estimator {\n",
409
+ " font-family: monospace;\n",
410
+ " border: 1px dotted var(--sklearn-color-border-box);\n",
411
+ " border-radius: 0.25em;\n",
412
+ " box-sizing: border-box;\n",
413
+ " margin-bottom: 0.5em;\n",
414
+ " /* unfitted */\n",
415
+ " background-color: var(--sklearn-color-unfitted-level-0);\n",
416
+ "}\n",
417
+ "\n",
418
+ "#sk-container-id-1 div.sk-estimator.fitted {\n",
419
+ " /* fitted */\n",
420
+ " background-color: var(--sklearn-color-fitted-level-0);\n",
421
+ "}\n",
422
+ "\n",
423
+ "/* on hover */\n",
424
+ "#sk-container-id-1 div.sk-estimator:hover {\n",
425
+ " /* unfitted */\n",
426
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
427
+ "}\n",
428
+ "\n",
429
+ "#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
430
+ " /* fitted */\n",
431
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
432
+ "}\n",
433
+ "\n",
434
+ "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
435
+ "\n",
436
+ "/* Common style for \"i\" and \"?\" */\n",
437
+ "\n",
438
+ ".sk-estimator-doc-link,\n",
439
+ "a:link.sk-estimator-doc-link,\n",
440
+ "a:visited.sk-estimator-doc-link {\n",
441
+ " float: right;\n",
442
+ " font-size: smaller;\n",
443
+ " line-height: 1em;\n",
444
+ " font-family: monospace;\n",
445
+ " background-color: var(--sklearn-color-background);\n",
446
+ " border-radius: 1em;\n",
447
+ " height: 1em;\n",
448
+ " width: 1em;\n",
449
+ " text-decoration: none !important;\n",
450
+ " margin-left: 0.5em;\n",
451
+ " text-align: center;\n",
452
+ " /* unfitted */\n",
453
+ " border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
454
+ " color: var(--sklearn-color-unfitted-level-1);\n",
455
+ "}\n",
456
+ "\n",
457
+ ".sk-estimator-doc-link.fitted,\n",
458
+ "a:link.sk-estimator-doc-link.fitted,\n",
459
+ "a:visited.sk-estimator-doc-link.fitted {\n",
460
+ " /* fitted */\n",
461
+ " border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
462
+ " color: var(--sklearn-color-fitted-level-1);\n",
463
+ "}\n",
464
+ "\n",
465
+ "/* On hover */\n",
466
+ "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
467
+ ".sk-estimator-doc-link:hover,\n",
468
+ "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
469
+ ".sk-estimator-doc-link:hover {\n",
470
+ " /* unfitted */\n",
471
+ " background-color: var(--sklearn-color-unfitted-level-3);\n",
472
+ " color: var(--sklearn-color-background);\n",
473
+ " text-decoration: none;\n",
474
+ "}\n",
475
+ "\n",
476
+ "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
477
+ ".sk-estimator-doc-link.fitted:hover,\n",
478
+ "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
479
+ ".sk-estimator-doc-link.fitted:hover {\n",
480
+ " /* fitted */\n",
481
+ " background-color: var(--sklearn-color-fitted-level-3);\n",
482
+ " color: var(--sklearn-color-background);\n",
483
+ " text-decoration: none;\n",
484
+ "}\n",
485
+ "\n",
486
+ "/* Span, style for the box shown on hovering the info icon */\n",
487
+ ".sk-estimator-doc-link span {\n",
488
+ " display: none;\n",
489
+ " z-index: 9999;\n",
490
+ " position: relative;\n",
491
+ " font-weight: normal;\n",
492
+ " right: .2ex;\n",
493
+ " padding: .5ex;\n",
494
+ " margin: .5ex;\n",
495
+ " width: min-content;\n",
496
+ " min-width: 20ex;\n",
497
+ " max-width: 50ex;\n",
498
+ " color: var(--sklearn-color-text);\n",
499
+ " box-shadow: 2pt 2pt 4pt #999;\n",
500
+ " /* unfitted */\n",
501
+ " background: var(--sklearn-color-unfitted-level-0);\n",
502
+ " border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
503
+ "}\n",
504
+ "\n",
505
+ ".sk-estimator-doc-link.fitted span {\n",
506
+ " /* fitted */\n",
507
+ " background: var(--sklearn-color-fitted-level-0);\n",
508
+ " border: var(--sklearn-color-fitted-level-3);\n",
509
+ "}\n",
510
+ "\n",
511
+ ".sk-estimator-doc-link:hover span {\n",
512
+ " display: block;\n",
513
+ "}\n",
514
+ "\n",
515
+ "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
516
+ "\n",
517
+ "#sk-container-id-1 a.estimator_doc_link {\n",
518
+ " float: right;\n",
519
+ " font-size: 1rem;\n",
520
+ " line-height: 1em;\n",
521
+ " font-family: monospace;\n",
522
+ " background-color: var(--sklearn-color-background);\n",
523
+ " border-radius: 1rem;\n",
524
+ " height: 1rem;\n",
525
+ " width: 1rem;\n",
526
+ " text-decoration: none;\n",
527
+ " /* unfitted */\n",
528
+ " color: var(--sklearn-color-unfitted-level-1);\n",
529
+ " border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
530
+ "}\n",
531
+ "\n",
532
+ "#sk-container-id-1 a.estimator_doc_link.fitted {\n",
533
+ " /* fitted */\n",
534
+ " border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
535
+ " color: var(--sklearn-color-fitted-level-1);\n",
536
+ "}\n",
537
+ "\n",
538
+ "/* On hover */\n",
539
+ "#sk-container-id-1 a.estimator_doc_link:hover {\n",
540
+ " /* unfitted */\n",
541
+ " background-color: var(--sklearn-color-unfitted-level-3);\n",
542
+ " color: var(--sklearn-color-background);\n",
543
+ " text-decoration: none;\n",
544
+ "}\n",
545
+ "\n",
546
+ "#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
547
+ " /* fitted */\n",
548
+ " background-color: var(--sklearn-color-fitted-level-3);\n",
549
+ "}\n",
550
+ "</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>XGBClassifier(base_score=None, booster=None, callbacks=None,\n",
551
+ " colsample_bylevel=None, colsample_bynode=None,\n",
552
+ " colsample_bytree=None, device=None, early_stopping_rounds=None,\n",
553
+ " enable_categorical=False, eval_metric=&#x27;mlogloss&#x27;,\n",
554
+ " feature_types=None, feature_weights=None, gamma=None,\n",
555
+ " grow_policy=None, importance_type=None,\n",
556
+ " interaction_constraints=None, learning_rate=0.1, max_bin=None,\n",
557
+ " max_cat_threshold=None, max_cat_to_onehot=None,\n",
558
+ " max_delta_step=None, max_depth=6, max_leaves=None,\n",
559
+ " min_child_weight=None, missing=nan, monotone_constraints=None,\n",
560
+ " multi_strategy=None, n_estimators=100, n_jobs=None, num_class=4, ...)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>XGBClassifier</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://xgboost.readthedocs.io/en/release_3.0.0/python/python_api.html#xgboost.XGBClassifier\">?<span>Documentation for XGBClassifier</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\"><pre>XGBClassifier(base_score=None, booster=None, callbacks=None,\n",
561
+ " colsample_bylevel=None, colsample_bynode=None,\n",
562
+ " colsample_bytree=None, device=None, early_stopping_rounds=None,\n",
563
+ " enable_categorical=False, eval_metric=&#x27;mlogloss&#x27;,\n",
564
+ " feature_types=None, feature_weights=None, gamma=None,\n",
565
+ " grow_policy=None, importance_type=None,\n",
566
+ " interaction_constraints=None, learning_rate=0.1, max_bin=None,\n",
567
+ " max_cat_threshold=None, max_cat_to_onehot=None,\n",
568
+ " max_delta_step=None, max_depth=6, max_leaves=None,\n",
569
+ " min_child_weight=None, missing=nan, monotone_constraints=None,\n",
570
+ " multi_strategy=None, n_estimators=100, n_jobs=None, num_class=4, ...)</pre></div> </div></div></div></div>"
571
+ ],
572
+ "text/plain": [
573
+ "XGBClassifier(base_score=None, booster=None, callbacks=None,\n",
574
+ " colsample_bylevel=None, colsample_bynode=None,\n",
575
+ " colsample_bytree=None, device=None, early_stopping_rounds=None,\n",
576
+ " enable_categorical=False, eval_metric='mlogloss',\n",
577
+ " feature_types=None, feature_weights=None, gamma=None,\n",
578
+ " grow_policy=None, importance_type=None,\n",
579
+ " interaction_constraints=None, learning_rate=0.1, max_bin=None,\n",
580
+ " max_cat_threshold=None, max_cat_to_onehot=None,\n",
581
+ " max_delta_step=None, max_depth=6, max_leaves=None,\n",
582
+ " min_child_weight=None, missing=nan, monotone_constraints=None,\n",
583
+ " multi_strategy=None, n_estimators=100, n_jobs=None, num_class=4, ...)"
584
+ ]
585
+ },
586
+ "execution_count": 3,
587
+ "metadata": {},
588
+ "output_type": "execute_result"
589
+ }
590
+ ],
591
+ "source": [
592
+ "df['combined_text'] = df['Context'] + \" \" + df['Response']\n",
593
+ "\n",
594
+ "le = LabelEncoder()\n",
595
+ "y = le.fit_transform(df['response_type'])\n",
596
+ "\n",
597
+ "vectorizer = TfidfVectorizer(max_features=2000, ngram_range=(1, 2))\n",
598
+ "X = vectorizer.fit_transform(df['combined_text'])\n",
599
+ "\n",
600
+ "X_train, X_test, y_train, y_test = train_test_split(\n",
601
+ " X, y, test_size=0.2, stratify=y, random_state=42\n",
602
+ ")\n",
603
+ "\n",
604
+ "xgb_model = XGBClassifier(\n",
605
+ " objective='multi:softmax',\n",
606
+ " num_class=len(le.classes_),\n",
607
+ " eval_metric='mlogloss',\n",
608
+ " use_label_encoder=False,\n",
609
+ " max_depth=6,\n",
610
+ " learning_rate=0.1,\n",
611
+ " n_estimators=100\n",
612
+ ")\n",
613
+ "xgb_model.fit(X_train, y_train)"
614
+ ]
615
+ },
616
+ {
617
+ "cell_type": "markdown",
618
+ "id": "c7b4e142-8479-4da0-8f6a-70e488f90349",
619
+ "metadata": {},
620
+ "source": [
621
+ "### Load LLM (Flan-T5)"
622
+ ]
623
+ },
624
+ {
625
+ "cell_type": "code",
626
+ "execution_count": 4,
627
+ "id": "ea35abb0-f2df-4331-b41a-965a9e42b4c5",
628
+ "metadata": {},
629
+ "outputs": [
630
+ {
631
+ "name": "stdout",
632
+ "output_type": "stream",
633
+ "text": [
634
+ "Loading Flan-T5 model... (this may take a few seconds)\n"
635
+ ]
636
+ },
637
+ {
638
+ "name": "stderr",
639
+ "output_type": "stream",
640
+ "text": [
641
+ "Device set to use mps:0\n"
642
+ ]
643
+ }
644
+ ],
645
+ "source": [
646
+ "print(\"Loading Flan-T5 model... (this may take a few seconds)\")\n",
647
+ "llm = pipeline(\"text2text-generation\", model=\"google/flan-t5-base\")"
648
+ ]
649
+ },
650
+ {
651
+ "cell_type": "markdown",
652
+ "id": "c1ccf043-7431-4767-9ac8-73c59fe46ccf",
653
+ "metadata": {},
654
+ "source": [
655
+ "### Prediction + Prompt Functions"
656
+ ]
657
+ },
658
+ {
659
+ "cell_type": "code",
660
+ "execution_count": 5,
661
+ "id": "982161f8-824c-45c2-b968-e6e7ad5e0874",
662
+ "metadata": {},
663
+ "outputs": [],
664
+ "source": [
665
+ "def predict_response_type(user_input):\n",
666
+ " combined = user_input + \" placeholder_response\"\n",
667
+ " vec = vectorizer.transform([combined])\n",
668
+ " prediction = xgb_model.predict(vec)[0]\n",
669
+ " predicted_class = le.inverse_transform([prediction])[0]\n",
670
+ " confidence = np.max(xgb_model.predict_proba(vec))\n",
671
+ " return predicted_class, confidence\n",
672
+ "\n",
673
+ "def prompt_templates(user_input, response_type):\n",
674
+ " templates = {\n",
675
+ " \"advice\": f\"A student said: \\\"{user_input}\\\". What practical advice should a mental health counselor offer?\",\n",
676
+ " \"validation\": f\"A student said: \\\"{user_input}\\\". Respond with an emotionally supportive message that shows empathy and validates their feelings.\",\n",
677
+ " \"information\": f\"A student said: \\\"{user_input}\\\". Explain what might be happening emotionally from a counselor's perspective.\",\n",
678
+ " \"question\": f\"A student said: \\\"{user_input}\\\". What are 1-2 thoughtful follow-up questions a counselor might ask?\"\n",
679
+ " }\n",
680
+ " return templates.get(response_type, templates[\"information\"])\n",
681
+ "\n",
682
+ "def generate_llm_response(user_input, response_type):\n",
683
+ " prompt = prompt_templates(user_input, response_type)\n",
684
+ " result = llm(prompt, max_length=150, do_sample=True, temperature=0.7, top_p=0.9)\n",
685
+ " return result[0][\"generated_text\"].strip()"
686
+ ]
687
+ },
688
+ {
689
+ "cell_type": "markdown",
690
+ "id": "8599f696-9a22-4f03-9021-596b46febf26",
691
+ "metadata": {},
692
+ "source": [
693
+ "### Conversation Memory + Exporting"
694
+ ]
695
+ },
696
+ {
697
+ "cell_type": "code",
698
+ "execution_count": 6,
699
+ "id": "f95ba731-e303-42b2-a46d-143f5aaeb914",
700
+ "metadata": {},
701
+ "outputs": [],
702
+ "source": [
703
+ "MAX_MEMORY_TURNS = 6\n",
704
+ "history = []\n",
705
+ "\n",
706
+ "def trim_memory(history, max_turns=MAX_MEMORY_TURNS):\n",
707
+ " return history[-max_turns:]\n",
708
+ "\n",
709
+ "def save_conversation(history, filename=\"chat_history.json\"):\n",
710
+ " with open(filename, \"w\") as f:\n",
711
+ " json.dump(history, f, indent=2)\n",
712
+ " print(f\"\\nConversation saved to {filename}\")"
713
+ ]
714
+ },
715
+ {
716
+ "cell_type": "markdown",
717
+ "id": "74e2aba2-20fd-48b7-b770-8206aa9fb396",
718
+ "metadata": {},
719
+ "source": [
720
+ "### Intro + Chat"
721
+ ]
722
+ },
723
+ {
724
+ "cell_type": "code",
725
+ "execution_count": 7,
726
+ "id": "f3e4b5a8-f2b0-4ed4-b6d3-23541f615c0a",
727
+ "metadata": {},
728
+ "outputs": [
729
+ {
730
+ "name": "stdout",
731
+ "output_type": "stream",
732
+ "text": [
733
+ "\n",
734
+ "--- Multi-Turn Mental Health Chatbot ---\n",
735
+ "This assistant simulates a counselor's conversation using AI.\n",
736
+ "- Type something your patient/student might say\n",
737
+ "- Type 'save' to export the conversation\n",
738
+ "- Type 'exit' to quit\n",
739
+ "\n",
740
+ "Example:\n",
741
+ "User: I feel like I’ll mess up my big presentation tomorrow.\n",
742
+ "Counselor: It’s completely normal to feel nervous before a big event...\n",
743
+ "\n"
744
+ ]
745
+ }
746
+ ],
747
+ "source": [
748
+ "def show_intro():\n",
749
+ " print(\"\\n--- Multi-Turn Mental Health Chatbot ---\")\n",
750
+ " print(\"This assistant simulates a counselor's conversation using AI.\")\n",
751
+ " print(\"- Type something your patient/student might say\")\n",
752
+ " print(\"- Type 'save' to export the conversation\")\n",
753
+ " print(\"- Type 'exit' to quit\\n\")\n",
754
+ "\n",
755
+ " print(\"Example:\")\n",
756
+ " print(\"User: I feel like I’ll mess up my big presentation tomorrow.\")\n",
757
+ " print(\"Counselor: It’s completely normal to feel nervous before a big event...\\n\")\n",
758
+ "\n",
759
+ "show_intro()"
760
+ ]
761
+ },
762
+ {
763
+ "cell_type": "markdown",
764
+ "id": "1b818787-dab2-4d0c-a384-55cfc6072b9d",
765
+ "metadata": {},
766
+ "source": [
767
+ "### Chat Loop"
768
+ ]
769
+ },
770
+ {
771
+ "cell_type": "code",
772
+ "execution_count": 8,
773
+ "id": "748b8c59-fbc0-4ca3-814f-5f299128fddd",
774
+ "metadata": {},
775
+ "outputs": [
776
+ {
777
+ "name": "stdin",
778
+ "output_type": "stream",
779
+ "text": [
780
+ "User: i'm nervous\n"
781
+ ]
782
+ },
783
+ {
784
+ "name": "stdout",
785
+ "output_type": "stream",
786
+ "text": [
787
+ "(Predicted: information, Confidence: 85.5%)\n",
788
+ "Counselor: The student might be feeling anxious or uncertain about the situation.\n"
789
+ ]
790
+ },
791
+ {
792
+ "name": "stdin",
793
+ "output_type": "stream",
794
+ "text": [
795
+ "User: exit\n"
796
+ ]
797
+ },
798
+ {
799
+ "name": "stdout",
800
+ "output_type": "stream",
801
+ "text": [
802
+ "Goodbye\n"
803
+ ]
804
+ }
805
+ ],
806
+ "source": [
807
+ "while True:\n",
808
+ " user_input = input(\"User: \").strip()\n",
809
+ "\n",
810
+ " if user_input.lower() == \"exit\":\n",
811
+ " print(\"Goodbye\")\n",
812
+ " break\n",
813
+ " elif user_input.lower() == \"save\":\n",
814
+ " save_conversation(history)\n",
815
+ " continue\n",
816
+ "\n",
817
+ " predicted_type, confidence = predict_response_type(user_input)\n",
818
+ " print(f\"(Predicted: {predicted_type}, Confidence: {confidence:.1%})\")\n",
819
+ "\n",
820
+ " llm_reply = generate_llm_response(user_input, predicted_type)\n",
821
+ "\n",
822
+ " history.append({\"role\": \"user\", \"content\": user_input})\n",
823
+ " history.append({\"role\": \"assistant\", \"content\": llm_reply})\n",
824
+ " history = trim_memory(history)\n",
825
+ "\n",
826
+ " print(\"Counselor:\", llm_reply)"
827
+ ]
828
+ },
829
+ {
830
+ "cell_type": "code",
831
+ "execution_count": null,
832
+ "id": "72251dc9-6090-4448-8fe9-04ad82079520",
833
+ "metadata": {},
834
+ "outputs": [],
835
+ "source": []
836
+ }
837
+ ],
838
+ "metadata": {
839
+ "kernelspec": {
840
+ "display_name": "Python (myenv)",
841
+ "language": "python",
842
+ "name": "myenv"
843
+ },
844
+ "language_info": {
845
+ "codemirror_mode": {
846
+ "name": "ipython",
847
+ "version": 3
848
+ },
849
+ "file_extension": ".py",
850
+ "mimetype": "text/x-python",
851
+ "name": "python",
852
+ "nbconvert_exporter": "python",
853
+ "pygments_lexer": "ipython3",
854
+ "version": "3.10.16"
855
+ }
856
+ },
857
+ "nbformat": 4,
858
+ "nbformat_minor": 5
859
+ }
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Stella Dong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
ML_on_Kaggle_Dataset.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
Mistral-7B_on_Kaggle_Dataset.ipynb ADDED
@@ -0,0 +1,721 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "ae79196c-1b84-4cde-8051-6cb113b80373",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "/Users/Pi/miniconda3/envs/myenv/lib/python3.10/site-packages/xgboost/training.py:183: UserWarning: [00:11:22] WARNING: /Users/runner/work/xgboost/xgboost/src/learner.cc:738: \n",
14
+ "Parameters: { \"use_label_encoder\" } are not used.\n",
15
+ "\n",
16
+ " bst.update(dtrain, iteration=i, fobj=obj)\n",
17
+ "llama_model_load_from_file_impl: using device Metal (Apple M2 Pro) - 21845 MiB free\n",
18
+ "llama_model_loader: loaded meta data with 20 key-value pairs and 291 tensors from /Users/Pi/models/mistral/mistral-7b-instruct-v0.1.Q4_K_M.gguf (version GGUF V2)\n",
19
+ "llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.\n",
20
+ "llama_model_loader: - kv 0: general.architecture str = llama\n",
21
+ "llama_model_loader: - kv 1: general.name str = mistralai_mistral-7b-instruct-v0.1\n",
22
+ "llama_model_loader: - kv 2: llama.context_length u32 = 32768\n",
23
+ "llama_model_loader: - kv 3: llama.embedding_length u32 = 4096\n",
24
+ "llama_model_loader: - kv 4: llama.block_count u32 = 32\n",
25
+ "llama_model_loader: - kv 5: llama.feed_forward_length u32 = 14336\n",
26
+ "llama_model_loader: - kv 6: llama.rope.dimension_count u32 = 128\n",
27
+ "llama_model_loader: - kv 7: llama.attention.head_count u32 = 32\n",
28
+ "llama_model_loader: - kv 8: llama.attention.head_count_kv u32 = 8\n",
29
+ "llama_model_loader: - kv 9: llama.attention.layer_norm_rms_epsilon f32 = 0.000010\n",
30
+ "llama_model_loader: - kv 10: llama.rope.freq_base f32 = 10000.000000\n",
31
+ "llama_model_loader: - kv 11: general.file_type u32 = 15\n",
32
+ "llama_model_loader: - kv 12: tokenizer.ggml.model str = llama\n",
33
+ "llama_model_loader: - kv 13: tokenizer.ggml.tokens arr[str,32000] = [\"<unk>\", \"<s>\", \"</s>\", \"<0x00>\", \"<...\n",
34
+ "llama_model_loader: - kv 14: tokenizer.ggml.scores arr[f32,32000] = [0.000000, 0.000000, 0.000000, 0.0000...\n",
35
+ "llama_model_loader: - kv 15: tokenizer.ggml.token_type arr[i32,32000] = [2, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, ...\n",
36
+ "llama_model_loader: - kv 16: tokenizer.ggml.bos_token_id u32 = 1\n",
37
+ "llama_model_loader: - kv 17: tokenizer.ggml.eos_token_id u32 = 2\n",
38
+ "llama_model_loader: - kv 18: tokenizer.ggml.unknown_token_id u32 = 0\n",
39
+ "llama_model_loader: - kv 19: general.quantization_version u32 = 2\n",
40
+ "llama_model_loader: - type f32: 65 tensors\n",
41
+ "llama_model_loader: - type q4_K: 193 tensors\n",
42
+ "llama_model_loader: - type q6_K: 33 tensors\n",
43
+ "print_info: file format = GGUF V2\n",
44
+ "print_info: file type = Q4_K - Medium\n",
45
+ "print_info: file size = 4.07 GiB (4.83 BPW) \n",
46
+ "init_tokenizer: initializing tokenizer for type 1\n",
47
+ "load: control token: 2 '</s>' is not marked as EOG\n",
48
+ "load: control token: 1 '<s>' is not marked as EOG\n",
49
+ "load: special_eos_id is not in special_eog_ids - the tokenizer config may be incorrect\n",
50
+ "load: special tokens cache size = 3\n",
51
+ "load: token to piece cache size = 0.1637 MB\n",
52
+ "print_info: arch = llama\n",
53
+ "print_info: vocab_only = 0\n",
54
+ "print_info: n_ctx_train = 32768\n",
55
+ "print_info: n_embd = 4096\n",
56
+ "print_info: n_layer = 32\n",
57
+ "print_info: n_head = 32\n",
58
+ "print_info: n_head_kv = 8\n",
59
+ "print_info: n_rot = 128\n",
60
+ "print_info: n_swa = 0\n",
61
+ "print_info: n_embd_head_k = 128\n",
62
+ "print_info: n_embd_head_v = 128\n",
63
+ "print_info: n_gqa = 4\n",
64
+ "print_info: n_embd_k_gqa = 1024\n",
65
+ "print_info: n_embd_v_gqa = 1024\n",
66
+ "print_info: f_norm_eps = 0.0e+00\n",
67
+ "print_info: f_norm_rms_eps = 1.0e-05\n",
68
+ "print_info: f_clamp_kqv = 0.0e+00\n",
69
+ "print_info: f_max_alibi_bias = 0.0e+00\n",
70
+ "print_info: f_logit_scale = 0.0e+00\n",
71
+ "print_info: f_attn_scale = 0.0e+00\n",
72
+ "print_info: n_ff = 14336\n",
73
+ "print_info: n_expert = 0\n",
74
+ "print_info: n_expert_used = 0\n",
75
+ "print_info: causal attn = 1\n",
76
+ "print_info: pooling type = 0\n",
77
+ "print_info: rope type = 0\n",
78
+ "print_info: rope scaling = linear\n",
79
+ "print_info: freq_base_train = 10000.0\n",
80
+ "print_info: freq_scale_train = 1\n",
81
+ "print_info: n_ctx_orig_yarn = 32768\n",
82
+ "print_info: rope_finetuned = unknown\n",
83
+ "print_info: ssm_d_conv = 0\n",
84
+ "print_info: ssm_d_inner = 0\n",
85
+ "print_info: ssm_d_state = 0\n",
86
+ "print_info: ssm_dt_rank = 0\n",
87
+ "print_info: ssm_dt_b_c_rms = 0\n",
88
+ "print_info: model type = 7B\n",
89
+ "print_info: model params = 7.24 B\n",
90
+ "print_info: general.name = mistralai_mistral-7b-instruct-v0.1\n",
91
+ "print_info: vocab type = SPM\n",
92
+ "print_info: n_vocab = 32000\n",
93
+ "print_info: n_merges = 0\n",
94
+ "print_info: BOS token = 1 '<s>'\n",
95
+ "print_info: EOS token = 2 '</s>'\n",
96
+ "print_info: UNK token = 0 '<unk>'\n",
97
+ "print_info: LF token = 13 '<0x0A>'\n",
98
+ "print_info: EOG token = 2 '</s>'\n",
99
+ "print_info: max token length = 48\n",
100
+ "load_tensors: loading model tensors, this can take a while... (mmap = true)\n",
101
+ "load_tensors: layer 0 assigned to device CPU\n",
102
+ "load_tensors: layer 1 assigned to device CPU\n",
103
+ "load_tensors: layer 2 assigned to device CPU\n",
104
+ "load_tensors: layer 3 assigned to device CPU\n",
105
+ "load_tensors: layer 4 assigned to device CPU\n",
106
+ "load_tensors: layer 5 assigned to device CPU\n",
107
+ "load_tensors: layer 6 assigned to device CPU\n",
108
+ "load_tensors: layer 7 assigned to device CPU\n",
109
+ "load_tensors: layer 8 assigned to device CPU\n",
110
+ "load_tensors: layer 9 assigned to device CPU\n",
111
+ "load_tensors: layer 10 assigned to device CPU\n",
112
+ "load_tensors: layer 11 assigned to device CPU\n",
113
+ "load_tensors: layer 12 assigned to device CPU\n",
114
+ "load_tensors: layer 13 assigned to device CPU\n",
115
+ "load_tensors: layer 14 assigned to device CPU\n",
116
+ "load_tensors: layer 15 assigned to device CPU\n",
117
+ "load_tensors: layer 16 assigned to device CPU\n",
118
+ "load_tensors: layer 17 assigned to device CPU\n",
119
+ "load_tensors: layer 18 assigned to device CPU\n",
120
+ "load_tensors: layer 19 assigned to device CPU\n",
121
+ "load_tensors: layer 20 assigned to device CPU\n",
122
+ "load_tensors: layer 21 assigned to device CPU\n",
123
+ "load_tensors: layer 22 assigned to device CPU\n",
124
+ "load_tensors: layer 23 assigned to device CPU\n",
125
+ "load_tensors: layer 24 assigned to device CPU\n",
126
+ "load_tensors: layer 25 assigned to device CPU\n",
127
+ "load_tensors: layer 26 assigned to device CPU\n",
128
+ "load_tensors: layer 27 assigned to device CPU\n",
129
+ "load_tensors: layer 28 assigned to device CPU\n",
130
+ "load_tensors: layer 29 assigned to device CPU\n",
131
+ "load_tensors: layer 30 assigned to device CPU\n",
132
+ "load_tensors: layer 31 assigned to device CPU\n",
133
+ "load_tensors: layer 32 assigned to device CPU\n",
134
+ "load_tensors: tensor 'token_embd.weight' (q4_K) (and 290 others) cannot be used with preferred buffer type CPU_AARCH64, using CPU instead\n",
135
+ "load_tensors: offloading 0 repeating layers to GPU\n",
136
+ "load_tensors: offloaded 0/33 layers to GPU\n",
137
+ "load_tensors: CPU_Mapped model buffer size = 4165.37 MiB\n",
138
+ ".................................................................................................\n",
139
+ "llama_init_from_model: n_seq_max = 1\n",
140
+ "llama_init_from_model: n_ctx = 2048\n",
141
+ "llama_init_from_model: n_ctx_per_seq = 2048\n",
142
+ "llama_init_from_model: n_batch = 512\n",
143
+ "llama_init_from_model: n_ubatch = 512\n",
144
+ "llama_init_from_model: flash_attn = 0\n",
145
+ "llama_init_from_model: freq_base = 10000.0\n",
146
+ "llama_init_from_model: freq_scale = 1\n",
147
+ "llama_init_from_model: n_ctx_per_seq (2048) < n_ctx_train (32768) -- the full capacity of the model will not be utilized\n",
148
+ "ggml_metal_init: allocating\n",
149
+ "ggml_metal_init: found device: Apple M2 Pro\n",
150
+ "ggml_metal_init: picking default device: Apple M2 Pro\n",
151
+ "ggml_metal_load_library: using embedded metal library\n",
152
+ "ggml_metal_init: GPU name: Apple M2 Pro\n",
153
+ "ggml_metal_init: GPU family: MTLGPUFamilyApple8 (1008)\n",
154
+ "ggml_metal_init: GPU family: MTLGPUFamilyCommon3 (3003)\n",
155
+ "ggml_metal_init: GPU family: MTLGPUFamilyMetal3 (5001)\n",
156
+ "ggml_metal_init: simdgroup reduction = true\n",
157
+ "ggml_metal_init: simdgroup matrix mul. = true\n",
158
+ "ggml_metal_init: has residency sets = true\n",
159
+ "ggml_metal_init: has bfloat = true\n",
160
+ "ggml_metal_init: use bfloat = false\n",
161
+ "ggml_metal_init: hasUnifiedMemory = true\n",
162
+ "ggml_metal_init: recommendedMaxWorkingSetSize = 22906.50 MB\n",
163
+ "ggml_metal_init: loaded kernel_add 0x11f38a990 | th_max = 1024 | th_width = 32\n",
164
+ "ggml_metal_init: loaded kernel_add_row 0x12ef6f310 | th_max = 1024 | th_width = 32\n",
165
+ "ggml_metal_init: loaded kernel_sub 0x11f405df0 | th_max = 1024 | th_width = 32\n",
166
+ "ggml_metal_init: loaded kernel_sub_row 0x11f38b080 | th_max = 1024 | th_width = 32\n",
167
+ "ggml_metal_init: loaded kernel_mul 0x11bc91a30 | th_max = 1024 | th_width = 32\n",
168
+ "ggml_metal_init: loaded kernel_mul_row 0x11f1aa2f0 | th_max = 1024 | th_width = 32\n",
169
+ "ggml_metal_init: loaded kernel_div 0x12ee21f20 | th_max = 1024 | th_width = 32\n",
170
+ "ggml_metal_init: loaded kernel_div_row 0x12ef82170 | th_max = 1024 | th_width = 32\n",
171
+ "ggml_metal_init: loaded kernel_repeat_f32 0x11bc91cc0 | th_max = 1024 | th_width = 32\n",
172
+ "ggml_metal_init: loaded kernel_repeat_f16 0x13b813e80 | th_max = 1024 | th_width = 32\n",
173
+ "ggml_metal_init: loaded kernel_repeat_i32 0x11f38b2e0 | th_max = 1024 | th_width = 32\n",
174
+ "ggml_metal_init: loaded kernel_repeat_i16 0x11f1aaa50 | th_max = 1024 | th_width = 32\n",
175
+ "ggml_metal_init: loaded kernel_scale 0x12ef826e0 | th_max = 1024 | th_width = 32\n",
176
+ "ggml_metal_init: loaded kernel_scale_4 0x11bc92230 | th_max = 1024 | th_width = 32\n",
177
+ "ggml_metal_init: loaded kernel_clamp 0x11f406d10 | th_max = 1024 | th_width = 32\n",
178
+ "ggml_metal_init: loaded kernel_tanh 0x11bc92580 | th_max = 1024 | th_width = 32\n",
179
+ "ggml_metal_init: loaded kernel_relu 0x11f423300 | th_max = 1024 | th_width = 32\n",
180
+ "ggml_metal_init: loaded kernel_sigmoid 0x13a3d6930 | th_max = 1024 | th_width = 32\n",
181
+ "ggml_metal_init: loaded kernel_gelu 0x11bc92a60 | th_max = 1024 | th_width = 32\n",
182
+ "ggml_metal_init: loaded kernel_gelu_4 0x11f1aacb0 | th_max = 1024 | th_width = 32\n",
183
+ "ggml_metal_init: loaded kernel_gelu_quick 0x11bc93220 | th_max = 1024 | th_width = 32\n",
184
+ "ggml_metal_init: loaded kernel_gelu_quick_4 0x11bc937a0 | th_max = 1024 | th_width = 32\n",
185
+ "ggml_metal_init: loaded kernel_silu 0x11bc93ce0 | th_max = 1024 | th_width = 32\n",
186
+ "ggml_metal_init: loaded kernel_silu_4 0x13a3d7120 | th_max = 1024 | th_width = 32\n",
187
+ "ggml_metal_init: loaded kernel_elu 0x13a3d7600 | th_max = 1024 | th_width = 32\n",
188
+ "ggml_metal_init: loaded kernel_soft_max_f16 0x11bc93fa0 | th_max = 1024 | th_width = 32\n",
189
+ "ggml_metal_init: loaded kernel_soft_max_f16_4 0x12ef82940 | th_max = 1024 | th_width = 32\n",
190
+ "ggml_metal_init: loaded kernel_soft_max_f32 0x11bc94400 | th_max = 1024 | th_width = 32\n",
191
+ "ggml_metal_init: loaded kernel_soft_max_f32_4 0x13a3d7860 | th_max = 1024 | th_width = 32\n",
192
+ "ggml_metal_init: loaded kernel_diag_mask_inf 0x12ef82ba0 | th_max = 1024 | th_width = 32\n",
193
+ "ggml_metal_init: loaded kernel_diag_mask_inf_8 0x13a3d7ac0 | th_max = 1024 | th_width = 32\n",
194
+ "ggml_metal_init: loaded kernel_get_rows_f32 0x13a3d7d20 | th_max = 1024 | th_width = 32\n",
195
+ "ggml_metal_init: loaded kernel_get_rows_f16 0x11bc94660 | th_max = 1024 | th_width = 32\n",
196
+ "ggml_metal_init: skipping kernel_get_rows_bf16 (not supported)\n",
197
+ "ggml_metal_init: loaded kernel_get_rows_q4_0 0x13a3d7f80 | th_max = 1024 | th_width = 32\n",
198
+ "ggml_metal_init: loaded kernel_get_rows_q4_1 0x11bc948c0 | th_max = 1024 | th_width = 32\n",
199
+ "ggml_metal_init: loaded kernel_get_rows_q5_0 0x11bc94b20 | th_max = 1024 | th_width = 32\n",
200
+ "ggml_metal_init: loaded kernel_get_rows_q5_1 0x11f423890 | th_max = 1024 | th_width = 32\n",
201
+ "ggml_metal_init: loaded kernel_get_rows_q8_0 0x11bc94d80 | th_max = 1024 | th_width = 32\n",
202
+ "ggml_metal_init: loaded kernel_get_rows_q2_K 0x11f1ab1d0 | th_max = 1024 | th_width = 32\n",
203
+ "ggml_metal_init: loaded kernel_get_rows_q3_K 0x11bc94fe0 | th_max = 1024 | th_width = 32\n",
204
+ "ggml_metal_init: loaded kernel_get_rows_q4_K 0x11bc95240 | th_max = 1024 | th_width = 32\n",
205
+ "ggml_metal_init: loaded kernel_get_rows_q5_K 0x11bc954a0 | th_max = 1024 | th_width = 32\n",
206
+ "ggml_metal_init: loaded kernel_get_rows_q6_K 0x11bc95700 | th_max = 1024 | th_width = 32\n",
207
+ "ggml_metal_init: loaded kernel_get_rows_iq2_xxs 0x11f1ab430 | th_max = 1024 | th_width = 32\n",
208
+ "ggml_metal_init: loaded kernel_get_rows_iq2_xs 0x12ef82e00 | th_max = 1024 | th_width = 32\n",
209
+ "ggml_metal_init: loaded kernel_get_rows_iq3_xxs 0x13a3d81e0 | th_max = 1024 | th_width = 32\n",
210
+ "ggml_metal_init: loaded kernel_get_rows_iq3_s 0x11bc95960 | th_max = 1024 | th_width = 32\n",
211
+ "ggml_metal_init: loaded kernel_get_rows_iq2_s 0x12ee225b0 | th_max = 1024 | th_width = 32\n",
212
+ "ggml_metal_init: loaded kernel_get_rows_iq1_s 0x11bc95bc0 | th_max = 1024 | th_width = 32\n",
213
+ "ggml_metal_init: loaded kernel_get_rows_iq1_m 0x13a3d6e10 | th_max = 1024 | th_width = 32\n",
214
+ "ggml_metal_init: loaded kernel_get_rows_iq4_nl 0x11f423c10 | th_max = 1024 | th_width = 32\n",
215
+ "ggml_metal_init: loaded kernel_get_rows_iq4_xs 0x13a3d8440 | th_max = 1024 | th_width = 32\n",
216
+ "ggml_metal_init: loaded kernel_get_rows_i32 0x11bc95e30 | th_max = 1024 | th_width = 32\n",
217
+ "ggml_metal_init: loaded kernel_rms_norm 0x13a3d86a0 | th_max = 1024 | th_width = 32\n",
218
+ "ggml_metal_init: loaded kernel_group_norm 0x11f1ab690 | th_max = 1024 | th_width = 32\n",
219
+ "ggml_metal_init: loaded kernel_norm 0x11bc96090 | th_max = 1024 | th_width = 32\n",
220
+ "ggml_metal_init: loaded kernel_ssm_conv_f32 0x12ef83060 | th_max = 1024 | th_width = 32\n",
221
+ "ggml_metal_init: loaded kernel_ssm_scan_f32 0x11bc962f0 | th_max = 1024 | th_width = 32\n",
222
+ "ggml_metal_init: loaded kernel_mul_mv_f32_f32 0x12ef833e0 | th_max = 1024 | th_width = 32\n",
223
+ "ggml_metal_init: skipping kernel_mul_mv_bf16_f32 (not supported)\n",
224
+ "ggml_metal_init: skipping kernel_mul_mv_bf16_f32_1row (not supported)\n",
225
+ "ggml_metal_init: skipping kernel_mul_mv_bf16_f32_l4 (not supported)\n",
226
+ "ggml_metal_init: skipping kernel_mul_mv_bf16_bf16 (not supported)\n",
227
+ "ggml_metal_init: loaded kernel_mul_mv_f16_f32 0x13a3d8900 | th_max = 1024 | th_width = 32\n",
228
+ "ggml_metal_init: loaded kernel_mul_mv_f16_f32_1row 0x11f1aba20 | th_max = 1024 | th_width = 32\n",
229
+ "ggml_metal_init: loaded kernel_mul_mv_f16_f32_l4 0x11bc96580 | th_max = 1024 | th_width = 32\n",
230
+ "ggml_metal_init: loaded kernel_mul_mv_f16_f16 0x11bc967e0 | th_max = 1024 | th_width = 32\n",
231
+ "ggml_metal_init: loaded kernel_mul_mv_q4_0_f32 0x12ef83760 | th_max = 640 | th_width = 32\n",
232
+ "ggml_metal_init: loaded kernel_mul_mv_q4_1_f32 0x12ef83ae0 | th_max = 832 | th_width = 32\n",
233
+ "ggml_metal_init: loaded kernel_mul_mv_q5_0_f32 0x11bc96a40 | th_max = 640 | th_width = 32\n",
234
+ "ggml_metal_init: loaded kernel_mul_mv_q5_1_f32 0x13a3d8b60 | th_max = 576 | th_width = 32\n",
235
+ "ggml_metal_init: loaded kernel_mul_mv_q8_0_f32 0x13a3d8dc0 | th_max = 1024 | th_width = 32\n",
236
+ "ggml_metal_init: loaded kernel_mul_mv_ext_f16_f32_r1_2 0x11bc96ca0 | th_max = 896 | th_width = 32\n",
237
+ "ggml_metal_init: loaded kernel_mul_mv_ext_f16_f32_r1_3 0x11f38b7d0 | th_max = 832 | th_width = 32\n",
238
+ "ggml_metal_init: loaded kernel_mul_mv_ext_f16_f32_r1_4 0x11f424100 | th_max = 832 | th_width = 32\n",
239
+ "ggml_metal_init: loaded kernel_mul_mv_ext_f16_f32_r1_5 0x13a3d9020 | th_max = 768 | th_width = 32\n",
240
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_0_f32_r1_2 0x13a3d9280 | th_max = 832 | th_width = 32\n",
241
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_0_f32_r1_3 0x11bc96f00 | th_max = 704 | th_width = 32\n",
242
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_0_f32_r1_4 0x13a3d94e0 | th_max = 640 | th_width = 32\n",
243
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_0_f32_r1_5 0x11bc97160 | th_max = 640 | th_width = 32\n",
244
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_1_f32_r1_2 0x12ef83e60 | th_max = 832 | th_width = 32\n",
245
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_1_f32_r1_3 0x11f1abf10 | th_max = 704 | th_width = 32\n",
246
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_1_f32_r1_4 0x11bc973c0 | th_max = 640 | th_width = 32\n",
247
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_1_f32_r1_5 0x13a3d9740 | th_max = 640 | th_width = 32\n",
248
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_0_f32_r1_2 0x13a3d99a0 | th_max = 704 | th_width = 32\n",
249
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_0_f32_r1_3 0x11bc97620 | th_max = 704 | th_width = 32\n",
250
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_0_f32_r1_4 0x13a3d9c00 | th_max = 576 | th_width = 32\n",
251
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_0_f32_r1_5 0x13a3d9e60 | th_max = 640 | th_width = 32\n",
252
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_1_f32_r1_2 0x11bc97880 | th_max = 640 | th_width = 32\n",
253
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_1_f32_r1_3 0x13a3da0c0 | th_max = 704 | th_width = 32\n",
254
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_1_f32_r1_4 0x11bc97ae0 | th_max = 576 | th_width = 32\n",
255
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_1_f32_r1_5 0x11f424360 | th_max = 640 | th_width = 32\n",
256
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q8_0_f32_r1_2 0x11f1ac170 | th_max = 832 | th_width = 32\n",
257
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q8_0_f32_r1_3 0x11f38ba30 | th_max = 704 | th_width = 32\n",
258
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q8_0_f32_r1_4 0x13a3da320 | th_max = 640 | th_width = 32\n",
259
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q8_0_f32_r1_5 0x11f1ac670 | th_max = 640 | th_width = 32\n",
260
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_K_f32_r1_2 0x13a3da580 | th_max = 832 | th_width = 32\n",
261
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_K_f32_r1_3 0x11f1ac8d0 | th_max = 704 | th_width = 32\n",
262
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_K_f32_r1_4 0x12ef841e0 | th_max = 640 | th_width = 32\n",
263
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q4_K_f32_r1_5 0x11bc97d40 | th_max = 640 | th_width = 32\n",
264
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_K_f32_r1_2 0x13a3da7e0 | th_max = 704 | th_width = 32\n",
265
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_K_f32_r1_3 0x13a3daa40 | th_max = 704 | th_width = 32\n",
266
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_K_f32_r1_4 0x11bc97fa0 | th_max = 640 | th_width = 32\n",
267
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q5_K_f32_r1_5 0x11bc98200 | th_max = 640 | th_width = 32\n",
268
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q6_K_f32_r1_2 0x11f38bf30 | th_max = 832 | th_width = 32\n",
269
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q6_K_f32_r1_3 0x13a3daca0 | th_max = 704 | th_width = 32\n",
270
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q6_K_f32_r1_4 0x11f424880 | th_max = 704 | th_width = 32\n",
271
+ "ggml_metal_init: loaded kernel_mul_mv_ext_q6_K_f32_r1_5 0x12ef84740 | th_max = 640 | th_width = 32\n",
272
+ "ggml_metal_init: loaded kernel_mul_mv_ext_iq4_nl_f32_r1_2 0x13b814370 | th_max = 832 | th_width = 32\n",
273
+ "ggml_metal_init: loaded kernel_mul_mv_ext_iq4_nl_f32_r1_3 0x11f424ae0 | th_max = 704 | th_width = 32\n",
274
+ "ggml_metal_init: loaded kernel_mul_mv_ext_iq4_nl_f32_r1_4 0x11f425270 | th_max = 640 | th_width = 32\n",
275
+ "ggml_metal_init: loaded kernel_mul_mv_ext_iq4_nl_f32_r1_5 0x12ef84ac0 | th_max = 640 | th_width = 32\n",
276
+ "ggml_metal_init: loaded kernel_mul_mv_q2_K_f32 0x11bc98460 | th_max = 640 | th_width = 32\n",
277
+ "ggml_metal_init: loaded kernel_mul_mv_q3_K_f32 0x13b8145d0 | th_max = 576 | th_width = 32\n",
278
+ "ggml_metal_init: loaded kernel_mul_mv_q4_K_f32 0x12ef84e40 | th_max = 576 | th_width = 32\n",
279
+ "ggml_metal_init: loaded kernel_mul_mv_q5_K_f32 0x11f4254d0 | th_max = 576 | th_width = 32\n",
280
+ "ggml_metal_init: loaded kernel_mul_mv_q6_K_f32 0x11f425730 | th_max = 1024 | th_width = 32\n",
281
+ "ggml_metal_init: loaded kernel_mul_mv_iq2_xxs_f32 0x12ef85250 | th_max = 832 | th_width = 32\n",
282
+ "ggml_metal_init: loaded kernel_mul_mv_iq2_xs_f32 0x11f425ce0 | th_max = 704 | th_width = 32\n",
283
+ "ggml_metal_init: loaded kernel_mul_mv_iq3_xxs_f32 0x11f425f40 | th_max = 768 | th_width = 32\n",
284
+ "ggml_metal_init: loaded kernel_mul_mv_iq3_s_f32 0x11f4262c0 | th_max = 640 | th_width = 32\n",
285
+ "ggml_metal_init: loaded kernel_mul_mv_iq2_s_f32 0x11f426640 | th_max = 640 | th_width = 32\n",
286
+ "ggml_metal_init: loaded kernel_mul_mv_iq1_s_f32 0x11f426c30 | th_max = 448 | th_width = 32\n",
287
+ "ggml_metal_init: loaded kernel_mul_mv_iq1_m_f32 0x12ef85720 | th_max = 576 | th_width = 32\n",
288
+ "ggml_metal_init: loaded kernel_mul_mv_iq4_nl_f32 0x11f4271e0 | th_max = 1024 | th_width = 32\n",
289
+ "ggml_metal_init: loaded kernel_mul_mv_iq4_xs_f32 0x11f427440 | th_max = 896 | th_width = 32\n",
290
+ "ggml_metal_init: loaded kernel_mul_mv_id_f32_f32 0x13a3daf00 | th_max = 1024 | th_width = 32\n",
291
+ "ggml_metal_init: loaded kernel_mul_mv_id_f16_f32 0x13b814830 | th_max = 1024 | th_width = 32\n",
292
+ "ggml_metal_init: skipping kernel_mul_mv_id_bf16_f32 (not supported)\n",
293
+ "ggml_metal_init: loaded kernel_mul_mv_id_q4_0_f32 0x11f4277c0 | th_max = 832 | th_width = 32\n",
294
+ "ggml_metal_init: loaded kernel_mul_mv_id_q4_1_f32 0x13a3db160 | th_max = 832 | th_width = 32\n",
295
+ "ggml_metal_init: loaded kernel_mul_mv_id_q5_0_f32 0x11f427b40 | th_max = 576 | th_width = 32\n",
296
+ "ggml_metal_init: loaded kernel_mul_mv_id_q5_1_f32 0x12ef85980 | th_max = 576 | th_width = 32\n",
297
+ "ggml_metal_init: loaded kernel_mul_mv_id_q8_0_f32 0x13b814a90 | th_max = 1024 | th_width = 32\n",
298
+ "ggml_metal_init: loaded kernel_mul_mv_id_q2_K_f32 0x13b814cf0 | th_max = 576 | th_width = 32\n",
299
+ "ggml_metal_init: loaded kernel_mul_mv_id_q3_K_f32 0x12ef85d00 | th_max = 576 | th_width = 32\n",
300
+ "ggml_metal_init: loaded kernel_mul_mv_id_q4_K_f32 0x12ef86080 | th_max = 576 | th_width = 32\n",
301
+ "ggml_metal_init: loaded kernel_mul_mv_id_q5_K_f32 0x11bc987f0 | th_max = 576 | th_width = 32\n",
302
+ "ggml_metal_init: loaded kernel_mul_mv_id_q6_K_f32 0x13b815070 | th_max = 1024 | th_width = 32\n",
303
+ "ggml_metal_init: loaded kernel_mul_mv_id_iq2_xxs_f32 0x11bc98a50 | th_max = 768 | th_width = 32\n",
304
+ "ggml_metal_init: loaded kernel_mul_mv_id_iq2_xs_f32 0x11f1acdd0 | th_max = 640 | th_width = 32\n",
305
+ "ggml_metal_init: loaded kernel_mul_mv_id_iq3_xxs_f32 0x11bc98cb0 | th_max = 704 | th_width = 32\n",
306
+ "ggml_metal_init: loaded kernel_mul_mv_id_iq3_s_f32 0x13a3db3c0 | th_max = 640 | th_width = 32\n",
307
+ "ggml_metal_init: loaded kernel_mul_mv_id_iq2_s_f32 0x13a3db620 | th_max = 640 | th_width = 32\n",
308
+ "ggml_metal_init: loaded kernel_mul_mv_id_iq1_s_f32 0x11f4280f0 | th_max = 448 | th_width = 32\n",
309
+ "ggml_metal_init: loaded kernel_mul_mv_id_iq1_m_f32 0x11bc98f10 | th_max = 576 | th_width = 32\n",
310
+ "ggml_metal_init: loaded kernel_mul_mv_id_iq4_nl_f32 0x13b8153f0 | th_max = 1024 | th_width = 32\n",
311
+ "ggml_metal_init: loaded kernel_mul_mv_id_iq4_xs_f32 0x11f4285c0 | th_max = 1024 | th_width = 32\n",
312
+ "ggml_metal_init: loaded kernel_mul_mm_f32_f32 0x12ee22810 | th_max = 832 | th_width = 32\n",
313
+ "ggml_metal_init: loaded kernel_mul_mm_f16_f32 0x11f428820 | th_max = 832 | th_width = 32\n",
314
+ "ggml_metal_init: skipping kernel_mul_mm_bf16_f32 (not supported)\n",
315
+ "ggml_metal_init: loaded kernel_mul_mm_q4_0_f32 0x11f428ba0 | th_max = 832 | th_width = 32\n",
316
+ "ggml_metal_init: loaded kernel_mul_mm_q4_1_f32 0x12ef86400 | th_max = 832 | th_width = 32\n",
317
+ "ggml_metal_init: loaded kernel_mul_mm_q5_0_f32 0x11f428f20 | th_max = 768 | th_width = 32\n",
318
+ "ggml_metal_init: loaded kernel_mul_mm_q5_1_f32 0x12ef86780 | th_max = 768 | th_width = 32\n",
319
+ "ggml_metal_init: loaded kernel_mul_mm_q8_0_f32 0x11f4292a0 | th_max = 832 | th_width = 32\n",
320
+ "ggml_metal_init: loaded kernel_mul_mm_q2_K_f32 0x12ef86d30 | th_max = 832 | th_width = 32\n",
321
+ "ggml_metal_init: loaded kernel_mul_mm_q3_K_f32 0x13a3db880 | th_max = 832 | th_width = 32\n",
322
+ "ggml_metal_init: loaded kernel_mul_mm_q4_K_f32 0x11f429620 | th_max = 832 | th_width = 32\n",
323
+ "ggml_metal_init: loaded kernel_mul_mm_q5_K_f32 0x12ee22b90 | th_max = 832 | th_width = 32\n",
324
+ "ggml_metal_init: loaded kernel_mul_mm_q6_K_f32 0x11bc99180 | th_max = 832 | th_width = 32\n",
325
+ "ggml_metal_init: loaded kernel_mul_mm_iq2_xxs_f32 0x11f38c190 | th_max = 768 | th_width = 32\n",
326
+ "ggml_metal_init: loaded kernel_mul_mm_iq2_xs_f32 0x11f4299a0 | th_max = 832 | th_width = 32\n",
327
+ "ggml_metal_init: loaded kernel_mul_mm_iq3_xxs_f32 0x12ee22df0 | th_max = 832 | th_width = 32\n",
328
+ "ggml_metal_init: loaded kernel_mul_mm_iq3_s_f32 0x11bc993e0 | th_max = 832 | th_width = 32\n",
329
+ "ggml_metal_init: loaded kernel_mul_mm_iq2_s_f32 0x11bc99640 | th_max = 832 | th_width = 32\n",
330
+ "ggml_metal_init: loaded kernel_mul_mm_iq1_s_f32 0x12ee233a0 | th_max = 832 | th_width = 32\n",
331
+ "ggml_metal_init: loaded kernel_mul_mm_iq1_m_f32 0x11f429d20 | th_max = 832 | th_width = 32\n",
332
+ "ggml_metal_init: loaded kernel_mul_mm_iq4_nl_f32 0x12ef86f90 | th_max = 832 | th_width = 32\n",
333
+ "ggml_metal_init: loaded kernel_mul_mm_iq4_xs_f32 0x12ee23870 | th_max = 832 | th_width = 32\n",
334
+ "ggml_metal_init: loaded kernel_mul_mm_id_f32_f32 0x13b815950 | th_max = 832 | th_width = 32\n",
335
+ "ggml_metal_init: loaded kernel_mul_mm_id_f16_f32 0x12ef87320 | th_max = 832 | th_width = 32\n",
336
+ "ggml_metal_init: skipping kernel_mul_mm_id_bf16_f32 (not supported)\n",
337
+ "ggml_metal_init: loaded kernel_mul_mm_id_q4_0_f32 0x11f42a0a0 | th_max = 832 | th_width = 32\n",
338
+ "ggml_metal_init: loaded kernel_mul_mm_id_q4_1_f32 0x11bc998a0 | th_max = 832 | th_width = 32\n",
339
+ "ggml_metal_init: loaded kernel_mul_mm_id_q5_0_f32 0x11f42a420 | th_max = 768 | th_width = 32\n",
340
+ "ggml_metal_init: loaded kernel_mul_mm_id_q5_1_f32 0x12ef878d0 | th_max = 768 | th_width = 32\n",
341
+ "ggml_metal_init: loaded kernel_mul_mm_id_q8_0_f32 0x11f42a7a0 | th_max = 832 | th_width = 32\n",
342
+ "ggml_metal_init: loaded kernel_mul_mm_id_q2_K_f32 0x13b815bb0 | th_max = 832 | th_width = 32\n",
343
+ "ggml_metal_init: loaded kernel_mul_mm_id_q3_K_f32 0x11f42ab20 | th_max = 832 | th_width = 32\n",
344
+ "ggml_metal_init: loaded kernel_mul_mm_id_q4_K_f32 0x12ee23ad0 | th_max = 832 | th_width = 32\n",
345
+ "ggml_metal_init: loaded kernel_mul_mm_id_q5_K_f32 0x11f42afc0 | th_max = 832 | th_width = 32\n",
346
+ "ggml_metal_init: loaded kernel_mul_mm_id_q6_K_f32 0x12ef87c50 | th_max = 832 | th_width = 32\n",
347
+ "ggml_metal_init: loaded kernel_mul_mm_id_iq2_xxs_f32 0x12ee23d30 | th_max = 832 | th_width = 32\n",
348
+ "ggml_metal_init: loaded kernel_mul_mm_id_iq2_xs_f32 0x12ef88120 | th_max = 832 | th_width = 32\n",
349
+ "ggml_metal_init: loaded kernel_mul_mm_id_iq3_xxs_f32 0x11f42b490 | th_max = 832 | th_width = 32\n",
350
+ "ggml_metal_init: loaded kernel_mul_mm_id_iq3_s_f32 0x13a3dbae0 | th_max = 832 | th_width = 32\n",
351
+ "ggml_metal_init: loaded kernel_mul_mm_id_iq2_s_f32 0x12ef88380 | th_max = 832 | th_width = 32\n",
352
+ "ggml_metal_init: loaded kernel_mul_mm_id_iq1_s_f32 0x11f42b6f0 | th_max = 832 | th_width = 32\n",
353
+ "ggml_metal_init: loaded kernel_mul_mm_id_iq1_m_f32 0x11bc99b10 | th_max = 832 | th_width = 32\n",
354
+ "ggml_metal_init: loaded kernel_mul_mm_id_iq4_nl_f32 0x11f42ba80 | th_max = 832 | th_width = 32\n",
355
+ "ggml_metal_init: loaded kernel_mul_mm_id_iq4_xs_f32 0x12ef885e0 | th_max = 832 | th_width = 32\n",
356
+ "ggml_metal_init: loaded kernel_rope_norm_f32 0x12ef88840 | th_max = 1024 | th_width = 32\n",
357
+ "ggml_metal_init: loaded kernel_rope_norm_f16 0x12ef88d60 | th_max = 1024 | th_width = 32\n",
358
+ "ggml_metal_init: loaded kernel_rope_neox_f32 0x13a3dbd40 | th_max = 1024 | th_width = 32\n",
359
+ "ggml_metal_init: loaded kernel_rope_neox_f16 0x12ee240b0 | th_max = 1024 | th_width = 32\n",
360
+ "ggml_metal_init: loaded kernel_im2col_f16 0x12ef88fc0 | th_max = 1024 | th_width = 32\n",
361
+ "ggml_metal_init: loaded kernel_im2col_f32 0x13b815f30 | th_max = 1024 | th_width = 32\n",
362
+ "ggml_metal_init: loaded kernel_im2col_ext_f16 0x11f42be00 | th_max = 1024 | th_width = 32\n",
363
+ "ggml_metal_init: loaded kernel_im2col_ext_f32 0x11f42c180 | th_max = 1024 | th_width = 32\n",
364
+ "ggml_metal_init: loaded kernel_conv_transpose_1d_f32_f32 0x11f42c500 | th_max = 1024 | th_width = 32\n",
365
+ "ggml_metal_init: loaded kernel_conv_transpose_1d_f16_f32 0x11f42ca60 | th_max = 1024 | th_width = 32\n",
366
+ "ggml_metal_init: loaded kernel_upscale_f32 0x11bc99d70 | th_max = 1024 | th_width = 32\n",
367
+ "ggml_metal_init: loaded kernel_pad_f32 0x11f42ccc0 | th_max = 1024 | th_width = 32\n",
368
+ "ggml_metal_init: loaded kernel_pad_reflect_1d_f32 0x12ee24490 | th_max = 1024 | th_width = 32\n",
369
+ "ggml_metal_init: loaded kernel_timestep_embedding_f32 0x11bc9a000 | th_max = 1024 | th_width = 32\n",
370
+ "ggml_metal_init: loaded kernel_arange_f32 0x11bc9a260 | th_max = 1024 | th_width = 32\n",
371
+ "ggml_metal_init: loaded kernel_argsort_f32_i32_asc 0x11f42d040 | th_max = 1024 | th_width = 32\n",
372
+ "ggml_metal_init: loaded kernel_argsort_f32_i32_desc 0x11f42d3c0 | th_max = 1024 | th_width = 32\n",
373
+ "ggml_metal_init: loaded kernel_leaky_relu_f32 0x11f42ddc0 | th_max = 1024 | th_width = 32\n",
374
+ "ggml_metal_init: loaded kernel_flash_attn_ext_f16_h64 0x11f42e2b0 | th_max = 640 | th_width = 32\n",
375
+ "ggml_metal_init: loaded kernel_flash_attn_ext_f16_h80 0x12ef89620 | th_max = 640 | th_width = 32\n",
376
+ "ggml_metal_init: loaded kernel_flash_attn_ext_f16_h96 0x11f42e510 | th_max = 576 | th_width = 32\n",
377
+ "ggml_metal_init: loaded kernel_flash_attn_ext_f16_h112 0x12ef89c80 | th_max = 576 | th_width = 32\n",
378
+ "ggml_metal_init: loaded kernel_flash_attn_ext_f16_h128 0x11f42e770 | th_max = 512 | th_width = 32\n",
379
+ "ggml_metal_init: loaded kernel_flash_attn_ext_f16_h256 0x12ee24980 | th_max = 512 | th_width = 32\n",
380
+ "ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h64 (not supported)\n",
381
+ "ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h80 (not supported)\n",
382
+ "ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h96 (not supported)\n",
383
+ "ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h112 (not supported)\n",
384
+ "ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h128 (not supported)\n",
385
+ "ggml_metal_init: skipping kernel_flash_attn_ext_bf16_h256 (not supported)\n",
386
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_0_h64 0x12ee24be0 | th_max = 704 | th_width = 32\n",
387
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_0_h80 0x12ef8a000 | th_max = 896 | th_width = 32\n",
388
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_0_h96 0x12ef8a260 | th_max = 896 | th_width = 32\n",
389
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_0_h112 0x12ef8a5e0 | th_max = 896 | th_width = 32\n",
390
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_0_h128 0x11f42ecd0 | th_max = 832 | th_width = 32\n",
391
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_0_h256 0x13b8162b0 | th_max = 832 | th_width = 32\n",
392
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_1_h64 0x11f42ef30 | th_max = 768 | th_width = 32\n",
393
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_1_h80 0x12ef8ab40 | th_max = 896 | th_width = 32\n",
394
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_1_h96 0x12ef8ada0 | th_max = 896 | th_width = 32\n",
395
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_1_h112 0x12ef8b250 | th_max = 896 | th_width = 32\n",
396
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_1_h128 0x11f42f6c0 | th_max = 832 | th_width = 32\n",
397
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q4_1_h256 0x11bc9a4c0 | th_max = 832 | th_width = 32\n",
398
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_0_h64 0x11bc9a990 | th_max = 576 | th_width = 32\n",
399
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_0_h80 0x11bc9abf0 | th_max = 832 | th_width = 32\n",
400
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_0_h96 0x13a3dbfa0 | th_max = 832 | th_width = 32\n",
401
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_0_h112 0x13a3dc200 | th_max = 832 | th_width = 32\n",
402
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_0_h128 0x11f38c3f0 | th_max = 768 | th_width = 32\n",
403
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_0_h256 0x11bc9ae50 | th_max = 768 | th_width = 32\n",
404
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_1_h64 0x12ef8b8e0 | th_max = 576 | th_width = 32\n",
405
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_1_h80 0x12ef8bb40 | th_max = 832 | th_width = 32\n",
406
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_1_h96 0x13a3dc460 | th_max = 832 | th_width = 32\n",
407
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_1_h112 0x11bc9b0b0 | th_max = 832 | th_width = 32\n",
408
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_1_h128 0x13a3dc6c0 | th_max = 768 | th_width = 32\n",
409
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q5_1_h256 0x11bc9b310 | th_max = 768 | th_width = 32\n",
410
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q8_0_h64 0x13a3dc920 | th_max = 704 | th_width = 32\n",
411
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q8_0_h80 0x11bc9b570 | th_max = 1024 | th_width = 32\n",
412
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q8_0_h96 0x11f38c770 | th_max = 1024 | th_width = 32\n",
413
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q8_0_h112 0x13a3dcb80 | th_max = 1024 | th_width = 32\n",
414
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q8_0_h128 0x13a3dcde0 | th_max = 896 | th_width = 32\n",
415
+ "ggml_metal_init: loaded kernel_flash_attn_ext_q8_0_h256 0x11bc9b7d0 | th_max = 896 | th_width = 32\n",
416
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_f16_h128 0x12ef8c040 | th_max = 1024 | th_width = 32\n",
417
+ "ggml_metal_init: skipping kernel_flash_attn_ext_vec_bf16_h128 (not supported)\n",
418
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q4_0_h128 0x13a3dd040 | th_max = 1024 | th_width = 32\n",
419
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q4_1_h128 0x13a3dd2a0 | th_max = 1024 | th_width = 32\n",
420
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q5_0_h128 0x13a3dd500 | th_max = 768 | th_width = 32\n",
421
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q5_1_h128 0x11bc9bc90 | th_max = 768 | th_width = 32\n",
422
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q8_0_h128 0x11bc9bef0 | th_max = 1024 | th_width = 32\n",
423
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_f16_h256 0x11bc9c150 | th_max = 1024 | th_width = 32\n",
424
+ "ggml_metal_init: skipping kernel_flash_attn_ext_vec_bf16_h256 (not supported)\n",
425
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q4_0_h256 0x11f1ad030 | th_max = 1024 | th_width = 32\n",
426
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q4_1_h256 0x11bc9c3b0 | th_max = 896 | th_width = 32\n",
427
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q5_0_h256 0x11f38caf0 | th_max = 704 | th_width = 32\n",
428
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q5_1_h256 0x11bc9c610 | th_max = 704 | th_width = 32\n",
429
+ "ggml_metal_init: loaded kernel_flash_attn_ext_vec_q8_0_h256 0x11bc9c870 | th_max = 832 | th_width = 32\n",
430
+ "ggml_metal_init: loaded kernel_set_f32 0x11bc9cc90 | th_max = 1024 | th_width = 32\n",
431
+ "ggml_metal_init: loaded kernel_set_i32 0x12ef8c2a0 | th_max = 1024 | th_width = 32\n",
432
+ "ggml_metal_init: loaded kernel_cpy_f32_f32 0x13a3dd760 | th_max = 1024 | th_width = 32\n",
433
+ "ggml_metal_init: loaded kernel_cpy_f32_f16 0x11f1ad530 | th_max = 1024 | th_width = 32\n",
434
+ "ggml_metal_init: skipping kernel_cpy_f32_bf16 (not supported)\n",
435
+ "ggml_metal_init: loaded kernel_cpy_f16_f32 0x13a3dd9c0 | th_max = 1024 | th_width = 32\n",
436
+ "ggml_metal_init: loaded kernel_cpy_f16_f16 0x13a3ddc20 | th_max = 1024 | th_width = 32\n",
437
+ "ggml_metal_init: skipping kernel_cpy_bf16_f32 (not supported)\n",
438
+ "ggml_metal_init: skipping kernel_cpy_bf16_bf16 (not supported)\n",
439
+ "ggml_metal_init: loaded kernel_cpy_f32_q8_0 0x11bc9cef0 | th_max = 1024 | th_width = 32\n",
440
+ "ggml_metal_init: loaded kernel_cpy_f32_q4_0 0x11bc9d150 | th_max = 1024 | th_width = 32\n",
441
+ "ggml_metal_init: loaded kernel_cpy_f32_q4_1 0x11bc9d3b0 | th_max = 1024 | th_width = 32\n",
442
+ "ggml_metal_init: loaded kernel_cpy_f32_q5_0 0x13a3dde80 | th_max = 1024 | th_width = 32\n",
443
+ "ggml_metal_init: loaded kernel_cpy_f32_q5_1 0x11f1ad790 | th_max = 1024 | th_width = 32\n",
444
+ "ggml_metal_init: loaded kernel_cpy_f32_iq4_nl 0x12ef8c920 | th_max = 1024 | th_width = 32\n",
445
+ "ggml_metal_init: loaded kernel_cpy_q4_0_f32 0x12ee250e0 | th_max = 1024 | th_width = 32\n",
446
+ "ggml_metal_init: loaded kernel_cpy_q4_0_f16 0x11bc9d610 | th_max = 1024 | th_width = 32\n",
447
+ "ggml_metal_init: loaded kernel_cpy_q4_1_f32 0x11bc9d870 | th_max = 1024 | th_width = 32\n",
448
+ "ggml_metal_init: loaded kernel_cpy_q4_1_f16 0x11bc9dad0 | th_max = 1024 | th_width = 32\n",
449
+ "ggml_metal_init: loaded kernel_cpy_q5_0_f32 0x11bc9dd30 | th_max = 1024 | th_width = 32\n",
450
+ "ggml_metal_init: loaded kernel_cpy_q5_0_f16 0x11bc9df90 | th_max = 1024 | th_width = 32\n",
451
+ "ggml_metal_init: loaded kernel_cpy_q5_1_f32 0x13a3de0e0 | th_max = 1024 | th_width = 32\n",
452
+ "ggml_metal_init: loaded kernel_cpy_q5_1_f16 0x11bc9e1f0 | th_max = 1024 | th_width = 32\n",
453
+ "ggml_metal_init: loaded kernel_cpy_q8_0_f32 0x13a3de340 | th_max = 1024 | th_width = 32\n",
454
+ "ggml_metal_init: loaded kernel_cpy_q8_0_f16 0x11bc9e450 | th_max = 1024 | th_width = 32\n",
455
+ "ggml_metal_init: loaded kernel_concat 0x11f1ad9f0 | th_max = 1024 | th_width = 32\n",
456
+ "ggml_metal_init: loaded kernel_sqr 0x11f1adf00 | th_max = 1024 | th_width = 32\n",
457
+ "ggml_metal_init: loaded kernel_sqrt 0x11f38d440 | th_max = 1024 | th_width = 32\n",
458
+ "ggml_metal_init: loaded kernel_sin 0x11f1ae820 | th_max = 1024 | th_width = 32\n",
459
+ "ggml_metal_init: loaded kernel_cos 0x13a3de820 | th_max = 1024 | th_width = 32\n",
460
+ "ggml_metal_init: loaded kernel_sum_rows 0x12ef8ce10 | th_max = 1024 | th_width = 32\n",
461
+ "ggml_metal_init: loaded kernel_argmax 0x11f38d6a0 | th_max = 1024 | th_width = 32\n",
462
+ "ggml_metal_init: loaded kernel_pool_2d_avg_f32 0x11f1aeba0 | th_max = 1024 | th_width = 32\n",
463
+ "ggml_metal_init: loaded kernel_pool_2d_max_f32 0x13a3dea80 | th_max = 1024 | th_width = 32\n",
464
+ "llama_kv_cache_init: kv_size = 2048, offload = 1, type_k = 'f16', type_v = 'f16', n_layer = 32, can_shift = 1\n",
465
+ "llama_kv_cache_init: layer 0: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
466
+ "llama_kv_cache_init: layer 1: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
467
+ "llama_kv_cache_init: layer 2: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
468
+ "llama_kv_cache_init: layer 3: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
469
+ "llama_kv_cache_init: layer 4: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
470
+ "llama_kv_cache_init: layer 5: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
471
+ "llama_kv_cache_init: layer 6: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
472
+ "llama_kv_cache_init: layer 7: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
473
+ "llama_kv_cache_init: layer 8: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
474
+ "llama_kv_cache_init: layer 9: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
475
+ "llama_kv_cache_init: layer 10: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
476
+ "llama_kv_cache_init: layer 11: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
477
+ "llama_kv_cache_init: layer 12: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
478
+ "llama_kv_cache_init: layer 13: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
479
+ "llama_kv_cache_init: layer 14: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
480
+ "llama_kv_cache_init: layer 15: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
481
+ "llama_kv_cache_init: layer 16: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
482
+ "llama_kv_cache_init: layer 17: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
483
+ "llama_kv_cache_init: layer 18: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
484
+ "llama_kv_cache_init: layer 19: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
485
+ "llama_kv_cache_init: layer 20: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
486
+ "llama_kv_cache_init: layer 21: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
487
+ "llama_kv_cache_init: layer 22: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
488
+ "llama_kv_cache_init: layer 23: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
489
+ "llama_kv_cache_init: layer 24: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
490
+ "llama_kv_cache_init: layer 25: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
491
+ "llama_kv_cache_init: layer 26: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
492
+ "llama_kv_cache_init: layer 27: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
493
+ "llama_kv_cache_init: layer 28: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
494
+ "llama_kv_cache_init: layer 29: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
495
+ "llama_kv_cache_init: layer 30: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
496
+ "llama_kv_cache_init: layer 31: n_embd_k_gqa = 1024, n_embd_v_gqa = 1024\n",
497
+ "llama_kv_cache_init: CPU KV buffer size = 256.00 MiB\n",
498
+ "llama_init_from_model: KV self size = 256.00 MiB, K (f16): 128.00 MiB, V (f16): 128.00 MiB\n",
499
+ "llama_init_from_model: CPU output buffer size = 0.12 MiB\n",
500
+ "llama_init_from_model: CPU compute buffer size = 164.01 MiB\n",
501
+ "llama_init_from_model: graph nodes = 1030\n",
502
+ "llama_init_from_model: graph splits = 514 (with bs=512), 1 (with bs=1)\n",
503
+ "Metal : EMBED_LIBRARY = 1 | CPU : NEON = 1 | ARM_FMA = 1 | FP16_VA = 1 | MATMUL_INT8 = 1 | DOTPROD = 1 | ACCELERATE = 1 | AARCH64_REPACK = 1 | \n",
504
+ "Model metadata: {'general.quantization_version': '2', 'tokenizer.ggml.unknown_token_id': '0', 'tokenizer.ggml.eos_token_id': '2', 'tokenizer.ggml.bos_token_id': '1', 'tokenizer.ggml.model': 'llama', 'llama.attention.head_count_kv': '8', 'llama.context_length': '32768', 'llama.attention.head_count': '32', 'llama.rope.freq_base': '10000.000000', 'llama.rope.dimension_count': '128', 'general.file_type': '15', 'llama.feed_forward_length': '14336', 'llama.embedding_length': '4096', 'llama.block_count': '32', 'general.architecture': 'llama', 'llama.attention.layer_norm_rms_epsilon': '0.000010', 'general.name': 'mistralai_mistral-7b-instruct-v0.1'}\n",
505
+ "Using fallback chat format: llama-2\n"
506
+ ]
507
+ },
508
+ {
509
+ "name": "stdout",
510
+ "output_type": "stream",
511
+ "text": [
512
+ "\n",
513
+ "--- Multi-Turn Mental Health Chatbot ---\n",
514
+ "This assistant simulates a counselor's conversation using AI.\n",
515
+ "- Type something your patient/student might say\n",
516
+ "- Type 'save' to export the conversation\n",
517
+ "- Type 'exit' to quit\n",
518
+ "\n",
519
+ "Example:\n",
520
+ "User: I feel like I’ll mess up my big presentation tomorrow.\n",
521
+ "Counselor: It’s completely normal to feel nervous before a big event...\n",
522
+ "\n"
523
+ ]
524
+ },
525
+ {
526
+ "name": "stdin",
527
+ "output_type": "stream",
528
+ "text": [
529
+ "User: i'm nervous\n"
530
+ ]
531
+ },
532
+ {
533
+ "name": "stdout",
534
+ "output_type": "stream",
535
+ "text": [
536
+ "(Predicted: information, Confidence: 85.5%)\n"
537
+ ]
538
+ },
539
+ {
540
+ "name": "stderr",
541
+ "output_type": "stream",
542
+ "text": [
543
+ "llama_perf_context_print: load time = 766.62 ms\n",
544
+ "llama_perf_context_print: prompt eval time = 766.43 ms / 23 tokens ( 33.32 ms per token, 30.01 tokens per second)\n",
545
+ "llama_perf_context_print: eval time = 17184.04 ms / 149 runs ( 115.33 ms per token, 8.67 tokens per second)\n",
546
+ "llama_perf_context_print: total time = 17971.68 ms / 172 tokens\n"
547
+ ]
548
+ },
549
+ {
550
+ "name": "stdout",
551
+ "output_type": "stream",
552
+ "text": [
553
+ "Counselor: From a mental health perspective, feeling nervous or anxious is a common and normal human experience. It's a natural response to stress or a challenging situation. However, if the feelings of nervousness persist or interfere with daily life, it could be a sign of an anxiety disorder.\n",
554
+ "\n",
555
+ "Anxiety disorders are a group of mental health conditions in which a person feels excessive and persistent worry or fear. These feelings can interfere with daily life, such as work, school, relationships, and personal activities. The symptoms of anxiety disorders vary from person to person, but typically include physical symptoms like sweating, trembling, and difficulty sleeping, as well as psychological symptoms like feelings of worry, fear, and avoidance\n"
556
+ ]
557
+ }
558
+ ],
559
+ "source": [
560
+ "# Multi-Turn Mental Health Chatbot using XGBoost + Mistral-7B\n",
561
+ "\n",
562
+ "import os\n",
563
+ "import pandas as pd\n",
564
+ "from sklearn.feature_extraction.text import TfidfVectorizer\n",
565
+ "from sklearn.preprocessing import LabelEncoder\n",
566
+ "from sklearn.model_selection import train_test_split\n",
567
+ "from xgboost import XGBClassifier\n",
568
+ "from llama_cpp import Llama\n",
569
+ "import json\n",
570
+ "\n",
571
+ "# --- Load and prepare the dataset ---\n",
572
+ "df = pd.read_csv(\"dataset/Kaggle_Mental_Health_Conversations_train.csv\")\n",
573
+ "df = df[['Context', 'Response']].dropna().copy()\n",
574
+ "\n",
575
+ "# Auto-labeling\n",
576
+ "keywords_to_labels = {\n",
577
+ " 'advice': ['try', 'should', 'suggest', 'recommend'],\n",
578
+ " 'validation': ['understand', 'feel', 'valid', 'normal'],\n",
579
+ " 'information': ['cause', 'often', 'disorder', 'symptom'],\n",
580
+ " 'question': ['how', 'what', 'why', 'have you']\n",
581
+ "}\n",
582
+ "\n",
583
+ "def auto_label_response(response):\n",
584
+ " response = response.lower()\n",
585
+ " for label, keywords in keywords_to_labels.items():\n",
586
+ " if any(word in response for word in keywords):\n",
587
+ " return label\n",
588
+ " return 'information'\n",
589
+ "\n",
590
+ "df['response_type'] = df['Response'].apply(auto_label_response)\n",
591
+ "\n",
592
+ "# Combine Context and Response for richer features\n",
593
+ "df['combined_text'] = df['Context'] + \" \" + df['Response']\n",
594
+ "\n",
595
+ "# Encode labels\n",
596
+ "le = LabelEncoder()\n",
597
+ "y = le.fit_transform(df['response_type'])\n",
598
+ "\n",
599
+ "# TF-IDF Vectorization\n",
600
+ "vectorizer = TfidfVectorizer(max_features=2000, ngram_range=(1, 2))\n",
601
+ "X = vectorizer.fit_transform(df['combined_text'])\n",
602
+ "\n",
603
+ "# Train/Test Split\n",
604
+ "X_train, X_test, y_train, y_test = train_test_split(\n",
605
+ " X, y, test_size=0.2, stratify=y, random_state=42\n",
606
+ ")\n",
607
+ "\n",
608
+ "# Train XGBoost Classifier\n",
609
+ "xgb_model = XGBClassifier(\n",
610
+ " objective='multi:softmax',\n",
611
+ " num_class=len(le.classes_),\n",
612
+ " eval_metric='mlogloss',\n",
613
+ " use_label_encoder=False,\n",
614
+ " max_depth=6,\n",
615
+ " learning_rate=0.1,\n",
616
+ " n_estimators=100\n",
617
+ ")\n",
618
+ "xgb_model.fit(X_train, y_train)\n",
619
+ "\n",
620
+ "# Load Mistral model\n",
621
+ "MODEL_PATH = os.path.expanduser(\"/Users/Pi/models/mistral/mistral-7b-instruct-v0.1.Q4_K_M.gguf\")\n",
622
+ "llm = Llama(model_path=MODEL_PATH, n_ctx=2048, n_threads=os.cpu_count())\n",
623
+ "\n",
624
+ "# --- Chatbot Functions ---\n",
625
+ "def predict_response_type(user_input):\n",
626
+ " vec = vectorizer.transform([user_input])\n",
627
+ " pred = xgb_model.predict(vec)\n",
628
+ " proba = xgb_model.predict_proba(vec).max()\n",
629
+ " label = le.inverse_transform(pred)[0]\n",
630
+ " return label, proba\n",
631
+ "\n",
632
+ "def build_prompt(user_input, response_type):\n",
633
+ " prompts = {\n",
634
+ " \"advice\": f\"A student said: \\\"{user_input}\\\". What advice should a counselor give to help?\",\n",
635
+ " \"validation\": f\"A student said: \\\"{user_input}\\\". How can a counselor validate the student's emotions?\",\n",
636
+ " \"information\": f\"A student said: \\\"{user_input}\\\". Explain what might be happening from a mental health perspective.\",\n",
637
+ " \"question\": f\"A student said: \\\"{user_input}\\\". What follow-up questions should a counselor ask?\"\n",
638
+ " }\n",
639
+ " return prompts.get(response_type, prompts[\"information\"])\n",
640
+ "\n",
641
+ "def generate_llm_response(user_input, response_type):\n",
642
+ " prompt = build_prompt(user_input, response_type)\n",
643
+ " result = llm(prompt, max_tokens=150, temperature=0.7)\n",
644
+ " return result['choices'][0]['text'].strip()\n",
645
+ "\n",
646
+ "def trim_memory(history, max_turns=6):\n",
647
+ " return history[-max_turns * 2:]\n",
648
+ "\n",
649
+ "def save_conversation(history):\n",
650
+ " with open(\"chat_history.json\", \"w\") as f:\n",
651
+ " json.dump(history, f, indent=2)\n",
652
+ " print(\"✅ Conversation saved to chat_history.json\\n\")\n",
653
+ "\n",
654
+ "def show_intro():\n",
655
+ " print(\"\\n--- Multi-Turn Mental Health Chatbot ---\")\n",
656
+ " print(\"This assistant simulates a counselor's conversation using AI.\")\n",
657
+ " print(\"- Type something your patient/student might say\")\n",
658
+ " print(\"- Type 'save' to export the conversation\")\n",
659
+ " print(\"- Type 'exit' to quit\\n\")\n",
660
+ "\n",
661
+ " print(\"Example:\")\n",
662
+ " print(\"User: I feel like I’ll mess up my big presentation tomorrow.\")\n",
663
+ " print(\"Counselor: It’s completely normal to feel nervous before a big event...\\n\")\n",
664
+ "\n",
665
+ "# --- Run Chatbot ---\n",
666
+ "history = []\n",
667
+ "show_intro()\n",
668
+ "\n",
669
+ "while True:\n",
670
+ " user_input = input(\"User: \").strip()\n",
671
+ "\n",
672
+ " if user_input.lower() == \"exit\":\n",
673
+ " print(\"Goodbye\")\n",
674
+ " break\n",
675
+ " elif user_input.lower() == \"save\":\n",
676
+ " save_conversation(history)\n",
677
+ " continue\n",
678
+ "\n",
679
+ " predicted_type, confidence = predict_response_type(user_input)\n",
680
+ " print(f\"(Prfedicted: {predicted_type}, Confidence: {confidence:.1%})\")\n",
681
+ "\n",
682
+ " llm_reply = generate_llm_response(user_input, predicted_type)\n",
683
+ "\n",
684
+ " history.append({\"role\": \"user\", \"content\": user_input})\n",
685
+ " history.append({\"role\": \"assistant\", \"content\": llm_reply})\n",
686
+ " history = trim_memory(history)\n",
687
+ "\n",
688
+ " print(\"Counselor:\", llm_reply)"
689
+ ]
690
+ },
691
+ {
692
+ "cell_type": "code",
693
+ "execution_count": null,
694
+ "id": "8e2f9122-f3dd-4d09-bfb1-c0438df2e8f1",
695
+ "metadata": {},
696
+ "outputs": [],
697
+ "source": []
698
+ }
699
+ ],
700
+ "metadata": {
701
+ "kernelspec": {
702
+ "display_name": "Python (myenv)",
703
+ "language": "python",
704
+ "name": "myenv"
705
+ },
706
+ "language_info": {
707
+ "codemirror_mode": {
708
+ "name": "ipython",
709
+ "version": 3
710
+ },
711
+ "file_extension": ".py",
712
+ "mimetype": "text/x-python",
713
+ "name": "python",
714
+ "nbconvert_exporter": "python",
715
+ "pygments_lexer": "ipython3",
716
+ "version": "3.10.16"
717
+ }
718
+ },
719
+ "nbformat": 4,
720
+ "nbformat_minor": 5
721
+ }
README.md CHANGED
@@ -1,13 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
- title: Mental Health Chatbot
3
- emoji:
4
- colorFrom: indigo
5
- colorTo: green
6
- sdk: streamlit
7
- sdk_version: 1.44.1
8
- app_file: app.py
9
- pinned: false
10
- license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🧠 Mental Health Counselor Assistant
2
+
3
+ A privacy-friendly, intelligent assistant designed to help mental health professionals explore **response suggestions** based on patient input. Built with `XGBoost` for intent classification and `Mistral-7B` for natural language generation, this app helps support clinical conversations with empathy and structure — while keeping you in full control.
4
+
5
+ ---
6
+
7
+ ## ✅ Problem Statement
8
+
9
+ Mental health counselors are tasked with responding to a wide range of complex emotions and situations. In high-pressure or uncertain moments, this tool helps:
10
+
11
+ - Predict the **intent** behind a patient's message (advice-seeking, validation, informational, or inquisitive)
12
+ - Generate a supportive, **AI-assisted counselor response**
13
+ - Log conversations for review and learning
14
+ - Preserve privacy with local inference — built for **HIPAA-aware workflows**
15
+
16
+ ---
17
+
18
+ ## ✨ Features
19
+
20
+ - 🔍 **Intent Prediction** — XGBoost classifier trained on annotated mental health dialogue
21
+ - 💬 **Response Generation** — LLM-backed replies using quantized [Mistral-7B](https://mistral.ai/news/announcing-mistral-7b/)
22
+ - 🧠 **Multi-turn Memory** — Maintains up to 6 rounds of conversation
23
+ - ✅ **Export to JSON + CSV** — With timestamps for traceability
24
+ - 🧰 **HIPAA-conscious Design** — No third-party API calls required; all runs locally
25
+
26
+ ---
27
+
28
+ ## 🖼️ App Preview
29
+
30
+ ![counselor assistant demo](demo/demo.gif)
31
+
32
+ ---
33
+
34
+ ## 🚀 How to Run
35
+
36
+ ### 🔧 Local (with Mistral-7B)
37
+
38
+ > 🧩 You must download a quantized `.gguf` model file from Hugging Face or TheBloke, e.g.:
39
+ >
40
+ > `/Users/yourname/models/mistral/mistral-7b-instruct-v0.1.Q4_K_M.gguf`
41
+
42
+ ```bash
43
+ git clone https://github.com/yourname/mental-health-chatbot.git
44
+ cd mental-health-chatbot
45
+ pip install -r requirements.txt
46
+ streamlit run app_local.py
47
+ ```
48
+
49
  ---
50
+
51
+ ### 🐳 Docker (Recommended)
52
+
53
+ ```bash
54
+ docker build -t counselor-assistant .
55
+ docker run -p 8501:8501 counselor-assistant
56
+ ```
57
+
58
+ ---
59
+
60
+ ## 📁 Project Structure
61
+
62
+ ```
63
+ mental-health-chatbot/
64
+
65
+ ├── app_local.py # Streamlit app (uses llama-cpp + XGBoost)
66
+ ├── requirements.txt
67
+ ├── Dockerfile
68
+ ├── demo/ # Optional: screenshots or .gif
69
+ ├── dataset/
70
+ │ └── Kaggle_Mental_Health_Conversations_train.csv
71
+ ├── models/
72
+ │ └── mistral-7b-instruct-v0.1.Q4_K_M.gguf
73
+ ├── README.md
74
+ └── LICENSE
75
+ ```
76
+
77
+ ---
78
+
79
+ ## 📌 Design Decisions
80
+
81
+ - 🧠 Used `TfidfVectorizer` + `XGBoost` as a **lightweight, interpretable** classifier
82
+ - 🔒 LLM inference handled locally with `llama-cpp-python` — no external data leaks
83
+ - 📦 Docker support to simulate realistic deployment and improve portability
84
+ - 🎯 Optimized for educational and prototyping use in **clinician settings**
85
+
86
  ---
87
 
88
+ ## 📍 Future Improvements
89
+
90
+ - Add long-form audio transcription support
91
+ - Integrate feedback loop for model tuning
92
+ - Auto-summary of sessions
93
+ - Hugging Face Space version (hosted with opt-in privacy tradeoffs)
94
+
95
+ ---
96
+
97
+ ## 👩‍⚕️ A Note to Reviewers
98
+
99
+ This project was developed for an interview to showcase how **AI and empathy** can work hand-in-hand to support mental health professionals. Thank you for reviewing, and I hope it sparks a great conversation about the intersection of tech and care. 💙
100
+
101
+ ---
102
+
103
+ ## 📄 License
104
+
105
+ MIT — free to use and modify, but please be thoughtful in healthcare applications.
106
+
app.py ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import pandas as pd
4
+ import json
5
+ import time
6
+ import csv
7
+ from datetime import datetime
8
+ from sklearn.feature_extraction.text import TfidfVectorizer
9
+ from sklearn.preprocessing import LabelEncoder
10
+ from sklearn.model_selection import train_test_split
11
+ from xgboost import XGBClassifier
12
+ from llama_cpp import Llama
13
+
14
+ st.set_page_config(page_title="Counselor Assistant", layout="centered")
15
+
16
+ st.markdown("""
17
+ <style>
18
+ .main { background-color: #f9f9f9; padding: 1rem 2rem; border-radius: 12px; }
19
+ h1 { color: #2c3e50; text-align: center; font-size: 2.4rem; }
20
+ .user { color: #1f77b4; font-weight: bold; }
21
+ .assistant { color: #2ca02c; font-weight: bold; }
22
+ </style>
23
+ """, unsafe_allow_html=True)
24
+
25
+ st.title("🧠 Mental Health Counselor Assistant")
26
+ st.markdown("""
27
+ Hi there, counselor 👋
28
+
29
+ This tool is here to offer **supportive, AI-generated suggestions** when you’re not quite sure how to respond to a patient.
30
+
31
+ ### How it helps:
32
+ - 🧩 Predicts the type of support your patient might need (advice, validation, information, & question.)
33
+ - 💬 Generates a supportive counselor response
34
+ - 📁 Lets you save and track conversations for reflection
35
+
36
+ It's a sidekick, not a substitute for your clinical judgment 💚
37
+ """)
38
+
39
+ df = pd.read_csv("dataset/Kaggle_Mental_Health_Conversations_train.csv")
40
+ df = df[['Context', 'Response']].dropna().copy()
41
+
42
+ keywords_to_labels = {
43
+ 'advice': ['try', 'should', 'suggest', 'recommend'],
44
+ 'validation': ['understand', 'feel', 'valid', 'normal'],
45
+ 'information': ['cause', 'often', 'disorder', 'symptom'],
46
+ 'question': ['how', 'what', 'why', 'have you']
47
+ }
48
+
49
+ def auto_label_response(response):
50
+ response = response.lower()
51
+ for label, keywords in keywords_to_labels.items():
52
+ if any(word in response for word in keywords):
53
+ return label
54
+ return 'information'
55
+
56
+ df['response_type'] = df['Response'].apply(auto_label_response)
57
+ df['combined_text'] = df['Context'] + " " + df['Response']
58
+
59
+ le = LabelEncoder()
60
+ y = le.fit_transform(df['response_type'])
61
+
62
+ vectorizer = TfidfVectorizer(max_features=2000, ngram_range=(1, 2))
63
+ X = vectorizer.fit_transform(df['combined_text'])
64
+
65
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)
66
+
67
+ xgb_model = XGBClassifier(
68
+ objective='multi:softmax',
69
+ num_class=len(le.classes_),
70
+ eval_metric='mlogloss',
71
+ use_label_encoder=False,
72
+ max_depth=6,
73
+ learning_rate=0.1,
74
+ n_estimators=100
75
+ )
76
+ xgb_model.fit(X_train, y_train)
77
+
78
+ MODEL_PATH = os.path.expanduser("/Users/Pi/models/mistral/mistral-7b-instruct-v0.1.Q4_K_M.gguf")
79
+ @st.cache_resource(show_spinner=True)
80
+ def load_llm():
81
+ return Llama(model_path=MODEL_PATH, n_ctx=2048, n_threads=os.cpu_count())
82
+
83
+ llm = load_llm()
84
+
85
+ def predict_response_type(user_input):
86
+ vec = vectorizer.transform([user_input])
87
+ pred = xgb_model.predict(vec)
88
+ proba = xgb_model.predict_proba(vec).max()
89
+ label = le.inverse_transform(pred)[0]
90
+ return label, proba
91
+
92
+ def build_prompt(user_input, response_type):
93
+ prompts = {
94
+ "advice": f"A patient said: \"{user_input}\". What advice should a mental health counselor give to support them?",
95
+ "validation": f"A patient said: \"{user_input}\". How can a counselor validate and empathize with their emotions?",
96
+ "information": f"A patient said: \"{user_input}\". Explain what might be happening from a mental health perspective.",
97
+ "question": f"A patient said: \"{user_input}\". What thoughtful follow-up questions should a counselor ask?"
98
+ }
99
+ return prompts.get(response_type, prompts["information"])
100
+
101
+ def generate_llm_response(user_input, response_type):
102
+ prompt = build_prompt(user_input, response_type)
103
+ start = time.time()
104
+ with st.spinner("Thinking through a helpful response for your patient..."):
105
+ result = llm(prompt, max_tokens=300, temperature=0.7)
106
+ end = time.time()
107
+ st.info(f"Response generated in {end - start:.1f} seconds")
108
+ return result['choices'][0]['text'].strip()
109
+
110
+ def trim_memory(history, max_turns=6):
111
+ return history[-max_turns * 2:]
112
+
113
+ def save_conversation(history):
114
+ now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
115
+ with open("chat_log_combined.csv", "w", newline='') as f:
116
+ writer = csv.writer(f)
117
+ writer.writerow(["Timestamp", "Role", "Content", "Intent", "Confidence"])
118
+ for entry in history:
119
+ writer.writerow([
120
+ now,
121
+ entry.get("role", ""),
122
+ entry.get("content", ""),
123
+ entry.get("label", ""),
124
+ round(float(entry.get("confidence", 0)), 2)
125
+ ])
126
+ st.success("Saved to chat_log_combined.csv")
127
+
128
+ if "history" not in st.session_state:
129
+ st.session_state.history = []
130
+ if "user_input" not in st.session_state:
131
+ st.session_state.user_input = ""
132
+
133
+ MAX_WORDS = 1000
134
+ word_count = len(st.session_state.user_input.split())
135
+ st.markdown(f"**📝 Input Length:** {word_count} / {MAX_WORDS} words")
136
+ st.session_state.user_input = st.text_area(
137
+ "💬 What did your patient say?",
138
+ value=st.session_state.user_input,
139
+ placeholder="e.g. I just feel like I'm never going to get better.",
140
+ height=100
141
+ )
142
+
143
+ col1, col2, col3 = st.columns([2, 1, 1])
144
+ with col1:
145
+ send = st.button("💡 Suggest Response")
146
+ with col2:
147
+ save = st.button("📁 Save This")
148
+ with col3:
149
+ reset = st.button("🔁 Reset")
150
+
151
+ if send and st.session_state.user_input:
152
+ user_input = st.session_state.user_input
153
+ predicted_type, confidence = predict_response_type(user_input)
154
+ reply = generate_llm_response(user_input, predicted_type)
155
+
156
+ st.session_state.history.append({"role": "user", "content": user_input})
157
+ st.session_state.history.append({"role": "assistant", "content": reply, "label": predicted_type, "confidence": confidence})
158
+ st.session_state.history = trim_memory(st.session_state.history)
159
+
160
+ if save:
161
+ save_conversation(st.session_state.history)
162
+
163
+ if reset:
164
+ st.session_state.history = []
165
+ st.session_state.user_input = ""
166
+ st.success("Conversation has been cleared.")
167
+
168
+ st.markdown("---")
169
+ for turn in st.session_state.history:
170
+ if turn["role"] == "user":
171
+ st.markdown(f"🧍‍♀️ **Patient:** {turn['content']}")
172
+ else:
173
+ st.markdown(f"👩‍⚕️👨‍⚕️ **Suggested Counselor Response:** {turn['content']}")
174
+ st.caption(f"_Intent: {turn['label']} (Confidence: {turn['confidence']:.0%})_")
175
+ st.markdown("---")
app_slow_version.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Streamlit App: Counselor Assistant using XGBoost + Flan-T5 (Cloud Version)
2
+
3
+ import streamlit as st
4
+ import os
5
+ import pandas as pd
6
+ import json
7
+ import time
8
+ import csv
9
+ from sklearn.feature_extraction.text import TfidfVectorizer
10
+ from sklearn.preprocessing import LabelEncoder
11
+ from sklearn.model_selection import train_test_split
12
+ from xgboost import XGBClassifier
13
+ from transformers import pipeline
14
+
15
+ st.set_page_config(page_title="Counselor Assistant", layout="centered")
16
+
17
+ st.markdown("""
18
+ <style>
19
+ .main { background-color: #f4f4f9; padding: 1rem 2rem; border-radius: 12px; }
20
+ h1 { color: #2c3e50; text-align: center; font-size: 2.4rem; }
21
+ .user { color: #1f77b4; font-weight: bold; }
22
+ .assistant { color: #2ca02c; font-weight: bold; }
23
+ </style>
24
+ """, unsafe_allow_html=True)
25
+
26
+ st.title("Mental Health Counselor Assistant")
27
+ st.markdown("""
28
+ Welcome, counselor 👩‍⚕️👨‍⚕️
29
+
30
+ This assistant is designed to provide you with **supportive, evidence-based suggestions** when you're unsure how to best respond to a patient’s concerns.
31
+
32
+ Just enter what your patient shared with you, and this tool will:
33
+ - Predict the type of support that fits best (e.g., advice, validation, information, and question)
34
+ - Generate a suggested counselor reply
35
+ - Let you save the conversation for your records
36
+
37
+ This is not a diagnostic tool — it’s here to support **your clinical intuition**.
38
+ """)
39
+
40
+ # Load and prepare the dataset
41
+ df = pd.read_csv("dataset/Kaggle_Mental_Health_Conversations_train.csv")
42
+ df = df[['Context', 'Response']].dropna().copy()
43
+
44
+ keywords_to_labels = {
45
+ 'advice': ['try', 'should', 'suggest', 'recommend'],
46
+ 'validation': ['understand', 'feel', 'valid', 'normal'],
47
+ 'information': ['cause', 'often', 'disorder', 'symptom'],
48
+ 'question': ['how', 'what', 'why', 'have you']
49
+ }
50
+
51
+ def auto_label_response(response):
52
+ response = response.lower()
53
+ for label, keywords in keywords_to_labels.items():
54
+ if any(word in response for word in keywords):
55
+ return label
56
+ return 'information'
57
+
58
+ df['response_type'] = df['Response'].apply(auto_label_response)
59
+ df['combined_text'] = df['Context'] + " " + df['Response']
60
+
61
+ le = LabelEncoder()
62
+ y = le.fit_transform(df['response_type'])
63
+
64
+ vectorizer = TfidfVectorizer(max_features=2000, ngram_range=(1, 2))
65
+ X = vectorizer.fit_transform(df['combined_text'])
66
+
67
+ X_train, X_test, y_train, y_test = train_test_split(
68
+ X, y, test_size=0.2, stratify=y, random_state=42
69
+ )
70
+
71
+ xgb_model = XGBClassifier(
72
+ objective='multi:softmax',
73
+ num_class=len(le.classes_),
74
+ eval_metric='mlogloss',
75
+ use_label_encoder=False,
76
+ max_depth=6,
77
+ learning_rate=0.1,
78
+ n_estimators=100
79
+ )
80
+ xgb_model.fit(X_train, y_train)
81
+
82
+ # Replace Mistral-7B with Flan-T5 hosted model
83
+ @st.cache_resource(show_spinner="Loading Flan-T5 model...")
84
+ def load_llm():
85
+ return pipeline("text2text-generation", model="google/flan-t5-base")
86
+
87
+ llm = load_llm()
88
+
89
+ def predict_response_type(user_input):
90
+ vec = vectorizer.transform([user_input])
91
+ pred = xgb_model.predict(vec)
92
+ proba = xgb_model.predict_proba(vec).max()
93
+ label = le.inverse_transform(pred)[0]
94
+ return label, proba
95
+
96
+ def build_prompt(user_input, response_type):
97
+ prompts = {
98
+ "advice": f"A patient said: \"{user_input}\". What advice should a mental health counselor give to support them?",
99
+ "validation": f"A patient said: \"{user_input}\". How can a counselor validate and empathize with their emotions?",
100
+ "information": f"A patient said: \"{user_input}\". Explain what might be happening from a mental health perspective.",
101
+ "question": f"A patient said: \"{user_input}\". What thoughtful follow-up questions should a counselor ask?"
102
+ }
103
+ return prompts.get(response_type, prompts["information"])
104
+
105
+ def generate_llm_response(user_input, response_type):
106
+ prompt = build_prompt(user_input, response_type)
107
+ start = time.time()
108
+ with st.spinner("Thinking through a helpful response for your patient..."):
109
+ result = llm(prompt, max_length=150, do_sample=True, temperature=0.7)
110
+ end = time.time()
111
+ st.info(f"Response generated in {end - start:.1f} seconds")
112
+ return result[0]["generated_text"].strip()
113
+
114
+ def trim_memory(history, max_turns=6):
115
+ return history[-max_turns * 2:]
116
+
117
+ def save_conversation(history):
118
+ with open("chat_history.json", "w") as f:
119
+ json.dump(history, f, indent=2)
120
+ with open("chat_log.csv", "w", newline='') as f:
121
+ writer = csv.writer(f)
122
+ writer.writerow(["Role", "Content"])
123
+ for entry in history:
124
+ writer.writerow([entry.get("role", ""), entry.get("content", "")])
125
+ st.success("Saved to chat_history.json and chat_log.csv")
126
+
127
+ # Streamlit UI
128
+ if "history" not in st.session_state:
129
+ st.session_state.history = []
130
+
131
+ with st.expander("💡 Sample inputs you can try"):
132
+ st.markdown("""
133
+ - My patient is constantly feeling overwhelmed at work.
134
+ - A student says they panic every time they have to speak in class.
135
+ - Someone told me they think they’ll never feel okay again.
136
+ """)
137
+
138
+ user_input = st.text_area("💬 What did your patient say?", placeholder="e.g. I just feel like I'm never going to get better.", height=100)
139
+
140
+ col1, col2, col3 = st.columns([2, 1, 1])
141
+
142
+ with col1:
143
+ send = st.button("Suggest Response")
144
+ with col2:
145
+ save = st.button("📁 Save This")
146
+ with col3:
147
+ reset = st.button("🔁 Reset")
148
+
149
+ if send and user_input:
150
+ predicted_type, confidence = predict_response_type(user_input)
151
+ reply = generate_llm_response(user_input, predicted_type)
152
+
153
+ st.session_state.history.append({"role": "user", "content": user_input})
154
+ st.session_state.history.append({"role": "assistant", "content": reply, "label": predicted_type, "confidence": confidence})
155
+ st.session_state.history = trim_memory(st.session_state.history)
156
+
157
+ if save:
158
+ save_conversation(st.session_state.history)
159
+
160
+ if reset:
161
+ st.session_state.history = []
162
+ st.success("Conversation has been cleared.")
163
+
164
+ st.markdown("---")
165
+ for turn in st.session_state.history:
166
+ if turn["role"] == "user":
167
+ st.markdown(f"🧍‍♀️ **Patient:** {turn['content']}")
168
+ else:
169
+ st.markdown(f"👩‍⚕️👨‍⚕️ **Suggested Counselor Response:** {turn['content']}")
170
+ st.caption(f"_Intent: {turn['label']} (Confidence: {turn['confidence']:.0%})_")
171
+ st.markdown("---")
172
+
chat_log_combined.csv ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Timestamp,Role,Content,Intent,Confidence
2
+ 2025-04-11 03:11:14,user,i am nervous about my incoming interview ,,0.0
3
+ 2025-04-11 03:11:14,assistant,"From a mental health perspective, it is understandable that the patient may be feeling nervous about their upcoming interview. Anxiety is a common and natural response to stressful situations, and it can manifest in various physical and emotional symptoms.
4
+
5
+ The patient's nervousness may be related to their fear of failure, uncertainty about the interview process, or concerns about their ability to perform well. These feelings of anxiety may be affecting their self-confidence, sleep, appetite, and overall well-being.
6
+
7
+ It is important for the patient to acknowledge and validate their feelings, and to take steps to manage their anxiety. Some effective coping strategies for managing anxiety include deep breathing exercises, progressive muscle relaxation, cognitive-behavioral therapy, and mindfulness practices. It may also be helpful for the patient to practice positive self-talk and visualization techniques to boost their confidence and self-esteem.
8
+
9
+ Overall, it is essential for the patient to prioritize their mental health and well-being during this time, and to seek support from friends, family, or a mental health professional if needed.",information,0.84
10
+ 2025-04-11 03:11:14,user,i cannot sleep ,,0.0
11
+ 2025-04-11 03:11:14,assistant,"There can be a variety of reasons why someone might have trouble sleeping from a mental health perspective. Some common causes include:
12
+
13
+ 1. Stress and anxiety: High levels of stress and anxiety can interfere with the ability to fall and stay asleep. This can be caused by a number of factors, such as work or family problems, financial difficulties, or health concerns.
14
+ 2. Depression: Depression can cause changes in sleep patterns, including difficulty falling and staying asleep, or feeling tired during the day.
15
+ 3. Bipolar disorder: Bipolar disorder is a mental health condition characterized by extreme mood swings, including periods of depression and mania. Sleep disturbances are common in people with bipolar disorder.
16
+ 4. Post-traumatic stress disorder (PTSD): PTSD is a mental health condition that can develop after experiencing or witnessing a traumatic event, such as a natural disaster, a serious accident, or a sexual assault. People with PTSD may have difficulty sleeping, as they may be haunted by memories of the event.
17
+ 5. Substance abuse: The use of drugs and alcohol can interfere with sleep, making it difficult to fall and stay asleep.
18
+
19
+ It is important to note that these are just a few examples, and that there may be other underlying factors that are contributing to the difficulty sleeping. If the patient is experiencing persistent difficulty sleeping, it may be helpful to seek professional help",information,0.85
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ scikit-learn
4
+ xgboost
5
+ seaborn
6
+ matplotlib
7
+ llama-cpp-python --prefer-binary