{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyOuxoYC0mOLg3qm/0hreMFy",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"2b1095050bb847c48855e3b74ae18b19": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HBoxModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HBoxModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HBoxView",
"box_style": "",
"children": [
"IPY_MODEL_a0a1c543115c4764b4150c5d0216370c",
"IPY_MODEL_23675bffa00749849ec944f84986ff52",
"IPY_MODEL_9e86b288110f4d418fd9761f59f5637f"
],
"layout": "IPY_MODEL_d6a4fd2a9cf7431b8bf738d9da0e2a7c"
}
},
"a0a1c543115c4764b4150c5d0216370c": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_700a1ffb298c4dd799c44fcee540b74c",
"placeholder": "",
"style": "IPY_MODEL_06e7a0370c8c46dd9a47c72a474212d1",
"value": "Parsing nodes: 100%"
}
},
"23675bffa00749849ec944f84986ff52": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FloatProgressModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "FloatProgressModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "ProgressView",
"bar_style": "success",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_268f6f0800164e0ab7f8f31718f7f9be",
"max": 14,
"min": 0,
"orientation": "horizontal",
"style": "IPY_MODEL_4001b95bd48147fb876b37a644e70dec",
"value": 14
}
},
"9e86b288110f4d418fd9761f59f5637f": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_22024efa09cb4330ab68a8c2bdbf92ac",
"placeholder": "",
"style": "IPY_MODEL_c14678e2b8c546fc9123c94fa47b924d",
"value": " 14/14 [00:00<00:00, 13.27it/s]"
}
},
"d6a4fd2a9cf7431b8bf738d9da0e2a7c": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"700a1ffb298c4dd799c44fcee540b74c": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"06e7a0370c8c46dd9a47c72a474212d1": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
},
"268f6f0800164e0ab7f8f31718f7f9be": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"4001b95bd48147fb876b37a644e70dec": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ProgressStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "ProgressStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"bar_color": null,
"description_width": ""
}
},
"22024efa09cb4330ab68a8c2bdbf92ac": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"c14678e2b8c546fc9123c94fa47b924d": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
},
"9dda1537424142e0b7f2fdd5f9c1b98d": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HBoxModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HBoxModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HBoxView",
"box_style": "",
"children": [
"IPY_MODEL_1db171d1920d432283f9e1795c4c0c80",
"IPY_MODEL_23e0caeaf15546f0b5c62aa263c99e09",
"IPY_MODEL_03b8aded009343f288f0945b64d1f41c"
],
"layout": "IPY_MODEL_4d922a99035d45c59ce9868a4ef73d68"
}
},
"1db171d1920d432283f9e1795c4c0c80": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_aea6b63cbced40619bf32b1a2c350259",
"placeholder": "",
"style": "IPY_MODEL_c89c9dd46b454181aadaf82c7296cdae",
"value": "Generating embeddings: 100%"
}
},
"23e0caeaf15546f0b5c62aa263c99e09": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FloatProgressModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "FloatProgressModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "ProgressView",
"bar_style": "success",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_bec71553390b44879accb638a5b4873f",
"max": 108,
"min": 0,
"orientation": "horizontal",
"style": "IPY_MODEL_97e4316196e84c7a82a2dd3e4698bc55",
"value": 108
}
},
"03b8aded009343f288f0945b64d1f41c": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_b2ab2dc287a9421ca812074389ee31a7",
"placeholder": "",
"style": "IPY_MODEL_fa5c2f509ec54c5695a406160ab0626a",
"value": " 108/108 [00:03<00:00, 30.08it/s]"
}
},
"4d922a99035d45c59ce9868a4ef73d68": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"aea6b63cbced40619bf32b1a2c350259": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"c89c9dd46b454181aadaf82c7296cdae": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
},
"bec71553390b44879accb638a5b4873f": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"97e4316196e84c7a82a2dd3e4698bc55": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ProgressStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "ProgressStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"bar_color": null,
"description_width": ""
}
},
"b2ab2dc287a9421ca812074389ee31a7": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"fa5c2f509ec54c5695a406160ab0626a": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
}
}
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "markdown",
"source": [
"# Install Packages and Setup Variables"
],
"metadata": {
"id": "-zE1h0uQV7uT"
}
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "QPJzr-I9XQ7l",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "8e808cc4-4c21-474b-c5b7-f6841ee08020"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m15.7/15.7 MB\u001b[0m \u001b[31m26.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m225.4/225.4 kB\u001b[0m \u001b[31m18.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m40.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m508.6/508.6 kB\u001b[0m \u001b[31m31.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m79.9/79.9 MB\u001b[0m \u001b[31m7.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m45.7/45.7 kB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m51.7/51.7 kB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.9/75.9 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m39.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m92.1/92.1 kB\u001b[0m \u001b[31m10.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m60.7/60.7 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.1/41.1 kB\u001b[0m \u001b[31m4.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.4/5.4 MB\u001b[0m \u001b[31m72.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.8/6.8 MB\u001b[0m \u001b[31m54.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.9/57.9 kB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m105.6/105.6 kB\u001b[0m \u001b[31m10.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.3/67.3 kB\u001b[0m \u001b[31m6.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m698.9/698.9 kB\u001b[0m \u001b[31m44.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m64.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.6/67.6 kB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.1/3.1 MB\u001b[0m \u001b[31m53.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.5/71.5 kB\u001b[0m \u001b[31m7.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m76.9/76.9 kB\u001b[0m \u001b[31m7.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.8/50.8 kB\u001b[0m \u001b[31m4.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m341.4/341.4 kB\u001b[0m \u001b[31m23.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.4/3.4 MB\u001b[0m \u001b[31m56.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m61.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.2/130.2 kB\u001b[0m \u001b[31m13.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.4/49.4 kB\u001b[0m \u001b[31m4.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m8.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h Building wheel for pypika (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n"
]
}
],
"source": [
"!pip install -q llama-index==0.9.21 openai==1.6.0 tiktoken==0.5.2 chromadb==0.4.21 kaleido==0.2.1 python-multipart==0.0.6 cohere==4.39"
]
},
{
"cell_type": "code",
"source": [
"import os\n",
"\n",
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
"os.environ[\"OPENAI_API_KEY\"] = \"\"\n",
"os.environ[\"CO_API_KEY\"] = \"\""
],
"metadata": {
"id": "riuXwpSPcvWC"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import nest_asyncio\n",
"\n",
"nest_asyncio.apply()"
],
"metadata": {
"id": "jIEeZzqLbz0J"
},
"execution_count": 3,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Load a Model"
],
"metadata": {
"id": "Bkgi2OrYzF7q"
}
},
{
"cell_type": "code",
"source": [
"from llama_index.llms import OpenAI\n",
"\n",
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
],
"metadata": {
"id": "9oGT6crooSSj"
},
"execution_count": 4,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Create a VectoreStore"
],
"metadata": {
"id": "0BwVuJXlzHVL"
}
},
{
"cell_type": "code",
"source": [
"import chromadb\n",
"\n",
"# create client and a new collection\n",
"# chromadb.EphemeralClient saves data in-memory.\n",
"chroma_client = chromadb.PersistentClient(path=\"./mini-llama-articles\")\n",
"chroma_collection = chroma_client.create_collection(\"mini-llama-articles\")"
],
"metadata": {
"id": "SQP87lHczHKc"
},
"execution_count": 5,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from llama_index.vector_stores import ChromaVectorStore\n",
"\n",
"# Define a storage context object using the created vector database.\n",
"vector_store = ChromaVectorStore(chroma_collection=chroma_collection)"
],
"metadata": {
"id": "zAaGcYMJzHAN"
},
"execution_count": 6,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Load the Dataset (CSV)"
],
"metadata": {
"id": "I9JbAzFcjkpn"
}
},
{
"cell_type": "markdown",
"source": [
"## Download"
],
"metadata": {
"id": "ceveDuYdWCYk"
}
},
{
"cell_type": "markdown",
"source": [
"The dataset includes several articles from the TowardsAI blog, which provide an in-depth explanation of the LLaMA2 model. Read the dataset as a long string."
],
"metadata": {
"id": "eZwf6pv7WFmD"
}
},
{
"cell_type": "code",
"source": [
"!wget https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles.csv"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wl_pbPvMlv1h",
"outputId": "bc9a0415-a1fb-4e89-a2b4-165420106b34"
},
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"--2024-02-06 20:32:51-- https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles.csv\n",
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.109.133, 185.199.110.133, ...\n",
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 173646 (170K) [text/plain]\n",
"Saving to: ‘mini-llama-articles.csv’\n",
"\n",
"\rmini-llama-articles 0%[ ] 0 --.-KB/s \rmini-llama-articles 100%[===================>] 169.58K --.-KB/s in 0.02s \n",
"\n",
"2024-02-06 20:32:51 (7.02 MB/s) - ‘mini-llama-articles.csv’ saved [173646/173646]\n",
"\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"## Read File"
],
"metadata": {
"id": "VWBLtDbUWJfA"
}
},
{
"cell_type": "code",
"source": [
"import csv\n",
"\n",
"rows = []\n",
"\n",
"# Load the file as a JSON\n",
"with open(\"./mini-llama-articles.csv\", mode=\"r\", encoding=\"utf-8\") as file:\n",
" csv_reader = csv.reader(file)\n",
"\n",
" for idx, row in enumerate( csv_reader ):\n",
" if idx == 0: continue; # Skip header row\n",
" rows.append( row )\n",
"\n",
"# The number of characters in the dataset.\n",
"len( rows )"
],
"metadata": {
"id": "0Q9sxuW0g3Gd",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "a8361aa6-522d-4def-e49b-ed08d9c8e7d1"
},
"execution_count": 8,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"14"
]
},
"metadata": {},
"execution_count": 8
}
]
},
{
"cell_type": "markdown",
"source": [
"# Convert to Document obj"
],
"metadata": {
"id": "S17g2RYOjmf2"
}
},
{
"cell_type": "code",
"source": [
"from llama_index import Document\n",
"\n",
"# Convert the chunks to Document objects so the LlamaIndex framework can process them.\n",
"documents = [Document(text=row[1], metadata={\"title\": row[0], \"url\": row[2], \"source_name\": row[3]}) for row in rows]"
],
"metadata": {
"id": "YizvmXPejkJE"
},
"execution_count": 9,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Transforming"
],
"metadata": {
"id": "qjuLbmFuWsyl"
}
},
{
"cell_type": "code",
"source": [
"from llama_index.text_splitter import TokenTextSplitter\n",
"\n",
"text_splitter = TokenTextSplitter(\n",
" separator=\" \", chunk_size=512, chunk_overlap=128\n",
")"
],
"metadata": {
"id": "9z3t70DGWsjO"
},
"execution_count": 10,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"There are two options to use the Cohere embeddings:\n",
"\n",
"- input_type=\"search_document\": Employ this option for texts (documents) intended for storage in your vector database.\n",
"\n",
"- input_type=\"search_query\": Use this when issuing search queries to locate the most related documents within your vector database."
],
"metadata": {
"id": "y28yMy0GxfGR"
}
},
{
"cell_type": "code",
"source": [
"from llama_index.extractors import (\n",
" SummaryExtractor,\n",
" QuestionsAnsweredExtractor,\n",
" KeywordExtractor,\n",
")\n",
"from llama_index.embeddings.cohereai import CohereEmbedding\n",
"from llama_index.ingestion import IngestionPipeline\n",
"\n",
"pipeline = IngestionPipeline(\n",
" transformations=[\n",
" text_splitter,\n",
" QuestionsAnsweredExtractor(questions=3, llm=llm),\n",
" SummaryExtractor(summaries=[\"prev\", \"self\"], llm=llm),\n",
" KeywordExtractor(keywords=10, llm=llm),\n",
" CohereEmbedding(model_name=\"embed-english-v3.0\", input_type=\"search_document\"),\n",
" ],\n",
" vector_store=vector_store\n",
")\n",
"\n",
"nodes = pipeline.run(documents=documents, show_progress=True);"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 385,
"referenced_widgets": [
"2b1095050bb847c48855e3b74ae18b19",
"a0a1c543115c4764b4150c5d0216370c",
"23675bffa00749849ec944f84986ff52",
"9e86b288110f4d418fd9761f59f5637f",
"d6a4fd2a9cf7431b8bf738d9da0e2a7c",
"700a1ffb298c4dd799c44fcee540b74c",
"06e7a0370c8c46dd9a47c72a474212d1",
"268f6f0800164e0ab7f8f31718f7f9be",
"4001b95bd48147fb876b37a644e70dec",
"22024efa09cb4330ab68a8c2bdbf92ac",
"c14678e2b8c546fc9123c94fa47b924d",
"9dda1537424142e0b7f2fdd5f9c1b98d",
"1db171d1920d432283f9e1795c4c0c80",
"23e0caeaf15546f0b5c62aa263c99e09",
"03b8aded009343f288f0945b64d1f41c",
"4d922a99035d45c59ce9868a4ef73d68",
"aea6b63cbced40619bf32b1a2c350259",
"c89c9dd46b454181aadaf82c7296cdae",
"bec71553390b44879accb638a5b4873f",
"97e4316196e84c7a82a2dd3e4698bc55",
"b2ab2dc287a9421ca812074389ee31a7",
"fa5c2f509ec54c5695a406160ab0626a"
]
},
"id": "P9LDJ7o-Wsc-",
"outputId": "cd49bff2-b0da-4722-8baa-6a07f1023b39"
},
"execution_count": 11,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"Parsing nodes: 0%| | 0/14 [00:00, ?it/s]"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "2b1095050bb847c48855e3b74ae18b19"
}
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"464\n",
"452\n",
"457\n",
"465\n",
"448\n",
"468\n",
"434\n",
"447\n",
"455\n",
"445\n",
"449\n",
"455\n",
"431\n",
"453\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"100%|██████████| 108/108 [00:41<00:00, 2.58it/s]\n",
"100%|██████████| 108/108 [00:57<00:00, 1.88it/s]\n",
"100%|██████████| 108/108 [00:43<00:00, 2.48it/s]\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"Generating embeddings: 0%| | 0/108 [00:00, ?it/s]"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "9dda1537424142e0b7f2fdd5f9c1b98d"
}
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": [
"len( nodes )"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mPGa85hM2P3P",
"outputId": "9d7811ba-1e10-4098-b6eb-77a4e7d37457"
},
"execution_count": 12,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"108"
]
},
"metadata": {},
"execution_count": 12
}
]
},
{
"cell_type": "code",
"source": [
"len( nodes[0].embedding )"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "jjnmscmq2cXK",
"outputId": "5f6fa176-4e09-4cc7-bd17-8236b061ad17"
},
"execution_count": 13,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"1024"
]
},
"metadata": {},
"execution_count": 13
}
]
},
{
"cell_type": "code",
"source": [
"!zip -r vectorstore_cohere.zip mini-llama-articles"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hV9G0lSUJJSa",
"outputId": "453a4ea3-dfda-4da1-ac29-929834c83b40"
},
"execution_count": 33,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" adding: mini-llama-articles/ (stored 0%)\n",
" adding: mini-llama-articles/c0aaa59e-d299-428e-b192-2666970017c4/ (stored 0%)\n",
" adding: mini-llama-articles/c0aaa59e-d299-428e-b192-2666970017c4/data_level0.bin (deflated 100%)\n",
" adding: mini-llama-articles/c0aaa59e-d299-428e-b192-2666970017c4/header.bin (deflated 61%)\n",
" adding: mini-llama-articles/c0aaa59e-d299-428e-b192-2666970017c4/link_lists.bin (stored 0%)\n",
" adding: mini-llama-articles/c0aaa59e-d299-428e-b192-2666970017c4/length.bin (deflated 73%)\n",
" adding: mini-llama-articles/chroma.sqlite3 (deflated 70%)\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# Load Indexes"
],
"metadata": {
"id": "OWaT6rL7ksp8"
}
},
{
"cell_type": "code",
"source": [
"!unzip vectorstore_cohere.zip"
],
"metadata": {
"id": "EF-wobGAJRgL"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Create your index\n",
"db = chromadb.PersistentClient(path=\"./mini-llama-articles\")\n",
"chroma_collection = db.get_or_create_collection(\"mini-llama-articles\")\n",
"vector_store = ChromaVectorStore(chroma_collection=chroma_collection)"
],
"metadata": {
"id": "mXi56KTXk2sp"
},
"execution_count": 14,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from llama_index import ServiceContext\n",
"\n",
"embed_model = CohereEmbedding(\n",
" model_name=\"embed-english-v3.0\",\n",
" input_type=\"search_query\",\n",
")\n",
"\n",
"service_context = ServiceContext.from_defaults(\n",
" llm=llm, embed_model=embed_model\n",
")"
],
"metadata": {
"id": "9l0PaY230syE"
},
"execution_count": 37,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Create your index\n",
"from llama_index import VectorStoreIndex\n",
"\n",
"index = VectorStoreIndex.from_vector_store(vector_store, service_context=service_context)"
],
"metadata": {
"id": "jKXURvLtkuTS"
},
"execution_count": 38,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Query Dataset"
],
"metadata": {
"id": "8JPD8yAinVSq"
}
},
{
"cell_type": "code",
"source": [
"# Define a query engine that is responsible for retrieving related pieces of text,\n",
"# and using a LLM to formulate the final answer.\n",
"query_engine = index.as_query_engine()\n",
"\n",
"res = query_engine.query(\"How many parameters LLaMA2 model has?\")"
],
"metadata": {
"id": "b0gue7cyctt1"
},
"execution_count": 29,
"outputs": []
},
{
"cell_type": "code",
"source": [
"res.response"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 53
},
"id": "VKK3jMprctre",
"outputId": "cb85d598-d1bc-49e9-818f-c7bbde465864"
},
"execution_count": 30,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'LLaMA2 model has four different sizes with varying numbers of parameters: 7 billion, 13 billion, 34 billion, and 70 billion parameters.'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 30
}
]
},
{
"cell_type": "code",
"source": [
"for src in res.source_nodes:\n",
" print(\"Node ID\\t\", src.node_id)\n",
" print(\"Title\\t\", src.metadata['title'])\n",
" print(\"Text\\t\", src.text)\n",
" print(\"Score\\t\", src.score)\n",
" print(\"-_\"*20)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "465dH4yQc7Ct",
"outputId": "3d2b3ce2-7705-41bb-80e3-4fe6b390dcef"
},
"execution_count": 31,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Node ID\t d1aa089e-160f-4a3c-9bba-f72700d0d0d8\n",
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
"Text\t The model demonstrates exceptionally low AI safety violation percentages, surpassing even ChatGPT in safety benchmarks. Finding the right balance between helpfulness and safety when optimizing a model poses significant challenges. While a highly helpful model may be capable of answering any question, including sensitive ones like \"How do I build a bomb?\", it also raises concerns about potential misuse. Thus, striking the perfect equilibrium between providing useful information and ensuring safety is paramount. However, prioritizing safety to an extreme extent can lead to a model that struggles to effectively address a diverse range of questions. This limitation could hinder the model's practical applicability and user experience. Thus, achieving an optimum balance that allows the model to be both helpful and safe is of utmost importance. To strike the right balance between helpfulness and safety, Meta employed two reward models - one for helpfulness and another for safety - to optimize the model's responses. The 34B parameter model has reported higher safety violations than other variants, possibly contributing to the delay in its release. IV. Helpfulness Comparison: Llama 2 Outperforms Competitors Llama 2 emerges as a strong contender in the open-source language model arena, outperforming its competitors in most categories. The 70B parameter model outperforms all other open-source models, while the 7B and 34B models outshine Falcon in all categories and MPT in all categories except coding. Despite being smaller, Llam a2's performance rivals that of Chat GPT 3.5, a significantly larger closed-source model. While GPT 4 and PalM-2-L, with their larger size, outperform Llama 2, this is expected due to their capacity for handling complex language tasks. Llama 2's impressive ability to compete with larger models highlights its efficiency and potential in the market. However, Llama 2 does face challenges in coding and math problems, where models like Chat GPT 4 excel, given their significantly larger size. Chat GPT 4 performed significantly better than Llama 2 for coding (HumanEval benchmark)and math problem tasks (GSM8k benchmark). Open-source AI technologies, like Llama 2, continue to advance, offering\n",
"Score\t 0.3275459219113103\n",
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n",
"Node ID\t bd8bdb4e-8ca2-4ae0-a98f-a4398611ef46\n",
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
"Text\t I. Llama 2: Revolutionizing Commercial Use Unlike its predecessor Llama 1, which was limited to research use, Llama 2 represents a major advancement as an open-source commercial model. Businesses can now integrate Llama 2 into products to create AI-powered applications. Availability on Azure and AWS facilitates fine-tuning and adoption. However, restrictions apply to prevent exploitation. Companies with over 700 million active daily users cannot use Llama 2. Additionally, its output cannot be used to improve other language models. II. Llama 2 Model Flavors Llama 2 is available in four different model sizes: 7 billion, 13 billion, 34 billion, and 70 billion parameters. While 7B, 13B, and 70B have already been released, the 34B model is still awaited. The pretrained variant, trained on a whopping 2 trillion tokens, boasts a context window of 4096 tokens, twice the size of its predecessor Llama 1. Meta also released a Llama 2 fine-tuned model for chat applications that was trained on over 1 million human annotations. Such extensive training comes at a cost, with the 70B model taking a staggering 1720320 GPU hours to train. The context window's length determines the amount of content the model can process at once, making Llama 2 a powerful language model in terms of scale and efficiency. III. Safety Considerations: A Top Priority for Meta Meta's commitment to safety and alignment shines through in Llama 2's design. The model demonstrates exceptionally low AI safety violation percentages, surpassing even ChatGPT in safety benchmarks. Finding the right balance between helpfulness and safety when optimizing a model poses significant challenges. While a highly helpful model may be capable of answering any question, including sensitive ones like \"How do I build a bomb?\", it also raises concerns about potential misuse. Thus, striking the perfect equilibrium between providing useful information and ensuring safety is paramount. However, prioritizing safety to an extreme extent can lead to a model that struggles to effectively address a diverse range of questions. This limitation could hinder the model's practical applicability and user experience. Thus, achieving\n",
"Score\t 0.3215658817412662\n",
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# Evaluate"
],
"metadata": {
"id": "iMkpzH7vvb09"
}
},
{
"cell_type": "code",
"source": [
"from llama_index.evaluation import generate_question_context_pairs\n",
"from llama_index.llms import OpenAI\n",
"\n",
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
"rag_eval_dataset = generate_question_context_pairs(\n",
" nodes,\n",
" llm=llm,\n",
" num_questions_per_chunk=1\n",
")\n",
"\n",
"# We can save the dataset as a json file for later use.\n",
"rag_eval_dataset.save_json(\"./rag_eval_dataset_cohere.json\")"
],
"metadata": {
"id": "H8a3eKgKvckU",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "85b0765e-5a42-4f60-ccff-fc4bc688f65a"
},
"execution_count": 32,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"100%|██████████| 108/108 [05:13<00:00, 2.90s/it]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"from llama_index.finetuning.embeddings.common import (\n",
" EmbeddingQAFinetuneDataset,\n",
")\n",
"rag_eval_dataset = EmbeddingQAFinetuneDataset.from_json(\n",
" \"./rag_eval_dataset_cohere.json\"\n",
")"
],
"metadata": {
"id": "3sA1K84U254o"
},
"execution_count": 34,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import pandas as pd\n",
"\n",
"def display_results_retriever(name, eval_results):\n",
" \"\"\"Display results from evaluate.\"\"\"\n",
"\n",
" metric_dicts = []\n",
" for eval_result in eval_results:\n",
" metric_dict = eval_result.metric_vals_dict\n",
" metric_dicts.append(metric_dict)\n",
"\n",
" full_df = pd.DataFrame(metric_dicts)\n",
"\n",
" hit_rate = full_df[\"hit_rate\"].mean()\n",
" mrr = full_df[\"mrr\"].mean()\n",
"\n",
" metric_df = pd.DataFrame(\n",
" {\"Retriever Name\": [name], \"Hit Rate\": [hit_rate], \"MRR\": [mrr]}\n",
" )\n",
"\n",
" return metric_df"
],
"metadata": {
"id": "H7ubvcbk27vr"
},
"execution_count": 35,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from llama_index.evaluation import RetrieverEvaluator\n",
"\n",
"# We can evaluate the retievers with different top_k values.\n",
"for i in [2, 4, 6, 8, 10]:\n",
" retriever = index.as_retriever(similarity_top_k=i)\n",
" retriever_evaluator = RetrieverEvaluator.from_metric_names(\n",
" [\"mrr\", \"hit_rate\"], retriever=retriever\n",
" )\n",
" eval_results = await retriever_evaluator.aevaluate_dataset(rag_eval_dataset)\n",
" print(display_results_retriever(f\"Retriever top_{i}\", eval_results))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "uNLxDxoc2-Ac",
"outputId": "8a2df94d-99b5-4aa4-a31e-b6c94256d1bb"
},
"execution_count": 39,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" Retriever Name Hit Rate MRR\n",
"0 Retriever top_2 0.606557 0.510383\n",
" Retriever Name Hit Rate MRR\n",
"0 Retriever top_4 0.753005 0.554554\n",
" Retriever Name Hit Rate MRR\n",
"0 Retriever top_6 0.80765 0.564681\n",
" Retriever Name Hit Rate MRR\n",
"0 Retriever top_8 0.848087 0.570126\n",
" Retriever Name Hit Rate MRR\n",
"0 Retriever top_10 0.871038 0.572517\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"from llama_index.evaluation import RelevancyEvaluator, FaithfulnessEvaluator, BatchEvalRunner\n",
"from llama_index import ServiceContext\n",
"from llama_index.llms import OpenAI\n",
"\n",
"for i in [2, 4, 6, 8, 10]:\n",
" # Set Faithfulness and Relevancy evaluators\n",
" query_engine = index.as_query_engine(similarity_top_k=i)\n",
"\n",
" # While we use GPT3.5-Turbo to answer questions, we can use GPT4 to evaluate the answers.\n",
" llm_gpt4 = OpenAI(temperature=0, model=\"gpt-4-1106-preview\")\n",
" service_context_gpt4 = ServiceContext.from_defaults(llm=llm_gpt4)\n",
"\n",
" faithfulness_evaluator = FaithfulnessEvaluator(service_context=service_context_gpt4)\n",
" relevancy_evaluator = RelevancyEvaluator(service_context=service_context_gpt4)\n",
"\n",
" # Run evaluation\n",
" queries = list(rag_eval_dataset.queries.values())\n",
" batch_eval_queries = queries[:20]\n",
"\n",
" runner = BatchEvalRunner(\n",
" {\"faithfulness\": faithfulness_evaluator, \"relevancy\": relevancy_evaluator},\n",
" workers=8,\n",
" )\n",
" eval_results = await runner.aevaluate_queries(\n",
" query_engine, queries=batch_eval_queries\n",
" )\n",
" faithfulness_score = sum(result.passing for result in eval_results['faithfulness']) / len(eval_results['faithfulness'])\n",
" print(f\"top_{i} faithfulness_score: {faithfulness_score}\")\n",
"\n",
" relevancy_score = sum(result.passing for result in eval_results['faithfulness']) / len(eval_results['relevancy'])\n",
" print(f\"top_{i} relevancy_score: {relevancy_score}\")\n",
" print(\"-_\"*10)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "3ukkWC9R2_0J",
"outputId": "d177c25d-a163-4b71-97f4-2af468737bbb"
},
"execution_count": 40,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"top_2 faithfulness_score: 1.0\n",
"top_2 relevancy_score: 1.0\n",
"-_-_-_-_-_-_-_-_-_-_\n",
"top_4 faithfulness_score: 1.0\n",
"top_4 relevancy_score: 1.0\n",
"-_-_-_-_-_-_-_-_-_-_\n",
"top_6 faithfulness_score: 1.0\n",
"top_6 relevancy_score: 1.0\n",
"-_-_-_-_-_-_-_-_-_-_\n",
"top_8 faithfulness_score: 1.0\n",
"top_8 relevancy_score: 1.0\n",
"-_-_-_-_-_-_-_-_-_-_\n",
"top_10 faithfulness_score: 1.0\n",
"top_10 relevancy_score: 1.0\n",
"-_-_-_-_-_-_-_-_-_-_\n"
]
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "1MB1YD1E3EKM"
},
"execution_count": null,
"outputs": []
}
]
}