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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"nbformat": 4,
|
| 3 |
+
"nbformat_minor": 0,
|
| 4 |
+
"metadata": {
|
| 5 |
+
"colab": {
|
| 6 |
+
"provenance": []
|
| 7 |
+
},
|
| 8 |
+
"kernelspec": {
|
| 9 |
+
"name": "python3",
|
| 10 |
+
"display_name": "Python 3"
|
| 11 |
+
},
|
| 12 |
+
"language_info": {
|
| 13 |
+
"name": "python"
|
| 14 |
+
},
|
| 15 |
+
"widgets": {
|
| 16 |
+
"application/vnd.jupyter.widget-state+json": {
|
| 17 |
+
"b78fb013688f49e09893f986b46e17b1": {
|
| 18 |
+
"model_module": "@jupyter-widgets/controls",
|
| 19 |
+
"model_name": "HBoxModel",
|
| 20 |
+
"model_module_version": "1.5.0",
|
| 21 |
+
"state": {
|
| 22 |
+
"_dom_classes": [],
|
| 23 |
+
"_model_module": "@jupyter-widgets/controls",
|
| 24 |
+
"_model_module_version": "1.5.0",
|
| 25 |
+
"_model_name": "HBoxModel",
|
| 26 |
+
"_view_count": null,
|
| 27 |
+
"_view_module": "@jupyter-widgets/controls",
|
| 28 |
+
"_view_module_version": "1.5.0",
|
| 29 |
+
"_view_name": "HBoxView",
|
| 30 |
+
"box_style": "",
|
| 31 |
+
"children": [
|
| 32 |
+
"IPY_MODEL_26a0f5c6aa35438094ba329b2cca24d1",
|
| 33 |
+
"IPY_MODEL_6d2205226c584736b22ac0009a647e0e",
|
| 34 |
+
"IPY_MODEL_7c481d8f47474772bc804c8d26ecc2da"
|
| 35 |
+
],
|
| 36 |
+
"layout": "IPY_MODEL_6a1bd864209c4e5fb2d06ae0470d9350"
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"26a0f5c6aa35438094ba329b2cca24d1": {
|
| 40 |
+
"model_module": "@jupyter-widgets/controls",
|
| 41 |
+
"model_name": "HTMLModel",
|
| 42 |
+
"model_module_version": "1.5.0",
|
| 43 |
+
"state": {
|
| 44 |
+
"_dom_classes": [],
|
| 45 |
+
"_model_module": "@jupyter-widgets/controls",
|
| 46 |
+
"_model_module_version": "1.5.0",
|
| 47 |
+
"_model_name": "HTMLModel",
|
| 48 |
+
"_view_count": null,
|
| 49 |
+
"_view_module": "@jupyter-widgets/controls",
|
| 50 |
+
"_view_module_version": "1.5.0",
|
| 51 |
+
"_view_name": "HTMLView",
|
| 52 |
+
"description": "",
|
| 53 |
+
"description_tooltip": null,
|
| 54 |
+
"layout": "IPY_MODEL_4fc282e7d6e647328ebcd013aefb774b",
|
| 55 |
+
"placeholder": "",
|
| 56 |
+
"style": "IPY_MODEL_bcb0a0dcf6044004867df51da0e3b307",
|
| 57 |
+
"value": "Batches: 100%"
|
| 58 |
+
}
|
| 59 |
+
},
|
| 60 |
+
"6d2205226c584736b22ac0009a647e0e": {
|
| 61 |
+
"model_module": "@jupyter-widgets/controls",
|
| 62 |
+
"model_name": "FloatProgressModel",
|
| 63 |
+
"model_module_version": "1.5.0",
|
| 64 |
+
"state": {
|
| 65 |
+
"_dom_classes": [],
|
| 66 |
+
"_model_module": "@jupyter-widgets/controls",
|
| 67 |
+
"_model_module_version": "1.5.0",
|
| 68 |
+
"_model_name": "FloatProgressModel",
|
| 69 |
+
"_view_count": null,
|
| 70 |
+
"_view_module": "@jupyter-widgets/controls",
|
| 71 |
+
"_view_module_version": "1.5.0",
|
| 72 |
+
"_view_name": "ProgressView",
|
| 73 |
+
"bar_style": "success",
|
| 74 |
+
"description": "",
|
| 75 |
+
"description_tooltip": null,
|
| 76 |
+
"layout": "IPY_MODEL_eb95669d0d0245aa9251ab35374307ce",
|
| 77 |
+
"max": 83,
|
| 78 |
+
"min": 0,
|
| 79 |
+
"orientation": "horizontal",
|
| 80 |
+
"style": "IPY_MODEL_cfed69b9f821407b8fd014d3748bd34f",
|
| 81 |
+
"value": 83
|
| 82 |
+
}
|
| 83 |
+
},
|
| 84 |
+
"7c481d8f47474772bc804c8d26ecc2da": {
|
| 85 |
+
"model_module": "@jupyter-widgets/controls",
|
| 86 |
+
"model_name": "HTMLModel",
|
| 87 |
+
"model_module_version": "1.5.0",
|
| 88 |
+
"state": {
|
| 89 |
+
"_dom_classes": [],
|
| 90 |
+
"_model_module": "@jupyter-widgets/controls",
|
| 91 |
+
"_model_module_version": "1.5.0",
|
| 92 |
+
"_model_name": "HTMLModel",
|
| 93 |
+
"_view_count": null,
|
| 94 |
+
"_view_module": "@jupyter-widgets/controls",
|
| 95 |
+
"_view_module_version": "1.5.0",
|
| 96 |
+
"_view_name": "HTMLView",
|
| 97 |
+
"description": "",
|
| 98 |
+
"description_tooltip": null,
|
| 99 |
+
"layout": "IPY_MODEL_d703773e6f7e42159e652bb40476a716",
|
| 100 |
+
"placeholder": "",
|
| 101 |
+
"style": "IPY_MODEL_e14ad5669d4f4df5a3a12dce60623ca9",
|
| 102 |
+
"value": " 83/83 [03:37<00:00, 2.39s/it]"
|
| 103 |
+
}
|
| 104 |
+
},
|
| 105 |
+
"6a1bd864209c4e5fb2d06ae0470d9350": {
|
| 106 |
+
"model_module": "@jupyter-widgets/base",
|
| 107 |
+
"model_name": "LayoutModel",
|
| 108 |
+
"model_module_version": "1.2.0",
|
| 109 |
+
"state": {
|
| 110 |
+
"_model_module": "@jupyter-widgets/base",
|
| 111 |
+
"_model_module_version": "1.2.0",
|
| 112 |
+
"_model_name": "LayoutModel",
|
| 113 |
+
"_view_count": null,
|
| 114 |
+
"_view_module": "@jupyter-widgets/base",
|
| 115 |
+
"_view_module_version": "1.2.0",
|
| 116 |
+
"_view_name": "LayoutView",
|
| 117 |
+
"align_content": null,
|
| 118 |
+
"align_items": null,
|
| 119 |
+
"align_self": null,
|
| 120 |
+
"border": null,
|
| 121 |
+
"bottom": null,
|
| 122 |
+
"display": null,
|
| 123 |
+
"flex": null,
|
| 124 |
+
"flex_flow": null,
|
| 125 |
+
"grid_area": null,
|
| 126 |
+
"grid_auto_columns": null,
|
| 127 |
+
"grid_auto_flow": null,
|
| 128 |
+
"grid_auto_rows": null,
|
| 129 |
+
"grid_column": null,
|
| 130 |
+
"grid_gap": null,
|
| 131 |
+
"grid_row": null,
|
| 132 |
+
"grid_template_areas": null,
|
| 133 |
+
"grid_template_columns": null,
|
| 134 |
+
"grid_template_rows": null,
|
| 135 |
+
"height": null,
|
| 136 |
+
"justify_content": null,
|
| 137 |
+
"justify_items": null,
|
| 138 |
+
"left": null,
|
| 139 |
+
"margin": null,
|
| 140 |
+
"max_height": null,
|
| 141 |
+
"max_width": null,
|
| 142 |
+
"min_height": null,
|
| 143 |
+
"min_width": null,
|
| 144 |
+
"object_fit": null,
|
| 145 |
+
"object_position": null,
|
| 146 |
+
"order": null,
|
| 147 |
+
"overflow": null,
|
| 148 |
+
"overflow_x": null,
|
| 149 |
+
"overflow_y": null,
|
| 150 |
+
"padding": null,
|
| 151 |
+
"right": null,
|
| 152 |
+
"top": null,
|
| 153 |
+
"visibility": null,
|
| 154 |
+
"width": null
|
| 155 |
+
}
|
| 156 |
+
},
|
| 157 |
+
"4fc282e7d6e647328ebcd013aefb774b": {
|
| 158 |
+
"model_module": "@jupyter-widgets/base",
|
| 159 |
+
"model_name": "LayoutModel",
|
| 160 |
+
"model_module_version": "1.2.0",
|
| 161 |
+
"state": {
|
| 162 |
+
"_model_module": "@jupyter-widgets/base",
|
| 163 |
+
"_model_module_version": "1.2.0",
|
| 164 |
+
"_model_name": "LayoutModel",
|
| 165 |
+
"_view_count": null,
|
| 166 |
+
"_view_module": "@jupyter-widgets/base",
|
| 167 |
+
"_view_module_version": "1.2.0",
|
| 168 |
+
"_view_name": "LayoutView",
|
| 169 |
+
"align_content": null,
|
| 170 |
+
"align_items": null,
|
| 171 |
+
"align_self": null,
|
| 172 |
+
"border": null,
|
| 173 |
+
"bottom": null,
|
| 174 |
+
"display": null,
|
| 175 |
+
"flex": null,
|
| 176 |
+
"flex_flow": null,
|
| 177 |
+
"grid_area": null,
|
| 178 |
+
"grid_auto_columns": null,
|
| 179 |
+
"grid_auto_flow": null,
|
| 180 |
+
"grid_auto_rows": null,
|
| 181 |
+
"grid_column": null,
|
| 182 |
+
"grid_gap": null,
|
| 183 |
+
"grid_row": null,
|
| 184 |
+
"grid_template_areas": null,
|
| 185 |
+
"grid_template_columns": null,
|
| 186 |
+
"grid_template_rows": null,
|
| 187 |
+
"height": null,
|
| 188 |
+
"justify_content": null,
|
| 189 |
+
"justify_items": null,
|
| 190 |
+
"left": null,
|
| 191 |
+
"margin": null,
|
| 192 |
+
"max_height": null,
|
| 193 |
+
"max_width": null,
|
| 194 |
+
"min_height": null,
|
| 195 |
+
"min_width": null,
|
| 196 |
+
"object_fit": null,
|
| 197 |
+
"object_position": null,
|
| 198 |
+
"order": null,
|
| 199 |
+
"overflow": null,
|
| 200 |
+
"overflow_x": null,
|
| 201 |
+
"overflow_y": null,
|
| 202 |
+
"padding": null,
|
| 203 |
+
"right": null,
|
| 204 |
+
"top": null,
|
| 205 |
+
"visibility": null,
|
| 206 |
+
"width": null
|
| 207 |
+
}
|
| 208 |
+
},
|
| 209 |
+
"bcb0a0dcf6044004867df51da0e3b307": {
|
| 210 |
+
"model_module": "@jupyter-widgets/controls",
|
| 211 |
+
"model_name": "DescriptionStyleModel",
|
| 212 |
+
"model_module_version": "1.5.0",
|
| 213 |
+
"state": {
|
| 214 |
+
"_model_module": "@jupyter-widgets/controls",
|
| 215 |
+
"_model_module_version": "1.5.0",
|
| 216 |
+
"_model_name": "DescriptionStyleModel",
|
| 217 |
+
"_view_count": null,
|
| 218 |
+
"_view_module": "@jupyter-widgets/base",
|
| 219 |
+
"_view_module_version": "1.2.0",
|
| 220 |
+
"_view_name": "StyleView",
|
| 221 |
+
"description_width": ""
|
| 222 |
+
}
|
| 223 |
+
},
|
| 224 |
+
"eb95669d0d0245aa9251ab35374307ce": {
|
| 225 |
+
"model_module": "@jupyter-widgets/base",
|
| 226 |
+
"model_name": "LayoutModel",
|
| 227 |
+
"model_module_version": "1.2.0",
|
| 228 |
+
"state": {
|
| 229 |
+
"_model_module": "@jupyter-widgets/base",
|
| 230 |
+
"_model_module_version": "1.2.0",
|
| 231 |
+
"_model_name": "LayoutModel",
|
| 232 |
+
"_view_count": null,
|
| 233 |
+
"_view_module": "@jupyter-widgets/base",
|
| 234 |
+
"_view_module_version": "1.2.0",
|
| 235 |
+
"_view_name": "LayoutView",
|
| 236 |
+
"align_content": null,
|
| 237 |
+
"align_items": null,
|
| 238 |
+
"align_self": null,
|
| 239 |
+
"border": null,
|
| 240 |
+
"bottom": null,
|
| 241 |
+
"display": null,
|
| 242 |
+
"flex": null,
|
| 243 |
+
"flex_flow": null,
|
| 244 |
+
"grid_area": null,
|
| 245 |
+
"grid_auto_columns": null,
|
| 246 |
+
"grid_auto_flow": null,
|
| 247 |
+
"grid_auto_rows": null,
|
| 248 |
+
"grid_column": null,
|
| 249 |
+
"grid_gap": null,
|
| 250 |
+
"grid_row": null,
|
| 251 |
+
"grid_template_areas": null,
|
| 252 |
+
"grid_template_columns": null,
|
| 253 |
+
"grid_template_rows": null,
|
| 254 |
+
"height": null,
|
| 255 |
+
"justify_content": null,
|
| 256 |
+
"justify_items": null,
|
| 257 |
+
"left": null,
|
| 258 |
+
"margin": null,
|
| 259 |
+
"max_height": null,
|
| 260 |
+
"max_width": null,
|
| 261 |
+
"min_height": null,
|
| 262 |
+
"min_width": null,
|
| 263 |
+
"object_fit": null,
|
| 264 |
+
"object_position": null,
|
| 265 |
+
"order": null,
|
| 266 |
+
"overflow": null,
|
| 267 |
+
"overflow_x": null,
|
| 268 |
+
"overflow_y": null,
|
| 269 |
+
"padding": null,
|
| 270 |
+
"right": null,
|
| 271 |
+
"top": null,
|
| 272 |
+
"visibility": null,
|
| 273 |
+
"width": null
|
| 274 |
+
}
|
| 275 |
+
},
|
| 276 |
+
"cfed69b9f821407b8fd014d3748bd34f": {
|
| 277 |
+
"model_module": "@jupyter-widgets/controls",
|
| 278 |
+
"model_name": "ProgressStyleModel",
|
| 279 |
+
"model_module_version": "1.5.0",
|
| 280 |
+
"state": {
|
| 281 |
+
"_model_module": "@jupyter-widgets/controls",
|
| 282 |
+
"_model_module_version": "1.5.0",
|
| 283 |
+
"_model_name": "ProgressStyleModel",
|
| 284 |
+
"_view_count": null,
|
| 285 |
+
"_view_module": "@jupyter-widgets/base",
|
| 286 |
+
"_view_module_version": "1.2.0",
|
| 287 |
+
"_view_name": "StyleView",
|
| 288 |
+
"bar_color": null,
|
| 289 |
+
"description_width": ""
|
| 290 |
+
}
|
| 291 |
+
},
|
| 292 |
+
"d703773e6f7e42159e652bb40476a716": {
|
| 293 |
+
"model_module": "@jupyter-widgets/base",
|
| 294 |
+
"model_name": "LayoutModel",
|
| 295 |
+
"model_module_version": "1.2.0",
|
| 296 |
+
"state": {
|
| 297 |
+
"_model_module": "@jupyter-widgets/base",
|
| 298 |
+
"_model_module_version": "1.2.0",
|
| 299 |
+
"_model_name": "LayoutModel",
|
| 300 |
+
"_view_count": null,
|
| 301 |
+
"_view_module": "@jupyter-widgets/base",
|
| 302 |
+
"_view_module_version": "1.2.0",
|
| 303 |
+
"_view_name": "LayoutView",
|
| 304 |
+
"align_content": null,
|
| 305 |
+
"align_items": null,
|
| 306 |
+
"align_self": null,
|
| 307 |
+
"border": null,
|
| 308 |
+
"bottom": null,
|
| 309 |
+
"display": null,
|
| 310 |
+
"flex": null,
|
| 311 |
+
"flex_flow": null,
|
| 312 |
+
"grid_area": null,
|
| 313 |
+
"grid_auto_columns": null,
|
| 314 |
+
"grid_auto_flow": null,
|
| 315 |
+
"grid_auto_rows": null,
|
| 316 |
+
"grid_column": null,
|
| 317 |
+
"grid_gap": null,
|
| 318 |
+
"grid_row": null,
|
| 319 |
+
"grid_template_areas": null,
|
| 320 |
+
"grid_template_columns": null,
|
| 321 |
+
"grid_template_rows": null,
|
| 322 |
+
"height": null,
|
| 323 |
+
"justify_content": null,
|
| 324 |
+
"justify_items": null,
|
| 325 |
+
"left": null,
|
| 326 |
+
"margin": null,
|
| 327 |
+
"max_height": null,
|
| 328 |
+
"max_width": null,
|
| 329 |
+
"min_height": null,
|
| 330 |
+
"min_width": null,
|
| 331 |
+
"object_fit": null,
|
| 332 |
+
"object_position": null,
|
| 333 |
+
"order": null,
|
| 334 |
+
"overflow": null,
|
| 335 |
+
"overflow_x": null,
|
| 336 |
+
"overflow_y": null,
|
| 337 |
+
"padding": null,
|
| 338 |
+
"right": null,
|
| 339 |
+
"top": null,
|
| 340 |
+
"visibility": null,
|
| 341 |
+
"width": null
|
| 342 |
+
}
|
| 343 |
+
},
|
| 344 |
+
"e14ad5669d4f4df5a3a12dce60623ca9": {
|
| 345 |
+
"model_module": "@jupyter-widgets/controls",
|
| 346 |
+
"model_name": "DescriptionStyleModel",
|
| 347 |
+
"model_module_version": "1.5.0",
|
| 348 |
+
"state": {
|
| 349 |
+
"_model_module": "@jupyter-widgets/controls",
|
| 350 |
+
"_model_module_version": "1.5.0",
|
| 351 |
+
"_model_name": "DescriptionStyleModel",
|
| 352 |
+
"_view_count": null,
|
| 353 |
+
"_view_module": "@jupyter-widgets/base",
|
| 354 |
+
"_view_module_version": "1.2.0",
|
| 355 |
+
"_view_name": "StyleView",
|
| 356 |
+
"description_width": ""
|
| 357 |
+
}
|
| 358 |
+
}
|
| 359 |
+
}
|
| 360 |
+
}
|
| 361 |
+
},
|
| 362 |
+
"cells": [
|
| 363 |
+
{
|
| 364 |
+
"cell_type": "code",
|
| 365 |
+
"execution_count": null,
|
| 366 |
+
"metadata": {
|
| 367 |
+
"colab": {
|
| 368 |
+
"base_uri": "https://localhost:8080/"
|
| 369 |
+
},
|
| 370 |
+
"id": "sXhN8B0iqec4",
|
| 371 |
+
"outputId": "a6c8eb17-9fce-42ae-dfdc-7ef300d4c737"
|
| 372 |
+
},
|
| 373 |
+
"outputs": [
|
| 374 |
+
{
|
| 375 |
+
"output_type": "stream",
|
| 376 |
+
"name": "stdout",
|
| 377 |
+
"text": [
|
| 378 |
+
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/67.3 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.3/67.3 kB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 379 |
+
"\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
|
| 380 |
+
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
|
| 381 |
+
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
|
| 382 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m19.3/19.3 MB\u001b[0m \u001b[31m30.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 383 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m284.2/284.2 kB\u001b[0m \u001b[31m15.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 384 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m47.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 385 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m101.6/101.6 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 386 |
+
"\u001b[2K \u001b[90m━━━━━��━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m16.4/16.4 MB\u001b[0m \u001b[31m71.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 387 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m65.8/65.8 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 388 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.7/55.7 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 389 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m118.5/118.5 kB\u001b[0m \u001b[31m7.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 390 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m196.2/196.2 kB\u001b[0m \u001b[31m14.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 391 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m105.4/105.4 kB\u001b[0m \u001b[31m8.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 392 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.2/71.2 kB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 393 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m459.8/459.8 kB\u001b[0m \u001b[31m26.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 394 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.0/4.0 MB\u001b[0m \u001b[31m65.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 395 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m453.1/453.1 kB\u001b[0m \u001b[31m31.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 396 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m3.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 397 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m6.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 398 |
+
"\u001b[?25h Building wheel for pypika (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
|
| 399 |
+
"Reading package lists...\n",
|
| 400 |
+
"Building dependency tree...\n",
|
| 401 |
+
"Reading state information...\n",
|
| 402 |
+
"tesseract-ocr is already the newest version (4.1.1-2.1build1).\n",
|
| 403 |
+
"The following NEW packages will be installed:\n",
|
| 404 |
+
" poppler-utils\n",
|
| 405 |
+
"0 upgraded, 1 newly installed, 0 to remove and 35 not upgraded.\n",
|
| 406 |
+
"Need to get 186 kB of archives.\n",
|
| 407 |
+
"After this operation, 697 kB of additional disk space will be used.\n",
|
| 408 |
+
"Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 poppler-utils amd64 22.02.0-2ubuntu0.8 [186 kB]\n",
|
| 409 |
+
"Fetched 186 kB in 1s (371 kB/s)\n",
|
| 410 |
+
"Selecting previously unselected package poppler-utils.\n",
|
| 411 |
+
"(Reading database ... 126319 files and directories currently installed.)\n",
|
| 412 |
+
"Preparing to unpack .../poppler-utils_22.02.0-2ubuntu0.8_amd64.deb ...\n",
|
| 413 |
+
"Unpacking poppler-utils (22.02.0-2ubuntu0.8) ...\n",
|
| 414 |
+
"Setting up poppler-utils (22.02.0-2ubuntu0.8) ...\n",
|
| 415 |
+
"Processing triggers for man-db (2.10.2-1) ...\n"
|
| 416 |
+
]
|
| 417 |
+
}
|
| 418 |
+
],
|
| 419 |
+
"source": [
|
| 420 |
+
"# Step 1: Install dependencies\n",
|
| 421 |
+
"!pip install -q chromadb tiktoken\n",
|
| 422 |
+
"!apt-get -q install -y poppler-utils tesseract-ocr\n",
|
| 423 |
+
"!pip install -q pytesseract"
|
| 424 |
+
]
|
| 425 |
+
},
|
| 426 |
+
{
|
| 427 |
+
"cell_type": "code",
|
| 428 |
+
"source": [
|
| 429 |
+
"# Step 2: Setup folder structure\n",
|
| 430 |
+
"import os\n",
|
| 431 |
+
"\n",
|
| 432 |
+
"# Clean slate (optional)\n",
|
| 433 |
+
"!rm -rf /content/wwmad_workspace\n",
|
| 434 |
+
"\n",
|
| 435 |
+
"# Create working folders\n",
|
| 436 |
+
"os.makedirs(\"/content/wwmad_workspace/data\", exist_ok=True)\n",
|
| 437 |
+
"os.makedirs(\"/content/wwmad_workspace/chroma_db\", exist_ok=True)\n",
|
| 438 |
+
"\n",
|
| 439 |
+
"# Display where to upload\n",
|
| 440 |
+
"print(\"Upload your cleaned .txt files to: /content/wwmad_workspace/data/\")\n"
|
| 441 |
+
],
|
| 442 |
+
"metadata": {
|
| 443 |
+
"colab": {
|
| 444 |
+
"base_uri": "https://localhost:8080/"
|
| 445 |
+
},
|
| 446 |
+
"id": "BNwakG9IrcFi",
|
| 447 |
+
"outputId": "83ff44c8-abb5-42bb-f2ea-9137471a092f"
|
| 448 |
+
},
|
| 449 |
+
"execution_count": null,
|
| 450 |
+
"outputs": [
|
| 451 |
+
{
|
| 452 |
+
"output_type": "stream",
|
| 453 |
+
"name": "stdout",
|
| 454 |
+
"text": [
|
| 455 |
+
"Upload your cleaned .txt files to: /content/wwmad_workspace/data/\n"
|
| 456 |
+
]
|
| 457 |
+
}
|
| 458 |
+
]
|
| 459 |
+
},
|
| 460 |
+
{
|
| 461 |
+
"cell_type": "code",
|
| 462 |
+
"source": [
|
| 463 |
+
"# Step 3: Enhanced Chunking with Heuristics and Metadata\n",
|
| 464 |
+
"import os\n",
|
| 465 |
+
"import re\n",
|
| 466 |
+
"import glob\n",
|
| 467 |
+
"import hashlib\n",
|
| 468 |
+
"from typing import List, Dict\n",
|
| 469 |
+
"\n",
|
| 470 |
+
"DATA_DIR = \"/content/wwmad_workspace/data\"\n",
|
| 471 |
+
"\n",
|
| 472 |
+
"def clean_and_chunk_text(path: str, chunk_size: int = 500, overlap: int = 50) -> List[Dict]:\n",
|
| 473 |
+
" with open(path, \"r\", encoding=\"utf-8\") as file:\n",
|
| 474 |
+
" raw_text = file.read()\n",
|
| 475 |
+
"\n",
|
| 476 |
+
" # Remove Project Gutenberg boilerplate (if present)\n",
|
| 477 |
+
" start_match = re.search(r\"\\*\\*\\* START OF.+?\\*\\*\\*\", raw_text, re.IGNORECASE)\n",
|
| 478 |
+
" if start_match:\n",
|
| 479 |
+
" raw_text = raw_text[start_match.end():]\n",
|
| 480 |
+
"\n",
|
| 481 |
+
" end_match = re.search(r\"\\*\\*\\* END OF.+?\\*\\*\\*\", raw_text, re.IGNORECASE)\n",
|
| 482 |
+
" if end_match:\n",
|
| 483 |
+
" raw_text = raw_text[:end_match.start()]\n",
|
| 484 |
+
"\n",
|
| 485 |
+
" # Normalize whitespace\n",
|
| 486 |
+
" raw_text = re.sub(r\"\\s+\", \" \", raw_text).strip()\n",
|
| 487 |
+
"\n",
|
| 488 |
+
" # Metadata extraction\n",
|
| 489 |
+
" file_name = os.path.basename(path)\n",
|
| 490 |
+
" title = os.path.splitext(file_name)[0].replace(\"_\", \" \").title()\n",
|
| 491 |
+
"\n",
|
| 492 |
+
" author_lookup = {\n",
|
| 493 |
+
" \"Meditations.txt\": \"Marcus Aurelius\",\n",
|
| 494 |
+
" \"ThoughtsMA.txt\": \"Marcus Aurelius\",\n",
|
| 495 |
+
" \"SelbstbetrachtungenMA.txt\": \"Marcus Aurelius\",\n",
|
| 496 |
+
" \"10_epictetus_quotes.txt\": \"Epictetus\",\n",
|
| 497 |
+
" \"200_epictetus_quotes.txt\": \"Epictetus\",\n",
|
| 498 |
+
" \"100_ma_quotes.txt\": \"Marcus Aurelius\",\n",
|
| 499 |
+
" \"100_seneca_quotes.txt\": \"Seneca\",\n",
|
| 500 |
+
" }\n",
|
| 501 |
+
" author = author_lookup.get(file_name, \"Unknown\")\n",
|
| 502 |
+
"\n",
|
| 503 |
+
" # Chunking\n",
|
| 504 |
+
" chunks = []\n",
|
| 505 |
+
" start = 0\n",
|
| 506 |
+
" chunk_id = 0\n",
|
| 507 |
+
" while start < len(raw_text):\n",
|
| 508 |
+
" end = start + chunk_size\n",
|
| 509 |
+
" chunk_text = raw_text[start:end]\n",
|
| 510 |
+
" chunk_hash = hashlib.md5(chunk_text.encode()).hexdigest()\n",
|
| 511 |
+
"\n",
|
| 512 |
+
" chunks.append({\n",
|
| 513 |
+
" \"content\": chunk_text,\n",
|
| 514 |
+
" \"metadata\": {\n",
|
| 515 |
+
" \"chunk_id\": chunk_id,\n",
|
| 516 |
+
" \"source\": file_name,\n",
|
| 517 |
+
" \"title\": title,\n",
|
| 518 |
+
" \"author\": author,\n",
|
| 519 |
+
" \"hash\": chunk_hash\n",
|
| 520 |
+
" }\n",
|
| 521 |
+
" })\n",
|
| 522 |
+
"\n",
|
| 523 |
+
" start += chunk_size - overlap\n",
|
| 524 |
+
" chunk_id += 1\n",
|
| 525 |
+
"\n",
|
| 526 |
+
" return chunks\n",
|
| 527 |
+
"\n",
|
| 528 |
+
"\n",
|
| 529 |
+
"# Run on all .txt files\n",
|
| 530 |
+
"all_chunks = []\n",
|
| 531 |
+
"file_paths = glob.glob(os.path.join(DATA_DIR, \"*.txt\"))\n",
|
| 532 |
+
"\n",
|
| 533 |
+
"for path in file_paths:\n",
|
| 534 |
+
" chunks = clean_and_chunk_text(path)\n",
|
| 535 |
+
" all_chunks.extend(chunks)\n",
|
| 536 |
+
"\n",
|
| 537 |
+
"print(f\"✅ Enriched {len(file_paths)} files into {len(all_chunks)} chunks with metadata.\")\n"
|
| 538 |
+
],
|
| 539 |
+
"metadata": {
|
| 540 |
+
"colab": {
|
| 541 |
+
"base_uri": "https://localhost:8080/"
|
| 542 |
+
},
|
| 543 |
+
"id": "NcI-GO6Lr3gC",
|
| 544 |
+
"outputId": "917abe43-b84d-4b46-b30d-ffef7e5593b3"
|
| 545 |
+
},
|
| 546 |
+
"execution_count": null,
|
| 547 |
+
"outputs": [
|
| 548 |
+
{
|
| 549 |
+
"output_type": "stream",
|
| 550 |
+
"name": "stdout",
|
| 551 |
+
"text": [
|
| 552 |
+
"✅ Enriched 7 files into 2632 chunks with metadata.\n"
|
| 553 |
+
]
|
| 554 |
+
}
|
| 555 |
+
]
|
| 556 |
+
},
|
| 557 |
+
{
|
| 558 |
+
"cell_type": "code",
|
| 559 |
+
"source": [
|
| 560 |
+
"# Install the updated ChromaDB (if not already done)\n",
|
| 561 |
+
"!pip install chromadb --upgrade --quiet\n",
|
| 562 |
+
"\n",
|
| 563 |
+
"# Correct import and setup\n",
|
| 564 |
+
"import chromadb\n",
|
| 565 |
+
"\n",
|
| 566 |
+
"CHROMA_DIR = \"/content/wwmad_workspace/chroma_db\"\n",
|
| 567 |
+
"\n",
|
| 568 |
+
"# Use the new client setup directly\n",
|
| 569 |
+
"client = chromadb.PersistentClient(path=CHROMA_DIR)\n",
|
| 570 |
+
"\n",
|
| 571 |
+
"# Create or load a collection\n",
|
| 572 |
+
"collection = client.get_or_create_collection(\"wwmad_quotes\")\n"
|
| 573 |
+
],
|
| 574 |
+
"metadata": {
|
| 575 |
+
"id": "fX6sbiDisCeN"
|
| 576 |
+
},
|
| 577 |
+
"execution_count": null,
|
| 578 |
+
"outputs": []
|
| 579 |
+
},
|
| 580 |
+
{
|
| 581 |
+
"cell_type": "code",
|
| 582 |
+
"source": [
|
| 583 |
+
"# Prepare for ingestion\n",
|
| 584 |
+
"documents = [chunk[\"content\"] for chunk in all_chunks]\n",
|
| 585 |
+
"metadatas = [chunk[\"metadata\"] for chunk in all_chunks]\n",
|
| 586 |
+
"ids = [chunk[\"metadata\"][\"hash\"] for chunk in all_chunks] # Unique hash-based ID\n",
|
| 587 |
+
"\n",
|
| 588 |
+
"# Compute embeddings\n",
|
| 589 |
+
"model = SentenceTransformer(\"all-MiniLM-L6-v2\")\n",
|
| 590 |
+
"embeddings = model.encode(documents, show_progress_bar=True)\n",
|
| 591 |
+
"\n",
|
| 592 |
+
"# Add to ChromaDB collection\n",
|
| 593 |
+
"collection.add(\n",
|
| 594 |
+
" documents=documents,\n",
|
| 595 |
+
" metadatas=metadatas,\n",
|
| 596 |
+
" embeddings=embeddings,\n",
|
| 597 |
+
" ids=ids\n",
|
| 598 |
+
")\n",
|
| 599 |
+
"\n",
|
| 600 |
+
"print(f\"✅ Ingested {len(documents)} enriched chunks into ChromaDB.\")"
|
| 601 |
+
],
|
| 602 |
+
"metadata": {
|
| 603 |
+
"colab": {
|
| 604 |
+
"base_uri": "https://localhost:8080/",
|
| 605 |
+
"height": 66,
|
| 606 |
+
"referenced_widgets": [
|
| 607 |
+
"b78fb013688f49e09893f986b46e17b1",
|
| 608 |
+
"26a0f5c6aa35438094ba329b2cca24d1",
|
| 609 |
+
"6d2205226c584736b22ac0009a647e0e",
|
| 610 |
+
"7c481d8f47474772bc804c8d26ecc2da",
|
| 611 |
+
"6a1bd864209c4e5fb2d06ae0470d9350",
|
| 612 |
+
"4fc282e7d6e647328ebcd013aefb774b",
|
| 613 |
+
"bcb0a0dcf6044004867df51da0e3b307",
|
| 614 |
+
"eb95669d0d0245aa9251ab35374307ce",
|
| 615 |
+
"cfed69b9f821407b8fd014d3748bd34f",
|
| 616 |
+
"d703773e6f7e42159e652bb40476a716",
|
| 617 |
+
"e14ad5669d4f4df5a3a12dce60623ca9"
|
| 618 |
+
]
|
| 619 |
+
},
|
| 620 |
+
"id": "77olnzOOtfqu",
|
| 621 |
+
"outputId": "0892f837-cef5-4f46-8b70-285918350a04"
|
| 622 |
+
},
|
| 623 |
+
"execution_count": null,
|
| 624 |
+
"outputs": [
|
| 625 |
+
{
|
| 626 |
+
"output_type": "display_data",
|
| 627 |
+
"data": {
|
| 628 |
+
"text/plain": [
|
| 629 |
+
"Batches: 0%| | 0/83 [00:00<?, ?it/s]"
|
| 630 |
+
],
|
| 631 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 632 |
+
"version_major": 2,
|
| 633 |
+
"version_minor": 0,
|
| 634 |
+
"model_id": "b78fb013688f49e09893f986b46e17b1"
|
| 635 |
+
}
|
| 636 |
+
},
|
| 637 |
+
"metadata": {}
|
| 638 |
+
},
|
| 639 |
+
{
|
| 640 |
+
"output_type": "stream",
|
| 641 |
+
"name": "stdout",
|
| 642 |
+
"text": [
|
| 643 |
+
"✅ Ingested 2632 enriched chunks into ChromaDB.\n"
|
| 644 |
+
]
|
| 645 |
+
}
|
| 646 |
+
]
|
| 647 |
+
},
|
| 648 |
+
{
|
| 649 |
+
"cell_type": "code",
|
| 650 |
+
"source": [
|
| 651 |
+
"query_text = \"What is Marcus Aurelius's view on pain and endurance?\"\n",
|
| 652 |
+
"query_embedding = model.encode([query_text])[0]\n",
|
| 653 |
+
"\n",
|
| 654 |
+
"results = collection.query(\n",
|
| 655 |
+
" query_embeddings=[query_embedding],\n",
|
| 656 |
+
" n_results=5,\n",
|
| 657 |
+
" include=[\"documents\", \"metadatas\", \"distances\"]\n",
|
| 658 |
+
")\n",
|
| 659 |
+
"\n",
|
| 660 |
+
"# Pretty print\n",
|
| 661 |
+
"for i in range(len(results[\"documents\"][0])):\n",
|
| 662 |
+
" doc = results[\"documents\"][0][i]\n",
|
| 663 |
+
" meta = results[\"metadatas\"][0][i]\n",
|
| 664 |
+
" distance = results[\"distances\"][0][i]\n",
|
| 665 |
+
" print(f\"\\n🔍 Result #{i+1}\")\n",
|
| 666 |
+
" print(f\"🧾 Document: {doc[:300]}...\")\n",
|
| 667 |
+
" print(f\"📎 Metadata: {meta}\")\n",
|
| 668 |
+
" print(f\"📏 Distance: {distance:.4f}\")\n"
|
| 669 |
+
],
|
| 670 |
+
"metadata": {
|
| 671 |
+
"colab": {
|
| 672 |
+
"base_uri": "https://localhost:8080/"
|
| 673 |
+
},
|
| 674 |
+
"id": "FdkRBLCOuTgH",
|
| 675 |
+
"outputId": "fc80d5ca-cc6f-4b76-c760-0bc70d76f4c8"
|
| 676 |
+
},
|
| 677 |
+
"execution_count": null,
|
| 678 |
+
"outputs": [
|
| 679 |
+
{
|
| 680 |
+
"output_type": "stream",
|
| 681 |
+
"name": "stdout",
|
| 682 |
+
"text": [
|
| 683 |
+
"\n",
|
| 684 |
+
"🔍 Result #1\n",
|
| 685 |
+
"🧾 Document: retreat; he has not that cheerful confidence which led Socrates through a life no less noble, to a death which was to bring him into the company of gods he had worshipped and men whom he had revered. But although Marcus Aurelius may have held intellectually that his soul was destined to be absorbed...\n",
|
| 686 |
+
"📎 Metadata: {'source': 'Meditations.txt', 'chunk_id': 56, 'title': 'Meditations', 'hash': '21e612782f4236bef39c5cf38b2a93ec', 'author': 'Marcus Aurelius'}\n",
|
| 687 |
+
"📏 Distance: 0.8549\n",
|
| 688 |
+
"\n",
|
| 689 |
+
"🔍 Result #2\n",
|
| 690 |
+
"🧾 Document: ity. Even when the gods stood on the side of righteousness, they were concerned with the act more than with the intent. But Marcus Aurelius knows that what the heart is full of, the man will do. 'Such as thy thoughts and ordinary cogitations are,' he says, 'such will thy mind be in time.' And every ...\n",
|
| 691 |
+
"📎 Metadata: {'hash': '1bed1717c3bcc21483a1593347e8186b', 'author': 'Marcus Aurelius', 'source': 'Meditations.txt', 'title': 'Meditations', 'chunk_id': 60}\n",
|
| 692 |
+
"📏 Distance: 0.8725\n",
|
| 693 |
+
"\n",
|
| 694 |
+
"🔍 Result #3\n",
|
| 695 |
+
"🧾 Document: there are many allusions to death as the natural end; doubtless he expected his soul one day to be absorbed into the universal soul, since nothing comes out of nothing, and nothing can be annihilated. His mood is one of strenuous weariness; he does his duty as a good soldier, waiting for the sound o...\n",
|
| 696 |
+
"📎 Metadata: {'chunk_id': 10, 'source': 'Meditations.txt', 'author': 'Unknown', 'title': 'Meditations'}\n",
|
| 697 |
+
"📏 Distance: 0.8927\n",
|
| 698 |
+
"\n",
|
| 699 |
+
"🔍 Result #4\n",
|
| 700 |
+
"🧾 Document: Marcus Aurelius. Pater’s “Marius the Epicurean” forms another outside commentary, which is of service in the imaginative attempt to create again the period. MARCUS AURELIUS ANTONINUS THE ROMAN EMPEROR HIS FIRST BOOK concerning HIMSELF: Wherein Antoninus recordeth, What and of whom, whether Parents, ...\n",
|
| 701 |
+
"📎 Metadata: {'source': 'Meditations.txt', 'author': 'Unknown', 'chunk_id': 12, 'title': 'Meditations'}\n",
|
| 702 |
+
"📏 Distance: 0.8959\n",
|
| 703 |
+
"\n",
|
| 704 |
+
"🔍 Result #5\n",
|
| 705 |
+
"🧾 Document: oung or turned out hateful, his life was one paradox. That nothing might lack, it was in camp before the face of the enemy that he passed away and went to his own place. The following is a list of the chief English translations of Marcus Aurelius: (1) By Meric Casaubon, 1634; (2) Jeremy Collier, 170...\n",
|
| 706 |
+
"📎 Metadata: {'author': 'Marcus Aurelius', 'source': 'Meditations.txt', 'hash': 'e5c533b25677c0517b36ec5051f4997f', 'title': 'Meditations', 'chunk_id': 65}\n",
|
| 707 |
+
"📏 Distance: 0.9105\n"
|
| 708 |
+
]
|
| 709 |
+
}
|
| 710 |
+
]
|
| 711 |
+
},
|
| 712 |
+
{
|
| 713 |
+
"cell_type": "code",
|
| 714 |
+
"source": [
|
| 715 |
+
"# Example query\n",
|
| 716 |
+
"query = \"How should I deal with adversity?\"\n",
|
| 717 |
+
"\n",
|
| 718 |
+
"# Embed the query\n",
|
| 719 |
+
"query_embedding = model.encode([query])\n",
|
| 720 |
+
"\n",
|
| 721 |
+
"# Query the ChromaDB collection\n",
|
| 722 |
+
"results = collection.query(\n",
|
| 723 |
+
" query_embeddings=query_embedding,\n",
|
| 724 |
+
" n_results=5,\n",
|
| 725 |
+
" include=[\"documents\", \"metadatas\", \"distances\"]\n",
|
| 726 |
+
")\n",
|
| 727 |
+
"\n",
|
| 728 |
+
"# Display results\n",
|
| 729 |
+
"for i, (doc, meta, dist) in enumerate(zip(results[\"documents\"][0], results[\"metadatas\"][0], results[\"distances\"][0]), 1):\n",
|
| 730 |
+
" print(f\"\\n🔹 Result #{i}\")\n",
|
| 731 |
+
" print(f\"Document: {doc}\")\n",
|
| 732 |
+
" print(f\"Metadata: {meta}\")\n",
|
| 733 |
+
" print(f\"Distance: {dist:.4f}\")\n"
|
| 734 |
+
],
|
| 735 |
+
"metadata": {
|
| 736 |
+
"colab": {
|
| 737 |
+
"base_uri": "https://localhost:8080/"
|
| 738 |
+
},
|
| 739 |
+
"id": "F5lsMUkw5d7E",
|
| 740 |
+
"outputId": "d4bf5842-60eb-4a18-be83-b61a16c8b1fd"
|
| 741 |
+
},
|
| 742 |
+
"execution_count": null,
|
| 743 |
+
"outputs": [
|
| 744 |
+
{
|
| 745 |
+
"output_type": "stream",
|
| 746 |
+
"name": "stdout",
|
| 747 |
+
"text": [
|
| 748 |
+
"\n",
|
| 749 |
+
"🔹 Result #1\n",
|
| 750 |
+
"Document: iting down one thing you can control and one thing you can't. Let go of the latter. 2. You Always Own Your Response ‘It is not the things themselves that disturb people but their judgements about those things.” Epictetus, Handbook, 5 Events happen, but our suffering begins with judgment. By managing our impressions and opinions, we reclaim agency, even in chaos. We then become true masters of how we view the world around us. Practice: Pause before reacting. Ask: “What am | adding to this situati\n",
|
| 751 |
+
"Metadata: {'author': 'Epictetus', 'title': '10 Epictetus Quotes', 'hash': '64d19f59da0c0ff214a013968496462f', 'chunk_id': 3, 'source': '10_epictetus_quotes.txt'}\n",
|
| 752 |
+
"Distance: 1.0127\n",
|
| 753 |
+
"\n",
|
| 754 |
+
"🔹 Result #2\n",
|
| 755 |
+
"Document: good and truly bad. But I that understand the nature of that which is good, that it only is to be desired, and of that which is bad, that it only is truly odious and shameful: who know moreover, that this transgressor, whosoever he be, is my kinsman, not by the same blood and seed, but by participation of the same reason, and of the same divine particle; How can I either be hurt by any of those, since it is not in their power to make me incur anything that is truly reproachful? or angry, and ill\n",
|
| 756 |
+
"Metadata: {'chunk_id': 109, 'title': 'Meditations', 'hash': '1b521172571b689ca371ce95a91b6e59', 'author': 'Marcus Aurelius', 'source': 'Meditations.txt'}\n",
|
| 757 |
+
"Distance: 1.2164\n",
|
| 758 |
+
"\n",
|
| 759 |
+
"🔹 Result #3\n",
|
| 760 |
+
"Document: and that thou art a man like others; and even if thou dost abstain from certain faults, still thou hast the disposition to commit them, though either through cowardice, or concern about reputation, or some such mean motive, thou dost abstain from such faults (i. 17). Fifth, consider that thou dost not even understand whether men are doing wrong or not, for many things are done with a certain reference to circumstances. And in short, a man must learn a great deal to enable him to pass a correct judgment on another man's acts (ix. 38; iv. 51). Sixth, consider when thou art much vexed or grieved, that man's life is only a moment, and after a short time we are all laid out dead (vii. 58; iv. 48). Seventh, that it is not men's acts which disturb us, for those acts have their foundation in men's ruling principles, but it is our own opinions which disturb us. Take away these opinions then, and resolve to dismiss thy judgment about an act as if it were something grievous, and thy anger is gone. How then shall I take away these opinions? By reflecting that no wrongful act of another brings shame on thee: for unless that which is shameful is alone bad, thou also must of necessity do many things wrong, and become a robber and everything else (v. 25; vii. 16). Eighth, consider how much more pain is brought on us by the anger and vexation caused by such acts than by the acts themselves, at which we are angry and vexed (iv. 39, 49; vii. 24). Ninth, consider that a good disposition is invincible if it be genuine, and not an affected smile and acting a part. For what will the most violent man do to thee, if thou continuest to be of a kind disposition towards him, and if, as opportunity offers, thou gently admonishest him and calmly correctest his errors at the very time when he is trying to do thee harm, saying, Not so, my child: we are constituted by nature for something else: I shall certainly not be injured, but thou art injuring thyself, my child.--And show him with gentle tact and by general principles that this is so, and that even bees do not do as he does, nor any animals which are formed by nature to be gregarious. And thou must do this neither with any double meaning nor in the way of reproach, but affectionately and without any rancor in thy soul; and not as if thou wert lecturing him, nor yet that any bystander may admire, but either when he is alone, and if others are present ...[A] [A] It appears that there is a defect in the text here. Remember these nine rules, as if thou hadst received them as a gift from the Muses, and begin at last to be a man while thou livest. But thou must equally avoid nattering men and being vexed at them, for\n",
|
| 761 |
+
"Metadata: {'title': 'ThoughtsMA', 'chunk_id': 150, 'author': 'Unknown', 'source': 'ThoughtsMA.txt'}\n",
|
| 762 |
+
"Distance: 1.2330\n",
|
| 763 |
+
"\n",
|
| 764 |
+
"🔹 Result #4\n",
|
| 765 |
+
"Document: to Overcome Self-Doubt A quote on the True Value “Look inward. Don’t let the true nature or value of anything elude you.” Marcus Aurelius Quotes: Over 100 Thoughts From a Stoic Emperor - Vi... VA srovce “ Post: How to Overcome Self-Doubt Il e “Dont waste the rest of your time here worrying about other people — unless it affects the common good. It will keep you from doing anything useful.” Marcus Aurelius, Meditations, Book 3.4 Post: How to Overcome Self-Doubt “You participate in a society by yo\n",
|
| 766 |
+
"Metadata: {'title': '100 Ma Quotes', 'chunk_id': 21, 'hash': 'e259f3daa1b6d7658834f546fcb588a0', 'author': 'Marcus Aurelius', 'source': '100_ma_quotes.txt'}\n",
|
| 767 |
+
"Distance: 1.2335\n",
|
| 768 |
+
"\n",
|
| 769 |
+
"🔹 Result #5\n",
|
| 770 |
+
"Document: ght way, and think and act in the right way. These two things are common both to the soul of God and to the soul of man, and to the soul of every rational being: not to be hindered by another; and to hold good to consist in the disposition to justice and the practice of it, and in this to let thy desire find its termination. 35. If this is neither my own badness, nor an effect of my own badness, and the common weal is not injured, why am I troubled about it, and what is the harm to the common we\n",
|
| 771 |
+
"Metadata: {'hash': 'd5cb9bf89dadc3aef915d95a0eb4821a', 'title': 'Thoughtsma', 'author': 'Marcus Aurelius', 'chunk_id': 495, 'source': 'ThoughtsMA.txt'}\n",
|
| 772 |
+
"Distance: 1.2486\n"
|
| 773 |
+
]
|
| 774 |
+
}
|
| 775 |
+
]
|
| 776 |
+
},
|
| 777 |
+
{
|
| 778 |
+
"cell_type": "code",
|
| 779 |
+
"source": [
|
| 780 |
+
"import shutil\n",
|
| 781 |
+
"\n",
|
| 782 |
+
"shutil.make_archive(\"/content/chroma_db_export\", \"zip\", \"/content/wwmad_workspace/chroma_db\")\n"
|
| 783 |
+
],
|
| 784 |
+
"metadata": {
|
| 785 |
+
"colab": {
|
| 786 |
+
"base_uri": "https://localhost:8080/",
|
| 787 |
+
"height": 35
|
| 788 |
+
},
|
| 789 |
+
"id": "XDyp5ppk6g5_",
|
| 790 |
+
"outputId": "68fe3f01-e6bc-4174-8f3a-60557166e2ef"
|
| 791 |
+
},
|
| 792 |
+
"execution_count": null,
|
| 793 |
+
"outputs": [
|
| 794 |
+
{
|
| 795 |
+
"output_type": "execute_result",
|
| 796 |
+
"data": {
|
| 797 |
+
"text/plain": [
|
| 798 |
+
"'/content/chroma_db_export.zip'"
|
| 799 |
+
],
|
| 800 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
| 801 |
+
"type": "string"
|
| 802 |
+
}
|
| 803 |
+
},
|
| 804 |
+
"metadata": {},
|
| 805 |
+
"execution_count": 18
|
| 806 |
+
}
|
| 807 |
+
]
|
| 808 |
+
},
|
| 809 |
+
{
|
| 810 |
+
"cell_type": "code",
|
| 811 |
+
"source": [
|
| 812 |
+
"from google.colab import files\n",
|
| 813 |
+
"files.download(\"/content/chroma_db_export.zip\")"
|
| 814 |
+
],
|
| 815 |
+
"metadata": {
|
| 816 |
+
"colab": {
|
| 817 |
+
"base_uri": "https://localhost:8080/",
|
| 818 |
+
"height": 17
|
| 819 |
+
},
|
| 820 |
+
"id": "pdN35dM06m42",
|
| 821 |
+
"outputId": "af4b9f72-c20c-4889-84eb-706c0b303581"
|
| 822 |
+
},
|
| 823 |
+
"execution_count": null,
|
| 824 |
+
"outputs": [
|
| 825 |
+
{
|
| 826 |
+
"output_type": "display_data",
|
| 827 |
+
"data": {
|
| 828 |
+
"text/plain": [
|
| 829 |
+
"<IPython.core.display.Javascript object>"
|
| 830 |
+
],
|
| 831 |
+
"application/javascript": [
|
| 832 |
+
"\n",
|
| 833 |
+
" async function download(id, filename, size) {\n",
|
| 834 |
+
" if (!google.colab.kernel.accessAllowed) {\n",
|
| 835 |
+
" return;\n",
|
| 836 |
+
" }\n",
|
| 837 |
+
" const div = document.createElement('div');\n",
|
| 838 |
+
" const label = document.createElement('label');\n",
|
| 839 |
+
" label.textContent = `Downloading \"${filename}\": `;\n",
|
| 840 |
+
" div.appendChild(label);\n",
|
| 841 |
+
" const progress = document.createElement('progress');\n",
|
| 842 |
+
" progress.max = size;\n",
|
| 843 |
+
" div.appendChild(progress);\n",
|
| 844 |
+
" document.body.appendChild(div);\n",
|
| 845 |
+
"\n",
|
| 846 |
+
" const buffers = [];\n",
|
| 847 |
+
" let downloaded = 0;\n",
|
| 848 |
+
"\n",
|
| 849 |
+
" const channel = await google.colab.kernel.comms.open(id);\n",
|
| 850 |
+
" // Send a message to notify the kernel that we're ready.\n",
|
| 851 |
+
" channel.send({})\n",
|
| 852 |
+
"\n",
|
| 853 |
+
" for await (const message of channel.messages) {\n",
|
| 854 |
+
" // Send a message to notify the kernel that we're ready.\n",
|
| 855 |
+
" channel.send({})\n",
|
| 856 |
+
" if (message.buffers) {\n",
|
| 857 |
+
" for (const buffer of message.buffers) {\n",
|
| 858 |
+
" buffers.push(buffer);\n",
|
| 859 |
+
" downloaded += buffer.byteLength;\n",
|
| 860 |
+
" progress.value = downloaded;\n",
|
| 861 |
+
" }\n",
|
| 862 |
+
" }\n",
|
| 863 |
+
" }\n",
|
| 864 |
+
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
|
| 865 |
+
" const a = document.createElement('a');\n",
|
| 866 |
+
" a.href = window.URL.createObjectURL(blob);\n",
|
| 867 |
+
" a.download = filename;\n",
|
| 868 |
+
" div.appendChild(a);\n",
|
| 869 |
+
" a.click();\n",
|
| 870 |
+
" div.remove();\n",
|
| 871 |
+
" }\n",
|
| 872 |
+
" "
|
| 873 |
+
]
|
| 874 |
+
},
|
| 875 |
+
"metadata": {}
|
| 876 |
+
},
|
| 877 |
+
{
|
| 878 |
+
"output_type": "display_data",
|
| 879 |
+
"data": {
|
| 880 |
+
"text/plain": [
|
| 881 |
+
"<IPython.core.display.Javascript object>"
|
| 882 |
+
],
|
| 883 |
+
"application/javascript": [
|
| 884 |
+
"download(\"download_2cd61887-507e-4bc6-a5ec-aee882e2720c\", \"chroma_db_export.zip\", 20504603)"
|
| 885 |
+
]
|
| 886 |
+
},
|
| 887 |
+
"metadata": {}
|
| 888 |
+
}
|
| 889 |
+
]
|
| 890 |
+
}
|
| 891 |
+
]
|
| 892 |
+
}
|