Skip to content

Commit a3e6f76

Browse files
Merge pull request #11 from mlrun/fix_pmck_bank
Fix pmck issues + cosmetics
2 parents fb547f7 + 1ff2253 commit a3e6f76

File tree

8 files changed

+111
-353
lines changed

8 files changed

+111
-353
lines changed

01_churn_ml_model.ipynb

Lines changed: 24 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
"![](images/01_churn_ml_model_architecture.png)"
2525
]
2626
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"id": "28f2ff57",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"!pip install tqdm"
35+
]
36+
},
2737
{
2838
"cell_type": "code",
2939
"execution_count": 1,
@@ -81,7 +91,7 @@
8191
"project_name = \"banking-agent\"\n",
8292
"project = mlrun.get_or_create_project(\n",
8393
" project_name,\n",
84-
" user_project=False,\n",
94+
" user_project=True,\n",
8595
" parameters={\n",
8696
" \"build_image\": True, # Disable after running once\n",
8797
" },\n",
@@ -128,39 +138,13 @@
128138
},
129139
{
130140
"cell_type": "code",
131-
"execution_count": 15,
141+
"execution_count": null,
132142
"id": "4e7060b9-3848-4753-99d8-8c16d3fb2ef3",
133143
"metadata": {},
134144
"outputs": [],
135145
"source": [
136-
"from src.model_monitoring_utils import enable_model_monitoring"
137-
]
138-
},
139-
{
140-
"cell_type": "code",
141-
"execution_count": 16,
142-
"id": "8516c667-9315-43cd-89a8-1def199ffbcb",
143-
"metadata": {},
144-
"outputs": [
145-
{
146-
"name": "stdout",
147-
"output_type": "stream",
148-
"text": [
149-
"> 2025-09-03 01:17:23,159 [info] Model monitoring credentials were set successfully. Please keep in mind that if you already had model monitoring functions / model monitoring infra / tracked model server deployed on your project, you will need to redeploy them. For redeploying the model monitoring infra, first disable it using `project.disable_model_monitoring()` and then enable it using `project.enable_model_monitoring()`.\n"
150-
]
151-
},
152-
{
153-
"data": {
154-
"text/plain": [
155-
"<mlrun.projects.project.MlrunProject at 0x7feb19efac10>"
156-
]
157-
},
158-
"execution_count": 16,
159-
"metadata": {},
160-
"output_type": "execute_result"
161-
}
162-
],
163-
"source": [
146+
"from src.model_monitoring_utils import enable_model_monitoring\n",
147+
"\n",
164148
"# Enable model monitoring\n",
165149
"enable_model_monitoring(project=project, base_period=10, wait_for_deployment=False)"
166150
]
@@ -215,41 +199,13 @@
215199
},
216200
{
217201
"cell_type": "code",
218-
"execution_count": 6,
202+
"execution_count": null,
219203
"id": "3ff4f142-5efd-4913-95c1-11e18b501e91",
220204
"metadata": {},
221205
"outputs": [],
222206
"source": [
223-
"from config import MainConfig"
224-
]
225-
},
226-
{
227-
"cell_type": "code",
228-
"execution_count": 7,
229-
"id": "de252aef-872f-47ca-b039-d2f8e49a9927",
230-
"metadata": {},
231-
"outputs": [
232-
{
233-
"data": {
234-
"text/plain": [
235-
"{'source_url': 'store://datasets/banking-agent/churn#0@6d4ffd11bfe20eab0ea3cb1cf03e1c3458b0408c^40c43a7cc1d445b90203ac2d2cf0a7abd91f8542',\n",
236-
" 'label_column': 'churn',\n",
237-
" 'allow_validation_failure': True,\n",
238-
" 'test_size': 0.2,\n",
239-
" 'model_name': 'churn_model',\n",
240-
" 'sentiment_model': 'cardiffnlp/twitter-roberta-base-sentiment-latest',\n",
241-
" 'text_column': 'chat_log',\n",
242-
" 'sentiment_column': 'sentiment_label',\n",
243-
" 'ordinal_columns': ['international_plan', 'voice_mail_plan'],\n",
244-
" 'drop_columns': ['area_code', 'chat_log', 'state']}"
245-
]
246-
},
247-
"execution_count": 7,
248-
"metadata": {},
249-
"output_type": "execute_result"
250-
}
251-
],
252-
"source": [
207+
"from config import MainConfig\n",
208+
"\n",
253209
"arguments = MainConfig(source_url=dataset.uri).model_dump()\n",
254210
"arguments"
255211
]
@@ -993,80 +949,26 @@
993949
},
994950
{
995951
"cell_type": "code",
996-
"execution_count": 16,
952+
"execution_count": null,
997953
"id": "292500a1-7c45-45ac-ae8d-e43153ecb55d",
998954
"metadata": {},
999955
"outputs": [],
1000956
"source": [
1001-
"data = test_set.drop(\"churn\", axis=1).to_dict(orient=\"split\")[\"data\"]"
1002-
]
1003-
},
1004-
{
1005-
"cell_type": "code",
1006-
"execution_count": 17,
1007-
"id": "db4a8bbf-51c7-44de-ad78-39ec5ea65a0c",
1008-
"metadata": {},
1009-
"outputs": [
1010-
{
1011-
"data": {
1012-
"text/plain": [
1013-
"[0.0,\n",
1014-
" 0.0,\n",
1015-
" 1.0,\n",
1016-
" 117,\n",
1017-
" 0,\n",
1018-
" 181.5,\n",
1019-
" 95,\n",
1020-
" 30.86,\n",
1021-
" 205.1,\n",
1022-
" 88,\n",
1023-
" 17.43,\n",
1024-
" 204.0,\n",
1025-
" 82,\n",
1026-
" 9.18,\n",
1027-
" 14.7,\n",
1028-
" 9,\n",
1029-
" 3.97,\n",
1030-
" 2,\n",
1031-
" 0.693109929561615]"
1032-
]
1033-
},
1034-
"execution_count": 17,
1035-
"metadata": {},
1036-
"output_type": "execute_result"
1037-
}
1038-
],
1039-
"source": [
957+
"data = test_set.drop(\"churn\", axis=1).to_dict(orient=\"split\")[\"data\"]\n",
1040958
"data[0]"
1041959
]
1042960
},
1043961
{
1044962
"cell_type": "code",
1045-
"execution_count": 18,
1046-
"id": "a62905db-0d1a-456d-beae-e371c8e92f04",
963+
"execution_count": null,
964+
"id": "f6929864-22e3-49f8-a351-fba39f795271",
1047965
"metadata": {},
1048966
"outputs": [],
1049967
"source": [
1050968
"from random import choice\n",
1051969
"from time import sleep\n",
1052-
"from tqdm import tqdm"
1053-
]
1054-
},
1055-
{
1056-
"cell_type": "code",
1057-
"execution_count": null,
1058-
"id": "f6929864-22e3-49f8-a351-fba39f795271",
1059-
"metadata": {},
1060-
"outputs": [
1061-
{
1062-
"name": "stderr",
1063-
"output_type": "stream",
1064-
"text": [
1065-
" 13%|█▎ | 127/1000 [00:13<01:31, 9.57it/s]"
1066-
]
1067-
}
1068-
],
1069-
"source": [
970+
"from tqdm import tqdm\n",
971+
"\n",
1070972
"for i in tqdm(range(1000)):\n",
1071973
" data_point = choice(data)\n",
1072974
" resp = serving_fn.invoke(\n",
@@ -1101,17 +1003,11 @@
11011003
"Once the churn model is deployed and invoked, you will be able to view the model monitoring results in the MLRun UI:\n",
11021004
"![](images/tabular_model_monitoring.png)"
11031005
]
1104-
},
1105-
{
1106-
"cell_type": "markdown",
1107-
"id": "8bc601cb",
1108-
"metadata": {},
1109-
"source": []
11101006
}
11111007
],
11121008
"metadata": {
11131009
"kernelspec": {
1114-
"display_name": "banking-agent",
1010+
"display_name": "Pyth(myenv)",
11151011
"language": "python",
11161012
"name": "venv"
11171013
},

02_guardrail_deployment.ipynb

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,12 @@
5858
},
5959
{
6060
"cell_type": "code",
61-
"execution_count": 2,
61+
"execution_count": null,
6262
"id": "4ea8ae0f-2bde-49c7-ade1-932fff5d66ff",
6363
"metadata": {},
64-
"outputs": [
65-
{
66-
"name": "stdout",
67-
"output_type": "stream",
68-
"text": [
69-
"Setting Source for the demo:\n",
70-
"Project Source: None\n",
71-
"> 2025-09-03 17:41:58,028 [info] Project loaded successfully: {\"project_name\":\"banking-agent\"}\n"
72-
]
73-
}
74-
],
64+
"outputs": [],
7565
"source": [
76-
"project = mlrun.get_or_create_project(\"banking-agent\", user_project=False)"
66+
"project = mlrun.get_or_create_project(\"banking-agent\", user_project=True)"
7767
]
7868
},
7969
{
@@ -233,7 +223,7 @@
233223
},
234224
{
235225
"cell_type": "code",
236-
"execution_count": 7,
226+
"execution_count": null,
237227
"id": "a13d05b3-3bb4-4a37-bf6a-6f9cfbdeb0dd",
238228
"metadata": {},
239229
"outputs": [],
@@ -244,27 +234,8 @@
244234
" model_file=\"src/no-op.pkl\",\n",
245235
" inputs=[Feature(value_type=\"str\", name=\"question\")],\n",
246236
" outputs=[Feature(value_type=\"str\", name=\"answer\")],\n",
247-
")"
248-
]
249-
},
250-
{
251-
"cell_type": "code",
252-
"execution_count": 8,
253-
"id": "184e70ee-7bf4-45ee-b53d-f1d71f93c356",
254-
"metadata": {},
255-
"outputs": [
256-
{
257-
"data": {
258-
"text/plain": [
259-
"'store://models/banking-agent/banking-topic-guardrail#0@5421ab454972a644c42a97b0ff0d382101802a8f^9084926892b55d790671abb2226368b58f88059d'"
260-
]
261-
},
262-
"execution_count": 8,
263-
"metadata": {},
264-
"output_type": "execute_result"
265-
}
266-
],
267-
"source": [
237+
")\n",
238+
"\n",
268239
"model_artifact.uri"
269240
]
270241
},
@@ -329,16 +300,6 @@
329300
"project.deploy_function(banking_topic_guardrail)"
330301
]
331302
},
332-
{
333-
"cell_type": "code",
334-
"execution_count": 3,
335-
"id": "42a09842-b3b1-48e7-a806-643450affddc",
336-
"metadata": {},
337-
"outputs": [],
338-
"source": [
339-
"banking_topic_guardrail = project.get_function(\"banking-topic-guardrail-v2\")"
340-
]
341-
},
342303
{
343304
"cell_type": "code",
344305
"execution_count": 4,
@@ -368,22 +329,16 @@
368329
},
369330
{
370331
"cell_type": "code",
371-
"execution_count": 5,
332+
"execution_count": null,
372333
"id": "e9195490-7088-40e1-850b-fd621802194e",
373334
"metadata": {},
374335
"outputs": [],
375336
"source": [
337+
"import time\n",
338+
"\n",
376339
"def _format_question(question: str, role: str = \"user\"):\n",
377-
" return {\"role\": role, \"content\": question}"
378-
]
379-
},
380-
{
381-
"cell_type": "code",
382-
"execution_count": 6,
383-
"id": "18454332-5e8c-4723-9b68-3e370489dcae",
384-
"metadata": {},
385-
"outputs": [],
386-
"source": [
340+
" return {\"role\": role, \"content\": question}\n",
341+
"\n",
387342
"def question_model(questions, serving_function):\n",
388343
" for question in questions:\n",
389344
" seconds = 0.5\n",
@@ -398,7 +353,7 @@
398353
},
399354
{
400355
"cell_type": "code",
401-
"execution_count": 7,
356+
"execution_count": null,
402357
"id": "fa51b347-fd31-4eda-96d8-51423d5e6247",
403358
"metadata": {},
404359
"outputs": [
@@ -490,8 +445,6 @@
490445
}
491446
],
492447
"source": [
493-
"import time\n",
494-
"\n",
495448
"for i in range(5):\n",
496449
" question_model(\n",
497450
" questions=example_questions,\n",
@@ -589,16 +542,6 @@
589542
"project.deploy_function(toxicity_guardrail)"
590543
]
591544
},
592-
{
593-
"cell_type": "code",
594-
"execution_count": 10,
595-
"id": "17542798-45d9-4705-89c1-d0ba936d9430",
596-
"metadata": {},
597-
"outputs": [],
598-
"source": [
599-
"toxicity_guardrail = project.get_function(\"toxicity-guardrail\")"
600-
]
601-
},
602545
{
603546
"cell_type": "code",
604547
"execution_count": 11,
@@ -627,9 +570,9 @@
627570
],
628571
"metadata": {
629572
"kernelspec": {
630-
"display_name": "banking-agent-test",
573+
"display_name": "Pyth(myenv)",
631574
"language": "python",
632-
"name": "conda-env-.conda-banking-agent-test-py"
575+
"name": "venv"
633576
},
634577
"language_info": {
635578
"codemirror_mode": {

0 commit comments

Comments
 (0)