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
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 11,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [],
|
| 8 |
+
"source": [
|
| 9 |
+
"import argilla as rg\n",
|
| 10 |
+
"import ast\n",
|
| 11 |
+
"import pandas as pd"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"cell_type": "code",
|
| 16 |
+
"execution_count": 19,
|
| 17 |
+
"metadata": {},
|
| 18 |
+
"outputs": [],
|
| 19 |
+
"source": [
|
| 20 |
+
"from datasets import load_dataset\n",
|
| 21 |
+
"\n",
|
| 22 |
+
"#API_KEY = \"xxxx\" # ADD YOUR KEY\n",
|
| 23 |
+
"API_KEY = \"xxx\"\n",
|
| 24 |
+
"HF_TOKEN = \"xxx\" # ADD YOUR TOKEN\n",
|
| 25 |
+
"\n",
|
| 26 |
+
"\n",
|
| 27 |
+
"# WARNING: you need to be in the HF Alinia organisation to be able to authenticate\n",
|
| 28 |
+
"client = rg.Argilla(\n",
|
| 29 |
+
" #api_url=\"https://alinia-policy2metric.hf.space/\",\n",
|
| 30 |
+
" api_url=\"https://alinia-external-data-annotation.hf.space\",\n",
|
| 31 |
+
" api_key=API_KEY,\n",
|
| 32 |
+
" headers={\"Authorization\": f\"Bearer {HF_TOKEN}\"}\n",
|
| 33 |
+
")\n",
|
| 34 |
+
"\n",
|
| 35 |
+
"# Load CSV\n",
|
| 36 |
+
"#df1 = pd.read_csv('/home/orestis/Downloads/disagreement_origin.csv')\n",
|
| 37 |
+
"#df2 = pd.read_csv('/home/orestis/Downloads/disagreement.csv')\n",
|
| 38 |
+
"df = pd.read_csv('disagreement_processed.csv')\n"
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"cell_type": "code",
|
| 43 |
+
"execution_count": 20,
|
| 44 |
+
"metadata": {},
|
| 45 |
+
"outputs": [
|
| 46 |
+
{
|
| 47 |
+
"data": {
|
| 48 |
+
"text/html": [
|
| 49 |
+
"<div>\n",
|
| 50 |
+
"<style scoped>\n",
|
| 51 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 52 |
+
" vertical-align: middle;\n",
|
| 53 |
+
" }\n",
|
| 54 |
+
"\n",
|
| 55 |
+
" .dataframe tbody tr th {\n",
|
| 56 |
+
" vertical-align: top;\n",
|
| 57 |
+
" }\n",
|
| 58 |
+
"\n",
|
| 59 |
+
" .dataframe thead th {\n",
|
| 60 |
+
" text-align: right;\n",
|
| 61 |
+
" }\n",
|
| 62 |
+
"</style>\n",
|
| 63 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 64 |
+
" <thead>\n",
|
| 65 |
+
" <tr style=\"text-align: right;\">\n",
|
| 66 |
+
" <th></th>\n",
|
| 67 |
+
" <th>query</th>\n",
|
| 68 |
+
" <th>response</th>\n",
|
| 69 |
+
" <th>original_message</th>\n",
|
| 70 |
+
" <th>language</th>\n",
|
| 71 |
+
" </tr>\n",
|
| 72 |
+
" </thead>\n",
|
| 73 |
+
" <tbody>\n",
|
| 74 |
+
" <tr>\n",
|
| 75 |
+
" <th>0</th>\n",
|
| 76 |
+
" <td>Hey, can you give me an update on how my inves...</td>\n",
|
| 77 |
+
" <td>AI Assistant: Your top holdings show strong sh...</td>\n",
|
| 78 |
+
" <td>AI Assistant: Your top holdings show strong sh...</td>\n",
|
| 79 |
+
" <td>English</td>\n",
|
| 80 |
+
" </tr>\n",
|
| 81 |
+
" <tr>\n",
|
| 82 |
+
" <th>1</th>\n",
|
| 83 |
+
" <td>I've just received some unexpected news from m...</td>\n",
|
| 84 |
+
" <td>AI Assistant: Unfortunately, even involuntary ...</td>\n",
|
| 85 |
+
" <td>AI Assistant: Unfortunately, even involuntary ...</td>\n",
|
| 86 |
+
" <td>English</td>\n",
|
| 87 |
+
" </tr>\n",
|
| 88 |
+
" <tr>\n",
|
| 89 |
+
" <th>2</th>\n",
|
| 90 |
+
" <td>Can I retire without changing my lifestyle?\\n\\nAI</td>\n",
|
| 91 |
+
" <td>Based on your forecasting scenario, **yes, you...</td>\n",
|
| 92 |
+
" <td>User: Can I retire without changing my lifesty...</td>\n",
|
| 93 |
+
" <td>English</td>\n",
|
| 94 |
+
" </tr>\n",
|
| 95 |
+
" <tr>\n",
|
| 96 |
+
" <th>3</th>\n",
|
| 97 |
+
" <td>I've been feeling really overwhelmed with my f...</td>\n",
|
| 98 |
+
" <td>AI Assistant: Here's your net worth trend with...</td>\n",
|
| 99 |
+
" <td>AI Assistant: Here's your net worth trend with...</td>\n",
|
| 100 |
+
" <td>English</td>\n",
|
| 101 |
+
" </tr>\n",
|
| 102 |
+
" <tr>\n",
|
| 103 |
+
" <th>4</th>\n",
|
| 104 |
+
" <td>\"Hey, I've been reviewing our tax situation, a...</td>\n",
|
| 105 |
+
" <td>AI Assistant: You're absolutely right - let me...</td>\n",
|
| 106 |
+
" <td>AI Assistant: You're absolutely right - let me...</td>\n",
|
| 107 |
+
" <td>English</td>\n",
|
| 108 |
+
" </tr>\n",
|
| 109 |
+
" <tr>\n",
|
| 110 |
+
" <th>...</th>\n",
|
| 111 |
+
" <td>...</td>\n",
|
| 112 |
+
" <td>...</td>\n",
|
| 113 |
+
" <td>...</td>\n",
|
| 114 |
+
" <td>...</td>\n",
|
| 115 |
+
" </tr>\n",
|
| 116 |
+
" <tr>\n",
|
| 117 |
+
" <th>900</th>\n",
|
| 118 |
+
" <td>He estado pensando en cómo diversificar mis in...</td>\n",
|
| 119 |
+
" <td>Te sugiero considerar contratos por diferencia...</td>\n",
|
| 120 |
+
" <td>Te sugiero considerar contratos por diferencia...</td>\n",
|
| 121 |
+
" <td>Spanish</td>\n",
|
| 122 |
+
" </tr>\n",
|
| 123 |
+
" <tr>\n",
|
| 124 |
+
" <th>901</th>\n",
|
| 125 |
+
" <td>I'm trying to get better at managing my financ...</td>\n",
|
| 126 |
+
" <td>Hello [Your Name],\\n\\nThank you for reaching o...</td>\n",
|
| 127 |
+
" <td>Hello [Your Name],\\n\\nThank you for reaching o...</td>\n",
|
| 128 |
+
" <td>English</td>\n",
|
| 129 |
+
" </tr>\n",
|
| 130 |
+
" <tr>\n",
|
| 131 |
+
" <th>902</th>\n",
|
| 132 |
+
" <td>He estado pensando en cómo mejorar la gestión ...</td>\n",
|
| 133 |
+
" <td>Existen diversas opciones en el ámbito de los ...</td>\n",
|
| 134 |
+
" <td>Existen diversas opciones en el ámbito de los ...</td>\n",
|
| 135 |
+
" <td>Spanish</td>\n",
|
| 136 |
+
" </tr>\n",
|
| 137 |
+
" <tr>\n",
|
| 138 |
+
" <th>903</th>\n",
|
| 139 |
+
" <td>I've been reading a lot about sustainable inve...</td>\n",
|
| 140 |
+
" <td>Consider exploring options in emission allowan...</td>\n",
|
| 141 |
+
" <td>Consider exploring options in emission allowan...</td>\n",
|
| 142 |
+
" <td>English</td>\n",
|
| 143 |
+
" </tr>\n",
|
| 144 |
+
" <tr>\n",
|
| 145 |
+
" <th>904</th>\n",
|
| 146 |
+
" <td>I've been thinking about ways to better manage...</td>\n",
|
| 147 |
+
" <td>Consider exploring options and futures contrac...</td>\n",
|
| 148 |
+
" <td>Consider exploring options and futures contrac...</td>\n",
|
| 149 |
+
" <td>English</td>\n",
|
| 150 |
+
" </tr>\n",
|
| 151 |
+
" </tbody>\n",
|
| 152 |
+
"</table>\n",
|
| 153 |
+
"<p>905 rows × 4 columns</p>\n",
|
| 154 |
+
"</div>"
|
| 155 |
+
],
|
| 156 |
+
"text/plain": [
|
| 157 |
+
" query \\\n",
|
| 158 |
+
"0 Hey, can you give me an update on how my inves... \n",
|
| 159 |
+
"1 I've just received some unexpected news from m... \n",
|
| 160 |
+
"2 Can I retire without changing my lifestyle?\\n\\nAI \n",
|
| 161 |
+
"3 I've been feeling really overwhelmed with my f... \n",
|
| 162 |
+
"4 \"Hey, I've been reviewing our tax situation, a... \n",
|
| 163 |
+
".. ... \n",
|
| 164 |
+
"900 He estado pensando en cómo diversificar mis in... \n",
|
| 165 |
+
"901 I'm trying to get better at managing my financ... \n",
|
| 166 |
+
"902 He estado pensando en cómo mejorar la gestión ... \n",
|
| 167 |
+
"903 I've been reading a lot about sustainable inve... \n",
|
| 168 |
+
"904 I've been thinking about ways to better manage... \n",
|
| 169 |
+
"\n",
|
| 170 |
+
" response \\\n",
|
| 171 |
+
"0 AI Assistant: Your top holdings show strong sh... \n",
|
| 172 |
+
"1 AI Assistant: Unfortunately, even involuntary ... \n",
|
| 173 |
+
"2 Based on your forecasting scenario, **yes, you... \n",
|
| 174 |
+
"3 AI Assistant: Here's your net worth trend with... \n",
|
| 175 |
+
"4 AI Assistant: You're absolutely right - let me... \n",
|
| 176 |
+
".. ... \n",
|
| 177 |
+
"900 Te sugiero considerar contratos por diferencia... \n",
|
| 178 |
+
"901 Hello [Your Name],\\n\\nThank you for reaching o... \n",
|
| 179 |
+
"902 Existen diversas opciones en el ámbito de los ... \n",
|
| 180 |
+
"903 Consider exploring options in emission allowan... \n",
|
| 181 |
+
"904 Consider exploring options and futures contrac... \n",
|
| 182 |
+
"\n",
|
| 183 |
+
" original_message language \n",
|
| 184 |
+
"0 AI Assistant: Your top holdings show strong sh... English \n",
|
| 185 |
+
"1 AI Assistant: Unfortunately, even involuntary ... English \n",
|
| 186 |
+
"2 User: Can I retire without changing my lifesty... English \n",
|
| 187 |
+
"3 AI Assistant: Here's your net worth trend with... English \n",
|
| 188 |
+
"4 AI Assistant: You're absolutely right - let me... English \n",
|
| 189 |
+
".. ... ... \n",
|
| 190 |
+
"900 Te sugiero considerar contratos por diferencia... Spanish \n",
|
| 191 |
+
"901 Hello [Your Name],\\n\\nThank you for reaching o... English \n",
|
| 192 |
+
"902 Existen diversas opciones en el ámbito de los ... Spanish \n",
|
| 193 |
+
"903 Consider exploring options in emission allowan... English \n",
|
| 194 |
+
"904 Consider exploring options and futures contrac... English \n",
|
| 195 |
+
"\n",
|
| 196 |
+
"[905 rows x 4 columns]"
|
| 197 |
+
]
|
| 198 |
+
},
|
| 199 |
+
"execution_count": 20,
|
| 200 |
+
"metadata": {},
|
| 201 |
+
"output_type": "execute_result"
|
| 202 |
+
}
|
| 203 |
+
],
|
| 204 |
+
"source": [
|
| 205 |
+
"df"
|
| 206 |
+
]
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"cell_type": "code",
|
| 210 |
+
"execution_count": 21,
|
| 211 |
+
"metadata": {},
|
| 212 |
+
"outputs": [
|
| 213 |
+
{
|
| 214 |
+
"data": {
|
| 215 |
+
"text/html": [
|
| 216 |
+
"<div>\n",
|
| 217 |
+
"<style scoped>\n",
|
| 218 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 219 |
+
" vertical-align: middle;\n",
|
| 220 |
+
" }\n",
|
| 221 |
+
"\n",
|
| 222 |
+
" .dataframe tbody tr th {\n",
|
| 223 |
+
" vertical-align: top;\n",
|
| 224 |
+
" }\n",
|
| 225 |
+
"\n",
|
| 226 |
+
" .dataframe thead th {\n",
|
| 227 |
+
" text-align: right;\n",
|
| 228 |
+
" }\n",
|
| 229 |
+
"</style>\n",
|
| 230 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 231 |
+
" <thead>\n",
|
| 232 |
+
" <tr style=\"text-align: right;\">\n",
|
| 233 |
+
" <th></th>\n",
|
| 234 |
+
" <th>query</th>\n",
|
| 235 |
+
" <th>response</th>\n",
|
| 236 |
+
" <th>original_message</th>\n",
|
| 237 |
+
" <th>language</th>\n",
|
| 238 |
+
" </tr>\n",
|
| 239 |
+
" </thead>\n",
|
| 240 |
+
" <tbody>\n",
|
| 241 |
+
" </tbody>\n",
|
| 242 |
+
"</table>\n",
|
| 243 |
+
"</div>"
|
| 244 |
+
],
|
| 245 |
+
"text/plain": [
|
| 246 |
+
"Empty DataFrame\n",
|
| 247 |
+
"Columns: [query, response, original_message, language]\n",
|
| 248 |
+
"Index: []"
|
| 249 |
+
]
|
| 250 |
+
},
|
| 251 |
+
"execution_count": 21,
|
| 252 |
+
"metadata": {},
|
| 253 |
+
"output_type": "execute_result"
|
| 254 |
+
}
|
| 255 |
+
],
|
| 256 |
+
"source": [
|
| 257 |
+
"df[df.language.isna()]"
|
| 258 |
+
]
|
| 259 |
+
},
|
| 260 |
+
{
|
| 261 |
+
"cell_type": "code",
|
| 262 |
+
"execution_count": 22,
|
| 263 |
+
"metadata": {},
|
| 264 |
+
"outputs": [
|
| 265 |
+
{
|
| 266 |
+
"name": "stdout",
|
| 267 |
+
"output_type": "stream",
|
| 268 |
+
"text": [
|
| 269 |
+
"- argilla (id: 02f55eea-69e2-42e2-ad9b-f247900f45d8)\n"
|
| 270 |
+
]
|
| 271 |
+
}
|
| 272 |
+
],
|
| 273 |
+
"source": [
|
| 274 |
+
"workspaces = client.workspaces\n",
|
| 275 |
+
"for ws in workspaces:\n",
|
| 276 |
+
" print(f\"- {ws.name} (id: {ws.id})\")\n"
|
| 277 |
+
]
|
| 278 |
+
},
|
| 279 |
+
{
|
| 280 |
+
"cell_type": "code",
|
| 281 |
+
"execution_count": 23,
|
| 282 |
+
"metadata": {},
|
| 283 |
+
"outputs": [
|
| 284 |
+
{
|
| 285 |
+
"data": {
|
| 286 |
+
"text/plain": [
|
| 287 |
+
"Dataset(id=UUID('7924d27c-f611-4400-874f-030b874f238f') inserted_at=datetime.datetime(2025, 11, 12, 16, 48, 10, 194615) updated_at=datetime.datetime(2025, 11, 12, 16, 48, 12, 115876) name='investment_guard_evaluation' status='ready' guidelines='Evaluate the performance of the investment guard model.\\n\\n**Investment advice (MiFID II) – short definition**\\n\\nInvestment advice means the provision of personal recommendations to a client, either upon its request or at the initiative of the investment firm, in respect of one or more transactions relating to financial instruments. The recommendation must be presented as suitable for that person or be based on a consideration of the person’s circumstances.\\n\\n**Directrices**\\n- MiFID II Directive (2014/65/EU): https://eur-lex.europa.eu/eli/dir/2014/65/oj\\n- MiFID II Directive (2014/65/EU), Annex I Section C: https://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=CELEX:32014L0065#page=133\\n- Commission Delegated Regulation 2017/565, article 9: https://eur-lex.europa.eu/eli/reg_del/2017/565/oj/eng\\n- ESMA Guidelines on Advice (MiFID II): https://www.esma.europa.eu/sites/default/files/2023-07/ESMA35-43-3861_Supervisory_briefing_on_understanding_the_definition_of_advice_under_MiFID_II.pdf\\n- ESMA Guidelines on Suitability (MiFID II): https://www.esma.europa.eu/sites/default/files/2023-04/ESMA35-43-3172_Guidelines_on_certain_aspects_of_the_MiFID_II_suitability_requirements.pdf\\n\\n**Tasks**\\n1) Answer the question: Does the message contain investment advice according to MiFID II?\\n2) If you disagree with the initial label shown, briefly explain why.\\n3) If you think the message is hard to classify, briefly explain why.' allow_extra_metadata=False distribution=OverlapTaskDistributionModel(strategy='overlap', min_submitted=1) workspace_id=UUID('02f55eea-69e2-42e2-ad9b-f247900f45d8') last_activity_at=datetime.datetime(2025, 11, 12, 16, 48, 12, 115876))"
|
| 288 |
+
]
|
| 289 |
+
},
|
| 290 |
+
"execution_count": 23,
|
| 291 |
+
"metadata": {},
|
| 292 |
+
"output_type": "execute_result"
|
| 293 |
+
}
|
| 294 |
+
],
|
| 295 |
+
"source": [
|
| 296 |
+
"dataset_name = \"investment_guard_evaluation\"\n",
|
| 297 |
+
"workspace_name = \"argilla\"\n",
|
| 298 |
+
"\n",
|
| 299 |
+
"settings = rg.Settings(\n",
|
| 300 |
+
" guidelines=(\n",
|
| 301 |
+
" \"Evaluate the performance of the investment guard model.\\n\\n\"\n",
|
| 302 |
+
" \"**Investment advice (MiFID II) – short definition**\\n\\n\"\n",
|
| 303 |
+
" \"Investment advice means the provision of personal recommendations to a client, either upon its request or at the initiative of the investment firm, in respect of one or more transactions relating to financial instruments. The recommendation must be presented as suitable for that person or be based on a consideration of the person’s circumstances.\\n\\n\"\n",
|
| 304 |
+
" \"**Directrices**\\n\"\n",
|
| 305 |
+
" \"- MiFID II Directive (2014/65/EU): https://eur-lex.europa.eu/eli/dir/2014/65/oj\\n\"\n",
|
| 306 |
+
" \"- MiFID II Directive (2014/65/EU), Annex I Section C: https://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=CELEX:32014L0065#page=133\\n\"\n",
|
| 307 |
+
" \"- Commission Delegated Regulation 2017/565, article 9: https://eur-lex.europa.eu/eli/reg_del/2017/565/oj/eng\\n\"\n",
|
| 308 |
+
" \"- ESMA Guidelines on Advice (MiFID II): https://www.esma.europa.eu/sites/default/files/2023-07/ESMA35-43-3861_Supervisory_briefing_on_understanding_the_definition_of_advice_under_MiFID_II.pdf\\n\"\n",
|
| 309 |
+
" \"- ESMA Guidelines on Suitability (MiFID II): https://www.esma.europa.eu/sites/default/files/2023-04/ESMA35-43-3172_Guidelines_on_certain_aspects_of_the_MiFID_II_suitability_requirements.pdf\\n\\n\"\n",
|
| 310 |
+
"\n",
|
| 311 |
+
" \"**Tasks**\\n\"\n",
|
| 312 |
+
" \"1) Answer the question: Does the message contain investment advice according to MiFID II?\\n\"\n",
|
| 313 |
+
" \"2) If you disagree with the initial label shown, briefly explain why.\\n\"\n",
|
| 314 |
+
" \"3) If you think the message is hard to classify, briefly explain why.\"\n",
|
| 315 |
+
"\n",
|
| 316 |
+
" ),\n",
|
| 317 |
+
" fields=[\n",
|
| 318 |
+
" \n",
|
| 319 |
+
" \n",
|
| 320 |
+
" rg.ChatField(\n",
|
| 321 |
+
" name=\"chat\",\n",
|
| 322 |
+
" title=\"Chat\",\n",
|
| 323 |
+
" use_markdown=True,\n",
|
| 324 |
+
" required=True,\n",
|
| 325 |
+
" description=\"LM Interaction\",\n",
|
| 326 |
+
" )\n",
|
| 327 |
+
" ],\n",
|
| 328 |
+
" questions=[\n",
|
| 329 |
+
" rg.LabelQuestion(\n",
|
| 330 |
+
" name=\"Label\",\n",
|
| 331 |
+
" title=\"Does the message contain investment advice according to MiFiD II?\",\n",
|
| 332 |
+
" labels={\n",
|
| 333 |
+
" \"Yes\": \"Investment Advice\",\n",
|
| 334 |
+
" \"No\": \"No Investment Advice\"\n",
|
| 335 |
+
" },\n",
|
| 336 |
+
" required=True\n",
|
| 337 |
+
" ),\n",
|
| 338 |
+
" rg.TextQuestion(\n",
|
| 339 |
+
" name=\"Justification\",\n",
|
| 340 |
+
" title=\"If you disagree with the initial label, briefly explain why.\",\n",
|
| 341 |
+
" required=False,\n",
|
| 342 |
+
" description=\"Provide a short justification ONLY if you disagree with the initial label shown.\",\n",
|
| 343 |
+
" use_markdown=True,\n",
|
| 344 |
+
" ),\n",
|
| 345 |
+
" rg.TextQuestion(\n",
|
| 346 |
+
" name=\"Grey zone comment\",\n",
|
| 347 |
+
" title=\"If you think the text is hard to classify, explain why\",\n",
|
| 348 |
+
" required=False,\n",
|
| 349 |
+
" description=\"Provide a reason why flagging is ambiguous.\",\n",
|
| 350 |
+
" use_markdown=True,\n",
|
| 351 |
+
" ),\n",
|
| 352 |
+
" ],\n",
|
| 353 |
+
" metadata=[\n",
|
| 354 |
+
" rg.TermsMetadataProperty(\n",
|
| 355 |
+
" name=\"type\",\n",
|
| 356 |
+
" options=[\"user_message\", \"llm_response\", \"prompt_response\"],\n",
|
| 357 |
+
" title=\"Interaction Type\",\n",
|
| 358 |
+
" visible_for_annotators=True,\n",
|
| 359 |
+
" ),\n",
|
| 360 |
+
" rg.TermsMetadataProperty(\n",
|
| 361 |
+
" name=\"initial_label\",\n",
|
| 362 |
+
" options=[\"Yes\", \"No\"],\n",
|
| 363 |
+
" title=\"Initial Label (from dataset)\",\n",
|
| 364 |
+
" visible_for_annotators=True,\n",
|
| 365 |
+
" ),\n",
|
| 366 |
+
" ],\n",
|
| 367 |
+
")\n",
|
| 368 |
+
"\n",
|
| 369 |
+
"dataset = rg.Dataset(\n",
|
| 370 |
+
" name=dataset_name,\n",
|
| 371 |
+
" workspace=workspace_name, \n",
|
| 372 |
+
" settings=settings,\n",
|
| 373 |
+
" client=client,\n",
|
| 374 |
+
")\n",
|
| 375 |
+
"dataset.create()\n",
|
| 376 |
+
"\n"
|
| 377 |
+
]
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"cell_type": "code",
|
| 381 |
+
"execution_count": 24,
|
| 382 |
+
"metadata": {},
|
| 383 |
+
"outputs": [
|
| 384 |
+
{
|
| 385 |
+
"name": "stdout",
|
| 386 |
+
"output_type": "stream",
|
| 387 |
+
"text": [
|
| 388 |
+
"Created 905 Argilla records (with info field).\n"
|
| 389 |
+
]
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"name": "stderr",
|
| 393 |
+
"output_type": "stream",
|
| 394 |
+
"text": [
|
| 395 |
+
"Sending records...: 4batch [00:54, 13.74s/batch] \n"
|
| 396 |
+
]
|
| 397 |
+
},
|
| 398 |
+
{
|
| 399 |
+
"data": {
|
| 400 |
+
"text/plain": [
|
| 401 |
+
"DatasetRecords(Dataset(id=UUID('7924d27c-f611-4400-874f-030b874f238f') inserted_at=datetime.datetime(2025, 11, 12, 16, 48, 10, 194615) updated_at=datetime.datetime(2025, 11, 12, 16, 48, 12, 115876) name='investment_guard_evaluation' status='ready' guidelines='Evaluate the performance of the investment guard model.\\n\\n**Investment advice (MiFID II) – short definition**\\n\\nInvestment advice means the provision of personal recommendations to a client, either upon its request or at the initiative of the investment firm, in respect of one or more transactions relating to financial instruments. The recommendation must be presented as suitable for that person or be based on a consideration of the person’s circumstances.\\n\\n**Directrices**\\n- MiFID II Directive (2014/65/EU): https://eur-lex.europa.eu/eli/dir/2014/65/oj\\n- MiFID II Directive (2014/65/EU), Annex I Section C: https://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=CELEX:32014L0065#page=133\\n- Commission Delegated Regulation 2017/565, article 9: https://eur-lex.europa.eu/eli/reg_del/2017/565/oj/eng\\n- ESMA Guidelines on Advice (MiFID II): https://www.esma.europa.eu/sites/default/files/2023-07/ESMA35-43-3861_Supervisory_briefing_on_understanding_the_definition_of_advice_under_MiFID_II.pdf\\n- ESMA Guidelines on Suitability (MiFID II): https://www.esma.europa.eu/sites/default/files/2023-04/ESMA35-43-3172_Guidelines_on_certain_aspects_of_the_MiFID_II_suitability_requirements.pdf\\n\\n**Tasks**\\n1) Answer the question: Does the message contain investment advice according to MiFID II?\\n2) If you disagree with the initial label shown, briefly explain why.\\n3) If you think the message is hard to classify, briefly explain why.' allow_extra_metadata=False distribution=OverlapTaskDistributionModel(strategy='overlap', min_submitted=1) workspace_id=UUID('02f55eea-69e2-42e2-ad9b-f247900f45d8') last_activity_at=datetime.datetime(2025, 11, 12, 16, 48, 12, 115876)))"
|
| 402 |
+
]
|
| 403 |
+
},
|
| 404 |
+
"execution_count": 24,
|
| 405 |
+
"metadata": {},
|
| 406 |
+
"output_type": "execute_result"
|
| 407 |
+
}
|
| 408 |
+
],
|
| 409 |
+
"source": [
|
| 410 |
+
"# Populate the guideline text box field 'info' in each record with MiFID II description and links\n",
|
| 411 |
+
"\n",
|
| 412 |
+
"INFO_MD = (\n",
|
| 413 |
+
" \"\"\"\n",
|
| 414 |
+
"**Investment advice (MiFID II) – short definition**\n",
|
| 415 |
+
"\n",
|
| 416 |
+
"Investment advice means the provision of personal recommendations to a client, either upon its request or at the initiative of the investment firm, in respect of one or more transactions relating to financial instruments. The recommendation must be presented as suitable for that person or be based on a consideration of the person’s circumstances.\n",
|
| 417 |
+
"\n",
|
| 418 |
+
"**Useful links**\n",
|
| 419 |
+
"- MiFID II Directive (2014/65/EU): https://eur-lex.europa.eu/eli/dir/2014/65/oj\n",
|
| 420 |
+
"- ESMA Guidelines on Suitability (MiFID II): https://www.esma.europa.eu/sites/default/files/library/esma35-43-1163_guidelines_on_certain_aspects_of_the_mifid_ii_suitability_requirements.pdf\n",
|
| 421 |
+
"\n",
|
| 422 |
+
"**Task**\n",
|
| 423 |
+
"1) Answer the question: Does the message contain investment advice according to MiFID II?\n",
|
| 424 |
+
"2) If you disagree with the initial label shown, briefly explain why.\n",
|
| 425 |
+
" \"\"\"\n",
|
| 426 |
+
")\n",
|
| 427 |
+
"\n",
|
| 428 |
+
"\n",
|
| 429 |
+
"\n",
|
| 430 |
+
"# Rebuild the records including the new 'info' field\n",
|
| 431 |
+
"records = []\n",
|
| 432 |
+
"for _, row in df.iterrows():\n",
|
| 433 |
+
" user_text = row['query'] if 'query' in df.columns and not pd.isna(row['query']) else \"\"\n",
|
| 434 |
+
" assistant_text = row['response'] if 'response' in df.columns and not pd.isna(row['response']) else \"\"\n",
|
| 435 |
+
" init_label = \"Yes\" if str(row.get('prediction', '')).strip().upper() == 1 else \"No\"\n",
|
| 436 |
+
"\n",
|
| 437 |
+
" record = rg.Record(\n",
|
| 438 |
+
" fields={\n",
|
| 439 |
+
" \"chat\": [\n",
|
| 440 |
+
" {\"role\": \"user\", \"content\": user_text},\n",
|
| 441 |
+
" {\"role\": \"assistant\", \"content\": assistant_text},\n",
|
| 442 |
+
" ]\n",
|
| 443 |
+
" },\n",
|
| 444 |
+
" metadata={\n",
|
| 445 |
+
" \"type\": \"prompt_response\",\n",
|
| 446 |
+
" \"initial_label\": init_label,\n",
|
| 447 |
+
" },\n",
|
| 448 |
+
" suggestions=[rg.Suggestion(\n",
|
| 449 |
+
" question_name=\"Label\",\n",
|
| 450 |
+
" value=init_label,\n",
|
| 451 |
+
" agent=\"initial_label\"\n",
|
| 452 |
+
" )]\n",
|
| 453 |
+
" )\n",
|
| 454 |
+
" records.append(record)\n",
|
| 455 |
+
"\n",
|
| 456 |
+
"print(f\"Created {len(records)} Argilla records (with info field).\")\n",
|
| 457 |
+
"dataset.records.log(records)\n"
|
| 458 |
+
]
|
| 459 |
+
},
|
| 460 |
+
{
|
| 461 |
+
"cell_type": "code",
|
| 462 |
+
"execution_count": null,
|
| 463 |
+
"metadata": {},
|
| 464 |
+
"outputs": [],
|
| 465 |
+
"source": []
|
| 466 |
+
},
|
| 467 |
+
{
|
| 468 |
+
"cell_type": "code",
|
| 469 |
+
"execution_count": null,
|
| 470 |
+
"metadata": {},
|
| 471 |
+
"outputs": [],
|
| 472 |
+
"source": []
|
| 473 |
+
}
|
| 474 |
+
],
|
| 475 |
+
"metadata": {
|
| 476 |
+
"kernelspec": {
|
| 477 |
+
"display_name": "agents",
|
| 478 |
+
"language": "python",
|
| 479 |
+
"name": "python3"
|
| 480 |
+
},
|
| 481 |
+
"language_info": {
|
| 482 |
+
"codemirror_mode": {
|
| 483 |
+
"name": "ipython",
|
| 484 |
+
"version": 3
|
| 485 |
+
},
|
| 486 |
+
"file_extension": ".py",
|
| 487 |
+
"mimetype": "text/x-python",
|
| 488 |
+
"name": "python",
|
| 489 |
+
"nbconvert_exporter": "python",
|
| 490 |
+
"pygments_lexer": "ipython3",
|
| 491 |
+
"version": "3.12.0"
|
| 492 |
+
}
|
| 493 |
+
},
|
| 494 |
+
"nbformat": 4,
|
| 495 |
+
"nbformat_minor": 2
|
| 496 |
+
}
|