Spaces:
Sleeping
Sleeping
Omar Solano
commited on
Commit
β’
a4ba306
1
Parent(s):
4f23541
update gpt version
Browse files- notebooks/01-Basic_Tutor.ipynb +108 -128
- notebooks/02-Basic_RAG.ipynb +939 -939
- notebooks/04-RAG_with_VectorStore.ipynb +2 -2
- notebooks/05-Improve_Prompts_+_Add_Source.ipynb +1 -1
- notebooks/06-Evaluate_RAG.ipynb +29 -36
- notebooks/07-RAG_Improve_Chunking.ipynb +5 -5
- notebooks/08-Finetune_Embedding.ipynb +1 -1
- notebooks/09-Better_Embedding_Model.ipynb +3 -3
- notebooks/10-Adding_Reranking.ipynb +2 -2
- notebooks/11-Adding_Hybrid_Search.ipynb +2 -2
- notebooks/12-Improve_Query.ipynb +3 -3
- notebooks/13-Adding_Router.ipynb +3 -3
- notebooks/14-Adding_Chat.ipynb +2 -2
- notebooks/15-Use_OpenSource_Models.ipynb +1 -1
- notebooks/17-Using_LLMs_to_rank_chunks_as_the_Judge.ipynb +259 -259
- scripts/basic_tutor.py +1 -1
- scripts/call_openai.py +1 -1
- scripts/create_db.ipynb +2 -2
- scripts/gradio-ui.py +1 -1
notebooks/01-Basic_Tutor.ipynb
CHANGED
@@ -1,26 +1,10 @@
|
|
1 |
{
|
2 |
-
"nbformat": 4,
|
3 |
-
"nbformat_minor": 0,
|
4 |
-
"metadata": {
|
5 |
-
"colab": {
|
6 |
-
"provenance": [],
|
7 |
-
"authorship_tag": "ABX9TyOUuEM41HPKH6uCJFqocvSD",
|
8 |
-
"include_colab_link": true
|
9 |
-
},
|
10 |
-
"kernelspec": {
|
11 |
-
"name": "python3",
|
12 |
-
"display_name": "Python 3"
|
13 |
-
},
|
14 |
-
"language_info": {
|
15 |
-
"name": "python"
|
16 |
-
}
|
17 |
-
},
|
18 |
"cells": [
|
19 |
{
|
20 |
"cell_type": "markdown",
|
21 |
"metadata": {
|
22 |
-
"
|
23 |
-
"
|
24 |
},
|
25 |
"source": [
|
26 |
"<a href=\"https://colab.research.google.com/github/towardsai/ai-tutor-rag-system/blob/main/notebooks/01-Basic_Tutor.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
@@ -28,27 +12,27 @@
|
|
28 |
},
|
29 |
{
|
30 |
"cell_type": "markdown",
|
31 |
-
"source": [
|
32 |
-
"# Install Packages and Setup Variables"
|
33 |
-
],
|
34 |
"metadata": {
|
35 |
"id": "DMXyyXD0xix9"
|
36 |
-
}
|
|
|
|
|
|
|
37 |
},
|
38 |
{
|
39 |
"cell_type": "code",
|
40 |
"execution_count": null,
|
41 |
"metadata": {
|
42 |
-
"id": "o4Q0N2omkAoZ",
|
43 |
"colab": {
|
44 |
"base_uri": "https://localhost:8080/"
|
45 |
},
|
|
|
46 |
"outputId": "703fe996-2acf-4e90-92c1-252041ba7d7a"
|
47 |
},
|
48 |
"outputs": [
|
49 |
{
|
50 |
-
"output_type": "stream",
|
51 |
"name": "stdout",
|
|
|
52 |
"text": [
|
53 |
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m225.4/225.4 kB\u001b[0m \u001b[31m3.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
54 |
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m51.7/51.7 kB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
@@ -62,74 +46,79 @@
|
|
62 |
}
|
63 |
],
|
64 |
"source": [
|
65 |
-
"!pip install -q openai==1.
|
66 |
]
|
67 |
},
|
68 |
{
|
69 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
70 |
"source": [
|
71 |
"import os\n",
|
72 |
"\n",
|
73 |
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
|
74 |
"os.environ[\"OPENAI_API_KEY\"] = \"<YOUR_OPENAI_KEY>\""
|
75 |
-
]
|
76 |
-
"metadata": {
|
77 |
-
"id": "xxK7EAAvr2aT"
|
78 |
-
},
|
79 |
-
"execution_count": null,
|
80 |
-
"outputs": []
|
81 |
},
|
82 |
{
|
83 |
"cell_type": "markdown",
|
84 |
-
"source": [
|
85 |
-
"# Load the API client"
|
86 |
-
],
|
87 |
"metadata": {
|
88 |
"id": "68RbStS-xpbL"
|
89 |
-
}
|
|
|
|
|
|
|
90 |
},
|
91 |
{
|
92 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
93 |
"source": [
|
94 |
"from openai import OpenAI\n",
|
95 |
"\n",
|
96 |
"# Defining the \"client\" object that enables\n",
|
97 |
"# us to connect to OpenAI API endpoints.\n",
|
98 |
"client = OpenAI()"
|
99 |
-
]
|
100 |
-
"metadata": {
|
101 |
-
"id": "La8hdWqJkFkh"
|
102 |
-
},
|
103 |
-
"execution_count": null,
|
104 |
-
"outputs": []
|
105 |
},
|
106 |
{
|
107 |
"cell_type": "markdown",
|
108 |
-
"source": [
|
109 |
-
"# Query the API"
|
110 |
-
],
|
111 |
"metadata": {
|
112 |
"id": "CC-sa_uv6J2C"
|
113 |
-
}
|
|
|
|
|
|
|
114 |
},
|
115 |
{
|
116 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
117 |
"source": [
|
118 |
"# Define two questions: 1) Related to AI, 2) Unrelated topic.\n",
|
119 |
"# These questions will be used to evaluate model's performance.\n",
|
120 |
"QUESTION_AI = \"List a number of famous artificial intelligence frameworks?\"\n",
|
121 |
"QUESTION_NOT_AI = \"What is the name of the highest mountain in the world and its height?\""
|
122 |
-
]
|
123 |
-
"metadata": {
|
124 |
-
"id": "7JRrn0uIsBfg"
|
125 |
-
},
|
126 |
-
"execution_count": null,
|
127 |
-
"outputs": []
|
128 |
},
|
129 |
{
|
130 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
131 |
"source": [
|
132 |
-
"# Defining a function to answer a question using \"gpt-3.5-turbo
|
133 |
"def ask_ai_tutor(question):\n",
|
134 |
" try:\n",
|
135 |
" # Formulating the system prompt and condition the model to answer only AI-related questions.\n",
|
@@ -143,8 +132,8 @@
|
|
143 |
"\n",
|
144 |
" # Call the OpenAI API\n",
|
145 |
" response = client.chat.completions.create(\n",
|
146 |
-
" model='gpt-3.5-turbo
|
147 |
-
" temperature=
|
148 |
" messages=[\n",
|
149 |
" {\"role\": \"system\", \"content\": system_prompt},\n",
|
150 |
" {\"role\": \"user\", \"content\": prompt}\n",
|
@@ -156,20 +145,11 @@
|
|
156 |
"\n",
|
157 |
" except Exception as e:\n",
|
158 |
" return f\"An error occurred: {e}\""
|
159 |
-
]
|
160 |
-
"metadata": {
|
161 |
-
"id": "CcP26IauuBuV"
|
162 |
-
},
|
163 |
-
"execution_count": null,
|
164 |
-
"outputs": []
|
165 |
},
|
166 |
{
|
167 |
"cell_type": "code",
|
168 |
-
"
|
169 |
-
"# Ask the AI-related question.\n",
|
170 |
-
"RES_AI = ask_ai_tutor( QUESTION_AI )\n",
|
171 |
-
"print( RES_AI )"
|
172 |
-
],
|
173 |
"metadata": {
|
174 |
"colab": {
|
175 |
"base_uri": "https://localhost:8080/"
|
@@ -177,36 +157,24 @@
|
|
177 |
"id": "W_dbwURpufR7",
|
178 |
"outputId": "3cd84fb9-fe6f-4561-e9ee-ed606a983629"
|
179 |
},
|
180 |
-
"execution_count": null,
|
181 |
"outputs": [
|
182 |
{
|
183 |
-
"output_type": "stream",
|
184 |
"name": "stdout",
|
|
|
185 |
"text": [
|
186 |
-
"
|
187 |
-
"\n",
|
188 |
-
"1. TensorFlow: Developed by Google, TensorFlow is an open-source framework that is widely used for machine learning and deep learning tasks. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying AI models.\n",
|
189 |
-
"\n",
|
190 |
-
"2. PyTorch: Developed by Facebook's AI Research lab, PyTorch is another popular open-source framework for deep learning. It is known for its dynamic computational graph, which allows for more flexibility and ease of use compared to other frameworks.\n",
|
191 |
-
"\n",
|
192 |
-
"3. Keras: Keras is a high-level neural networks API written in Python. It is built on top of TensorFlow and provides a user-friendly interface for building and training deep learning models. Keras is known for its simplicity and ease of use, making it a popular choice for beginners.\n",
|
193 |
-
"\n",
|
194 |
-
"4. Caffe: Caffe is a deep learning framework developed by Berkeley AI Research (BAIR). It is known for its speed and efficiency, particularly for convolutional neural networks (CNNs). Caffe has been widely used in computer vision tasks and has a large community of users and contributors.\n",
|
195 |
-
"\n",
|
196 |
-
"5. Theano: Theano is a Python library that allows for efficient mathematical computations, particularly for deep learning tasks. It provides a high-level interface for defining and optimizing mathematical expressions, making it a popular choice for researchers and developers.\n",
|
197 |
-
"\n",
|
198 |
-
"These are just a few examples of famous AI frameworks, and there are many others available depending on specific needs and preferences.\n"
|
199 |
]
|
200 |
}
|
|
|
|
|
|
|
|
|
|
|
201 |
]
|
202 |
},
|
203 |
{
|
204 |
"cell_type": "code",
|
205 |
-
"
|
206 |
-
"# Ask the unrelated question.\n",
|
207 |
-
"RES_NOT_AI = ask_ai_tutor( QUESTION_NOT_AI )\n",
|
208 |
-
"print( RES_NOT_AI )"
|
209 |
-
],
|
210 |
"metadata": {
|
211 |
"colab": {
|
212 |
"base_uri": "https://localhost:8080/"
|
@@ -214,44 +182,33 @@
|
|
214 |
"id": "37YuVJQquhpN",
|
215 |
"outputId": "4550c44d-2150-4cca-f23e-c89ea43e2040"
|
216 |
},
|
217 |
-
"execution_count": null,
|
218 |
"outputs": [
|
219 |
{
|
220 |
-
"output_type": "stream",
|
221 |
"name": "stdout",
|
|
|
222 |
"text": [
|
223 |
-
"I'm sorry, but I cannot answer
|
224 |
]
|
225 |
}
|
|
|
|
|
|
|
|
|
|
|
226 |
]
|
227 |
},
|
228 |
{
|
229 |
"cell_type": "markdown",
|
230 |
-
"source": [
|
231 |
-
"# History"
|
232 |
-
],
|
233 |
"metadata": {
|
234 |
"id": "NRBgk6WToIK0"
|
235 |
-
}
|
|
|
|
|
|
|
236 |
},
|
237 |
{
|
238 |
"cell_type": "code",
|
239 |
-
"
|
240 |
-
"response = client.chat.completions.create(\n",
|
241 |
-
" model='gpt-3.5-turbo-16k',\n",
|
242 |
-
" temperature=0.0,\n",
|
243 |
-
" messages=[\n",
|
244 |
-
" {\"role\": \"system\", \"content\": \"You are an AI tutor specialized in answering artificial intelligence-related questions. Only answer AI-related question, else say that you cannot answer this question.\"},\n",
|
245 |
-
" {\"role\": \"user\", \"content\": \"Please provide an informative and accurate answer to the following question.\\nQuestion: List a number of famous artificial intelligence frameworks?\\nAnswer:\"},\n",
|
246 |
-
" {\"role\": \"assistant\", \"content\": RES_AI},\n",
|
247 |
-
" {\"role\": \"user\", \"content\": \"Please provide an informative and accurate answer to the following question.\\nQuestion: What is the name of the highest mountain in the world and its height?\\nAnswer:\"},\n",
|
248 |
-
" {\"role\": \"assistant\", \"content\": RES_NOT_AI},\n",
|
249 |
-
" {\"role\": \"user\", \"content\": \"Please provide an informative and accurate answer to the following question.\\nQuestion: Can you write a summary of the first suggested AI framework in the first question?\\nAnswer:\"}\n",
|
250 |
-
" ]\n",
|
251 |
-
" )\n",
|
252 |
-
"\n",
|
253 |
-
"print( response.choices[0].message.content.strip() )"
|
254 |
-
],
|
255 |
"metadata": {
|
256 |
"colab": {
|
257 |
"base_uri": "https://localhost:8080/"
|
@@ -259,33 +216,56 @@
|
|
259 |
"id": "0_6GN2XsoEyM",
|
260 |
"outputId": "3e66a833-a552-4bcc-9808-7b9f6b539310"
|
261 |
},
|
262 |
-
"execution_count": null,
|
263 |
"outputs": [
|
264 |
{
|
265 |
-
"output_type": "stream",
|
266 |
"name": "stdout",
|
|
|
267 |
"text": [
|
268 |
-
"
|
269 |
-
"\n",
|
270 |
-
"TensorFlow provides a comprehensive ecosystem of tools, libraries, and resources that make it easier for developers to create and deploy AI models. It offers a flexible architecture that allows for efficient computation on both CPUs and GPUs, enabling faster training and inference.\n",
|
271 |
-
"\n",
|
272 |
-
"One of the key features of TensorFlow is its ability to construct and execute computational graphs. These graphs represent the flow of data through a series of mathematical operations, making it easier to visualize and understand the model's structure. TensorFlow also supports automatic differentiation, which simplifies the process of calculating gradients for training neural networks.\n",
|
273 |
-
"\n",
|
274 |
-
"Moreover, TensorFlow has a vast community of users and contributors, which means there is extensive documentation, tutorials, and pre-trained models available. This makes it easier for developers to get started and leverage the collective knowledge of the community.\n",
|
275 |
-
"\n",
|
276 |
-
"Overall, TensorFlow is a powerful and versatile AI framework that has been widely adopted in various domains, including computer vision, natural language processing, and reinforcement learning. Its flexibility, scalability, and extensive community support make it a popular choice for both researchers and practitioners in the field of artificial intelligence.\n"
|
277 |
]
|
278 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
},
|
281 |
-
{
|
282 |
-
"
|
283 |
-
"
|
284 |
-
|
285 |
-
|
|
|
|
|
|
|
286 |
},
|
287 |
-
"
|
288 |
-
"
|
|
|
|
|
|
|
|
|
289 |
}
|
290 |
-
|
291 |
-
|
|
|
|
|
|
1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "markdown",
|
5 |
"metadata": {
|
6 |
+
"colab_type": "text",
|
7 |
+
"id": "view-in-github"
|
8 |
},
|
9 |
"source": [
|
10 |
"<a href=\"https://colab.research.google.com/github/towardsai/ai-tutor-rag-system/blob/main/notebooks/01-Basic_Tutor.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "markdown",
|
|
|
|
|
|
|
15 |
"metadata": {
|
16 |
"id": "DMXyyXD0xix9"
|
17 |
+
},
|
18 |
+
"source": [
|
19 |
+
"# Install Packages and Setup Variables"
|
20 |
+
]
|
21 |
},
|
22 |
{
|
23 |
"cell_type": "code",
|
24 |
"execution_count": null,
|
25 |
"metadata": {
|
|
|
26 |
"colab": {
|
27 |
"base_uri": "https://localhost:8080/"
|
28 |
},
|
29 |
+
"id": "o4Q0N2omkAoZ",
|
30 |
"outputId": "703fe996-2acf-4e90-92c1-252041ba7d7a"
|
31 |
},
|
32 |
"outputs": [
|
33 |
{
|
|
|
34 |
"name": "stdout",
|
35 |
+
"output_type": "stream",
|
36 |
"text": [
|
37 |
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m225.4/225.4 kB\u001b[0m \u001b[31m3.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
38 |
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m51.7/51.7 kB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
|
|
46 |
}
|
47 |
],
|
48 |
"source": [
|
49 |
+
"!pip install -q openai==1.30.1"
|
50 |
]
|
51 |
},
|
52 |
{
|
53 |
"cell_type": "code",
|
54 |
+
"execution_count": 1,
|
55 |
+
"metadata": {
|
56 |
+
"id": "xxK7EAAvr2aT"
|
57 |
+
},
|
58 |
+
"outputs": [],
|
59 |
"source": [
|
60 |
"import os\n",
|
61 |
"\n",
|
62 |
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
|
63 |
"os.environ[\"OPENAI_API_KEY\"] = \"<YOUR_OPENAI_KEY>\""
|
64 |
+
]
|
|
|
|
|
|
|
|
|
|
|
65 |
},
|
66 |
{
|
67 |
"cell_type": "markdown",
|
|
|
|
|
|
|
68 |
"metadata": {
|
69 |
"id": "68RbStS-xpbL"
|
70 |
+
},
|
71 |
+
"source": [
|
72 |
+
"# Load the API client"
|
73 |
+
]
|
74 |
},
|
75 |
{
|
76 |
"cell_type": "code",
|
77 |
+
"execution_count": 2,
|
78 |
+
"metadata": {
|
79 |
+
"id": "La8hdWqJkFkh"
|
80 |
+
},
|
81 |
+
"outputs": [],
|
82 |
"source": [
|
83 |
"from openai import OpenAI\n",
|
84 |
"\n",
|
85 |
"# Defining the \"client\" object that enables\n",
|
86 |
"# us to connect to OpenAI API endpoints.\n",
|
87 |
"client = OpenAI()"
|
88 |
+
]
|
|
|
|
|
|
|
|
|
|
|
89 |
},
|
90 |
{
|
91 |
"cell_type": "markdown",
|
|
|
|
|
|
|
92 |
"metadata": {
|
93 |
"id": "CC-sa_uv6J2C"
|
94 |
+
},
|
95 |
+
"source": [
|
96 |
+
"# Query the API"
|
97 |
+
]
|
98 |
},
|
99 |
{
|
100 |
"cell_type": "code",
|
101 |
+
"execution_count": 3,
|
102 |
+
"metadata": {
|
103 |
+
"id": "7JRrn0uIsBfg"
|
104 |
+
},
|
105 |
+
"outputs": [],
|
106 |
"source": [
|
107 |
"# Define two questions: 1) Related to AI, 2) Unrelated topic.\n",
|
108 |
"# These questions will be used to evaluate model's performance.\n",
|
109 |
"QUESTION_AI = \"List a number of famous artificial intelligence frameworks?\"\n",
|
110 |
"QUESTION_NOT_AI = \"What is the name of the highest mountain in the world and its height?\""
|
111 |
+
]
|
|
|
|
|
|
|
|
|
|
|
112 |
},
|
113 |
{
|
114 |
"cell_type": "code",
|
115 |
+
"execution_count": 4,
|
116 |
+
"metadata": {
|
117 |
+
"id": "CcP26IauuBuV"
|
118 |
+
},
|
119 |
+
"outputs": [],
|
120 |
"source": [
|
121 |
+
"# Defining a function to answer a question using \"gpt-3.5-turbo\" model.\n",
|
122 |
"def ask_ai_tutor(question):\n",
|
123 |
" try:\n",
|
124 |
" # Formulating the system prompt and condition the model to answer only AI-related questions.\n",
|
|
|
132 |
"\n",
|
133 |
" # Call the OpenAI API\n",
|
134 |
" response = client.chat.completions.create(\n",
|
135 |
+
" model='gpt-3.5-turbo',\n",
|
136 |
+
" temperature=1,\n",
|
137 |
" messages=[\n",
|
138 |
" {\"role\": \"system\", \"content\": system_prompt},\n",
|
139 |
" {\"role\": \"user\", \"content\": prompt}\n",
|
|
|
145 |
"\n",
|
146 |
" except Exception as e:\n",
|
147 |
" return f\"An error occurred: {e}\""
|
148 |
+
]
|
|
|
|
|
|
|
|
|
|
|
149 |
},
|
150 |
{
|
151 |
"cell_type": "code",
|
152 |
+
"execution_count": 5,
|
|
|
|
|
|
|
|
|
153 |
"metadata": {
|
154 |
"colab": {
|
155 |
"base_uri": "https://localhost:8080/"
|
|
|
157 |
"id": "W_dbwURpufR7",
|
158 |
"outputId": "3cd84fb9-fe6f-4561-e9ee-ed606a983629"
|
159 |
},
|
|
|
160 |
"outputs": [
|
161 |
{
|
|
|
162 |
"name": "stdout",
|
163 |
+
"output_type": "stream",
|
164 |
"text": [
|
165 |
+
"Some famous artificial intelligence frameworks include TensorFlow, PyTorch, Keras, Microsoft Cognitive Toolkit (CNTK), and Apache MXNet.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
]
|
167 |
}
|
168 |
+
],
|
169 |
+
"source": [
|
170 |
+
"# Ask the AI-related question.\n",
|
171 |
+
"RES_AI = ask_ai_tutor( QUESTION_AI )\n",
|
172 |
+
"print( RES_AI )"
|
173 |
]
|
174 |
},
|
175 |
{
|
176 |
"cell_type": "code",
|
177 |
+
"execution_count": 6,
|
|
|
|
|
|
|
|
|
178 |
"metadata": {
|
179 |
"colab": {
|
180 |
"base_uri": "https://localhost:8080/"
|
|
|
182 |
"id": "37YuVJQquhpN",
|
183 |
"outputId": "4550c44d-2150-4cca-f23e-c89ea43e2040"
|
184 |
},
|
|
|
185 |
"outputs": [
|
186 |
{
|
|
|
187 |
"name": "stdout",
|
188 |
+
"output_type": "stream",
|
189 |
"text": [
|
190 |
+
"I'm sorry, but I cannot answer this question as it is not related to artificial intelligence. If you have any AI-related questions, feel free to ask!\n"
|
191 |
]
|
192 |
}
|
193 |
+
],
|
194 |
+
"source": [
|
195 |
+
"# Ask the unrelated question.\n",
|
196 |
+
"RES_NOT_AI = ask_ai_tutor( QUESTION_NOT_AI )\n",
|
197 |
+
"print( RES_NOT_AI )"
|
198 |
]
|
199 |
},
|
200 |
{
|
201 |
"cell_type": "markdown",
|
|
|
|
|
|
|
202 |
"metadata": {
|
203 |
"id": "NRBgk6WToIK0"
|
204 |
+
},
|
205 |
+
"source": [
|
206 |
+
"# History"
|
207 |
+
]
|
208 |
},
|
209 |
{
|
210 |
"cell_type": "code",
|
211 |
+
"execution_count": 7,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
"metadata": {
|
213 |
"colab": {
|
214 |
"base_uri": "https://localhost:8080/"
|
|
|
216 |
"id": "0_6GN2XsoEyM",
|
217 |
"outputId": "3e66a833-a552-4bcc-9808-7b9f6b539310"
|
218 |
},
|
|
|
219 |
"outputs": [
|
220 |
{
|
|
|
221 |
"name": "stdout",
|
222 |
+
"output_type": "stream",
|
223 |
"text": [
|
224 |
+
"The first suggested AI framework in the list provided earlier is TensorFlow. TensorFlow is an open-source machine learning library developed by Google that has become popular for its flexibility, scalability, and extensive support for deep learning algorithms. It allows users to build and train machine learning models efficiently, with various tools and resources available to aid in the development process. TensorFlow is widely used in research and industry for tasks such as image recognition, natural language processing, and reinforcement learning.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
]
|
226 |
}
|
227 |
+
],
|
228 |
+
"source": [
|
229 |
+
"response = client.chat.completions.create(\n",
|
230 |
+
" model='gpt-3.5-turbo',\n",
|
231 |
+
" temperature=1,\n",
|
232 |
+
" messages=[\n",
|
233 |
+
" {\"role\": \"system\", \"content\": \"You are an AI tutor specialized in answering artificial intelligence-related questions. Only answer AI-related question, else say that you cannot answer this question.\"},\n",
|
234 |
+
" {\"role\": \"user\", \"content\": \"Please provide an informative and accurate answer to the following question.\\nQuestion: List a number of famous artificial intelligence frameworks?\\nAnswer:\"},\n",
|
235 |
+
" {\"role\": \"assistant\", \"content\": RES_AI},\n",
|
236 |
+
" {\"role\": \"user\", \"content\": \"Please provide an informative and accurate answer to the following question.\\nQuestion: What is the name of the highest mountain in the world and its height?\\nAnswer:\"},\n",
|
237 |
+
" {\"role\": \"assistant\", \"content\": RES_NOT_AI},\n",
|
238 |
+
" {\"role\": \"user\", \"content\": \"Please provide an informative and accurate answer to the following question.\\nQuestion: Can you write a summary of the first suggested AI framework in the first question?\\nAnswer:\"}\n",
|
239 |
+
" ]\n",
|
240 |
+
" )\n",
|
241 |
+
"\n",
|
242 |
+
"print( response.choices[0].message.content.strip() )"
|
243 |
]
|
244 |
+
}
|
245 |
+
],
|
246 |
+
"metadata": {
|
247 |
+
"colab": {
|
248 |
+
"authorship_tag": "ABX9TyOUuEM41HPKH6uCJFqocvSD",
|
249 |
+
"include_colab_link": true,
|
250 |
+
"provenance": []
|
251 |
},
|
252 |
+
"kernelspec": {
|
253 |
+
"display_name": "Python 3",
|
254 |
+
"name": "python3"
|
255 |
+
},
|
256 |
+
"language_info": {
|
257 |
+
"codemirror_mode": {
|
258 |
+
"name": "ipython",
|
259 |
+
"version": 3
|
260 |
},
|
261 |
+
"file_extension": ".py",
|
262 |
+
"mimetype": "text/x-python",
|
263 |
+
"name": "python",
|
264 |
+
"nbconvert_exporter": "python",
|
265 |
+
"pygments_lexer": "ipython3",
|
266 |
+
"version": "3.11.8"
|
267 |
}
|
268 |
+
},
|
269 |
+
"nbformat": 4,
|
270 |
+
"nbformat_minor": 0
|
271 |
+
}
|
notebooks/02-Basic_RAG.ipynb
CHANGED
@@ -1,1083 +1,1083 @@
|
|
1 |
{
|
2 |
-
"
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
9 |
},
|
10 |
-
|
11 |
-
"
|
12 |
-
"
|
|
|
|
|
|
|
|
|
|
|
13 |
},
|
14 |
-
|
15 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
},
|
17 |
-
|
18 |
-
"
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
},
|
41 |
-
"
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
"
|
50 |
-
"
|
51 |
-
"
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
},
|
62 |
-
"
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
"
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
"bar_style": "success",
|
76 |
-
"description": "",
|
77 |
-
"description_tooltip": null,
|
78 |
-
"layout": "IPY_MODEL_c4ceff5437e0470089c161e21488d2a7",
|
79 |
-
"max": 1,
|
80 |
-
"min": 0,
|
81 |
-
"orientation": "horizontal",
|
82 |
-
"style": "IPY_MODEL_6aafd52b0e3e4e0183b1666ad1e8a448",
|
83 |
-
"value": 1
|
84 |
-
}
|
85 |
-
},
|
86 |
-
"a4a232c5b5e1493897e9acdd25b8efd4": {
|
87 |
-
"model_module": "@jupyter-widgets/controls",
|
88 |
-
"model_name": "HTMLModel",
|
89 |
-
"model_module_version": "1.5.0",
|
90 |
-
"state": {
|
91 |
-
"_dom_classes": [],
|
92 |
-
"_model_module": "@jupyter-widgets/controls",
|
93 |
-
"_model_module_version": "1.5.0",
|
94 |
-
"_model_name": "HTMLModel",
|
95 |
-
"_view_count": null,
|
96 |
-
"_view_module": "@jupyter-widgets/controls",
|
97 |
-
"_view_module_version": "1.5.0",
|
98 |
-
"_view_name": "HTMLView",
|
99 |
-
"description": "",
|
100 |
-
"description_tooltip": null,
|
101 |
-
"layout": "IPY_MODEL_80137fc11d4b4e518d8c8957ca5461b1",
|
102 |
-
"placeholder": "β",
|
103 |
-
"style": "IPY_MODEL_c4236d507b354bff830620a8bde32191",
|
104 |
-
"value": "β174/?β[00:31<00:00,ββ6.30it/s]"
|
105 |
-
}
|
106 |
-
},
|
107 |
-
"b2e91819e1c94f28b7bbad66918cb797": {
|
108 |
-
"model_module": "@jupyter-widgets/base",
|
109 |
-
"model_name": "LayoutModel",
|
110 |
-
"model_module_version": "1.2.0",
|
111 |
-
"state": {
|
112 |
-
"_model_module": "@jupyter-widgets/base",
|
113 |
-
"_model_module_version": "1.2.0",
|
114 |
-
"_model_name": "LayoutModel",
|
115 |
-
"_view_count": null,
|
116 |
-
"_view_module": "@jupyter-widgets/base",
|
117 |
-
"_view_module_version": "1.2.0",
|
118 |
-
"_view_name": "LayoutView",
|
119 |
-
"align_content": null,
|
120 |
-
"align_items": null,
|
121 |
-
"align_self": null,
|
122 |
-
"border": null,
|
123 |
-
"bottom": null,
|
124 |
-
"display": null,
|
125 |
-
"flex": null,
|
126 |
-
"flex_flow": null,
|
127 |
-
"grid_area": null,
|
128 |
-
"grid_auto_columns": null,
|
129 |
-
"grid_auto_flow": null,
|
130 |
-
"grid_auto_rows": null,
|
131 |
-
"grid_column": null,
|
132 |
-
"grid_gap": null,
|
133 |
-
"grid_row": null,
|
134 |
-
"grid_template_areas": null,
|
135 |
-
"grid_template_columns": null,
|
136 |
-
"grid_template_rows": null,
|
137 |
-
"height": null,
|
138 |
-
"justify_content": null,
|
139 |
-
"justify_items": null,
|
140 |
-
"left": null,
|
141 |
-
"margin": null,
|
142 |
-
"max_height": null,
|
143 |
-
"max_width": null,
|
144 |
-
"min_height": null,
|
145 |
-
"min_width": null,
|
146 |
-
"object_fit": null,
|
147 |
-
"object_position": null,
|
148 |
-
"order": null,
|
149 |
-
"overflow": null,
|
150 |
-
"overflow_x": null,
|
151 |
-
"overflow_y": null,
|
152 |
-
"padding": null,
|
153 |
-
"right": null,
|
154 |
-
"top": null,
|
155 |
-
"visibility": null,
|
156 |
-
"width": null
|
157 |
-
}
|
158 |
-
},
|
159 |
-
"010cbcb0f1364576b15f792f4d11f605": {
|
160 |
-
"model_module": "@jupyter-widgets/base",
|
161 |
-
"model_name": "LayoutModel",
|
162 |
-
"model_module_version": "1.2.0",
|
163 |
-
"state": {
|
164 |
-
"_model_module": "@jupyter-widgets/base",
|
165 |
-
"_model_module_version": "1.2.0",
|
166 |
-
"_model_name": "LayoutModel",
|
167 |
-
"_view_count": null,
|
168 |
-
"_view_module": "@jupyter-widgets/base",
|
169 |
-
"_view_module_version": "1.2.0",
|
170 |
-
"_view_name": "LayoutView",
|
171 |
-
"align_content": null,
|
172 |
-
"align_items": null,
|
173 |
-
"align_self": null,
|
174 |
-
"border": null,
|
175 |
-
"bottom": null,
|
176 |
-
"display": null,
|
177 |
-
"flex": null,
|
178 |
-
"flex_flow": null,
|
179 |
-
"grid_area": null,
|
180 |
-
"grid_auto_columns": null,
|
181 |
-
"grid_auto_flow": null,
|
182 |
-
"grid_auto_rows": null,
|
183 |
-
"grid_column": null,
|
184 |
-
"grid_gap": null,
|
185 |
-
"grid_row": null,
|
186 |
-
"grid_template_areas": null,
|
187 |
-
"grid_template_columns": null,
|
188 |
-
"grid_template_rows": null,
|
189 |
-
"height": null,
|
190 |
-
"justify_content": null,
|
191 |
-
"justify_items": null,
|
192 |
-
"left": null,
|
193 |
-
"margin": null,
|
194 |
-
"max_height": null,
|
195 |
-
"max_width": null,
|
196 |
-
"min_height": null,
|
197 |
-
"min_width": null,
|
198 |
-
"object_fit": null,
|
199 |
-
"object_position": null,
|
200 |
-
"order": null,
|
201 |
-
"overflow": null,
|
202 |
-
"overflow_x": null,
|
203 |
-
"overflow_y": null,
|
204 |
-
"padding": null,
|
205 |
-
"right": null,
|
206 |
-
"top": null,
|
207 |
-
"visibility": null,
|
208 |
-
"width": null
|
209 |
-
}
|
210 |
-
},
|
211 |
-
"f51d5da0f39e4c1885357d3d4c9964d9": {
|
212 |
-
"model_module": "@jupyter-widgets/controls",
|
213 |
-
"model_name": "DescriptionStyleModel",
|
214 |
-
"model_module_version": "1.5.0",
|
215 |
-
"state": {
|
216 |
-
"_model_module": "@jupyter-widgets/controls",
|
217 |
-
"_model_module_version": "1.5.0",
|
218 |
-
"_model_name": "DescriptionStyleModel",
|
219 |
-
"_view_count": null,
|
220 |
-
"_view_module": "@jupyter-widgets/base",
|
221 |
-
"_view_module_version": "1.2.0",
|
222 |
-
"_view_name": "StyleView",
|
223 |
-
"description_width": ""
|
224 |
-
}
|
225 |
-
},
|
226 |
-
"c4ceff5437e0470089c161e21488d2a7": {
|
227 |
-
"model_module": "@jupyter-widgets/base",
|
228 |
-
"model_name": "LayoutModel",
|
229 |
-
"model_module_version": "1.2.0",
|
230 |
-
"state": {
|
231 |
-
"_model_module": "@jupyter-widgets/base",
|
232 |
-
"_model_module_version": "1.2.0",
|
233 |
-
"_model_name": "LayoutModel",
|
234 |
-
"_view_count": null,
|
235 |
-
"_view_module": "@jupyter-widgets/base",
|
236 |
-
"_view_module_version": "1.2.0",
|
237 |
-
"_view_name": "LayoutView",
|
238 |
-
"align_content": null,
|
239 |
-
"align_items": null,
|
240 |
-
"align_self": null,
|
241 |
-
"border": null,
|
242 |
-
"bottom": null,
|
243 |
-
"display": null,
|
244 |
-
"flex": null,
|
245 |
-
"flex_flow": null,
|
246 |
-
"grid_area": null,
|
247 |
-
"grid_auto_columns": null,
|
248 |
-
"grid_auto_flow": null,
|
249 |
-
"grid_auto_rows": null,
|
250 |
-
"grid_column": null,
|
251 |
-
"grid_gap": null,
|
252 |
-
"grid_row": null,
|
253 |
-
"grid_template_areas": null,
|
254 |
-
"grid_template_columns": null,
|
255 |
-
"grid_template_rows": null,
|
256 |
-
"height": null,
|
257 |
-
"justify_content": null,
|
258 |
-
"justify_items": null,
|
259 |
-
"left": null,
|
260 |
-
"margin": null,
|
261 |
-
"max_height": null,
|
262 |
-
"max_width": null,
|
263 |
-
"min_height": null,
|
264 |
-
"min_width": null,
|
265 |
-
"object_fit": null,
|
266 |
-
"object_position": null,
|
267 |
-
"order": null,
|
268 |
-
"overflow": null,
|
269 |
-
"overflow_x": null,
|
270 |
-
"overflow_y": null,
|
271 |
-
"padding": null,
|
272 |
-
"right": null,
|
273 |
-
"top": null,
|
274 |
-
"visibility": null,
|
275 |
-
"width": "20px"
|
276 |
-
}
|
277 |
-
},
|
278 |
-
"6aafd52b0e3e4e0183b1666ad1e8a448": {
|
279 |
-
"model_module": "@jupyter-widgets/controls",
|
280 |
-
"model_name": "ProgressStyleModel",
|
281 |
-
"model_module_version": "1.5.0",
|
282 |
-
"state": {
|
283 |
-
"_model_module": "@jupyter-widgets/controls",
|
284 |
-
"_model_module_version": "1.5.0",
|
285 |
-
"_model_name": "ProgressStyleModel",
|
286 |
-
"_view_count": null,
|
287 |
-
"_view_module": "@jupyter-widgets/base",
|
288 |
-
"_view_module_version": "1.2.0",
|
289 |
-
"_view_name": "StyleView",
|
290 |
-
"bar_color": null,
|
291 |
-
"description_width": ""
|
292 |
-
}
|
293 |
-
},
|
294 |
-
"80137fc11d4b4e518d8c8957ca5461b1": {
|
295 |
-
"model_module": "@jupyter-widgets/base",
|
296 |
-
"model_name": "LayoutModel",
|
297 |
-
"model_module_version": "1.2.0",
|
298 |
-
"state": {
|
299 |
-
"_model_module": "@jupyter-widgets/base",
|
300 |
-
"_model_module_version": "1.2.0",
|
301 |
-
"_model_name": "LayoutModel",
|
302 |
-
"_view_count": null,
|
303 |
-
"_view_module": "@jupyter-widgets/base",
|
304 |
-
"_view_module_version": "1.2.0",
|
305 |
-
"_view_name": "LayoutView",
|
306 |
-
"align_content": null,
|
307 |
-
"align_items": null,
|
308 |
-
"align_self": null,
|
309 |
-
"border": null,
|
310 |
-
"bottom": null,
|
311 |
-
"display": null,
|
312 |
-
"flex": null,
|
313 |
-
"flex_flow": null,
|
314 |
-
"grid_area": null,
|
315 |
-
"grid_auto_columns": null,
|
316 |
-
"grid_auto_flow": null,
|
317 |
-
"grid_auto_rows": null,
|
318 |
-
"grid_column": null,
|
319 |
-
"grid_gap": null,
|
320 |
-
"grid_row": null,
|
321 |
-
"grid_template_areas": null,
|
322 |
-
"grid_template_columns": null,
|
323 |
-
"grid_template_rows": null,
|
324 |
-
"height": null,
|
325 |
-
"justify_content": null,
|
326 |
-
"justify_items": null,
|
327 |
-
"left": null,
|
328 |
-
"margin": null,
|
329 |
-
"max_height": null,
|
330 |
-
"max_width": null,
|
331 |
-
"min_height": null,
|
332 |
-
"min_width": null,
|
333 |
-
"object_fit": null,
|
334 |
-
"object_position": null,
|
335 |
-
"order": null,
|
336 |
-
"overflow": null,
|
337 |
-
"overflow_x": null,
|
338 |
-
"overflow_y": null,
|
339 |
-
"padding": null,
|
340 |
-
"right": null,
|
341 |
-
"top": null,
|
342 |
-
"visibility": null,
|
343 |
-
"width": null
|
344 |
-
}
|
345 |
-
},
|
346 |
-
"c4236d507b354bff830620a8bde32191": {
|
347 |
-
"model_module": "@jupyter-widgets/controls",
|
348 |
-
"model_name": "DescriptionStyleModel",
|
349 |
-
"model_module_version": "1.5.0",
|
350 |
-
"state": {
|
351 |
-
"_model_module": "@jupyter-widgets/controls",
|
352 |
-
"_model_module_version": "1.5.0",
|
353 |
-
"_model_name": "DescriptionStyleModel",
|
354 |
-
"_view_count": null,
|
355 |
-
"_view_module": "@jupyter-widgets/base",
|
356 |
-
"_view_module_version": "1.2.0",
|
357 |
-
"_view_name": "StyleView",
|
358 |
-
"description_width": ""
|
359 |
-
}
|
360 |
}
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
{
|
366 |
"cell_type": "markdown",
|
367 |
"metadata": {
|
368 |
-
"id": "
|
369 |
-
"colab_type": "text"
|
370 |
},
|
371 |
"source": [
|
372 |
-
"
|
373 |
]
|
374 |
},
|
375 |
{
|
376 |
-
"cell_type": "
|
377 |
-
"
|
378 |
-
"# Install Packages and Setup Variables"
|
379 |
-
],
|
380 |
"metadata": {
|
381 |
-
"id": "
|
382 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
},
|
384 |
{
|
385 |
"cell_type": "code",
|
386 |
"execution_count": null,
|
387 |
"metadata": {
|
388 |
"colab": {
|
389 |
-
"base_uri": "https://localhost:8080/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
},
|
391 |
-
"id": "
|
392 |
-
"outputId": "
|
393 |
},
|
394 |
"outputs": [
|
395 |
{
|
396 |
-
"output_type": "stream",
|
397 |
"name": "stdout",
|
|
|
398 |
"text": [
|
399 |
-
"
|
400 |
-
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m51.7/51.7 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
401 |
-
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m17.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
402 |
-
"\u001b[2K \u001b[90mββββββββββββββοΏ½οΏ½βββββββββββββββββββββββββ\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
403 |
-
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m3.1/3.1 MB\u001b[0m \u001b[31m17.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
404 |
-
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m77.8/77.8 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
405 |
-
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
406 |
-
"\u001b[?25h"
|
407 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
408 |
}
|
409 |
],
|
410 |
"source": [
|
411 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
]
|
413 |
},
|
414 |
{
|
415 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
416 |
"source": [
|
417 |
-
"
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
"metadata": {
|
423 |
-
"id": "
|
424 |
},
|
425 |
-
"
|
426 |
-
|
|
|
427 |
},
|
428 |
{
|
429 |
"cell_type": "code",
|
430 |
-
"
|
431 |
-
|
432 |
-
"
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
"metadata": {
|
436 |
-
"id": "
|
437 |
},
|
438 |
-
"
|
439 |
-
|
|
|
440 |
},
|
441 |
{
|
442 |
"cell_type": "markdown",
|
|
|
|
|
|
|
443 |
"source": [
|
444 |
-
"
|
445 |
-
]
|
|
|
|
|
|
|
|
|
446 |
"metadata": {
|
447 |
-
"id": "
|
448 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
},
|
450 |
{
|
451 |
"cell_type": "markdown",
|
|
|
|
|
|
|
452 |
"source": [
|
453 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
454 |
],
|
455 |
-
"metadata": {
|
456 |
-
"id": "5JpI7GiZ--Gw"
|
457 |
-
}
|
458 |
-
},
|
459 |
-
{
|
460 |
-
"cell_type": "markdown",
|
461 |
"source": [
|
462 |
-
"The
|
463 |
-
|
464 |
-
|
465 |
-
"
|
466 |
-
|
467 |
},
|
468 |
{
|
469 |
"cell_type": "code",
|
470 |
-
"
|
471 |
-
"!wget https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles.csv\n",
|
472 |
-
"!wget https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles-with_embeddings.csv"
|
473 |
-
],
|
474 |
"metadata": {
|
475 |
"colab": {
|
476 |
"base_uri": "https://localhost:8080/"
|
477 |
},
|
478 |
-
"id": "
|
479 |
-
"outputId": "
|
480 |
},
|
481 |
-
"execution_count": null,
|
482 |
"outputs": [
|
483 |
{
|
484 |
-
"output_type": "stream",
|
485 |
"name": "stdout",
|
|
|
486 |
"text": [
|
487 |
-
"
|
488 |
-
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...\n",
|
489 |
-
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.\n",
|
490 |
-
"HTTP request sent, awaiting response... 200 OK\n",
|
491 |
-
"Length: 173646 (170K) [text/plain]\n",
|
492 |
-
"Saving to: βmini-llama-articles.csvβ\n",
|
493 |
-
"\n",
|
494 |
-
"\rmini-llama-articles 0%[ ] 0 --.-KB/s \rmini-llama-articles 100%[===================>] 169.58K --.-KB/s in 0.02s \n",
|
495 |
-
"\n",
|
496 |
-
"2024-03-20 16:18:40 (6.91 MB/s) - βmini-llama-articles.csvβ saved [173646/173646]\n",
|
497 |
-
"\n",
|
498 |
-
"--2024-03-20 16:18:40-- https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles-with_embeddings.csv\n",
|
499 |
-
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...\n",
|
500 |
-
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.\n",
|
501 |
-
"HTTP request sent, awaiting response... 200 OK\n",
|
502 |
-
"Length: 11868176 (11M) [text/plain]\n",
|
503 |
-
"Saving to: βmini-llama-articles-with_embeddings.csvβ\n",
|
504 |
-
"\n",
|
505 |
-
"mini-llama-articles 100%[===================>] 11.32M --.-KB/s in 0.1s \n",
|
506 |
-
"\n",
|
507 |
-
"2024-03-20 16:18:40 (103 MB/s) - βmini-llama-articles-with_embeddings.csvβ saved [11868176/11868176]\n",
|
508 |
-
"\n"
|
509 |
]
|
510 |
}
|
511 |
-
]
|
512 |
-
},
|
513 |
-
{
|
514 |
-
"cell_type": "markdown",
|
515 |
-
"source": [
|
516 |
-
"## Read File"
|
517 |
-
],
|
518 |
-
"metadata": {
|
519 |
-
"id": "oYDd03Qn_clh"
|
520 |
-
}
|
521 |
-
},
|
522 |
-
{
|
523 |
-
"cell_type": "code",
|
524 |
-
"source": [
|
525 |
-
"# Split the input text into chunks of specified size.\n",
|
526 |
-
"def split_into_chunks(text, chunk_size=1024):\n",
|
527 |
-
" chunks = []\n",
|
528 |
-
" for i in range(0, len(text), chunk_size):\n",
|
529 |
-
" chunks.append( text[i:i+chunk_size] )\n",
|
530 |
-
"\n",
|
531 |
-
" return chunks"
|
532 |
],
|
533 |
-
"metadata": {
|
534 |
-
"id": "_bfhs5NMYr4N"
|
535 |
-
},
|
536 |
-
"execution_count": null,
|
537 |
-
"outputs": []
|
538 |
-
},
|
539 |
-
{
|
540 |
-
"cell_type": "code",
|
541 |
"source": [
|
542 |
-
"import
|
543 |
"\n",
|
544 |
-
"
|
545 |
"\n",
|
546 |
-
"#
|
547 |
-
"
|
548 |
-
" csv_reader = csv.reader(file)\n",
|
549 |
"\n",
|
550 |
-
"
|
551 |
-
"
|
552 |
-
"
|
553 |
-
]
|
554 |
-
"metadata": {
|
555 |
-
"id": "UcQ7Ge_XCuXa"
|
556 |
-
},
|
557 |
-
"execution_count": null,
|
558 |
-
"outputs": []
|
559 |
},
|
560 |
{
|
561 |
"cell_type": "code",
|
562 |
-
"
|
563 |
-
"import pandas as pd\n",
|
564 |
-
"\n",
|
565 |
-
"# Convert the JSON list to a Pandas Dataframe\n",
|
566 |
-
"df = pd.DataFrame(chunks, columns=['chunk'])\n",
|
567 |
-
"\n",
|
568 |
-
"df.keys()"
|
569 |
-
],
|
570 |
"metadata": {
|
571 |
"colab": {
|
572 |
"base_uri": "https://localhost:8080/"
|
573 |
},
|
574 |
-
"id": "
|
575 |
-
"outputId": "
|
576 |
},
|
577 |
-
"execution_count": null,
|
578 |
"outputs": [
|
579 |
{
|
580 |
-
"
|
581 |
-
"
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
|
|
|
|
|
|
|
|
|
|
588 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
589 |
]
|
590 |
},
|
591 |
{
|
592 |
"cell_type": "markdown",
|
593 |
-
"source": [
|
594 |
-
"# Generate Embedding"
|
595 |
-
],
|
596 |
"metadata": {
|
597 |
-
"id": "
|
598 |
-
}
|
|
|
|
|
|
|
599 |
},
|
600 |
{
|
601 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
602 |
"source": [
|
603 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
604 |
"\n",
|
605 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
606 |
"\n",
|
607 |
-
"#
|
608 |
-
"
|
609 |
-
"
|
610 |
-
"
|
611 |
-
"
|
612 |
-
"
|
|
|
|
|
|
|
613 |
"\n",
|
614 |
-
"
|
|
|
615 |
"\n",
|
616 |
-
"
|
617 |
-
"
|
618 |
-
]
|
619 |
-
"metadata": {
|
620 |
-
"id": "AfS9w9eQAKyu"
|
621 |
-
},
|
622 |
-
"execution_count": null,
|
623 |
-
"outputs": []
|
624 |
},
|
625 |
{
|
626 |
"cell_type": "code",
|
627 |
-
"
|
628 |
-
|
629 |
-
"
|
630 |
-
|
631 |
-
"# Generate embedding\n",
|
632 |
-
"if not load_embedding:\n",
|
633 |
-
" print(\"Generating embeddings...\")\n",
|
634 |
-
" embeddings = []\n",
|
635 |
-
" for index, row in tqdm( df.iterrows() ):\n",
|
636 |
-
" # df.at[index, 'embedding'] = get_embedding( row['chunk'] )\n",
|
637 |
-
" embeddings.append( get_embedding( row['chunk'] ) )\n",
|
638 |
-
"\n",
|
639 |
-
" embeddings_values = pd.Series(embeddings)\n",
|
640 |
-
" df.insert(loc=1, column='embedding', value=embeddings_values)\n",
|
641 |
-
"\n",
|
642 |
-
"# Or, load the embedding from the file.\n",
|
643 |
-
"else:\n",
|
644 |
-
" print(\"Loaded the embedding file.\")\n",
|
645 |
-
" # Load the file as a CSV\n",
|
646 |
-
" df = pd.read_csv('mini-llama-articles-with_embeddings.csv')\n",
|
647 |
-
" # Convert embedding column to an array\n",
|
648 |
-
" df['embedding'] = df['embedding'].apply(lambda x: np.array(eval(x)), 0)"
|
649 |
-
],
|
650 |
-
"metadata": {
|
651 |
-
"colab": {
|
652 |
-
"base_uri": "https://localhost:8080/",
|
653 |
-
"height": 67,
|
654 |
-
"referenced_widgets": [
|
655 |
-
"46a91770024e4802acd3e64e9bc46f32",
|
656 |
-
"613898a418d64df3b18d35083f0bb36d",
|
657 |
-
"9f9427eb6a644166906bb321f13eaf48",
|
658 |
-
"a4a232c5b5e1493897e9acdd25b8efd4",
|
659 |
-
"b2e91819e1c94f28b7bbad66918cb797",
|
660 |
-
"010cbcb0f1364576b15f792f4d11f605",
|
661 |
-
"f51d5da0f39e4c1885357d3d4c9964d9",
|
662 |
-
"c4ceff5437e0470089c161e21488d2a7",
|
663 |
-
"6aafd52b0e3e4e0183b1666ad1e8a448",
|
664 |
-
"80137fc11d4b4e518d8c8957ca5461b1",
|
665 |
-
"c4236d507b354bff830620a8bde32191"
|
666 |
-
]
|
667 |
},
|
668 |
-
"id": "
|
669 |
-
"outputId": "
|
670 |
},
|
671 |
-
"execution_count": null,
|
672 |
"outputs": [
|
673 |
{
|
674 |
-
"output_type": "stream",
|
675 |
"name": "stdout",
|
|
|
676 |
"text": [
|
677 |
-
"
|
678 |
]
|
679 |
-
},
|
680 |
-
{
|
681 |
-
"output_type": "display_data",
|
682 |
-
"data": {
|
683 |
-
"text/plain": [
|
684 |
-
"0it [00:00, ?it/s]"
|
685 |
-
],
|
686 |
-
"application/vnd.jupyter.widget-view+json": {
|
687 |
-
"version_major": 2,
|
688 |
-
"version_minor": 0,
|
689 |
-
"model_id": "46a91770024e4802acd3e64e9bc46f32"
|
690 |
-
}
|
691 |
-
},
|
692 |
-
"metadata": {}
|
693 |
}
|
|
|
|
|
|
|
694 |
]
|
695 |
},
|
696 |
{
|
697 |
-
"cell_type": "
|
698 |
-
"source": [
|
699 |
-
"# df.to_csv('mini-llama-articles-with_embeddings.csv')"
|
700 |
-
],
|
701 |
"metadata": {
|
702 |
-
"id": "
|
703 |
},
|
704 |
-
"
|
705 |
-
|
|
|
706 |
},
|
707 |
{
|
708 |
"cell_type": "markdown",
|
709 |
-
"source": [
|
710 |
-
"# User Question"
|
711 |
-
],
|
712 |
"metadata": {
|
713 |
-
"id": "
|
714 |
-
}
|
|
|
|
|
|
|
715 |
},
|
716 |
{
|
717 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
718 |
"source": [
|
719 |
-
"#
|
720 |
-
"
|
721 |
-
"
|
|
|
722 |
"\n",
|
723 |
-
"
|
724 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
725 |
"metadata": {
|
726 |
"colab": {
|
727 |
"base_uri": "https://localhost:8080/"
|
728 |
},
|
729 |
-
"id": "
|
730 |
-
"outputId": "
|
731 |
},
|
732 |
-
"execution_count": null,
|
733 |
"outputs": [
|
734 |
{
|
735 |
-
"
|
736 |
-
"
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
},
|
741 |
-
"metadata": {},
|
742 |
-
"execution_count": 15
|
743 |
}
|
744 |
-
]
|
745 |
-
},
|
746 |
-
{
|
747 |
-
"cell_type": "markdown",
|
748 |
-
"source": [
|
749 |
-
"# Test Cosine Similarity"
|
750 |
],
|
751 |
-
"metadata": {
|
752 |
-
"id": "BXNzNWrJYWhU"
|
753 |
-
}
|
754 |
-
},
|
755 |
-
{
|
756 |
-
"cell_type": "markdown",
|
757 |
"source": [
|
758 |
-
"
|
759 |
-
]
|
760 |
-
|
761 |
-
|
762 |
-
|
|
|
|
|
|
|
|
|
763 |
},
|
764 |
-
{
|
765 |
-
"
|
766 |
-
"
|
767 |
-
"BAD_SOURCE_emb = get_embedding( \"The sky is blue.\" )\n",
|
768 |
-
"GOOD_SOURCE_emb = get_embedding( \"LLaMA2 model has a total of 2B parameters.\" )"
|
769 |
-
],
|
770 |
-
"metadata": {
|
771 |
-
"id": "LqDWcPd4b-ZI"
|
772 |
-
},
|
773 |
-
"execution_count": null,
|
774 |
-
"outputs": []
|
775 |
},
|
776 |
-
{
|
777 |
-
"
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
"
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
789 |
},
|
790 |
-
"
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
"
|
800 |
-
"
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
825 |
},
|
826 |
-
"
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
"
|
836 |
-
"
|
837 |
-
"
|
838 |
-
"
|
839 |
-
"
|
840 |
-
"
|
841 |
-
"
|
842 |
-
"
|
843 |
-
"
|
844 |
-
"
|
845 |
-
"
|
846 |
-
"
|
847 |
-
"
|
848 |
-
|
849 |
-
" 0.77074756 0.7356681 0.77452715 0.76224969 0.79906149 0.84520641\n",
|
850 |
-
" 0.82301383 0.8362749 0.81676624 0.8035085 0.80532594 0.81186134\n",
|
851 |
-
" 0.69082726 0.72587048 0.70070204 0.7155819 0.71758016 0.74945217\n",
|
852 |
-
" 0.72555195 0.7356198 0.73695714 0.75553407 0.77502366 0.71438692\n",
|
853 |
-
" 0.75846916 0.79831901 0.78600515 0.7601161 0.78696534 0.80404804\n",
|
854 |
-
" 0.85209549 0.77037783 0.76985195 0.75062239 0.69339426 0.7108229\n",
|
855 |
-
" 0.72051435 0.75137579 0.71168549 0.72276919 0.77669437 0.7726572\n",
|
856 |
-
" 0.74774188 0.73290677 0.70262553 0.72831247 0.7525444 0.7495277\n",
|
857 |
-
" 0.75188765 0.71491865 0.74460111 0.73599028 0.76314747 0.71318814\n",
|
858 |
-
" 0.70723754 0.73098562 0.72745902 0.76077793 0.72614335 0.72636887\n",
|
859 |
-
" 0.77770561 0.69882456 0.72396024 0.70349095 0.70541201 0.76424393\n",
|
860 |
-
" 0.72785191 0.74371405 0.67802651 0.7353597 0.69916559 0.70605271\n",
|
861 |
-
" 0.71477477 0.71021711 0.77423355 0.70897606 0.74946665 0.70971011\n",
|
862 |
-
" 0.72360056 0.72906996 0.76590153 0.74469991 0.73669136 0.71547661\n",
|
863 |
-
" 0.6958848 0.71459824 0.74863434 0.71430407 0.75165385 0.74221148]]\n"
|
864 |
-
]
|
865 |
-
}
|
866 |
-
]
|
867 |
-
},
|
868 |
-
{
|
869 |
-
"cell_type": "code",
|
870 |
-
"source": [
|
871 |
-
"import numpy as np\n",
|
872 |
-
"\n",
|
873 |
-
"number_of_chunks_to_retrieve = 3\n",
|
874 |
-
"\n",
|
875 |
-
"# Sort the scores\n",
|
876 |
-
"highest_index = np.argmax( cosine_similarities )\n",
|
877 |
-
"\n",
|
878 |
-
"# Pick the N highest scored chunks\n",
|
879 |
-
"indices = np.argsort(cosine_similarities[0])[::-1][:number_of_chunks_to_retrieve]\n",
|
880 |
-
"print( indices )"
|
881 |
-
],
|
882 |
-
"metadata": {
|
883 |
-
"colab": {
|
884 |
-
"base_uri": "https://localhost:8080/"
|
885 |
},
|
886 |
-
"
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
"
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
"
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
912 |
},
|
913 |
-
"
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
"
|
923 |
-
"
|
924 |
-
"
|
925 |
-
"
|
926 |
-
|
927 |
-
"----\n",
|
928 |
-
"> Chunk 3\n",
|
929 |
-
"vely 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. \n",
|
930 |
-
"----\n"
|
931 |
-
]
|
932 |
-
}
|
933 |
-
]
|
934 |
-
},
|
935 |
-
{
|
936 |
-
"cell_type": "markdown",
|
937 |
-
"source": [
|
938 |
-
"# Augment the Prompt"
|
939 |
-
],
|
940 |
-
"metadata": {
|
941 |
-
"id": "7uvQACqAkHg4"
|
942 |
-
}
|
943 |
-
},
|
944 |
-
{
|
945 |
-
"cell_type": "code",
|
946 |
-
"source": [
|
947 |
-
"# Use the OpenAI API to answer the questions based on the retrieved pieces of text.\n",
|
948 |
-
"try:\n",
|
949 |
-
" # Formulating the system prompt and condition the model to answer only AI-related questions.\n",
|
950 |
-
" system_prompt = (\n",
|
951 |
-
" \"You are an assistant and expert in answering questions from a chunks of content. \"\n",
|
952 |
-
" \"Only answer AI-related question, else say that you cannot answer this question.\"\n",
|
953 |
-
" )\n",
|
954 |
-
"\n",
|
955 |
-
" # Create a user prompt with the user's question\n",
|
956 |
-
" prompt = (\n",
|
957 |
-
" \"Read the following informations that might contain the context you require to answer the question. You can use the informations starting from the <START_OF_CONTEXT> tag and end with the <END_OF_CONTEXT> tag. Here is the content:\\n\\n<START_OF_CONTEXT>\\n{}\\n<END_OF_CONTEXT>\\n\\n\"\n",
|
958 |
-
" \"Please provide an informative and accurate answer to the following question based on the avaiable context. Be concise and take your time. \\nQuestion: {}\\nAnswer:\"\n",
|
959 |
-
" )\n",
|
960 |
-
" # Add the retrieved pieces of text to the prompt.\n",
|
961 |
-
" prompt = prompt.format( \"\".join( df.chunk[indices] ), QUESTION )\n",
|
962 |
-
"\n",
|
963 |
-
" # Call the OpenAI API\n",
|
964 |
-
" response = client.chat.completions.create(\n",
|
965 |
-
" model='gpt-3.5-turbo-16k',\n",
|
966 |
-
" temperature=0.0,\n",
|
967 |
-
" messages=[\n",
|
968 |
-
" {\"role\": \"system\", \"content\": system_prompt},\n",
|
969 |
-
" {\"role\": \"user\", \"content\": prompt}\n",
|
970 |
-
" ]\n",
|
971 |
-
" )\n",
|
972 |
-
"\n",
|
973 |
-
" # Return the AI's response\n",
|
974 |
-
" res = response.choices[0].message.content.strip()\n",
|
975 |
-
"\n",
|
976 |
-
"except Exception as e:\n",
|
977 |
-
" print( f\"An error occurred: {e}\" )"
|
978 |
-
],
|
979 |
-
"metadata": {
|
980 |
-
"id": "MXRdzta5kJ3V"
|
981 |
-
},
|
982 |
-
"execution_count": null,
|
983 |
-
"outputs": []
|
984 |
-
},
|
985 |
-
{
|
986 |
-
"cell_type": "code",
|
987 |
-
"source": [
|
988 |
-
"print( res )"
|
989 |
-
],
|
990 |
-
"metadata": {
|
991 |
-
"colab": {
|
992 |
-
"base_uri": "https://localhost:8080/"
|
993 |
},
|
994 |
-
"
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
"
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
" {\"role\": \"system\", \"content\": system_prompt},\n",
|
1046 |
-
" {\"role\": \"user\", \"content\": prompt}\n",
|
1047 |
-
" ]\n",
|
1048 |
-
")\n",
|
1049 |
-
"\n",
|
1050 |
-
"# Return the AI's response\n",
|
1051 |
-
"res = response.choices[0].message.content.strip()"
|
1052 |
-
],
|
1053 |
-
"metadata": {
|
1054 |
-
"id": "RuyXjzZyuecE"
|
1055 |
-
},
|
1056 |
-
"execution_count": null,
|
1057 |
-
"outputs": []
|
1058 |
-
},
|
1059 |
-
{
|
1060 |
-
"cell_type": "code",
|
1061 |
-
"source": [
|
1062 |
-
"print( res )"
|
1063 |
-
],
|
1064 |
-
"metadata": {
|
1065 |
-
"colab": {
|
1066 |
-
"base_uri": "https://localhost:8080/"
|
1067 |
},
|
1068 |
-
"
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
"
|
1078 |
-
|
|
|
|
|
|
|
1079 |
}
|
1080 |
-
|
1081 |
}
|
1082 |
-
|
1083 |
-
|
|
|
|
|
|
1 |
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"metadata": {
|
6 |
+
"colab_type": "text",
|
7 |
+
"id": "view-in-github"
|
8 |
+
},
|
9 |
+
"source": [
|
10 |
+
"<a href=\"https://colab.research.google.com/github/towardsai/ai-tutor-rag-system/blob/main/notebooks/02-Basic_RAG.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
11 |
+
]
|
12 |
},
|
13 |
+
{
|
14 |
+
"cell_type": "markdown",
|
15 |
+
"metadata": {
|
16 |
+
"id": "4Tw3tvMs6R-Y"
|
17 |
+
},
|
18 |
+
"source": [
|
19 |
+
"# Install Packages and Setup Variables"
|
20 |
+
]
|
21 |
},
|
22 |
+
{
|
23 |
+
"cell_type": "code",
|
24 |
+
"execution_count": null,
|
25 |
+
"metadata": {
|
26 |
+
"colab": {
|
27 |
+
"base_uri": "https://localhost:8080/"
|
28 |
+
},
|
29 |
+
"id": "HaB4G9zr0BYm",
|
30 |
+
"outputId": "2a76e676-6fae-44df-ae8c-e4869bfbbc2d"
|
31 |
+
},
|
32 |
+
"outputs": [
|
33 |
+
{
|
34 |
+
"name": "stdout",
|
35 |
+
"output_type": "stream",
|
36 |
+
"text": [
|
37 |
+
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m225.4/225.4 kB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
38 |
+
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m51.7/51.7 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
39 |
+
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m17.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
40 |
+
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
41 |
+
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m3.1/3.1 MB\u001b[0m \u001b[31m17.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
42 |
+
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m77.8/77.8 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
43 |
+
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
44 |
+
"\u001b[?25h"
|
45 |
+
]
|
46 |
+
}
|
47 |
+
],
|
48 |
+
"source": [
|
49 |
+
"!pip install -q openai==1.12.0 cohere==4.47 tiktoken==0.6.0"
|
50 |
+
]
|
51 |
},
|
52 |
+
{
|
53 |
+
"cell_type": "code",
|
54 |
+
"execution_count": null,
|
55 |
+
"metadata": {
|
56 |
+
"id": "MYvUA6CF2Le6"
|
57 |
+
},
|
58 |
+
"outputs": [],
|
59 |
+
"source": [
|
60 |
+
"import os\n",
|
61 |
+
"\n",
|
62 |
+
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
|
63 |
+
"os.environ[\"OPENAI_API_KEY\"] = \"<YOUR_OPENAI_KEY>\""
|
64 |
+
]
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"cell_type": "code",
|
68 |
+
"execution_count": null,
|
69 |
+
"metadata": {
|
70 |
+
"id": "0ViVXXIqXBai"
|
71 |
+
},
|
72 |
+
"outputs": [],
|
73 |
+
"source": [
|
74 |
+
"# False: Generate the embedding for the dataset. (Associated cost with using OpenAI endpoint)\n",
|
75 |
+
"# True: Load the dataset that already has the embedding vectors.\n",
|
76 |
+
"load_embedding = False"
|
77 |
+
]
|
78 |
+
},
|
79 |
+
{
|
80 |
+
"cell_type": "markdown",
|
81 |
+
"metadata": {
|
82 |
+
"id": "D8Nzx-cN_bDz"
|
83 |
+
},
|
84 |
+
"source": [
|
85 |
+
"# Load Dataset"
|
86 |
+
]
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"cell_type": "markdown",
|
90 |
+
"metadata": {
|
91 |
+
"id": "5JpI7GiZ--Gw"
|
92 |
+
},
|
93 |
+
"source": [
|
94 |
+
"## Download Dataset (JSON)"
|
95 |
+
]
|
96 |
+
},
|
97 |
+
{
|
98 |
+
"cell_type": "markdown",
|
99 |
+
"metadata": {
|
100 |
+
"id": "NT68BDYt-GkG"
|
101 |
+
},
|
102 |
+
"source": [
|
103 |
+
"The dataset includes several articles from the TowardsAI blog, which provide an in-depth explanation of the LLaMA2 model."
|
104 |
+
]
|
105 |
+
},
|
106 |
+
{
|
107 |
+
"cell_type": "code",
|
108 |
+
"execution_count": null,
|
109 |
+
"metadata": {
|
110 |
+
"colab": {
|
111 |
+
"base_uri": "https://localhost:8080/"
|
112 |
},
|
113 |
+
"id": "p6NEJT9S2OoH",
|
114 |
+
"outputId": "fd3aa19c-a644-4635-9838-2c20526c4da2"
|
115 |
+
},
|
116 |
+
"outputs": [
|
117 |
+
{
|
118 |
+
"name": "stdout",
|
119 |
+
"output_type": "stream",
|
120 |
+
"text": [
|
121 |
+
"--2024-03-20 16:18:39-- https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles.csv\n",
|
122 |
+
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...\n",
|
123 |
+
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.\n",
|
124 |
+
"HTTP request sent, awaiting response... 200 OK\n",
|
125 |
+
"Length: 173646 (170K) [text/plain]\n",
|
126 |
+
"Saving to: βmini-llama-articles.csvβ\n",
|
127 |
+
"\n",
|
128 |
+
"\rmini-llama-articles 0%[ ] 0 --.-KB/s \rmini-llama-articles 100%[===================>] 169.58K --.-KB/s in 0.02s \n",
|
129 |
+
"\n",
|
130 |
+
"2024-03-20 16:18:40 (6.91 MB/s) - βmini-llama-articles.csvβ saved [173646/173646]\n",
|
131 |
+
"\n",
|
132 |
+
"--2024-03-20 16:18:40-- https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles-with_embeddings.csv\n",
|
133 |
+
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...\n",
|
134 |
+
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.\n",
|
135 |
+
"HTTP request sent, awaiting response... 200 OK\n",
|
136 |
+
"Length: 11868176 (11M) [text/plain]\n",
|
137 |
+
"Saving to: βmini-llama-articles-with_embeddings.csvβ\n",
|
138 |
+
"\n",
|
139 |
+
"mini-llama-articles 100%[===================>] 11.32M --.-KB/s in 0.1s \n",
|
140 |
+
"\n",
|
141 |
+
"2024-03-20 16:18:40 (103 MB/s) - βmini-llama-articles-with_embeddings.csvβ saved [11868176/11868176]\n",
|
142 |
+
"\n"
|
143 |
+
]
|
144 |
+
}
|
145 |
+
],
|
146 |
+
"source": [
|
147 |
+
"!wget https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles.csv\n",
|
148 |
+
"!wget https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles-with_embeddings.csv"
|
149 |
+
]
|
150 |
+
},
|
151 |
+
{
|
152 |
+
"cell_type": "markdown",
|
153 |
+
"metadata": {
|
154 |
+
"id": "oYDd03Qn_clh"
|
155 |
+
},
|
156 |
+
"source": [
|
157 |
+
"## Read File"
|
158 |
+
]
|
159 |
+
},
|
160 |
+
{
|
161 |
+
"cell_type": "code",
|
162 |
+
"execution_count": null,
|
163 |
+
"metadata": {
|
164 |
+
"id": "_bfhs5NMYr4N"
|
165 |
+
},
|
166 |
+
"outputs": [],
|
167 |
+
"source": [
|
168 |
+
"# Split the input text into chunks of specified size.\n",
|
169 |
+
"def split_into_chunks(text, chunk_size=1024):\n",
|
170 |
+
" chunks = []\n",
|
171 |
+
" for i in range(0, len(text), chunk_size):\n",
|
172 |
+
" chunks.append( text[i:i+chunk_size] )\n",
|
173 |
+
"\n",
|
174 |
+
" return chunks"
|
175 |
+
]
|
176 |
+
},
|
177 |
+
{
|
178 |
+
"cell_type": "code",
|
179 |
+
"execution_count": null,
|
180 |
+
"metadata": {
|
181 |
+
"id": "UcQ7Ge_XCuXa"
|
182 |
+
},
|
183 |
+
"outputs": [],
|
184 |
+
"source": [
|
185 |
+
"import csv\n",
|
186 |
+
"\n",
|
187 |
+
"chunks = []\n",
|
188 |
+
"\n",
|
189 |
+
"# Load the file as a CSV\n",
|
190 |
+
"with open(\"./mini-llama-articles.csv\", mode=\"r\", encoding=\"utf-8\") as file:\n",
|
191 |
+
" csv_reader = csv.reader(file)\n",
|
192 |
+
"\n",
|
193 |
+
" for idx, row in enumerate( csv_reader ):\n",
|
194 |
+
" if idx == 0: continue; # Skip header row\n",
|
195 |
+
" chunks.extend( split_into_chunks(row[1]) )"
|
196 |
+
]
|
197 |
+
},
|
198 |
+
{
|
199 |
+
"cell_type": "code",
|
200 |
+
"execution_count": null,
|
201 |
+
"metadata": {
|
202 |
+
"colab": {
|
203 |
+
"base_uri": "https://localhost:8080/"
|
204 |
},
|
205 |
+
"id": "JKdFSOb0NXjx",
|
206 |
+
"outputId": "ce43c97f-2083-49b5-837d-62cc427fe848"
|
207 |
+
},
|
208 |
+
"outputs": [
|
209 |
+
{
|
210 |
+
"data": {
|
211 |
+
"text/plain": [
|
212 |
+
"Index(['chunk'], dtype='object')"
|
213 |
+
]
|
214 |
+
},
|
215 |
+
"execution_count": 8,
|
216 |
+
"metadata": {},
|
217 |
+
"output_type": "execute_result"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
}
|
219 |
+
],
|
220 |
+
"source": [
|
221 |
+
"import pandas as pd\n",
|
222 |
+
"\n",
|
223 |
+
"# Convert the JSON list to a Pandas Dataframe\n",
|
224 |
+
"df = pd.DataFrame(chunks, columns=['chunk'])\n",
|
225 |
+
"\n",
|
226 |
+
"df.keys()"
|
227 |
+
]
|
228 |
+
},
|
229 |
{
|
230 |
"cell_type": "markdown",
|
231 |
"metadata": {
|
232 |
+
"id": "21pFDgNdW9rO"
|
|
|
233 |
},
|
234 |
"source": [
|
235 |
+
"# Generate Embedding"
|
236 |
]
|
237 |
},
|
238 |
{
|
239 |
+
"cell_type": "code",
|
240 |
+
"execution_count": null,
|
|
|
|
|
241 |
"metadata": {
|
242 |
+
"id": "AfS9w9eQAKyu"
|
243 |
+
},
|
244 |
+
"outputs": [],
|
245 |
+
"source": [
|
246 |
+
"from openai import OpenAI\n",
|
247 |
+
"\n",
|
248 |
+
"client = OpenAI()\n",
|
249 |
+
"\n",
|
250 |
+
"# Defining a function that converts a text to embedding vector using OpenAI's Ada model.\n",
|
251 |
+
"def get_embedding(text):\n",
|
252 |
+
" try:\n",
|
253 |
+
" # Remove newlines\n",
|
254 |
+
" text = text.replace(\"\\n\", \" \")\n",
|
255 |
+
" res = client.embeddings.create(input = [text], model=\"text-embedding-ada-002\")\n",
|
256 |
+
"\n",
|
257 |
+
" return res.data[0].embedding\n",
|
258 |
+
"\n",
|
259 |
+
" except:\n",
|
260 |
+
" return None"
|
261 |
+
]
|
262 |
},
|
263 |
{
|
264 |
"cell_type": "code",
|
265 |
"execution_count": null,
|
266 |
"metadata": {
|
267 |
"colab": {
|
268 |
+
"base_uri": "https://localhost:8080/",
|
269 |
+
"height": 67,
|
270 |
+
"referenced_widgets": [
|
271 |
+
"46a91770024e4802acd3e64e9bc46f32",
|
272 |
+
"613898a418d64df3b18d35083f0bb36d",
|
273 |
+
"9f9427eb6a644166906bb321f13eaf48",
|
274 |
+
"a4a232c5b5e1493897e9acdd25b8efd4",
|
275 |
+
"b2e91819e1c94f28b7bbad66918cb797",
|
276 |
+
"010cbcb0f1364576b15f792f4d11f605",
|
277 |
+
"f51d5da0f39e4c1885357d3d4c9964d9",
|
278 |
+
"c4ceff5437e0470089c161e21488d2a7",
|
279 |
+
"6aafd52b0e3e4e0183b1666ad1e8a448",
|
280 |
+
"80137fc11d4b4e518d8c8957ca5461b1",
|
281 |
+
"c4236d507b354bff830620a8bde32191"
|
282 |
+
]
|
283 |
},
|
284 |
+
"id": "qC6aeFr3Rmi2",
|
285 |
+
"outputId": "7f54333f-fcb9-44ce-d4a0-94a9a8d822d5"
|
286 |
},
|
287 |
"outputs": [
|
288 |
{
|
|
|
289 |
"name": "stdout",
|
290 |
+
"output_type": "stream",
|
291 |
"text": [
|
292 |
+
"Generating embeddings...\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
]
|
294 |
+
},
|
295 |
+
{
|
296 |
+
"data": {
|
297 |
+
"application/vnd.jupyter.widget-view+json": {
|
298 |
+
"model_id": "46a91770024e4802acd3e64e9bc46f32",
|
299 |
+
"version_major": 2,
|
300 |
+
"version_minor": 0
|
301 |
+
},
|
302 |
+
"text/plain": [
|
303 |
+
"0it [00:00, ?it/s]"
|
304 |
+
]
|
305 |
+
},
|
306 |
+
"metadata": {},
|
307 |
+
"output_type": "display_data"
|
308 |
}
|
309 |
],
|
310 |
"source": [
|
311 |
+
"from tqdm.notebook import tqdm\n",
|
312 |
+
"import numpy as np\n",
|
313 |
+
"\n",
|
314 |
+
"# Generate embedding\n",
|
315 |
+
"if not load_embedding:\n",
|
316 |
+
" print(\"Generating embeddings...\")\n",
|
317 |
+
" embeddings = []\n",
|
318 |
+
" for index, row in tqdm( df.iterrows() ):\n",
|
319 |
+
" # df.at[index, 'embedding'] = get_embedding( row['chunk'] )\n",
|
320 |
+
" embeddings.append( get_embedding( row['chunk'] ) )\n",
|
321 |
+
"\n",
|
322 |
+
" embeddings_values = pd.Series(embeddings)\n",
|
323 |
+
" df.insert(loc=1, column='embedding', value=embeddings_values)\n",
|
324 |
+
"\n",
|
325 |
+
"# Or, load the embedding from the file.\n",
|
326 |
+
"else:\n",
|
327 |
+
" print(\"Loaded the embedding file.\")\n",
|
328 |
+
" # Load the file as a CSV\n",
|
329 |
+
" df = pd.read_csv('mini-llama-articles-with_embeddings.csv')\n",
|
330 |
+
" # Convert embedding column to an array\n",
|
331 |
+
" df['embedding'] = df['embedding'].apply(lambda x: np.array(eval(x)), 0)"
|
332 |
]
|
333 |
},
|
334 |
{
|
335 |
"cell_type": "code",
|
336 |
+
"execution_count": null,
|
337 |
+
"metadata": {
|
338 |
+
"id": "jyX9M_n9o2ve"
|
339 |
+
},
|
340 |
+
"outputs": [],
|
341 |
"source": [
|
342 |
+
"# df.to_csv('mini-llama-articles-with_embeddings.csv')"
|
343 |
+
]
|
344 |
+
},
|
345 |
+
{
|
346 |
+
"cell_type": "markdown",
|
347 |
"metadata": {
|
348 |
+
"id": "E_qrXwImXrXJ"
|
349 |
},
|
350 |
+
"source": [
|
351 |
+
"# User Question"
|
352 |
+
]
|
353 |
},
|
354 |
{
|
355 |
"cell_type": "code",
|
356 |
+
"execution_count": null,
|
357 |
+
"metadata": {
|
358 |
+
"colab": {
|
359 |
+
"base_uri": "https://localhost:8080/"
|
360 |
+
},
|
361 |
+
"id": "xGTa7cqCX97q",
|
362 |
+
"outputId": "6ae836e3-1a65-4447-b732-88758378e9dd"
|
363 |
+
},
|
364 |
+
"outputs": [
|
365 |
+
{
|
366 |
+
"data": {
|
367 |
+
"text/plain": [
|
368 |
+
"1536"
|
369 |
+
]
|
370 |
+
},
|
371 |
+
"execution_count": 15,
|
372 |
+
"metadata": {},
|
373 |
+
"output_type": "execute_result"
|
374 |
+
}
|
375 |
],
|
376 |
+
"source": [
|
377 |
+
"# Define the user question, and convert it to embedding.\n",
|
378 |
+
"QUESTION = \"How many parameters LLaMA2 model has?\"\n",
|
379 |
+
"QUESTION_emb = get_embedding( QUESTION )\n",
|
380 |
+
"\n",
|
381 |
+
"len( QUESTION_emb )"
|
382 |
+
]
|
383 |
+
},
|
384 |
+
{
|
385 |
+
"cell_type": "markdown",
|
386 |
"metadata": {
|
387 |
+
"id": "BXNzNWrJYWhU"
|
388 |
},
|
389 |
+
"source": [
|
390 |
+
"# Test Cosine Similarity"
|
391 |
+
]
|
392 |
},
|
393 |
{
|
394 |
"cell_type": "markdown",
|
395 |
+
"metadata": {
|
396 |
+
"id": "Vxaq-FgLIhIj"
|
397 |
+
},
|
398 |
"source": [
|
399 |
+
"Calculating the similarity of embedding representations can help us to find pieces of text that are close to each other. In the following sample you see how the Cosine Similarity metric can identify which sentence could be a possible answer for the given user question. Obviously, the unrelated answer will score lower."
|
400 |
+
]
|
401 |
+
},
|
402 |
+
{
|
403 |
+
"cell_type": "code",
|
404 |
+
"execution_count": null,
|
405 |
"metadata": {
|
406 |
+
"id": "LqDWcPd4b-ZI"
|
407 |
+
},
|
408 |
+
"outputs": [],
|
409 |
+
"source": [
|
410 |
+
"BAD_SOURCE_emb = get_embedding( \"The sky is blue.\" )\n",
|
411 |
+
"GOOD_SOURCE_emb = get_embedding( \"LLaMA2 model has a total of 2B parameters.\" )"
|
412 |
+
]
|
413 |
+
},
|
414 |
+
{
|
415 |
+
"cell_type": "code",
|
416 |
+
"execution_count": null,
|
417 |
+
"metadata": {
|
418 |
+
"colab": {
|
419 |
+
"base_uri": "https://localhost:8080/"
|
420 |
+
},
|
421 |
+
"id": "OI00eN86YZKB",
|
422 |
+
"outputId": "0d06c9ea-7de2-48a0-e6d8-3fc6e428914b"
|
423 |
+
},
|
424 |
+
"outputs": [
|
425 |
+
{
|
426 |
+
"name": "stdout",
|
427 |
+
"output_type": "stream",
|
428 |
+
"text": [
|
429 |
+
"> Bad Response Score: [[0.69953438]]\n",
|
430 |
+
"> Good Response Score: [[0.93126147]]\n"
|
431 |
+
]
|
432 |
+
}
|
433 |
+
],
|
434 |
+
"source": [
|
435 |
+
"from sklearn.metrics.pairwise import cosine_similarity\n",
|
436 |
+
"\n",
|
437 |
+
"# A sample that how a good piece of text can achieve high similarity score compared\n",
|
438 |
+
"# to a completely unrelated text.\n",
|
439 |
+
"print(\"> Bad Response Score:\", cosine_similarity([QUESTION_emb], [BAD_SOURCE_emb]) )\n",
|
440 |
+
"print(\"> Good Response Score:\", cosine_similarity([QUESTION_emb], [GOOD_SOURCE_emb]) )"
|
441 |
+
]
|
442 |
},
|
443 |
{
|
444 |
"cell_type": "markdown",
|
445 |
+
"metadata": {
|
446 |
+
"id": "kdJlEtaaJC4I"
|
447 |
+
},
|
448 |
"source": [
|
449 |
+
"# Calculate Cosine Similarities"
|
450 |
+
]
|
451 |
+
},
|
452 |
+
{
|
453 |
+
"cell_type": "code",
|
454 |
+
"execution_count": null,
|
455 |
+
"metadata": {
|
456 |
+
"colab": {
|
457 |
+
"base_uri": "https://localhost:8080/"
|
458 |
+
},
|
459 |
+
"id": "PNPN7OAXemmH",
|
460 |
+
"outputId": "54beed07-04de-4696-b513-f49a935d6820"
|
461 |
+
},
|
462 |
+
"outputs": [
|
463 |
+
{
|
464 |
+
"name": "stdout",
|
465 |
+
"output_type": "stream",
|
466 |
+
"text": [
|
467 |
+
"[[0.82047387 0.79858187 0.74135248 0.73226232 0.72406104 0.75608299\n",
|
468 |
+
" 0.76808965 0.77621683 0.80498431 0.71399955 0.69822549 0.67532971\n",
|
469 |
+
" 0.72473021 0.73449361 0.69998132 0.73749561 0.68490681 0.75076836\n",
|
470 |
+
" 0.72540663 0.70675593 0.76047822 0.73849418 0.78103858 0.75189435\n",
|
471 |
+
" 0.73619013 0.76962672 0.71289635 0.76996122 0.7827543 0.77959332\n",
|
472 |
+
" 0.82716952 0.77719335 0.80172766 0.76301732 0.78111546 0.75179235\n",
|
473 |
+
" 0.74741505 0.7576328 0.78998865 0.77283347 0.79180172 0.78170323\n",
|
474 |
+
" 0.80264132 0.79923073 0.76146584 0.75199024 0.8341403 0.74460259\n",
|
475 |
+
" 0.76259332 0.73693499 0.78469623 0.81698455 0.8254561 0.77921093\n",
|
476 |
+
" 0.75351863 0.79319721 0.73098248 0.71716001 0.73210099 0.74684248\n",
|
477 |
+
" 0.75760574 0.71070101 0.71507394 0.70847896 0.72395535 0.77801292\n",
|
478 |
+
" 0.75446732 0.75100258 0.7361131 0.78430831 0.74170516 0.71862961\n",
|
479 |
+
" 0.76792911 0.76471996 0.78551313 0.80846857 0.79231644 0.79505895\n",
|
480 |
+
" 0.76910825 0.78341548 0.74952152 0.7849115 0.80407507 0.82641741\n",
|
481 |
+
" 0.77074756 0.7356681 0.77452715 0.76224969 0.79906149 0.84520641\n",
|
482 |
+
" 0.82301383 0.8362749 0.81676624 0.8035085 0.80532594 0.81186134\n",
|
483 |
+
" 0.69082726 0.72587048 0.70070204 0.7155819 0.71758016 0.74945217\n",
|
484 |
+
" 0.72555195 0.7356198 0.73695714 0.75553407 0.77502366 0.71438692\n",
|
485 |
+
" 0.75846916 0.79831901 0.78600515 0.7601161 0.78696534 0.80404804\n",
|
486 |
+
" 0.85209549 0.77037783 0.76985195 0.75062239 0.69339426 0.7108229\n",
|
487 |
+
" 0.72051435 0.75137579 0.71168549 0.72276919 0.77669437 0.7726572\n",
|
488 |
+
" 0.74774188 0.73290677 0.70262553 0.72831247 0.7525444 0.7495277\n",
|
489 |
+
" 0.75188765 0.71491865 0.74460111 0.73599028 0.76314747 0.71318814\n",
|
490 |
+
" 0.70723754 0.73098562 0.72745902 0.76077793 0.72614335 0.72636887\n",
|
491 |
+
" 0.77770561 0.69882456 0.72396024 0.70349095 0.70541201 0.76424393\n",
|
492 |
+
" 0.72785191 0.74371405 0.67802651 0.7353597 0.69916559 0.70605271\n",
|
493 |
+
" 0.71477477 0.71021711 0.77423355 0.70897606 0.74946665 0.70971011\n",
|
494 |
+
" 0.72360056 0.72906996 0.76590153 0.74469991 0.73669136 0.71547661\n",
|
495 |
+
" 0.6958848 0.71459824 0.74863434 0.71430407 0.75165385 0.74221148]]\n"
|
496 |
+
]
|
497 |
+
}
|
498 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
"source": [
|
500 |
+
"# The similarity between the questions and each part of the essay.\n",
|
501 |
+
"cosine_similarities = cosine_similarity( [QUESTION_emb], df['embedding'].tolist() )\n",
|
502 |
+
"\n",
|
503 |
+
"print( cosine_similarities )"
|
504 |
+
]
|
505 |
},
|
506 |
{
|
507 |
"cell_type": "code",
|
508 |
+
"execution_count": null,
|
|
|
|
|
|
|
509 |
"metadata": {
|
510 |
"colab": {
|
511 |
"base_uri": "https://localhost:8080/"
|
512 |
},
|
513 |
+
"id": "1-XI1_7mhlw4",
|
514 |
+
"outputId": "9598da10-ab61-45e9-e0bb-3e1d7046b657"
|
515 |
},
|
|
|
516 |
"outputs": [
|
517 |
{
|
|
|
518 |
"name": "stdout",
|
519 |
+
"output_type": "stream",
|
520 |
"text": [
|
521 |
+
"[114 89 91]\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
]
|
523 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
"source": [
|
526 |
+
"import numpy as np\n",
|
527 |
"\n",
|
528 |
+
"number_of_chunks_to_retrieve = 3\n",
|
529 |
"\n",
|
530 |
+
"# Sort the scores\n",
|
531 |
+
"highest_index = np.argmax( cosine_similarities )\n",
|
|
|
532 |
"\n",
|
533 |
+
"# Pick the N highest scored chunks\n",
|
534 |
+
"indices = np.argsort(cosine_similarities[0])[::-1][:number_of_chunks_to_retrieve]\n",
|
535 |
+
"print( indices )"
|
536 |
+
]
|
|
|
|
|
|
|
|
|
|
|
537 |
},
|
538 |
{
|
539 |
"cell_type": "code",
|
540 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
541 |
"metadata": {
|
542 |
"colab": {
|
543 |
"base_uri": "https://localhost:8080/"
|
544 |
},
|
545 |
+
"id": "JPmhCb9kfB0w",
|
546 |
+
"outputId": "5089b207-a65a-4856-c065-56b3b9bbba72"
|
547 |
},
|
|
|
548 |
"outputs": [
|
549 |
{
|
550 |
+
"name": "stdout",
|
551 |
+
"output_type": "stream",
|
552 |
+
"text": [
|
553 |
+
"> Chunk 1\n",
|
554 |
+
"by Meta that ventures into both the AI and academic spaces. The model aims to help researchers, scientists, and engineers advance their work in exploring AI applications. It will be released under a non-commercial license to prevent misuse, and access will be granted to academic researchers, individuals, and organizations affiliated with the government, civil society, academia, and industry research facilities on a selective case-by-case basis. The sharing of codes and weights allows other researchers to test new approaches in LLMs. The LLaMA models have a range of 7 billion to 65 billion parameters. LLaMA-65B can be compared to DeepMind's Chinchilla and Google's PaLM. Publicly available unlabeled data was used to train these models, and training smaller foundational models require less computing power and resources. LLaMA 65B and 33B have been trained on 1.4 trillion tokens in 20 different languages, and according to the Facebook Artificial Intelligence Research (FAIR) team, the model's performance varies ac\n",
|
555 |
+
"----\n",
|
556 |
+
"> Chunk 2\n",
|
557 |
+
"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 annota\n",
|
558 |
+
"----\n",
|
559 |
+
"> Chunk 3\n",
|
560 |
+
"vely 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. \n",
|
561 |
+
"----\n"
|
562 |
+
]
|
563 |
}
|
564 |
+
],
|
565 |
+
"source": [
|
566 |
+
"# Look at the highest scored retrieved pieces of text\n",
|
567 |
+
"for idx, item in enumerate( df.chunk[indices] ):\n",
|
568 |
+
" print(f\"> Chunk {idx+1}\")\n",
|
569 |
+
" print(item)\n",
|
570 |
+
" print(\"----\")"
|
571 |
]
|
572 |
},
|
573 |
{
|
574 |
"cell_type": "markdown",
|
|
|
|
|
|
|
575 |
"metadata": {
|
576 |
+
"id": "7uvQACqAkHg4"
|
577 |
+
},
|
578 |
+
"source": [
|
579 |
+
"# Augment the Prompt"
|
580 |
+
]
|
581 |
},
|
582 |
{
|
583 |
"cell_type": "code",
|
584 |
+
"execution_count": null,
|
585 |
+
"metadata": {
|
586 |
+
"id": "MXRdzta5kJ3V"
|
587 |
+
},
|
588 |
+
"outputs": [],
|
589 |
"source": [
|
590 |
+
"# Use the OpenAI API to answer the questions based on the retrieved pieces of text.\n",
|
591 |
+
"try:\n",
|
592 |
+
" # Formulating the system prompt and condition the model to answer only AI-related questions.\n",
|
593 |
+
" system_prompt = (\n",
|
594 |
+
" \"You are an assistant and expert in answering questions from a chunks of content. \"\n",
|
595 |
+
" \"Only answer AI-related question, else say that you cannot answer this question.\"\n",
|
596 |
+
" )\n",
|
597 |
"\n",
|
598 |
+
" # Create a user prompt with the user's question\n",
|
599 |
+
" prompt = (\n",
|
600 |
+
" \"Read the following informations that might contain the context you require to answer the question. You can use the informations starting from the <START_OF_CONTEXT> tag and end with the <END_OF_CONTEXT> tag. Here is the content:\\n\\n<START_OF_CONTEXT>\\n{}\\n<END_OF_CONTEXT>\\n\\n\"\n",
|
601 |
+
" \"Please provide an informative and accurate answer to the following question based on the avaiable context. Be concise and take your time. \\nQuestion: {}\\nAnswer:\"\n",
|
602 |
+
" )\n",
|
603 |
+
" # Add the retrieved pieces of text to the prompt.\n",
|
604 |
+
" prompt = prompt.format( \"\".join( df.chunk[indices] ), QUESTION )\n",
|
605 |
"\n",
|
606 |
+
" # Call the OpenAI API\n",
|
607 |
+
" response = client.chat.completions.create(\n",
|
608 |
+
" model='gpt-3.5-turbo',\n",
|
609 |
+
" temperature=0.0,\n",
|
610 |
+
" messages=[\n",
|
611 |
+
" {\"role\": \"system\", \"content\": system_prompt},\n",
|
612 |
+
" {\"role\": \"user\", \"content\": prompt}\n",
|
613 |
+
" ]\n",
|
614 |
+
" )\n",
|
615 |
"\n",
|
616 |
+
" # Return the AI's response\n",
|
617 |
+
" res = response.choices[0].message.content.strip()\n",
|
618 |
"\n",
|
619 |
+
"except Exception as e:\n",
|
620 |
+
" print( f\"An error occurred: {e}\" )"
|
621 |
+
]
|
|
|
|
|
|
|
|
|
|
|
622 |
},
|
623 |
{
|
624 |
"cell_type": "code",
|
625 |
+
"execution_count": null,
|
626 |
+
"metadata": {
|
627 |
+
"colab": {
|
628 |
+
"base_uri": "https://localhost:8080/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
629 |
},
|
630 |
+
"id": "9tBvJ8oMucha",
|
631 |
+
"outputId": "418c0220-c2ee-43cf-a9bc-0ea755f7a04e"
|
632 |
},
|
|
|
633 |
"outputs": [
|
634 |
{
|
|
|
635 |
"name": "stdout",
|
636 |
+
"output_type": "stream",
|
637 |
"text": [
|
638 |
+
"The LLaMA2 model has four different sizes: 7 billion, 13 billion, 34 billion, and 70 billion parameters.\n"
|
639 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
640 |
}
|
641 |
+
],
|
642 |
+
"source": [
|
643 |
+
"print( res )"
|
644 |
]
|
645 |
},
|
646 |
{
|
647 |
+
"cell_type": "markdown",
|
|
|
|
|
|
|
648 |
"metadata": {
|
649 |
+
"id": "pW-BNCAC2JzE"
|
650 |
},
|
651 |
+
"source": [
|
652 |
+
"# Without Augmentation"
|
653 |
+
]
|
654 |
},
|
655 |
{
|
656 |
"cell_type": "markdown",
|
|
|
|
|
|
|
657 |
"metadata": {
|
658 |
+
"id": "tr5zXEGIMwJu"
|
659 |
+
},
|
660 |
+
"source": [
|
661 |
+
"Test the OpenAI API to answer the same question without the addition of retrieved documents. Basically, the LLM will use its knowledge to answer the question."
|
662 |
+
]
|
663 |
},
|
664 |
{
|
665 |
"cell_type": "code",
|
666 |
+
"execution_count": null,
|
667 |
+
"metadata": {
|
668 |
+
"id": "RuyXjzZyuecE"
|
669 |
+
},
|
670 |
+
"outputs": [],
|
671 |
"source": [
|
672 |
+
"# Formulating the system prompt\n",
|
673 |
+
"system_prompt = (\n",
|
674 |
+
" \"You are an assistant and expert in answering questions.\"\n",
|
675 |
+
")\n",
|
676 |
"\n",
|
677 |
+
"# Combining the system prompt with the user's question\n",
|
678 |
+
"prompt = (\n",
|
679 |
+
" \"Be concise and take your time to answer the following question. \\nQuestion: {}\\nAnswer:\"\n",
|
680 |
+
")\n",
|
681 |
+
"prompt = prompt.format( QUESTION )\n",
|
682 |
+
"\n",
|
683 |
+
"# Call the OpenAI API\n",
|
684 |
+
"response = client.chat.completions.create(\n",
|
685 |
+
" model='gpt-3.5-turbo',\n",
|
686 |
+
" temperature=.9,\n",
|
687 |
+
" messages=[\n",
|
688 |
+
" {\"role\": \"system\", \"content\": system_prompt},\n",
|
689 |
+
" {\"role\": \"user\", \"content\": prompt}\n",
|
690 |
+
" ]\n",
|
691 |
+
")\n",
|
692 |
+
"\n",
|
693 |
+
"# Return the AI's response\n",
|
694 |
+
"res = response.choices[0].message.content.strip()"
|
695 |
+
]
|
696 |
+
},
|
697 |
+
{
|
698 |
+
"cell_type": "code",
|
699 |
+
"execution_count": null,
|
700 |
"metadata": {
|
701 |
"colab": {
|
702 |
"base_uri": "https://localhost:8080/"
|
703 |
},
|
704 |
+
"id": "YAy34tPTzGbh",
|
705 |
+
"outputId": "54041329-dd5f-4cdd-db38-f1440ae77181"
|
706 |
},
|
|
|
707 |
"outputs": [
|
708 |
{
|
709 |
+
"name": "stdout",
|
710 |
+
"output_type": "stream",
|
711 |
+
"text": [
|
712 |
+
"The LLaMA2 model has a total of [insert number] parameters.\n"
|
713 |
+
]
|
|
|
|
|
|
|
714 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
715 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
716 |
"source": [
|
717 |
+
"print( res )"
|
718 |
+
]
|
719 |
+
}
|
720 |
+
],
|
721 |
+
"metadata": {
|
722 |
+
"colab": {
|
723 |
+
"authorship_tag": "ABX9TyMiGemqWYAYHaqF1t8bElQ/",
|
724 |
+
"include_colab_link": true,
|
725 |
+
"provenance": []
|
726 |
},
|
727 |
+
"kernelspec": {
|
728 |
+
"display_name": "Python 3",
|
729 |
+
"name": "python3"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
730 |
},
|
731 |
+
"language_info": {
|
732 |
+
"name": "python"
|
733 |
+
},
|
734 |
+
"widgets": {
|
735 |
+
"application/vnd.jupyter.widget-state+json": {
|
736 |
+
"010cbcb0f1364576b15f792f4d11f605": {
|
737 |
+
"model_module": "@jupyter-widgets/base",
|
738 |
+
"model_module_version": "1.2.0",
|
739 |
+
"model_name": "LayoutModel",
|
740 |
+
"state": {
|
741 |
+
"_model_module": "@jupyter-widgets/base",
|
742 |
+
"_model_module_version": "1.2.0",
|
743 |
+
"_model_name": "LayoutModel",
|
744 |
+
"_view_count": null,
|
745 |
+
"_view_module": "@jupyter-widgets/base",
|
746 |
+
"_view_module_version": "1.2.0",
|
747 |
+
"_view_name": "LayoutView",
|
748 |
+
"align_content": null,
|
749 |
+
"align_items": null,
|
750 |
+
"align_self": null,
|
751 |
+
"border": null,
|
752 |
+
"bottom": null,
|
753 |
+
"display": null,
|
754 |
+
"flex": null,
|
755 |
+
"flex_flow": null,
|
756 |
+
"grid_area": null,
|
757 |
+
"grid_auto_columns": null,
|
758 |
+
"grid_auto_flow": null,
|
759 |
+
"grid_auto_rows": null,
|
760 |
+
"grid_column": null,
|
761 |
+
"grid_gap": null,
|
762 |
+
"grid_row": null,
|
763 |
+
"grid_template_areas": null,
|
764 |
+
"grid_template_columns": null,
|
765 |
+
"grid_template_rows": null,
|
766 |
+
"height": null,
|
767 |
+
"justify_content": null,
|
768 |
+
"justify_items": null,
|
769 |
+
"left": null,
|
770 |
+
"margin": null,
|
771 |
+
"max_height": null,
|
772 |
+
"max_width": null,
|
773 |
+
"min_height": null,
|
774 |
+
"min_width": null,
|
775 |
+
"object_fit": null,
|
776 |
+
"object_position": null,
|
777 |
+
"order": null,
|
778 |
+
"overflow": null,
|
779 |
+
"overflow_x": null,
|
780 |
+
"overflow_y": null,
|
781 |
+
"padding": null,
|
782 |
+
"right": null,
|
783 |
+
"top": null,
|
784 |
+
"visibility": null,
|
785 |
+
"width": null
|
786 |
+
}
|
787 |
+
},
|
788 |
+
"46a91770024e4802acd3e64e9bc46f32": {
|
789 |
+
"model_module": "@jupyter-widgets/controls",
|
790 |
+
"model_module_version": "1.5.0",
|
791 |
+
"model_name": "HBoxModel",
|
792 |
+
"state": {
|
793 |
+
"_dom_classes": [],
|
794 |
+
"_model_module": "@jupyter-widgets/controls",
|
795 |
+
"_model_module_version": "1.5.0",
|
796 |
+
"_model_name": "HBoxModel",
|
797 |
+
"_view_count": null,
|
798 |
+
"_view_module": "@jupyter-widgets/controls",
|
799 |
+
"_view_module_version": "1.5.0",
|
800 |
+
"_view_name": "HBoxView",
|
801 |
+
"box_style": "",
|
802 |
+
"children": [
|
803 |
+
"IPY_MODEL_613898a418d64df3b18d35083f0bb36d",
|
804 |
+
"IPY_MODEL_9f9427eb6a644166906bb321f13eaf48",
|
805 |
+
"IPY_MODEL_a4a232c5b5e1493897e9acdd25b8efd4"
|
806 |
+
],
|
807 |
+
"layout": "IPY_MODEL_b2e91819e1c94f28b7bbad66918cb797"
|
808 |
+
}
|
809 |
+
},
|
810 |
+
"613898a418d64df3b18d35083f0bb36d": {
|
811 |
+
"model_module": "@jupyter-widgets/controls",
|
812 |
+
"model_module_version": "1.5.0",
|
813 |
+
"model_name": "HTMLModel",
|
814 |
+
"state": {
|
815 |
+
"_dom_classes": [],
|
816 |
+
"_model_module": "@jupyter-widgets/controls",
|
817 |
+
"_model_module_version": "1.5.0",
|
818 |
+
"_model_name": "HTMLModel",
|
819 |
+
"_view_count": null,
|
820 |
+
"_view_module": "@jupyter-widgets/controls",
|
821 |
+
"_view_module_version": "1.5.0",
|
822 |
+
"_view_name": "HTMLView",
|
823 |
+
"description": "",
|
824 |
+
"description_tooltip": null,
|
825 |
+
"layout": "IPY_MODEL_010cbcb0f1364576b15f792f4d11f605",
|
826 |
+
"placeholder": "β",
|
827 |
+
"style": "IPY_MODEL_f51d5da0f39e4c1885357d3d4c9964d9",
|
828 |
+
"value": ""
|
829 |
+
}
|
830 |
+
},
|
831 |
+
"6aafd52b0e3e4e0183b1666ad1e8a448": {
|
832 |
+
"model_module": "@jupyter-widgets/controls",
|
833 |
+
"model_module_version": "1.5.0",
|
834 |
+
"model_name": "ProgressStyleModel",
|
835 |
+
"state": {
|
836 |
+
"_model_module": "@jupyter-widgets/controls",
|
837 |
+
"_model_module_version": "1.5.0",
|
838 |
+
"_model_name": "ProgressStyleModel",
|
839 |
+
"_view_count": null,
|
840 |
+
"_view_module": "@jupyter-widgets/base",
|
841 |
+
"_view_module_version": "1.2.0",
|
842 |
+
"_view_name": "StyleView",
|
843 |
+
"bar_color": null,
|
844 |
+
"description_width": ""
|
845 |
+
}
|
846 |
},
|
847 |
+
"80137fc11d4b4e518d8c8957ca5461b1": {
|
848 |
+
"model_module": "@jupyter-widgets/base",
|
849 |
+
"model_module_version": "1.2.0",
|
850 |
+
"model_name": "LayoutModel",
|
851 |
+
"state": {
|
852 |
+
"_model_module": "@jupyter-widgets/base",
|
853 |
+
"_model_module_version": "1.2.0",
|
854 |
+
"_model_name": "LayoutModel",
|
855 |
+
"_view_count": null,
|
856 |
+
"_view_module": "@jupyter-widgets/base",
|
857 |
+
"_view_module_version": "1.2.0",
|
858 |
+
"_view_name": "LayoutView",
|
859 |
+
"align_content": null,
|
860 |
+
"align_items": null,
|
861 |
+
"align_self": null,
|
862 |
+
"border": null,
|
863 |
+
"bottom": null,
|
864 |
+
"display": null,
|
865 |
+
"flex": null,
|
866 |
+
"flex_flow": null,
|
867 |
+
"grid_area": null,
|
868 |
+
"grid_auto_columns": null,
|
869 |
+
"grid_auto_flow": null,
|
870 |
+
"grid_auto_rows": null,
|
871 |
+
"grid_column": null,
|
872 |
+
"grid_gap": null,
|
873 |
+
"grid_row": null,
|
874 |
+
"grid_template_areas": null,
|
875 |
+
"grid_template_columns": null,
|
876 |
+
"grid_template_rows": null,
|
877 |
+
"height": null,
|
878 |
+
"justify_content": null,
|
879 |
+
"justify_items": null,
|
880 |
+
"left": null,
|
881 |
+
"margin": null,
|
882 |
+
"max_height": null,
|
883 |
+
"max_width": null,
|
884 |
+
"min_height": null,
|
885 |
+
"min_width": null,
|
886 |
+
"object_fit": null,
|
887 |
+
"object_position": null,
|
888 |
+
"order": null,
|
889 |
+
"overflow": null,
|
890 |
+
"overflow_x": null,
|
891 |
+
"overflow_y": null,
|
892 |
+
"padding": null,
|
893 |
+
"right": null,
|
894 |
+
"top": null,
|
895 |
+
"visibility": null,
|
896 |
+
"width": null
|
897 |
+
}
|
898 |
},
|
899 |
+
"9f9427eb6a644166906bb321f13eaf48": {
|
900 |
+
"model_module": "@jupyter-widgets/controls",
|
901 |
+
"model_module_version": "1.5.0",
|
902 |
+
"model_name": "FloatProgressModel",
|
903 |
+
"state": {
|
904 |
+
"_dom_classes": [],
|
905 |
+
"_model_module": "@jupyter-widgets/controls",
|
906 |
+
"_model_module_version": "1.5.0",
|
907 |
+
"_model_name": "FloatProgressModel",
|
908 |
+
"_view_count": null,
|
909 |
+
"_view_module": "@jupyter-widgets/controls",
|
910 |
+
"_view_module_version": "1.5.0",
|
911 |
+
"_view_name": "ProgressView",
|
912 |
+
"bar_style": "success",
|
913 |
+
"description": "",
|
914 |
+
"description_tooltip": null,
|
915 |
+
"layout": "IPY_MODEL_c4ceff5437e0470089c161e21488d2a7",
|
916 |
+
"max": 1,
|
917 |
+
"min": 0,
|
918 |
+
"orientation": "horizontal",
|
919 |
+
"style": "IPY_MODEL_6aafd52b0e3e4e0183b1666ad1e8a448",
|
920 |
+
"value": 1
|
921 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
922 |
},
|
923 |
+
"a4a232c5b5e1493897e9acdd25b8efd4": {
|
924 |
+
"model_module": "@jupyter-widgets/controls",
|
925 |
+
"model_module_version": "1.5.0",
|
926 |
+
"model_name": "HTMLModel",
|
927 |
+
"state": {
|
928 |
+
"_dom_classes": [],
|
929 |
+
"_model_module": "@jupyter-widgets/controls",
|
930 |
+
"_model_module_version": "1.5.0",
|
931 |
+
"_model_name": "HTMLModel",
|
932 |
+
"_view_count": null,
|
933 |
+
"_view_module": "@jupyter-widgets/controls",
|
934 |
+
"_view_module_version": "1.5.0",
|
935 |
+
"_view_name": "HTMLView",
|
936 |
+
"description": "",
|
937 |
+
"description_tooltip": null,
|
938 |
+
"layout": "IPY_MODEL_80137fc11d4b4e518d8c8957ca5461b1",
|
939 |
+
"placeholder": "β",
|
940 |
+
"style": "IPY_MODEL_c4236d507b354bff830620a8bde32191",
|
941 |
+
"value": "β174/?β[00:31<00:00,ββ6.30it/s]"
|
942 |
+
}
|
943 |
+
},
|
944 |
+
"b2e91819e1c94f28b7bbad66918cb797": {
|
945 |
+
"model_module": "@jupyter-widgets/base",
|
946 |
+
"model_module_version": "1.2.0",
|
947 |
+
"model_name": "LayoutModel",
|
948 |
+
"state": {
|
949 |
+
"_model_module": "@jupyter-widgets/base",
|
950 |
+
"_model_module_version": "1.2.0",
|
951 |
+
"_model_name": "LayoutModel",
|
952 |
+
"_view_count": null,
|
953 |
+
"_view_module": "@jupyter-widgets/base",
|
954 |
+
"_view_module_version": "1.2.0",
|
955 |
+
"_view_name": "LayoutView",
|
956 |
+
"align_content": null,
|
957 |
+
"align_items": null,
|
958 |
+
"align_self": null,
|
959 |
+
"border": null,
|
960 |
+
"bottom": null,
|
961 |
+
"display": null,
|
962 |
+
"flex": null,
|
963 |
+
"flex_flow": null,
|
964 |
+
"grid_area": null,
|
965 |
+
"grid_auto_columns": null,
|
966 |
+
"grid_auto_flow": null,
|
967 |
+
"grid_auto_rows": null,
|
968 |
+
"grid_column": null,
|
969 |
+
"grid_gap": null,
|
970 |
+
"grid_row": null,
|
971 |
+
"grid_template_areas": null,
|
972 |
+
"grid_template_columns": null,
|
973 |
+
"grid_template_rows": null,
|
974 |
+
"height": null,
|
975 |
+
"justify_content": null,
|
976 |
+
"justify_items": null,
|
977 |
+
"left": null,
|
978 |
+
"margin": null,
|
979 |
+
"max_height": null,
|
980 |
+
"max_width": null,
|
981 |
+
"min_height": null,
|
982 |
+
"min_width": null,
|
983 |
+
"object_fit": null,
|
984 |
+
"object_position": null,
|
985 |
+
"order": null,
|
986 |
+
"overflow": null,
|
987 |
+
"overflow_x": null,
|
988 |
+
"overflow_y": null,
|
989 |
+
"padding": null,
|
990 |
+
"right": null,
|
991 |
+
"top": null,
|
992 |
+
"visibility": null,
|
993 |
+
"width": null
|
994 |
+
}
|
995 |
},
|
996 |
+
"c4236d507b354bff830620a8bde32191": {
|
997 |
+
"model_module": "@jupyter-widgets/controls",
|
998 |
+
"model_module_version": "1.5.0",
|
999 |
+
"model_name": "DescriptionStyleModel",
|
1000 |
+
"state": {
|
1001 |
+
"_model_module": "@jupyter-widgets/controls",
|
1002 |
+
"_model_module_version": "1.5.0",
|
1003 |
+
"_model_name": "DescriptionStyleModel",
|
1004 |
+
"_view_count": null,
|
1005 |
+
"_view_module": "@jupyter-widgets/base",
|
1006 |
+
"_view_module_version": "1.2.0",
|
1007 |
+
"_view_name": "StyleView",
|
1008 |
+
"description_width": ""
|
1009 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1010 |
},
|
1011 |
+
"c4ceff5437e0470089c161e21488d2a7": {
|
1012 |
+
"model_module": "@jupyter-widgets/base",
|
1013 |
+
"model_module_version": "1.2.0",
|
1014 |
+
"model_name": "LayoutModel",
|
1015 |
+
"state": {
|
1016 |
+
"_model_module": "@jupyter-widgets/base",
|
1017 |
+
"_model_module_version": "1.2.0",
|
1018 |
+
"_model_name": "LayoutModel",
|
1019 |
+
"_view_count": null,
|
1020 |
+
"_view_module": "@jupyter-widgets/base",
|
1021 |
+
"_view_module_version": "1.2.0",
|
1022 |
+
"_view_name": "LayoutView",
|
1023 |
+
"align_content": null,
|
1024 |
+
"align_items": null,
|
1025 |
+
"align_self": null,
|
1026 |
+
"border": null,
|
1027 |
+
"bottom": null,
|
1028 |
+
"display": null,
|
1029 |
+
"flex": null,
|
1030 |
+
"flex_flow": null,
|
1031 |
+
"grid_area": null,
|
1032 |
+
"grid_auto_columns": null,
|
1033 |
+
"grid_auto_flow": null,
|
1034 |
+
"grid_auto_rows": null,
|
1035 |
+
"grid_column": null,
|
1036 |
+
"grid_gap": null,
|
1037 |
+
"grid_row": null,
|
1038 |
+
"grid_template_areas": null,
|
1039 |
+
"grid_template_columns": null,
|
1040 |
+
"grid_template_rows": null,
|
1041 |
+
"height": null,
|
1042 |
+
"justify_content": null,
|
1043 |
+
"justify_items": null,
|
1044 |
+
"left": null,
|
1045 |
+
"margin": null,
|
1046 |
+
"max_height": null,
|
1047 |
+
"max_width": null,
|
1048 |
+
"min_height": null,
|
1049 |
+
"min_width": null,
|
1050 |
+
"object_fit": null,
|
1051 |
+
"object_position": null,
|
1052 |
+
"order": null,
|
1053 |
+
"overflow": null,
|
1054 |
+
"overflow_x": null,
|
1055 |
+
"overflow_y": null,
|
1056 |
+
"padding": null,
|
1057 |
+
"right": null,
|
1058 |
+
"top": null,
|
1059 |
+
"visibility": null,
|
1060 |
+
"width": "20px"
|
1061 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1062 |
},
|
1063 |
+
"f51d5da0f39e4c1885357d3d4c9964d9": {
|
1064 |
+
"model_module": "@jupyter-widgets/controls",
|
1065 |
+
"model_module_version": "1.5.0",
|
1066 |
+
"model_name": "DescriptionStyleModel",
|
1067 |
+
"state": {
|
1068 |
+
"_model_module": "@jupyter-widgets/controls",
|
1069 |
+
"_model_module_version": "1.5.0",
|
1070 |
+
"_model_name": "DescriptionStyleModel",
|
1071 |
+
"_view_count": null,
|
1072 |
+
"_view_module": "@jupyter-widgets/base",
|
1073 |
+
"_view_module_version": "1.2.0",
|
1074 |
+
"_view_name": "StyleView",
|
1075 |
+
"description_width": ""
|
1076 |
+
}
|
1077 |
}
|
1078 |
+
}
|
1079 |
}
|
1080 |
+
},
|
1081 |
+
"nbformat": 4,
|
1082 |
+
"nbformat_minor": 0
|
1083 |
+
}
|
notebooks/04-RAG_with_VectorStore.ipynb
CHANGED
@@ -285,7 +285,7 @@
|
|
285 |
"# Define a query engine that is responsible for retrieving related pieces of text,\n",
|
286 |
"# and using a LLM to formulate the final answer.\n",
|
287 |
"\n",
|
288 |
-
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo
|
289 |
"query_engine = index.as_query_engine(llm=llm)"
|
290 |
]
|
291 |
},
|
@@ -386,7 +386,7 @@
|
|
386 |
"source": [
|
387 |
"from langchain_openai import ChatOpenAI\n",
|
388 |
"# Initializing the LLM model\n",
|
389 |
-
"llm = ChatOpenAI(temperature=0, model=\"gpt-3.5-turbo
|
390 |
]
|
391 |
},
|
392 |
{
|
|
|
285 |
"# Define a query engine that is responsible for retrieving related pieces of text,\n",
|
286 |
"# and using a LLM to formulate the final answer.\n",
|
287 |
"\n",
|
288 |
+
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo\", max_tokens=512)\n",
|
289 |
"query_engine = index.as_query_engine(llm=llm)"
|
290 |
]
|
291 |
},
|
|
|
386 |
"source": [
|
387 |
"from langchain_openai import ChatOpenAI\n",
|
388 |
"# Initializing the LLM model\n",
|
389 |
+
"llm = ChatOpenAI(temperature=0, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
390 |
]
|
391 |
},
|
392 |
{
|
notebooks/05-Improve_Prompts_+_Add_Source.ipynb
CHANGED
@@ -82,7 +82,7 @@
|
|
82 |
"source": [
|
83 |
"from llama_index.llms.openai import OpenAI\n",
|
84 |
"\n",
|
85 |
-
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo
|
86 |
]
|
87 |
},
|
88 |
{
|
|
|
82 |
"source": [
|
83 |
"from llama_index.llms.openai import OpenAI\n",
|
84 |
"\n",
|
85 |
+
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
86 |
]
|
87 |
},
|
88 |
{
|
notebooks/06-Evaluate_RAG.ipynb
CHANGED
@@ -31,7 +31,7 @@
|
|
31 |
},
|
32 |
"outputs": [],
|
33 |
"source": [
|
34 |
-
"!pip install -q llama-index==0.10.
|
35 |
]
|
36 |
},
|
37 |
{
|
@@ -82,7 +82,7 @@
|
|
82 |
"source": [
|
83 |
"from llama_index.llms.openai import OpenAI\n",
|
84 |
"\n",
|
85 |
-
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo
|
86 |
]
|
87 |
},
|
88 |
{
|
@@ -168,7 +168,7 @@
|
|
168 |
"text": [
|
169 |
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
|
170 |
" Dload Upload Total Spent Left Speed\n",
|
171 |
-
"100 169k 100 169k 0 0
|
172 |
]
|
173 |
}
|
174 |
],
|
@@ -356,17 +356,10 @@
|
|
356 |
"name": "stderr",
|
357 |
"output_type": "stream",
|
358 |
"text": [
|
359 |
-
"/Users/
|
360 |
" from .autonotebook import tqdm as notebook_tqdm\n",
|
361 |
-
"Parsing nodes:
|
362 |
-
|
363 |
-
},
|
364 |
-
{
|
365 |
-
"name": "stderr",
|
366 |
-
"output_type": "stream",
|
367 |
-
"text": [
|
368 |
-
"Parsing nodes: 100%|ββββββββββ| 14/14 [00:00<00:00, 38.11it/s]\n",
|
369 |
-
"Generating embeddings: 100%|ββββββββββ| 108/108 [00:01<00:00, 75.25it/s]\n"
|
370 |
]
|
371 |
}
|
372 |
],
|
@@ -393,7 +386,7 @@
|
|
393 |
{
|
394 |
"data": {
|
395 |
"text/plain": [
|
396 |
-
"TextNode(id_='4ab5bd897f01474fc9b0049f95e31edae3ccd9e74d0f0acd3932b50a74d608b6', embedding=[-0.022741511464118958, 0.010871483013033867, -0.017776913940906525, -0.013163917697966099, 0.004405552521348, 0.013564742170274258, -0.02842337265610695, 0.025638697668910027, -0.03861978277564049, -0.02869058959186077, 0.02842337265610695, 0.028282733634114265, -0.028310861438512802, -0.014127302914857864, 0.008079776540398598, 0.01933801919221878, 0.014879727736115456, 0.0029657490085810423, 0.004658704623579979, -0.004802860785275698, -0.0027108388021588326, 8.63068999024108e-05, -0.006613602861762047, -0.01984432525932789, 0.004848569165915251, 0.026398155838251114, 0.025976235046982765, -0.028887486085295677, -0.017312802374362946, 0.001968962140381336, 0.01291076559573412, 0.014056982472538948, -0.029225021600723267, -0.00135805644094944, -0.013853054493665695, -0.017256546765565872, 0.01682056114077568, -0.0057416339404881, 0.035750724375247955, -0.010927739553153515, 0.014296070672571659, 0.007974295876920223, 0.006483510602265596, -0.030462656170129776, -0.027888940647244453, -8.394458563998342e-05, 0.022572742775082588, -0.02655285969376564, -0.025498058646917343, 0.0010969931026920676, -0.004036372061818838, 0.04545489326119423, -0.03299417719244957, 0.019858388230204582, 0.0024524126201868057, -0.004117240197956562, 0.006311226636171341, -0.0013053163420408964, 0.02604655548930168, 0.013824926689267159, -0.0024770244490355253, -0.004141852259635925, -0.017819106578826904, 0.021278854459524155, -0.010730843059718609, -0.00561505788937211, -0.030575167387723923, 0.033022306859493256, 0.008930649608373642, -0.008635304868221283, -0.0006724356790073216, 0.01545635238289833, 0.008473568595945835, -0.022910280153155327, 0.028831230476498604, 0.007833655923604965, -0.018578562885522842, -0.02040688507258892, -0.024935496971011162, 0.006392094772309065, 0.017003392800688744, 0.003584565594792366, -0.001132153207436204, 0.03456934913992882, 0.017383122816681862, -0.005024369340389967, 0.02116634137928486, -0.019155187532305717, -0.011982540600001812, -0.027087291702628136, -0.0009071289678104222, -0.0011550071649253368, 0.05105237290263176, 0.022249270230531693, -0.031644031405448914, 0.0063604507595300674, -0.01480940729379654, 0.014000726863741875, -0.020899126306176186, -0.021827351301908493, -0.025287097319960594, -0.019112994894385338, -0.018086323514580727, -0.019731812179088593, -0.015400095842778683, 0.010189378634095192, 0.01698932982981205, 0.021672645583748817, 0.0048942770808935165, 0.03127836808562279, -0.01703152246773243, 0.045567408204078674, 0.005386517383158207, -0.04013869911432266, -0.017354993149638176, 0.0065186708234250546, 0.027720171958208084, -0.010751939378678799, -0.009275217540562153, 0.022010182961821556, 0.02680601179599762, 0.02210863120853901, 0.00830480083823204, -0.00379376788623631, 0.021025702357292175, 9.32290349737741e-05, -0.016398640349507332, -0.003577533643692732, -0.020055284723639488, 0.0017799768829718232, 0.023543160408735275, 0.024190105497837067, 0.03380989283323288, 0.004201624542474747, -0.03794471174478531, 0.02441512979567051, -0.02019592560827732, -0.013227205723524094, -0.02594810724258423, -0.01770659349858761, -0.0036144517362117767, 0.02594810724258423, 0.003022005083039403, 0.013613966293632984, -0.020055284723639488, 0.017987875267863274, 0.021278854459524155, 0.014401551336050034, 0.026398155838251114, 0.0005067440215498209, 0.005400581751018763, -0.03347235545516014, -0.021967990323901176, 0.011806740425527096, 0.002165858168154955, 0.014893791638314724, 0.019225507974624634, 0.006919495295733213, -0.01608923263847828, -0.0027723689563572407, -0.014992239885032177, 0.014253878965973854, -0.013473326340317726, 0.006068622227758169, 0.0272701233625412, 0.03181280195713043, 0.02984383888542652, -0.018128514289855957, 0.0013457504101097584, -0.017903489992022514, -0.03108147159218788, 0.013234238140285015, -0.044245388358831406, 0.02099757455289364, -0.0010732600931078196, 0.011982540600001812, 0.003305043326690793, -0.005488481838256121, -0.014978175051510334, -0.020294373854994774, 0.0017544857691973448, 0.001155886217020452, 0.0035634697414934635, 0.007165615446865559, -0.02210863120853901, -0.011391852051019669, 0.0019619299564510584, 0.010646458715200424, 0.0017035037744790316, -0.010899611748754978, 0.02902812696993351, 0.01720028929412365, -0.002190470229834318, -0.023754119873046875, -0.618816614151001, -0.032122209668159485, -0.0021482782904058695, -0.03226285055279732, -0.0014064015122130513, -0.01592046394944191, -0.01878952421247959, -0.005463869776576757, -0.02334626391530037, 0.03850727155804634, -0.021067893132567406, -0.003493149532005191, 0.010449563153088093, -0.0165674090385437, 0.002985086990520358, -0.023149367421865463, 0.0019021580228582025, -0.023121239617466927, 0.019689619541168213, 0.007320319768041372, -0.011398883536458015, -0.0023627544287592173, 0.0028514789883047342, -0.007242967374622822, -0.01711590588092804, -0.0023170465137809515, -0.01265761349350214, 0.00934553798288107, 0.009514305740594864, 0.01250994112342596, -0.04587681591510773, 0.019436467438936234, 0.004739572759717703, -0.026116875931620598, 0.04058874770998955, -0.008860329166054726, -0.01150436419993639, 0.01831134781241417, -0.0053126816637814045, 0.013993694446980953, -0.02372599206864834, -0.015779824927449226, 0.013262365944683552, 0.013494421727955341, -0.01517507154494524, 0.029337534680962563, 0.02411978505551815, -0.006427254527807236, -0.021714838221669197, -0.014049950987100601, 0.0036566436756402254, -5.878318552277051e-05, 0.020772550255060196, -0.008543889038264751, 0.001970720011740923, 0.012439620681107044, 0.04013869911432266, -0.011293403804302216, 0.003962535876780748, 0.005804921966046095, -0.0010213990462943912, 0.010632394813001156, -0.032544128596782684, -0.02804364450275898, -0.02646847628057003, 0.017622210085392, 0.006578442640602589, 0.013332685455679893, 0.0073695434257388115, 0.0006047526258043945, 0.00031116630998440087, 0.027607660740613937, 0.013093597255647182, -0.016243936493992805, -0.002934104995802045, 0.01480940729379654, 0.01035111490637064, -0.00815009605139494, 0.014092142693698406, 0.03189718350768089, 0.015779824927449226, -0.01521726418286562, 0.004880213178694248, -0.009225993417203426, 0.03718525543808937, 0.01163094025105238, -0.002315288409590721, -0.011497331783175468, 0.0270591638982296, 0.011201987974345684, 0.018902035430073738, 0.012179436162114143, -0.038141608238220215, -0.032769154757261276, 0.015386031940579414, 0.021321045234799385, -0.01732686534523964, 0.012109116651117802, 0.018930163234472275, -0.03200969845056534, -0.015245391987264156, -0.016961202025413513, 0.032206594944000244, 0.008782977238297462, 0.03366925194859505, 0.02770610898733139, -0.03808535262942314, -0.008248544298112392, 0.0160470400005579, -0.03400678560137749, -0.01009796280413866, 0.0051861051470041275, -0.016061104834079742, -0.016764305531978607, 0.019183315336704254, -0.02514645829796791, -0.0013334443792700768, -0.016975264996290207, -0.003433377481997013, -0.008297768421471119, 0.0320940800011158, -0.013698350638151169, 0.009036129340529442, -0.017144033685326576, 0.01900048367679119, 0.02634189836680889, -0.008965808898210526, -0.024808920919895172, -0.014049950987100601, 0.018887972459197044, -0.014739086851477623, -0.01082225888967514, 0.012481813319027424, -0.01566731184720993, 0.003106389194726944, 0.01310766115784645, 0.044245388358831406, 0.005010304972529411, 0.007320319768041372, -0.013803830370306969, -0.026876332238316536, -0.009127545170485973, 0.01860669068992138, -0.004475872498005629, -0.03915421664714813, -0.031193984672427177, -0.01916925236582756, 0.008107904344797134, 0.007063651457428932, -0.006574926897883415, -0.014795343391597271, -0.008993937633931637, 0.009148641489446163, 0.018986418843269348, 0.0015171555569395423, -0.011820804327726364, -0.005783826112747192, -0.030068863183259964, -0.0043879724107682705, -0.01642676815390587, 0.008368088863790035, 4.3263327825115994e-05, -0.006859723012894392, 0.0019759940914809704, 0.004169980529695749, -0.010442530736327171, -0.022896215319633484, 0.028029581531882286, -0.025498058646917343, -0.021096020936965942, -0.004581352695822716, -0.03518816456198692, 0.006782371085137129, 0.011961444281041622, -0.014007758349180222, 0.02420416846871376, -0.003804316045716405, -0.00504898140206933, -0.0074961199425160885, -0.001010851003229618, 0.003296253504231572, 0.031109599396586418, 0.0004518064670264721, -0.02177109383046627, 0.0158360805362463, 0.017622210085392, 0.03760717436671257, 0.014457806944847107, -0.021053830161690712, 0.010850387625396252, 0.016511153429746628, 0.01686275377869606, -0.022994663566350937, 0.03375363349914551, -0.017214354127645493, 0.011623907834291458, 0.0070601352490484715, -0.01805819384753704, 0.013156885281205177, 0.0377478152513504, 0.00894471351057291, 0.0156251210719347, -0.016722112894058228, -0.010238602757453918, 0.010533946566283703, -0.030153246596455574, 0.012306013144552708, -0.019014548510313034, -0.010393306612968445, -0.005608025938272476, 0.003994180355221033, -0.00656437873840332, -0.008740784600377083, -0.012207564897835255, 0.0011330321431159973, 0.031475264579057693, -0.005491997580975294, 0.007183195557445288, -0.02642628364264965, 0.010674587450921535, 0.003213627263903618, 0.016919009387493134, -0.01376867014914751, 0.012678708881139755, -0.010801163502037525, 0.004704413004219532, -0.019689619541168213, 0.020378757268190384, -0.007545343600213528, -0.03144713491201401, 0.004500484559684992, 0.00932444166392088, 0.0327128991484642, 0.004528612829744816, 0.023107176646590233, -0.017833169549703598, 0.022769639268517494, 0.0011602812446653843, 0.044414158910512924, -0.005952594336122274, -0.00727812759578228, 0.003642579773440957, -4.436207746039145e-05, -0.03068768046796322, 0.012629484757781029, -0.01033001858741045, 0.038141608238220215, -0.014471870847046375, -0.017312802374362946, -0.005414645653218031, -0.036482054740190506, 0.011680164374411106, -0.0024383484851568937, 0.00471496069803834, 0.029309406876564026, -0.009830745868384838, 0.004349296446889639, 0.0031169371213763952, 0.015287583693861961, 0.0036671918351203203, -0.013086565770208836, 0.0012965262867510319, -0.0029358630999922752, 0.014978175051510334, 0.021883606910705566, -0.005231813527643681, -0.00420514028519392, -0.011427012272179127, -0.007165615446865559, -0.0137897664681077, -0.020842868834733963, -0.01005577016621828, 0.024612026289105415, -0.040532488375902176, 0.042838986963033676, 0.020856933668255806, 0.004560256842523813, 0.014725022949278355, -0.003726963885128498, 0.03170028701424599, -0.024851113557815552, -0.03752278909087181, 0.015076623298227787, -0.00843137688934803, -0.032037824392318726, -0.019577108323574066, -0.018705138936638832, 0.007657855749130249, -0.0017035037744790316, 0.00044235720997676253, -0.009092384949326515, -0.008635304868221283, -0.01237633265554905, 0.012460717000067234, 0.00033292159787379205, 0.008093840442597866, 0.015146943740546703, -0.0065995389595627785, 0.00830480083823204, -0.020983509719371796, 0.02028030902147293, 0.011834868229925632, -0.00966900959610939, -0.005361905321478844, 0.01197550818324089, -0.01579388789832592, -0.03364112228155136, 0.0001978850777959451, 0.0003425906179472804, -0.03347235545516014, 0.003646095748990774, -0.007545343600213528, 0.008157128468155861, -0.04098253697156906, 0.015822015702724457, 0.012481813319027424, 0.020603781566023827, 0.0033683315850794315, 0.019239572808146477, 0.013185014016926289, -0.008129000663757324, 0.001795798889361322, -0.010787099599838257, 0.01933801919221878, 0.04838021099567413, 0.01873326674103737, 0.0039273761212825775, 0.0011312741553410888, -0.005878758151084185, 0.003296253504231572, -0.024837050586938858, 0.0017369057750329375, 0.0009800860425457358, 0.010836322791874409, -0.0165674090385437, -0.019323956221342087, 0.018241027370095253, 0.001310590305365622, 0.04008243978023529, 0.0030817771330475807, 0.010301890783011913, -0.014239815063774586, -0.009514305740594864, -0.012974053621292114, 0.014570319093763828, -0.002651066752150655, 0.009929194115102291, 0.024358872324228287, 0.011729388497769833, -0.009739330038428307, 0.008143064565956593, 0.02847963012754917, -0.006339354440569878, -0.02168671041727066, 0.01212318055331707, 0.004612996708601713, 0.008768913336098194, 0.008614208549261093, -0.016792433336377144, 0.01146217156201601, -0.0003208353300578892, -0.0036918038967996836, 0.01391634251922369, 0.015090687200427055, 0.004380940459668636, 0.02403540164232254, 0.008192288689315319, 0.013262365944683552, 0.009619786404073238, -0.014950047247111797, -0.003923859912902117, 0.010154218412935734, -0.006958171259611845, -0.03935111314058304, 0.0036812557373195887, 0.004398520570248365, -0.04084189981222153, -0.001738663762807846, 0.028451502323150635, 0.00656437873840332, 0.0013360814191401005, -0.011019155383110046, -0.004669252783060074, -0.03513190895318985, -0.006300678476691246, -0.03051891177892685, 0.007559407968074083, -0.015315711498260498, -0.003642579773440957, -0.0036953198723495007, -0.003934408072382212, 0.0012437863042578101, -0.016511153429746628, -0.0004693864902947098, -0.01644083298742771, -0.010871483013033867, -0.05805625393986702, -0.013649126514792442, -0.0014090384356677532, -0.004268428310751915, 0.010885546915233135, -0.002598326653242111, 0.0035740176681429148, 0.021799223497509956, -0.008677496574819088, -0.02057565376162529, 0.002466476522386074, -0.019999029114842415, 0.0057416339404881, -0.023275943472981453, -0.003797283861786127, -0.020674102008342743, -0.012531036511063576, 0.022558679804205894, -0.008881425485014915, -0.014092142693698406, -0.020097477361559868, 0.0024207686074078083, 0.005583413876593113, 0.02420416846871376, 0.015990784391760826, 0.006757759023457766, 0.02330407127737999, -0.023191560059785843, -0.0009449259960092604, -0.018044130876660347, -0.019956836476922035, -0.035835109651088715, 0.0031257271766662598, 0.008550920523703098, 0.03538506105542183, 0.008515761233866215, 0.010147186927497387, -0.020645974203944206, 0.0007199017563834786, -0.014120270498096943, 0.01212318055331707, -0.0017773398431017995, 0.01248884480446577, -0.014106206595897675, 0.01186299603432417, -0.003447441617026925, -0.004848569165915251, -0.029900094494223595, 0.017003392800688744, -0.03018137440085411, 0.020392820239067078, 0.01030892226845026, 0.010140154510736465, 0.017186226323246956, 0.022657128050923347, 0.001765912864357233, -0.045398637652397156, 0.0003348993486724794, 0.001233238261193037, 0.014155430719256401, -0.003814863972365856, -0.011419979855418205, -0.0023838505148887634, -0.014570319093763828, -0.015231328085064888, 0.009099417366087437, -0.02487924136221409, 0.0063604507595300674, -0.015118815936148167, -0.004324684385210276, -0.009317409247159958, -0.01492191944271326, 0.004757152870297432, -0.02919689379632473, -0.009401793591678143, 0.029309406876564026, 0.017383122816681862, 0.031137729063630104, -0.013494421727955341, 0.010386275127530098, -0.03811347857117653, -0.016412705183029175, 0.0005243240157142282, -0.02361348085105419, -0.010744906961917877, -0.005970173981040716, 0.011722356081008911, 0.016539281234145164, 0.021785158663988113, 0.006036978214979172, 0.018283218145370483, 0.01575169712305069, -0.001937318011187017, -0.0064307707361876965, -0.009929194115102291, 0.00021964035113342106, -0.02001309208571911, -0.013466293923556805, 0.012650581076741219, -0.0034861175809055567, 0.009844809770584106, 0.004764184821397066, -0.0019654459320008755, 0.002165858168154955, -0.015118815936148167, -0.00407504802569747, -0.0183535385876894, -0.04098253697156906, -0.021335110068321228, 0.008550920523703098, -0.0065010907128453255, -0.002301224274560809, -0.04643937572836876, -0.017790978774428368, 0.01856449991464615, 0.008438408374786377, 0.014626574702560902, 0.011912220157682896, 0.03704461455345154, -0.028887486085295677, -0.0025860206224024296, 0.030378270894289017, 0.016975264996290207, -0.00828370451927185, -0.007063651457428932, -0.043907854706048965, 0.013909310102462769, 0.015203199349343777, 0.007179679349064827, 0.040448106825351715, 0.02629970759153366, -0.015639184042811394, 0.016876816749572754, 0.014141366817057133, 0.0032487872522324324, 0.010231570340692997, -0.004451260436326265, -0.010259699076414108, 0.0035828077234327793, -0.012263820506632328, -0.025118330493569374, -0.023768184706568718, -0.019239572808146477, 0.011047283187508583, 0.01329752616584301, 0.030631422996520996, -0.024921434000134468, -0.020730357617139816, 0.02372599206864834, 0.008958777412772179, 0.050827350467443466, 0.013311590068042278, 0.008396216668188572, 0.02378224954009056, 0.009549465961754322, -0.01113869994878769, 0.01109650731086731, 0.01238336507230997, -0.014106206595897675, 0.020645974203944206, 0.015822015702724457, 0.002637002617120743, -0.009788554161787033, 0.012446653097867966, 0.010315954685211182, -0.03935111314058304, -0.04860523343086243, 0.010034674778580666, 0.02129291743040085, 0.0055060614831745625, -0.03589136525988579, -0.0300969909876585, -0.02510426566004753, -0.0009765700669959188, -0.02535741776227951, 0.023163432255387306, 0.009992482140660286, -0.008185256272554398, 0.010998059064149857, 0.008881425485014915, 0.010119058191776276, -0.0005753060686402023, -0.004873181227594614, 0.021714838221669197, 0.004651672672480345, 0.0014406824484467506, -0.0032030793372541666, 0.010168282315135002, -0.006128394510596991, 0.03760717436671257, -0.008930649608373642, 0.011968476697802544, 0.010428466834127903, -0.0013633304042741656, 0.0061811343766748905, -0.008192288689315319, 0.004426648374646902, 0.03693210333585739, -0.03552570194005966, -0.011110571213066578, -0.008241512812674046, -0.016187680885195732, 0.016243936493992805, -0.015892336145043373, 0.014049950987100601, -0.004612996708601713, -0.01374757383018732, 0.0036777397617697716, 0.023571288213133812, 0.024021336808800697, -0.03181280195713043, 0.006944107357412577, 0.0028690588660538197, -0.03240348771214485, -0.027002908289432526, 0.005797890014946461, 0.03257225826382637, -0.0371289998292923, 0.007854752242565155, 0.008916584774851799, -0.0213913656771183, 0.021278854459524155, 0.021025702357292175, -0.003814863972365856, -0.029421918094158173, 0.03231910616159439, -0.03386614844202995, 0.02189766988158226, 0.0010591960744932294, -0.010400339029729366, -0.026651307940483093, -0.001455625519156456, -0.015273519791662693, -0.029253149405121803, 0.004468840546905994, -0.025413675233721733, -0.022094566375017166, -0.011448107659816742, 0.01690494641661644, 0.0065714106895029545, -0.010217506438493729, 0.01355067826807499, 0.003635547822341323, 0.0031116632744669914, -0.001038100104779005, -0.01575169712305069, -0.00142222351860255, 0.023191560059785843, 0.000530477031134069, 0.003885183949023485, 0.030575167387723923, -0.003380637615919113, 0.011926284059882164, -0.013958534225821495, -0.00555880181491375, -0.009486177936196327, -0.057606205344200134, -0.020674102008342743, 0.009493209421634674, 0.001775581855326891, -7.636320515302941e-05, 0.001283341320231557, -0.01648302562534809, -0.01020344253629446, -0.01263651717454195, -0.0020234601106494665, 0.010372210294008255, 0.0027477568946778774, 0.007390639744699001, 0.023360328748822212, -0.00031160583603195846, 0.008614208549261093, -0.01801600307226181, -0.02074442058801651, -0.019014548510313034, -0.003157371189445257, -0.03189718350768089, -0.018620755523443222, -0.03366925194859505, 0.05063045397400856, -0.006374514661729336, -0.03876042366027832, -0.02122259885072708, -0.014992239885032177, -0.03825411945581436, -0.020730357617139816, 0.002598326653242111, 0.018114451318979263, 0.012531036511063576, 0.016933074221014977, 0.0025719567202031612, 0.036003876477479935, 0.006339354440569878, 0.0050630453042685986, -0.027481084689497948, 0.012685741297900677, -0.000674193724989891, -0.012917797081172466, 0.01278418954461813, 0.01776285097002983, -0.02103976532816887, 0.018536372110247612, 0.012031764723360538, -0.02783268503844738, -0.024429192766547203, 0.02701697126030922, -0.01521726418286562, -0.009901066310703754, 0.022038310766220093, -0.008867361582815647, 0.007046071346849203, -0.012650581076741219, 0.020435012876987457, -0.03116585686802864, -0.009493209421634674, 0.026398155838251114, -0.006409674417227507, 0.016272064298391342, -0.014781279489398003, 0.0174112506210804, 0.0093314740806818, 0.008804073557257652, 0.016314256936311722, -0.012594325467944145, 0.00619871448725462, 0.004686832893639803, 0.043823469430208206, 0.01959117315709591, 0.01073787547647953, 0.029393790289759636, -0.01634238474071026, -0.0015250665601342916, -0.007678952068090439, 0.015090687200427055, 0.0007809923263266683, -0.00855795294046402, 0.04354218766093254, -0.016511153429746628, 0.00981668196618557, -0.010133122093975544, 0.002937620971351862, -0.02250242419540882, -0.017228417098522186, -0.016272064298391342, -0.0027917069382965565, -0.022685255855321884, 0.014246846549212933, 0.019872453063726425, -0.022164886817336082, -0.0031608871649950743, -0.012931860983371735, 0.02258680760860443, 0.0036707078106701374, -0.01404291857033968, -0.005818985868245363, -0.0012341173132881522, -0.003450957592576742, 0.019239572808146477, 0.010126090608537197, -0.006184650585055351, 0.014324198476970196, 0.003595113754272461, -0.022136759012937546, 0.0158360805362463, 0.199258953332901, -0.031222112476825714, 0.013909310102462769, 0.02873278222978115, 0.01715809851884842, -0.016637729480862617, 0.04435790330171585, 0.007981328293681145, 0.001445077476091683, -0.004553224891424179, 0.006673374678939581, 0.005931498017162085, -0.016328321769833565, 0.00015118815645109862, 0.01912705972790718, -0.026327835395932198, -0.021588262170553207, -0.035919494926929474, -0.017861299216747284, -0.00420514028519392, 0.005949078127741814, 0.0009370149928145111, -0.00689488323405385, -0.022572742775082588, -0.0030677132308483124, 0.005235329270362854, 3.282519173808396e-05, -0.0031485813669860363, 0.01869107596576214, 0.0013018003664910793, -0.01660960167646408, 0.005207201465964317, -0.008368088863790035, 0.0019197380170226097, 0.00042521668365225196, -0.00966900959610939, 0.010379242710769176, -0.0004133501788601279, 0.006100266240537167, 0.024738602340221405, 0.02189766988158226, 0.022136759012937546, 0.0036812557373195887, -0.025301162153482437, 0.01545635238289833, 0.011363723315298557, -0.003892216132953763, 0.008593113161623478, 0.008009456098079681, 0.007341415621340275, -0.022558679804205894, 0.022657128050923347, 0.023233752697706223, 0.020842868834733963, -0.006497574504464865, 0.0011752241989597678, -0.01963336393237114, 0.015090687200427055, 0.00044389546383172274, -0.004852084908634424, -0.027115419507026672, -0.008501696400344372, 0.00033907461329363286, 0.02399320900440216, -0.010442530736327171, 0.012242725118994713, -0.007510183844715357, -0.023922888562083244, 0.007875848561525345, -0.02911251038312912, -0.011954412795603275, -0.014865663833916187, 0.00011613799870247021, -0.011574683710932732, -0.019830260425806046, -0.03887293487787247, 0.021841414272785187, 0.028015516698360443, 0.0007084747194312513, 0.04874587431550026, -0.003790251910686493, -0.03906983137130737, 0.004268428310751915, -0.012038796208798885, 0.005245877429842949, -0.023669736459851265, 0.009394762106239796, -0.015273519791662693, -0.021616389974951744, -0.011546555906534195, -0.016722112894058228, -0.0095424335449934, 0.004212172236293554, 0.025160521268844604, -0.00016404355119448155, 0.004493452608585358, 0.007671920116990805, 0.005734601989388466, -0.010660522617399693, -0.03116585686802864, -0.007249999325722456, 0.05923762917518616, 0.021714838221669197, 0.0031749513000249863, -0.0006869392236694694, 0.01933801919221878, -0.002934104995802045, 0.000356215110514313, -0.0023064983543008566, 0.0006966082146391273, 0.009640881791710854, -0.027903005480766296, 0.011201987974345684, 0.003617967711761594, -0.0031151792500168085, 0.011989572085440159, 0.010927739553153515, -0.009753393940627575, 0.016159553080797195, -0.009992482140660286, -0.007200775668025017, -0.022052375599741936, -0.005903370212763548, 0.011427012272179127, -0.00012185150262666866, -0.02714354731142521, 0.0069792671129107475, 0.0008552678627893329, -0.027860812842845917, 0.017186226323246956, 0.0003729161398950964, -0.03982928767800331, 0.009605721570551395, 0.003660159884020686, 0.0006271671736612916, -0.008593113161623478, 0.014654703438282013, -0.006374514661729336, -0.02860620617866516, 0.013628030195832253, -0.008782977238297462, 0.024597961455583572, 0.004169980529695749, -0.021757030859589577, 0.014324198476970196, -0.014106206595897675, 0.0022766124457120895, 0.01530164759606123, -0.013044373132288456, -0.020125605165958405, -0.01980213262140751, 0.007995392195880413, 0.005274005234241486, 0.009443986229598522, -0.0011945621808990836, 0.024133849889039993, -0.011968476697802544, -0.0006983662024140358, 0.022980600595474243, 0.008607177063822746, -0.028578078374266624, 0.00297278119251132, 0.01558292843401432, 0.007042555138468742, -0.016032977029681206, -0.006543282885104418, -0.180806964635849, -0.014753151684999466, 0.011553588323295116, -0.04022308066487312, 0.018381666392087936, 0.005629121791571379, 0.012967021204531193, 0.008325896225869656, -0.011187923140823841, 0.001034584129229188, 0.021714838221669197, -0.0183535385876894, -0.0046270606108009815, -0.005984238348901272, -0.0009106449433602393, 0.00826260820031166, -0.008438408374786377, 0.009809650480747223, 0.011884092353284359, 0.0008056043297983706, 0.03127836808562279, -0.026876332238316536, 0.00981668196618557, -0.009465081617236137, 0.017523761838674545, 0.012334140948951244, 0.009190833196043968, 0.042276427149772644, -0.01736905798316002, -0.03099708817899227, -0.011265275999903679, -0.015034431591629982, 0.028999997302889824, 0.006212778389453888, 0.030968960374593735, 0.031193984672427177, 0.011490300297737122, -0.01967555657029152, -0.018578562885522842, -0.015653248876333237, 0.022375846281647682, 0.013424102216959, 0.023979144170880318, -0.008593113161623478, -0.032122209668159485, 0.007573471870273352, 0.007573471870273352, -0.021503878757357597, -0.0015022126026451588, -0.01291076559573412, 0.016398640349507332, 0.009718233719468117, 0.014654703438282013, -0.004286008421331644, 0.024865178391337395, 0.03085644729435444, -0.005695926025509834, 0.003632031846791506, -0.007123423274606466, -0.020224053412675858, -0.00035885212128050625, -0.0001596485381014645, 0.0007027612300589681, -0.0007317682611756027, 0.00857904925942421, -0.03496313840150833, -0.007819592021405697, 0.005207201465964317, -0.04025121033191681, 0.0018617239547893405, -0.03338797017931938, 0.003080019261687994, -0.028057709336280823, -0.013986662030220032, 0.027818620204925537, 0.038788553327322006, -0.030490783974528313, 0.01736905798316002, 0.04427351802587509, 0.008459504693746567, -0.019984964281320572, 0.0027477568946778774, -0.01874733157455921, 0.02129291743040085, -0.004099660087376833, 0.005516609642654657, 0.015934528782963753, 0.0254839938133955, -0.015245391987264156, -0.009183801710605621, 0.019619300961494446, -0.009844809770584106, 0.017397185787558556, -0.011827835813164711, -0.0007642912678420544, 0.01374757383018732, 0.010780067183077335, -0.03479437157511711, -0.0058717261999845505, -0.016468960791826248, 0.0074679916724562645, 0.0060123661532998085, -0.009289281442761421, -0.011012122966349125, 0.019956836476922035, 0.022136759012937546, -0.022952470928430557, 0.021025702357292175, 0.028324924409389496, -0.003278673393651843, -0.01950678788125515, -0.00892361719161272, 0.0023539643734693527, 0.003345477394759655, 0.0018441439606249332, -0.0009686590055935085, -0.018817652016878128, -0.028676524758338928, 0.03248787298798561, -0.0020093959756195545, 0.05136178061366081, -0.007967264391481876, 0.0026440348010510206, 0.02185547910630703, -0.009774490259587765, -0.03456934913992882, -0.10452375560998917, -0.03563821315765381, 0.018902035430073738, 0.03150339424610138, -0.016581473872065544, 0.03282541036605835, -0.005140397232025862, 0.04115130752325058, -0.00771411182358861, 0.03926672786474228, -0.005210717208683491, -0.004187560174614191, 0.023965081200003624, 0.016145488247275352, 0.014471870847046375, -0.011982540600001812, 0.000530477031134069, -0.015822015702724457, -0.027888940647244453, 0.029478173702955246, 0.017045585438609123, -0.01020344253629446, 0.01061129942536354, -0.03217846527695656, 0.01365615800023079, -0.020772550255060196, -0.038225989788770676, 0.019408339634537697, 0.005414645653218031, -0.003378879511728883, 0.012291948311030865, -0.0156251210719347, 0.008986905217170715, -0.016792433336377144, 0.011180891655385494, -0.004261396359652281, 0.015245391987264156, -0.019816195592284203, 0.015526671893894672, -0.00015261652879416943, -0.010252666659653187, 0.023022791370749474, 0.01214427687227726, -0.008775944821536541, -0.02531522698700428, 0.004595416598021984, -0.009310377761721611, 0.019070804119110107, 0.003340203547850251, -0.028156157582998276, -0.040194954723119736, -0.0027407249435782433, -0.048295825719833374, 0.008958777412772179, 0.013030309230089188, -0.010344082489609718, -0.0016797707648947835, 0.02539961040019989, -0.011005091480910778, -0.009261153638362885, -0.000408515683375299, -0.018423859030008316, -0.014078078791499138, 0.0028409308288246393, -0.014366391114890575, 0.006553830578923225, -0.008642337284982204, -0.024612026289105415, 0.02594810724258423, -0.004859116859734058, 0.00039313314482569695, 0.023374391719698906, -0.011834868229925632, 0.0035458896309137344, -0.01686275377869606, -0.006156522314995527, -0.000893064949195832, -0.016665857285261154, 0.0112230833619833, -0.0014740845654159784, -0.01797381043434143, -0.011441076174378395, 0.016848688945174217, -0.013613966293632984, -0.005066561046987772, 0.011427012272179127, -0.014710959047079086, -0.008396216668188572, 0.01022453885525465, -0.054062072187662125, -0.007320319768041372, 0.032544128596782684, 0.007116391323506832, -0.018030066043138504, 0.023177495226264, 0.0007840688340365887, -0.011623907834291458, 0.004841537214815617, 0.006086202338337898, 0.0004056589095853269, -0.02120853401720524, -0.02198205515742302, -0.07212026417255402, 0.019577108323574066, 0.0016832867404446006, -0.010147186927497387, 0.014028854668140411, -0.012812317349016666, 0.007517215795814991, -0.010491754859685898, 0.009753393940627575, 0.026524731889367104, -0.028099901974201202, 0.011933316476643085, -0.022938407957553864, -0.03403491526842117, -0.008853296749293804, -0.009366633370518684, 0.0188739076256752, -0.00919786561280489, 0.005080625414848328, -0.0015373725909739733, 0.032937921583652496, -0.025849658995866776, 0.025723082944750786, 0.018550435081124306, -0.0004966355045326054, -0.002341658342629671, -0.043907854706048965, 0.01406401488929987, -0.009633850306272507, -0.01587827317416668, 0.0070882635191082954, -0.014317166991531849, 0.013388941995799541, 0.014795343391597271, 0.001852933899499476, -0.016497088596224785, 8.790009451331571e-05, 0.026187194511294365, 0.007826624438166618, 0.03428806737065315, -0.013206109404563904, -0.04238893836736679, 0.015104752033948898, -0.005713506136089563, -0.0024524126201868057, -0.00817822478711605, -0.02246023155748844, -0.00890252087265253, 0.04624247923493385, 0.010533946566283703, 0.04199514910578728, 0.0017738238675519824, -0.019858388230204582, -0.050517939031124115, -0.011778612621128559, 0.0018582079792395234, 0.024654217064380646, -0.009999514557421207, 0.014204654842615128, 0.012685741297900677, 0.0377478152513504, 0.008037583902478218, 0.020603781566023827, -0.015020367689430714, -0.0038640880957245827, -0.014260910451412201, -0.004500484559684992, -0.008255576714873314, -0.0011620392324402928, -0.03234723210334778, 0.010140154510736465, -0.004039888270199299, 0.014851599000394344, -0.0011708291713148355, 0.0030677132308483124, -0.010062802582979202, 0.0013018003664910793, 0.014401551336050034, -0.01665179245173931, 0.01720028929412365, 0.018831714987754822, -0.024949561804533005, -0.002348690526559949, -0.0004386214422993362, 0.025596506893634796, 0.0001995332131627947, -0.019155187532305717, 0.007693015970289707, -0.015132879838347435, -0.0011708291713148355, 0.0023609965573996305, 0.0018248058622702956, -0.007042555138468742, 0.0190848670899868, 0.0018142579356208444, -0.018072258681058884, -0.0017878878861665726, -0.008508728817105293, 0.027438892051577568, -0.009043161757290363, 0.00010284310701536015, -0.010491754859685898, 0.00427897647023201, -0.007091779261827469, -0.008192288689315319, -0.009528369642794132, -0.0448923334479332, -0.021967990323901176, 0.03974490612745285, 0.03853540122509003, 0.015639184042811394, -0.009296313859522343, -0.012474780902266502, 0.0040680160745978355, -0.012664644978940487, 0.017045585438609123, -0.004521580878645182, -0.015132879838347435, -0.0247526653110981, 0.03341609984636307, 0.028718717396259308, 0.015596992336213589, 0.05344325676560402, 0.0001705261820461601, 0.020097477361559868, 0.006620634812861681, 0.030743936076760292, -0.0026739207096397877, 0.025554314255714417, 0.020252181217074394, -0.005562317557632923, -0.010815227404236794, -0.015104752033948898, -0.010147186927497387, -0.0056748297065496445, -0.013213141821324825, -0.020927254110574722, 0.016708049923181534, 0.012221628800034523, 0.09467894583940506, 0.01810038648545742, -0.012566196732223034, 0.009633850306272507, -0.009451017715036869, 0.010920707136392593, 0.008691561408340931, 0.022769639268517494, 0.0076648881658911705, -0.010878515429794788, -0.002415494527667761, -0.011659068055450916, -0.012559165246784687, -0.015132879838347435, 0.020800678059458733, -0.003934408072382212, -0.01071677915751934, 0.015639184042811394, 0.005646701902151108, -0.0022396943531930447, 0.04199514910578728, -0.012594325467944145, 0.006195198278874159, 0.005344325676560402, -0.012052860110998154, 0.022178951650857925, 0.029421918094158173, 0.0042367842979729176, 0.0032259332947432995, -0.018114451318979263, 0.03265664353966713, 0.018466051667928696, -0.05015227571129799, -0.019197380170226097, -0.009493209421634674, -0.008550920523703098, 0.004859116859734058, -0.013311590068042278, -0.005752182099968195, 0.005586929619312286, 0.005833050236105919, 0.0020709261298179626, -0.014338262379169464, -0.026918523013591766, 0.024991754442453384, -0.013072501868009567, -0.015146943740546703, -0.02002715691924095, -0.028057709336280823], metadata={'title': \"Beyond GPT-4: What's New?\", 'url': 'https://pub.towardsai.net/beyond-gpt-4-whats-new-cbd61a448eb9#dda8', 'source_name': 'towards_ai'}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='doc_0', node_type=<ObjectType.DOCUMENT: '4'>, metadata={'title': \"Beyond GPT-4: What's New?\", 'url': 'https://pub.towardsai.net/beyond-gpt-4-whats-new-cbd61a448eb9#dda8', 'source_name': 'towards_ai'}, hash='3b095b0e25cdf965d950cdbd7feb8024030e7645998c1a33dc4427affca624ab'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='e470fa0d001e50b3ec3088022462a94ea7c87dd80106411b7d120f90b379e977', node_type=<ObjectType.TEXT: '1'>, metadata={}, hash='71418de3d50e604c2581574f1abf2248e5cc3ab7c74a3182c37cb1152d0cfd21')}, text='LLM Variants and Meta\\'s Open Source Before shedding light on four major trends, I\\'d share the latest Meta\\'s Llama 2 and Code Llama. Meta\\'s Llama 2 represents a sophisticated evolution in LLMs. This suite spans models pretrained and fine-tuned across a parameter spectrum of 7 billion to 70 billion. A specialized derivative, Llama 2-Chat, has been engineered explicitly for dialogue-centric applications. Benchmarking revealed Llama 2\\'s superior performance over most extant open-source chat models. Human-centric evaluations, focusing on safety and utility metrics, positioned Llama 2-Chat as a potential contender against proprietary, closed-source counterparts. The development trajectory of Llama 2 emphasized rigorous fine-tuning methodologies. Meta\\'s transparent delineation of these processes aims to catalyze community-driven advancements in LLMs, underscoring a commitment to collaborative and responsible AI development. Code Llama is built on top of Llama 2 and is available in three models: Code Llama, the foundational code model;Codel Llama - Python specialized for Python;and Code Llama - Instruct, which is fine-tuned for understanding natural language instructions. Based on its benchmark testing, Code Llama outperformed state-of-the-art publicly available LLMs (except GPT-4) on code tasks. Llama 2, Llama 2-Chat, and Code Llama are key steps in LLM development but still have a way to go compared to GPT-4. Meta\\'s open access and commitment to improving these models promise transparent and faster LLM progress in the future. Please refer to the LLM and Llama variants below: From LLMs to Multimodal LLMs, like OpenAI\\'s ChatGPT (GPT-3.5), primarily focus on understanding and generating human language. They\\'ve been instrumental in tasks like text generation, translation, and even creative writing. However, their scope is limited to text. Enter multimodal models like GPT-4. These are a new breed of AI models that can understand and generate not just text, but also images, sounds, and potentially other types of data. The term \"multimodal\" refers to their ability to process multiple modes or', start_char_idx=0, end_char_idx=2117, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n')"
|
397 |
]
|
398 |
},
|
399 |
"execution_count": 12,
|
@@ -509,12 +502,12 @@
|
|
509 |
"Node ID\t f707756065d1f788b41fb97fcef81979e1fd241dbfa4034a24bec8e57b648482\n",
|
510 |
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
|
511 |
"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",
|
512 |
-
"Score\t 0.
|
513 |
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n",
|
514 |
"Node ID\t 636f98cf8754c3a4759da02aa11a3f2aa7cdeb848a4980ec99300ece4a2e92fd\n",
|
515 |
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
|
516 |
"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",
|
517 |
-
"Score\t 0.
|
518 |
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"
|
519 |
]
|
520 |
}
|
@@ -581,7 +574,7 @@
|
|
581 |
"name": "stderr",
|
582 |
"output_type": "stream",
|
583 |
"text": [
|
584 |
-
"100%|ββββββββββ| 108/108 [05:
|
585 |
]
|
586 |
}
|
587 |
],
|
@@ -589,7 +582,7 @@
|
|
589 |
"from llama_index.core.evaluation import generate_question_context_pairs\n",
|
590 |
"from llama_index.llms.openai import OpenAI\n",
|
591 |
"\n",
|
592 |
-
"llm = OpenAI(model=\"gpt-3.5-turbo
|
593 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
594 |
" nodes,\n",
|
595 |
" llm=llm,\n",
|
@@ -668,15 +661,15 @@
|
|
668 |
"output_type": "stream",
|
669 |
"text": [
|
670 |
" Retriever Name Hit Rate MRR\n",
|
671 |
-
"0 Retriever top_2 0.
|
672 |
-
" Retriever Name Hit Rate
|
673 |
-
"0 Retriever top_4 0.
|
674 |
" Retriever Name Hit Rate MRR\n",
|
675 |
-
"0 Retriever top_6 0.
|
676 |
" Retriever Name Hit Rate MRR\n",
|
677 |
-
"0 Retriever top_8 0.
|
678 |
-
" Retriever Name Hit Rate
|
679 |
-
"0 Retriever top_10 0.
|
680 |
]
|
681 |
}
|
682 |
],
|
@@ -701,7 +694,7 @@
|
|
701 |
"\n",
|
702 |
"Here, we evaluate the answer generated by the LLM. Is the answer using the correct context? Is the answer faithful to the context? Is the answer relevant to the question?\n",
|
703 |
"\n",
|
704 |
-
"An LLM will answer these questions, more specifically `gpt-
|
705 |
"\n",
|
706 |
"**`FaithfulnessEvaluator`**\n",
|
707 |
"Evaluates if the answer is faithful to the retrieved contexts (in other words, whether there's an hallucination).\n",
|
@@ -722,16 +715,16 @@
|
|
722 |
"name": "stdout",
|
723 |
"output_type": "stream",
|
724 |
"text": [
|
725 |
-
"top_2 faithfulness_score:
|
726 |
-
"top_2 relevancy_score:
|
727 |
-
"top_4 faithfulness_score:
|
728 |
-
"top_4 relevancy_score: 0
|
729 |
-
"top_6 faithfulness_score:
|
730 |
"top_6 relevancy_score: 0.95\n",
|
731 |
-
"top_8 faithfulness_score: 0.
|
732 |
-
"top_8 relevancy_score: 0.
|
733 |
-
"top_10 faithfulness_score: 0
|
734 |
-
"top_10 relevancy_score: 0.
|
735 |
]
|
736 |
}
|
737 |
],
|
@@ -739,7 +732,7 @@
|
|
739 |
"from llama_index.core.evaluation import RelevancyEvaluator, FaithfulnessEvaluator, BatchEvalRunner\n",
|
740 |
"from llama_index.llms.openai import OpenAI\n",
|
741 |
"\n",
|
742 |
-
"llm_gpt4 = OpenAI(temperature=0, model=\"gpt-
|
743 |
"\n",
|
744 |
"faithfulness_evaluator = FaithfulnessEvaluator(llm=llm_gpt4)\n",
|
745 |
"relevancy_evaluator = RelevancyEvaluator(llm=llm_gpt4)\n",
|
|
|
31 |
},
|
32 |
"outputs": [],
|
33 |
"source": [
|
34 |
+
"!pip install -q llama-index==0.10.37 openai==1.30.1 cohere==5.5.0 tiktoken==0.7.0 chromadb==0.5.0"
|
35 |
]
|
36 |
},
|
37 |
{
|
|
|
82 |
"source": [
|
83 |
"from llama_index.llms.openai import OpenAI\n",
|
84 |
"\n",
|
85 |
+
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
86 |
]
|
87 |
},
|
88 |
{
|
|
|
168 |
"text": [
|
169 |
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
|
170 |
" Dload Upload Total Spent Left Speed\n",
|
171 |
+
"100 169k 100 169k 0 0 520k 0 --:--:-- --:--:-- --:--:-- 520k\n"
|
172 |
]
|
173 |
}
|
174 |
],
|
|
|
356 |
"name": "stderr",
|
357 |
"output_type": "stream",
|
358 |
"text": [
|
359 |
+
"/Users/omar/Documents/ai_repos/ai-tutor-rag-system/env/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
360 |
" from .autonotebook import tqdm as notebook_tqdm\n",
|
361 |
+
"Parsing nodes: 100%|ββββββββββ| 14/14 [00:00<00:00, 78.75it/s]\n",
|
362 |
+
"Generating embeddings: 100%|ββββββββββ| 108/108 [00:02<00:00, 51.67it/s]\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
]
|
364 |
}
|
365 |
],
|
|
|
386 |
{
|
387 |
"data": {
|
388 |
"text/plain": [
|
389 |
+
"TextNode(id_='4ab5bd897f01474fc9b0049f95e31edae3ccd9e74d0f0acd3932b50a74d608b6', embedding=[-0.022489557042717934, 0.010829868726432323, -0.017510632053017616, -0.013220878317952156, 0.00476795481517911, 0.01368501503020525, -0.028073269873857498, 0.025499416515231133, -0.03817176818847656, -0.028706183657050133, 0.028424888849258423, 0.028059205040335655, -0.02846708334982395, -0.01441638357937336, 0.008023947477340698, 0.019254662096500397, 0.014894585125148296, 0.003285880433395505, 0.004690598696470261, -0.004845311399549246, -0.002776032779365778, 0.00021833348728250712, -0.0064733074977993965, -0.019775059074163437, 0.004556983709335327, 0.02648395113646984, 0.026272978633642197, -0.028537405654788017, -0.017580954357981682, 0.0022995888721197844, 0.012756740674376488, 0.014036634936928749, -0.02931096777319908, -0.0015875602839514613, -0.0138326957821846, -0.017580954357981682, 0.016948040574789047, -0.005618873052299023, 0.035780761390924454, -0.010970516130328178, 0.01465548388659954, 0.007644199300557375, 0.006318595260381699, -0.030604926869273186, -0.027806038036942482, 8.427870488958433e-05, 0.023009954020380974, -0.026357367634773254, -0.025372834876179695, 0.0009801381966099143, -0.004335463512688875, 0.04509163275361061, -0.03293967619538307, 0.020140742883086205, 0.002515834756195545, -0.004085814114660025, 0.006199044641107321, -0.001410871627740562, 0.02624484896659851, 0.01378346886485815, -0.002285524271428585, -0.003994393162429333, -0.017651278525590897, 0.021378440782427788, -0.010893159545958042, -0.005780618172138929, -0.030267372727394104, 0.032855287194252014, 0.008924093097448349, -0.008656862191855907, -0.0007274119998328388, 0.015386851504445076, 0.008474020287394524, -0.022967759519815445, 0.028917154297232628, 0.007320709526538849, -0.018101351335644722, -0.020604878664016724, -0.02482430823147297, 0.0063959513790905476, 0.016877716407179832, 0.0035284976474940777, -0.0007964172400534153, 0.0344868004322052, 0.01715901307761669, -0.005158252082765102, 0.021026821807026863, -0.019198402762413025, -0.011969114653766155, -0.026934023946523666, -0.0012078116415068507, -0.0008223491604439914, 0.05054876208305359, 0.02251768670976162, -0.03150507062673569, 0.006642085034400225, -0.014613290317356586, 0.013931148685514927, -0.02115340530872345, -0.021941032260656357, -0.02552754618227482, -0.019423440098762512, -0.018129481002688408, -0.019915705546736717, -0.015696275979280472, 0.010182889178395271, 0.01728559471666813, 0.021406570449471474, 0.004676533862948418, 0.03184262663125992, -0.016976170241832733, 0.04542918875813484, 0.00532351341098547, -0.04028148576617241, -0.017398113384842873, 0.007071060128509998, 0.0276653915643692, -0.010801739059388638, -0.008895963430404663, 0.02243329957127571, 0.027201253920793533, 0.022250456735491753, 0.008066141977906227, -0.0038220996502786875, 0.02105495147407055, 0.0001253741793334484, -0.016554227098822594, -0.003452899632975459, -0.020056353881955147, 0.001645577372983098, 0.023263119161128998, 0.023867905139923096, 0.03364291414618492, 0.0041244919411838055, -0.037862345576286316, 0.024374235421419144, -0.02002822421491146, -0.012974744662642479, -0.025330640375614166, -0.01776379719376564, -0.004106910899281502, 0.025893229991197586, 0.0028709699399769306, 0.01352327037602663, -0.02012667804956436, 0.017890380695462227, 0.021265923976898193, 0.014669548720121384, 0.02652614563703537, 0.0006192891160026193, 0.005383288487792015, -0.03322097286581993, -0.02143470011651516, 0.011751110665500164, 0.001861823140643537, 0.014683613553643227, 0.019296856597065926, 0.006838991306722164, -0.015696275979280472, -0.0026213203091174364, -0.01507742702960968, 0.014402318745851517, -0.013122424483299255, 0.0060091703198850155, 0.027159059420228004, 0.03161758929491043, 0.030042335391044617, -0.018199805170297623, 0.001641182112507522, -0.018031027168035507, -0.03113938681781292, 0.013417785055935383, -0.04419148713350296, 0.020703332498669624, -0.0010856239823624492, 0.011877693235874176, 0.0033790594898164272, -0.005720842629671097, -0.014950844459235668, -0.020436102524399757, 0.0013387897051870823, 0.00120429543312639, 0.003709581447765231, 0.0075457459315657616, -0.022067613899707794, -0.01146981492638588, 0.0022644270211458206, 0.010485281236469746, 0.001576132606714964, -0.01064702682197094, 0.029085932299494743, 0.016976170241832733, -0.0023470574524253607, -0.023670997470617294, -0.6188496351242065, -0.032292697578668594, -0.0018881945870816708, -0.03206766024231911, -0.0015699792420491576, -0.015907248482108116, -0.018579553812742233, -0.005580195225775242, -0.02303808368742466, 0.038284286856651306, -0.02125185914337635, -0.003692000638693571, 0.01055560540407896, -0.01630106195807457, 0.002658240497112274, -0.0228552408516407, 0.0021519088186323643, -0.02351628616452217, 0.019760994240641594, 0.007320709526538849, -0.011758143082261086, -0.0022943145595490932, 0.002684611827135086, -0.007384001277387142, -0.017130883410573006, -0.002331234747543931, -0.0124824782833457, 0.009451521560549736, 0.009233517572283745, 0.012960679829120636, -0.045907389372587204, 0.01960628107190132, 0.004237010143697262, -0.026174526661634445, 0.04047838971018791, -0.008614667691290379, -0.011631559580564499, 0.018298257142305374, -0.005538000725209713, 0.014085860922932625, -0.023769451305270195, -0.015794729813933372, 0.013178683817386627, 0.013741274364292622, -0.015400916337966919, 0.02902967296540737, 0.02407887578010559, -0.0062799169681966305, -0.02171599492430687, -0.013980375602841377, 0.0038994557689875364, 9.400316776009277e-05, 0.020562684163451195, -0.008305243216454983, 0.001870613661594689, 0.012637190520763397, 0.04036587104201317, -0.01109709870070219, 0.0041104271076619625, 0.006061913445591927, -0.0005656672292388976, 0.010956451296806335, -0.03246147558093071, -0.027960751205682755, -0.026554275304079056, 0.017552824690937996, 0.006575277075171471, 0.012876291759312153, 0.007566843181848526, 0.0006012686644680798, 0.0006219262722879648, 0.0273700300604105, 0.012967712245881557, -0.015949442982673645, -0.003273573936894536, 0.014753937721252441, 0.009887529537081718, -0.008755316026508808, 0.014177282340824604, 0.03184262663125992, 0.01597757264971733, -0.015147751197218895, 0.004535886459052563, -0.009205387905240059, 0.03670903295278549, 0.011476847343146801, -0.0021114726550877094, -0.011279940605163574, 0.027074670419096947, 0.011181487701833248, 0.019198402762413025, 0.012292603962123394, -0.03797486424446106, -0.032911546528339386, 0.014950844459235668, 0.02133624628186226, -0.017215270549058914, 0.012264474295079708, 0.018874913454055786, -0.03232082724571228, -0.015007102862000465, -0.01691991090774536, 0.03226456791162491, 0.008741251192986965, 0.033333491533994675, 0.027271578088402748, -0.03811550885438919, -0.008431825786828995, 0.016216672956943512, -0.034177377820014954, -0.009887529537081718, 0.004964861553162336, -0.016230737790465355, -0.016793327406048775, 0.0190436914563179, -0.025091538205742836, -0.0014706469373777509, -0.01700429990887642, -0.0035232233349233866, -0.008431825786828995, 0.03203953430056572, -0.013881921768188477, 0.009282744489610195, -0.017398113384842873, 0.01880458928644657, 0.026399562135338783, -0.009029578417539597, -0.02469772659242153, -0.01411399058997631, 0.018438905477523804, -0.01486645545810461, -0.010921289213001728, 0.012524672783911228, -0.015414981171488762, 0.003029198618605733, 0.013157586567103863, 0.04433213546872139, 0.004757406655699015, 0.007320709526538849, -0.013600626960396767, -0.02661053277552128, -0.009071772918105125, 0.018452970311045647, -0.004258107393980026, -0.03904378414154053, -0.031111259013414383, -0.019395310431718826, 0.007974721491336823, 0.00753871351480484, -0.007180062122642994, -0.01479613222181797, -0.009226485155522823, 0.008867833763360977, 0.018692070618271828, 0.0015866812318563461, -0.011504977010190487, -0.005668099969625473, -0.029986076056957245, -0.004170202650129795, -0.016512032598257065, 0.008248983882367611, -0.0002192125393776223, -0.007000736426562071, 0.0017906202701851726, 0.004426884464919567, -0.010703285224735737, -0.022967759519815445, 0.027679456397891045, -0.025640064850449562, -0.02097056247293949, -0.004455014131963253, -0.03530255705118179, 0.007039414253085852, 0.012243377044796944, -0.014282767660915852, 0.02431797794997692, -0.003632225329056382, -0.004908602684736252, -0.007876267656683922, -0.0011735287262126803, 0.0032014918979257345, 0.030970610678195953, 0.00027382338885217905, -0.02171599492430687, 0.01592131331562996, 0.01710275374352932, 0.037862345576286316, 0.014331994578242302, -0.021125275641679764, 0.010991613380610943, 0.016512032598257065, 0.016877716407179832, -0.022630205377936363, 0.033389750868082047, -0.017355918884277344, 0.011118195950984955, 0.007278515491634607, -0.01790444552898407, 0.013108359649777412, 0.03755291923880577, 0.009078805334866047, 0.015400916337966919, -0.016793327406048775, -0.010133662261068821, 0.010829868726432323, -0.03029550239443779, 0.012095697224140167, -0.019198402762413025, -0.010548572987318039, -0.0057243588380515575, 0.003667387180030346, -0.006547147873789072, -0.008874866180121899, -0.012032405473291874, 0.0010363972978666425, 0.031589459627866745, -0.005727875046432018, 0.007447292562574148, -0.026357367634773254, 0.0109775485470891, 0.003607611870393157, 0.017046494409441948, -0.013649853877723217, 0.012855194509029388, -0.010407925583422184, 0.004834762774407864, -0.020154807716608047, 0.02073146216571331, -0.007482454646378756, -0.03133629262447357, 0.004335463512688875, 0.009627331048250198, 0.032770901918411255, 0.004455014131963253, 0.023009954020380974, -0.01798883266746998, 0.02247549220919609, 0.001355491578578949, 0.044219616800546646, -0.005696229636669159, -0.007285547908395529, 0.0034511415287852287, 2.4956714696600102e-05, -0.031083129346370697, 0.012749708257615566, -0.010112565010786057, 0.03831241652369499, -0.014395286329090595, -0.017173076048493385, -0.005541516933590174, -0.03673716261982918, 0.011504977010190487, -0.0021765222772955894, 0.005056282505393028, 0.02925470843911171, -0.009444489143788815, 0.004764438606798649, 0.0032120405230671167, 0.015358722768723965, 0.0036181604955345392, -0.013417785055935383, 0.0012675868347287178, -0.002943051978945732, 0.015302463434636593, 0.02209574356675148, -0.005077379755675793, -0.003825615858659148, -0.011554203927516937, -0.007000736426562071, -0.013860825449228287, -0.02111121080815792, -0.01001411210745573, 0.024866502732038498, -0.04067529737949371, 0.042700622230768204, 0.020886175334453583, 0.004103394690901041, 0.014894585125148296, -0.003488061483949423, 0.03203953430056572, -0.024852437898516655, -0.03777795657515526, 0.014613290317356586, -0.008635764941573143, -0.03198327496647835, -0.019662540405988693, -0.018579553812742233, 0.007405098062008619, -0.0017202964518219233, 0.00044391912524588406, -0.008895963430404663, -0.008544344455003738, -0.012299636378884315, 0.01227150671184063, 0.00034810291253961623, 0.008094271644949913, 0.014683613553643227, -0.006234206724911928, 0.008052077144384384, -0.020759591832756996, 0.02016887255012989, 0.012257441878318787, -0.00979610811918974, -0.005608324892818928, 0.011645624414086342, -0.01616041362285614, -0.03367104381322861, -0.00027338386280462146, 0.00030239243642427027, -0.033896081149578094, 0.0037728729657828808, -0.007362904027104378, 0.008558409288525581, -0.041491053998470306, 0.015597823075950146, 0.012728611938655376, 0.02039390802383423, 0.0034300442785024643, 0.019437503069639206, 0.013530302792787552, -0.007890332490205765, 0.002086859429255128, -0.010949418880045414, 0.019001496955752373, 0.048551566898822784, 0.018931172788143158, 0.003938133828341961, 0.0009801381966099143, -0.0057524885050952435, 0.003681452013552189, -0.024613337591290474, 0.0019743412267416716, 0.00083157914923504, 0.010365731082856655, -0.016371386125683784, -0.019578151404857635, 0.01804509200155735, 0.000988049665465951, 0.04005644842982292, 0.003213798627257347, 0.010351666249334812, -0.013811598531901836, -0.00954294204711914, -0.013094295747578144, 0.014444512315094471, -0.0026828537229448557, 0.010239148512482643, 0.024416429921984673, 0.011554203927516937, -0.009922690689563751, 0.007974721491336823, 0.028326435014605522, -0.006793281063437462, -0.021448764950037003, 0.012166020460426807, 0.004585112910717726, 0.008741251192986965, 0.008649829775094986, -0.016933975741267204, 0.011322135105729103, -0.0005085291340947151, -0.003305219579488039, 0.014036634936928749, 0.015344657935202122, 0.004138556774705648, 0.02450081892311573, 0.008023947477340698, 0.013502173125743866, 0.009824237786233425, -0.014472641982138157, -0.003920552786439657, 0.010140694677829742, -0.007004252634942532, -0.0392969511449337, 0.0036533225793391466, 0.004820697940886021, -0.040872205048799515, -0.0015937135322019458, 0.028256110846996307, 0.006543631665408611, 0.0013546126428991556, -0.011371362023055553, -0.00489805405959487, -0.03575263172388077, -0.00665614940226078, -0.030351761728525162, 0.006933928467333317, -0.015302463434636593, -0.004057684447616339, -0.003370269201695919, -0.00360409589484334, 0.0011708915699273348, -0.01611821912229061, 0.00015108633670024574, -0.016286997124552727, -0.011153358034789562, -0.05805934593081474, -0.013396687805652618, -0.0014935021754354239, -0.0040471358224749565, 0.010639994405210018, -0.002587916562333703, 0.0031751205679029226, 0.021941032260656357, -0.008895963430404663, -0.02040797285735607, 0.0025527547113597393, -0.01992977038025856, 0.005615356843918562, -0.023305313661694527, -0.0038642939180135727, -0.02077365666627884, -0.012384024448692799, 0.022264521569013596, -0.008769379928708076, -0.013797533698379993, -0.020182935521006584, 0.0024630918633192778, 0.005253189243376255, 0.02464146725833416, 0.016174478456377983, 0.006772183813154697, 0.022925565019249916, -0.02337563782930374, -0.0009230001596733928, -0.01850922964513302, -0.019845381379127502, -0.03575263172388077, 0.003143474692478776, 0.008396663703024387, 0.03558385372161865, 0.008488085120916367, 0.010316504165530205, -0.020858045667409897, 0.0006166520179249346, -0.014233541674911976, 0.012264474295079708, -0.0017071107868105173, 0.01286222692579031, -0.014015537686645985, 0.012151956558227539, -0.0037974861916154623, -0.005457128398120403, -0.029901688918471336, 0.01696210540831089, -0.030182983726263046, 0.02012667804956436, 0.01038682833313942, 0.00979610811918974, 0.01720120571553707, 0.022405169904232025, 0.002146634506061673, -0.045260410755872726, 0.00016075585153885186, 0.0010592525359243155, 0.014310897327959538, -0.0038783587515354156, -0.011125228367745876, -0.00249122129753232, -0.014753937721252441, -0.015246204100549221, 0.00893112551420927, -0.02469772659242153, 0.006431113462895155, -0.015218074433505535, -0.004261623602360487, -0.009317906573414803, -0.01479613222181797, 0.004824214149266481, -0.029339097440242767, -0.009233517572283745, 0.029142191633582115, 0.016807392239570618, 0.031026870012283325, -0.013586562126874924, 0.01060483232140541, -0.03825615718960762, -0.016371386125683784, 0.0005313843721523881, -0.023614738136529922, -0.010478248819708824, -0.006104107480496168, 0.011540139093995094, 0.016427643597126007, 0.021842578426003456, 0.005741939879953861, 0.017580954357981682, 0.015696275979280472, -0.0022556365001946688, -0.006336176302284002, -0.010316504165530205, 0.00018888538761530071, -0.02040797285735607, -0.013234943151473999, 0.012672352604568005, -0.003428286174312234, 0.009690622799098492, 0.004658953286707401, -0.0021817965898662806, 0.0020112611819058657, -0.01486645545810461, -0.004092846531420946, -0.018340451642870903, -0.041097242385149, -0.02139250561594963, 0.008445890620350838, -0.006329143885523081, -0.0020851013250648975, -0.04621681571006775, -0.017679408192634583, 0.018340451642870903, 0.008248983882367611, 0.014627354219555855, 0.012151956558227539, 0.03699032962322235, -0.0291703213006258, -0.002804162446409464, 0.029929818585515022, 0.016849586740136147, -0.008066141977906227, -0.007503551431000233, -0.04402271285653114, 0.013755339197814465, 0.015274333767592907, 0.007376968860626221, 0.040731556713581085, 0.026216719299554825, -0.015386851504445076, 0.016610486432909966, 0.014247605577111244, 0.003319284413009882, 0.010077403858304024, -0.0047187283635139465, -0.010288374498486519, 0.0036427739541977644, -0.012334798462688923, -0.025175927206873894, -0.023670997470617294, -0.019156208261847496, 0.011209617368876934, 0.013206813484430313, 0.030829962342977524, -0.02473991923034191, -0.02039390802383423, 0.02393822930753231, 0.008628732524812222, 0.05066128075122833, 0.013502173125743866, 0.008874866180121899, 0.02379758097231388, 0.009810172952711582, -0.010625929571688175, 0.011385426856577396, 0.01260202843695879, -0.014268702827394009, 0.020759591832756996, 0.01578066498041153, 0.002853388898074627, -0.009739848785102367, 0.012285571545362473, 0.010119597427546978, -0.03924069181084633, -0.04843904823064804, 0.00979610811918974, 0.02147689461708069, 0.005604808684438467, -0.03597766533493996, -0.03029550239443779, -0.025316575542092323, -0.0006333538913168013, -0.02552754618227482, 0.023066213354468346, 0.010232116095721722, -0.00808020681142807, 0.011174455285072327, 0.008938157930970192, 0.010253213346004486, -0.0006386282038874924, -0.004715212155133486, 0.0220535509288311, 0.004750374238938093, 0.0012702239910140634, -0.003263025311753154, 0.010211018845438957, -0.006227174308151007, 0.03763730823993683, -0.009339002892374992, 0.011589366011321545, 0.01029540691524744, -0.0010935354512184858, 0.006272884551435709, -0.008115368895232677, 0.004416335839778185, 0.03701845929026604, -0.035499464720487595, -0.010935354046523571, -0.008136466145515442, -0.016497967764735222, 0.01635732129216194, -0.01556969340890646, 0.014142120257019997, -0.004500724375247955, -0.013931148685514927, 0.003860777709633112, 0.02383977547287941, 0.02383977547287941, -0.03203953430056572, 0.0069655743427574635, 0.00284987292252481, -0.032348956912755966, -0.02708873525261879, 0.0057384236715734005, 0.032489605247974396, -0.037384141236543655, 0.007679361384361982, 0.00850214995443821, -0.021589413285255432, 0.021279988810420036, 0.021181534975767136, -0.0037447435315698385, -0.029282838106155396, 0.03237708657979965, -0.03381169214844704, 0.0217581894248724, 0.0013704354641959071, -0.010119597427546978, -0.026891829445958138, -0.0018547907238826156, -0.014978974126279354, -0.029085932299494743, 0.004535886459052563, -0.025316575542092323, -0.022123873233795166, -0.011715948581695557, 0.016807392239570618, 0.006733505986630917, -0.01059779990464449, 0.013333396054804325, 0.0033526881597936153, 0.003055569948628545, -0.0007427953532896936, -0.015907248482108116, -0.001497897319495678, 0.02303808368742466, 0.0010144211119040847, 0.0036533225793391466, 0.03043614886701107, -0.0035232233349233866, 0.012116794474422932, -0.013910051435232162, -0.005288351327180862, -0.009866432286798954, -0.05817186459898949, -0.02082991600036621, 0.009810172952711582, 0.0017132640350610018, -2.734662666625809e-05, 0.0012798935640603304, -0.016807392239570618, -0.010351666249334812, -0.012566866353154182, -0.002035874640569091, 0.010140694677829742, 0.0028692118357867002, 0.00724335340783, 0.023263119161128998, -0.0001748206268530339, 0.008523247204720974, -0.017918508499860764, -0.020562684163451195, -0.018973367288708687, -0.003681452013552189, -0.03175823763012886, -0.0187483299523592, -0.033614784479141235, 0.05037998408079147, -0.006336176302284002, -0.03887500613927841, -0.021097145974636078, -0.01507742702960968, -0.038424935191869736, -0.020464232191443443, 0.0025597871281206608, 0.01822793483734131, 0.012883324176073074, 0.01691991090774536, 0.002827017568051815, 0.03586514666676521, 0.006561212241649628, 0.004992991220206022, -0.026962153613567352, 0.01293255016207695, -0.0007502672378905118, -0.013635789044201374, 0.01276377309113741, 0.01776379719376564, -0.021069016307592392, 0.01860768347978592, 0.012095697224140167, -0.027806038036942482, -0.024247653782367706, 0.026934023946523666, -0.01507742702960968, -0.010042241774499416, 0.021884772926568985, -0.009078805334866047, 0.007021833676844835, -0.0124824782833457, 0.020281389355659485, -0.03133629262447357, -0.009324938990175724, 0.026596467941999435, -0.006592858117073774, 0.01635732129216194, -0.015035232529044151, 0.017018364742398262, 0.009036610834300518, 0.008734218776226044, 0.01610415428876877, -0.012144924141466618, 0.006304530426859856, 0.004483143333345652, 0.044078972190618515, 0.01936718076467514, 0.010464184917509556, 0.029367227107286453, -0.016737069934606552, -0.0018125964561477304, -0.0076371668837964535, 0.015007102862000465, 0.0009669525315985084, -0.008741251192986965, 0.04368515685200691, -0.01686365157365799, 0.009852367453277111, -0.010119597427546978, 0.0030696347821503878, -0.022461427375674248, -0.01714494824409485, -0.016216672956943512, -0.0027637260500341654, -0.022700529545545578, 0.014402318745851517, 0.019943835213780403, -0.021786319091916084, -0.0032419280614703894, -0.012876291759312153, 0.02261614054441452, 0.003713097656145692, -0.014142120257019997, -0.0058650067076087, -0.001107600168325007, -0.0034863033797591925, 0.019437503069639206, 0.01006333902478218, -0.006417048629373312, 0.01448670681566, 0.003507400630041957, -0.0218566432595253, 0.015485305339097977, 0.19926957786083221, -0.03164571896195412, 0.01357249729335308, 0.02873431332409382, 0.017046494409441948, -0.016694875434041023, 0.04447278380393982, 0.008213821798563004, 0.0015277849743142724, -0.004535886459052563, 0.006993704009801149, 0.005847425665706396, -0.016526097431778908, 7.318072312045842e-05, 0.019240597262978554, -0.026272978633642197, -0.021322181448340416, -0.03575263172388077, -0.017609084025025368, -0.004008457530289888, 0.006051364820450544, 0.0010768334614112973, -0.007074576336890459, -0.02265833504498005, -0.0030450213234871626, 0.005330545362085104, -4.8842091928236187e-05, -0.003489819588139653, 0.018481099978089333, 0.0006667576963081956, -0.016751134768128395, 0.005154735874384642, -0.008354470133781433, 0.0019479697803035378, 0.00027360362582840025, -0.009704687632620335, 0.010534508153796196, -0.0005085291340947151, 0.006188496015965939, 0.025119667872786522, 0.02199729159474373, 0.021350311115384102, 0.003723646281287074, -0.025049345567822456, 0.015429046005010605, 0.011061936616897583, -0.003920552786439657, 0.008790477178990841, 0.007834073156118393, 0.007398066110908985, -0.022461427375674248, 0.02271459437906742, 0.02341783232986927, 0.020618943497538567, -0.006733505986630917, 0.0007511462899856269, -0.019732864573597908, 0.015021167695522308, 0.00022184968111105263, -0.005073863547295332, -0.027313772588968277, -0.008509182371199131, -0.00019910431001335382, 0.024416429921984673, -0.010689220391213894, 0.012475445866584778, -0.0075879404321312904, -0.02393822930753231, 0.007953624241054058, -0.029001543298363686, -0.012166020460426807, -0.014782067388296127, 0.0001852593122748658, -0.011540139093995094, -0.019845381379127502, -0.03901565447449684, 0.02209574356675148, 0.02774977870285511, 0.00071290775667876, 0.04866408184170723, -0.003966263495385647, -0.03881875053048134, 0.004648404661566019, -0.012032405473291874, 0.005295383743941784, -0.02389603480696678, 0.009767978452146053, -0.015218074433505535, -0.0217581894248724, -0.011083033867180347, -0.016512032598257065, -0.009500748477876186, 0.004208880476653576, 0.024866502732038498, -1.9572547898860648e-05, 0.004578080493956804, 0.007524648681282997, 0.0060091703198850155, -0.010450120083987713, -0.03113938681781292, -0.007165997289121151, 0.059240784496068954, 0.02133624628186226, 0.0028305337764322758, -0.0009414601372554898, 0.019353115931153297, -0.0032559928949922323, 0.00015734955377411097, -0.0021712479647248983, 0.00013306585606187582, 0.009669525548815727, -0.02794668637216091, 0.011441685259342194, 0.0036111280787736177, -0.0025545128155499697, 0.011962082237005234, 0.011209617368876934, -0.009831270202994347, 0.016413578763604164, -0.010407925583422184, -0.006990187801420689, -0.02223639190196991, -0.0056891972199082375, 0.011448717676103115, -3.656289118225686e-05, -0.0274684838950634, 0.006751086562871933, 0.0009871706133708358, -0.027693521231412888, 0.01706055924296379, 0.0004386448417790234, -0.04005644842982292, 0.009353067725896835, 0.003994393162429333, 0.0006364305736497045, -0.008614667691290379, 0.014824260957539082, -0.006733505986630917, -0.02864992432296276, 0.013600626960396767, -0.00876234844326973, 0.024289848282933235, 0.004683566279709339, -0.02147689461708069, 0.01436715666204691, -0.014542966149747372, 0.002616046229377389, 0.015583758242428303, -0.013052101247012615, -0.019915705546736717, -0.020014159381389618, 0.008023947477340698, 0.00514770345762372, 0.009641395881772041, -0.0008403696701861918, 0.024374235421419144, -0.01189879048615694, -0.0006496162968687713, 0.022827111184597015, 0.008509182371199131, -0.028284240514039993, 0.0031803948804736137, 0.01556969340890646, 0.006895250640809536, -0.015907248482108116, -0.0070183174684643745, -0.18081660568714142, -0.015063362196087837, 0.011385426856577396, -0.040309615433216095, 0.018438905477523804, 0.006192012224346399, 0.012721579521894455, 0.007735620252788067, -0.010921289213001728, 0.0010759544093161821, 0.021701930090785027, -0.01852329447865486, -0.004891021642833948, -0.0062166256830096245, -0.0007252143695950508, 0.007932526990771294, -0.008790477178990841, 0.009620298631489277, 0.012327766045928001, 0.0008922334527596831, 0.03150507062673569, -0.027018411085009575, 0.009901593439280987, -0.00951481331139803, 0.017820056527853012, 0.012398089282214642, 0.00930384173989296, 0.04239119961857796, -0.017130883410573006, -0.03133629262447357, -0.01114632561802864, -0.01469767838716507, 0.0291703213006258, 0.006420564837753773, 0.03125190734863281, 0.030829962342977524, 0.011744078248739243, -0.019353115931153297, -0.018551424145698547, -0.015893183648586273, 0.02227858640253544, 0.013445914722979069, 0.02421952411532402, -0.008614667691290379, -0.03189888596534729, 0.007651231717318296, 0.007433227729052305, -0.02153315395116806, -0.0012078116415068507, -0.01303100399672985, 0.016933975741267204, 0.00989456195384264, 0.014317929744720459, -0.004198331851512194, 0.024753984063863754, 0.030492408201098442, -0.005344610195606947, 0.0034810290671885014, -0.006708892527967691, -0.02012667804956436, -0.0005155614926479757, -0.00027514193789102137, 0.0008816848858259618, -0.0005181986489333212, 0.008530279621481895, -0.035218168050050735, -0.008115368895232677, 0.004978926386684179, -0.04008457809686661, 0.0020552135538309813, -0.03386795148253441, 0.003231379436329007, -0.027806038036942482, -0.014360124245285988, 0.0275669377297163, 0.0389031358063221, -0.0305767972022295, 0.016765199601650238, 0.04413522779941559, 0.008263048715889454, -0.01992977038025856, 0.002658240497112274, -0.0190436914563179, 0.021139340475201607, -0.004001425579190254, 0.0054395473562181, 0.01587911881506443, 0.025738518685102463, -0.01528839860111475, -0.00930384173989296, 0.02002822421491146, -0.010000047273933887, 0.017609084025025368, -0.011561236344277859, -0.0008579505956731737, 0.014085860922932625, 0.010731414891779423, -0.034683708101511, -0.006125204730778933, -0.016455773264169693, 0.007566843181848526, 0.006336176302284002, -0.00893112551420927, -0.010970516130328178, 0.02011261321604252, 0.022222327068448067, -0.02275678887963295, 0.02115340530872345, 0.02841082401573658, -0.0028199851512908936, -0.02007041871547699, -0.008692024275660515, 0.0023910098243504763, 0.0035408043768256903, 0.00166315829847008, -0.0007827920489944518, -0.018579553812742233, -0.02845301851630211, 0.03237708657979965, -0.0019884060602635145, 0.05164581537246704, -0.008368534967303276, 0.0025756098330020905, 0.021983226761221886, -0.009978950023651123, -0.034599319100379944, -0.10464184731245041, -0.03547133505344391, 0.01926872693002224, 0.03142068162560463, -0.0163432564586401, 0.0330803245306015, -0.00514770345762372, 0.04126601666212082, -0.008045044727623463, 0.03966263309121132, -0.005538000725209713, -0.00419481610879302, 0.024135135114192963, 0.01601976715028286, 0.01448670681566, -0.011863628402352333, 0.000535779632627964, -0.015893183648586273, -0.02794668637216091, 0.029929818585515022, 0.017116818577051163, -0.01043605525046587, 0.01050637848675251, -0.03206766024231911, 0.013474044390022755, -0.02030951902270317, -0.03819989785552025, 0.019114013761281967, 0.005682164803147316, -0.0036849682219326496, 0.012039437890052795, -0.015302463434636593, 0.008635764941573143, -0.01648390293121338, 0.010914256796240807, -0.004581596702337265, 0.015400916337966919, -0.01983131654560566, 0.015738470479846, -0.0001563606201671064, -0.01033760141581297, 0.023024018853902817, 0.01227150671184063, -0.00850214995443821, -0.025457223877310753, 0.004444465506821871, -0.009592168964445591, 0.01917027309536934, 0.003646290162578225, -0.028157657012343407, -0.04008457809686661, -0.002616046229377389, -0.04829839989542961, 0.009177258238196373, 0.01340372022241354, -0.010464184917509556, -0.0014407592825591564, 0.025330640375614166, -0.010745479725301266, -0.008973319083452225, -0.0007515858160331845, -0.01818574033677578, -0.01399444043636322, 0.0025580290239304304, -0.014500771649181843, 0.006339692510664463, -0.00867092702537775, -0.0244586244225502, 0.025654129683971405, -0.004630823619663715, 0.0003617281618062407, 0.023333443328738213, -0.012018340639770031, 0.0038502290844917297, -0.016948040574789047, -0.006097075063735247, -0.00090541917597875, -0.0163432564586401, 0.011272908188402653, -0.0011269391980022192, -0.017791926860809326, -0.011526074260473251, 0.01686365157365799, -0.013818630948662758, -0.005214511416852474, 0.011371362023055553, -0.01436715666204691, -0.008656862191855907, 0.0101266298443079, -0.05403682217001915, -0.007250385824590921, 0.03265838325023651, 0.006838991306722164, -0.018073221668601036, 0.023291248828172684, 0.0007696063257753849, -0.011315102688968182, 0.0051125418394804, 0.005956427659839392, 0.0005973129300400615, -0.020984627306461334, -0.021870708093047142, -0.07206784933805466, 0.019845381379127502, 0.0018653393490239978, -0.010421990416944027, 0.014240573160350323, -0.012686417438089848, 0.007531681098043919, -0.010239148512482643, 0.009838302619755268, 0.02658240497112274, -0.02827017568051815, 0.011990210972726345, -0.023249054327607155, -0.03400859981775284, -0.00909287016838789, -0.00926164723932743, 0.018734265118837357, -0.00954294204711914, 0.0049261837266385555, -0.001507566892541945, 0.032995935529470444, -0.02578071318566799, 0.02524625137448311, 0.019001496955752373, -0.00014284526696428657, -0.002306621288880706, -0.043797675520181656, 0.014219476841390133, -0.009831270202994347, -0.01582285948097706, 0.006895250640809536, -0.014057731255888939, 0.013474044390022755, 0.01486645545810461, 0.0017739183967933059, -0.016286997124552727, 0.0008311396231874824, 0.026357367634773254, 0.007946591824293137, 0.03443054109811783, -0.01361469179391861, -0.04272875189781189, 0.015485305339097977, -0.006090042646974325, -0.002596707083284855, -0.008220854215323925, -0.02257394604384899, -0.008755316026508808, 0.04601990804076195, 0.010372763499617577, 0.041716091334819794, 0.00188467837870121, -0.019859446212649345, -0.05068941041827202, -0.011997243389487267, 0.001956760184839368, 0.024796178564429283, -0.009578104130923748, 0.014099925756454468, 0.01291145384311676, 0.03744040057063103, 0.008199757896363735, 0.02040797285735607, -0.015541564673185349, -0.003920552786439657, -0.013537335209548473, -0.004630823619663715, -0.008277113549411297, -0.0011849564034491777, -0.03220830857753754, 0.009985982440412045, -0.004106910899281502, 0.015091491863131523, -0.000993323978036642, 0.0028094365261495113, -0.00954294204711914, 0.001296595437452197, 0.014514836482703686, -0.016765199601650238, 0.01714494824409485, 0.018579553812742233, -0.02516186237335205, -0.002225748961791396, -0.0005595139227807522, 0.02568225935101509, 2.2415717467083596e-05, -0.019353115931153297, 0.00808020681142807, -0.015400916337966919, -0.001359886839054525, 0.0024103489704430103, 0.0016622792463749647, -0.007046446669846773, 0.019156208261847496, 0.0021079564467072487, -0.017876315861940384, -0.001709747826680541, -0.008888931013643742, 0.027876362204551697, -0.008938157930970192, 0.0003894181572832167, -0.010091467760503292, 0.004514789208769798, -0.007496519014239311, -0.007897364906966686, -0.009613266214728355, -0.045204151421785355, -0.021884772926568985, 0.039465729147195816, 0.03831241652369499, 0.015963507816195488, -0.008959254249930382, -0.012130859307944775, 0.004205364268273115, -0.012447316199541092, 0.016427643597126007, -0.004585112910717726, -0.014978974126279354, -0.024613337591290474, 0.03310845419764519, 0.02846708334982395, 0.015555629506707191, 0.05316480994224548, 0.00037579290801659226, 0.0204501673579216, 0.006691311486065388, 0.03043614886701107, -0.0024208975955843925, 0.025119667872786522, 0.02021106518805027, -0.005291867535561323, -0.010520443320274353, -0.014782067388296127, -0.010049274191260338, -0.005232092458754778, -0.013713144697248936, -0.021350311115384102, 0.01728559471666813, 0.012166020460426807, 0.09485276788473129, 0.018171675503253937, -0.01244028378278017, 0.009458553977310658, -0.009268679656088352, 0.0109775485470891, 0.008895963430404663, 0.02303808368742466, 0.0071097384206950665, -0.011315102688968182, -0.002434962196275592, -0.011751110665500164, -0.01244028378278017, -0.014838325791060925, 0.02105495147407055, -0.0037869377993047237, -0.010358698666095734, 0.015625953674316406, 0.005625905469059944, -0.0023329928517341614, 0.0421099029481411, -0.012243377044796944, 0.006339692510664463, 0.005203962791711092, -0.01168078649789095, 0.022180132567882538, 0.029142191633582115, 0.004163170233368874, 0.0028938252944499254, -0.018199805170297623, 0.032770901918411255, 0.01822793483734131, -0.050239335745573044, -0.019381245598196983, -0.009233517572283745, -0.008663894608616829, 0.0049402485601603985, -0.013438882306218147, -0.005485258065164089, 0.005464160814881325, 0.00570326205343008, 0.00209740805439651, -0.014268702827394009, -0.026652727276086807, 0.02516186237335205, -0.012841129675507545, -0.01490864995867014, -0.020225130021572113, -0.028002945706248283], metadata={'title': \"Beyond GPT-4: What's New?\", 'url': 'https://pub.towardsai.net/beyond-gpt-4-whats-new-cbd61a448eb9#dda8', 'source_name': 'towards_ai'}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='doc_0', node_type=<ObjectType.DOCUMENT: '4'>, metadata={'title': \"Beyond GPT-4: What's New?\", 'url': 'https://pub.towardsai.net/beyond-gpt-4-whats-new-cbd61a448eb9#dda8', 'source_name': 'towards_ai'}, hash='3b095b0e25cdf965d950cdbd7feb8024030e7645998c1a33dc4427affca624ab'), <NodeRelationship.NEXT: '3'>: RelatedNodeInfo(node_id='e470fa0d001e50b3ec3088022462a94ea7c87dd80106411b7d120f90b379e977', node_type=<ObjectType.TEXT: '1'>, metadata={}, hash='71418de3d50e604c2581574f1abf2248e5cc3ab7c74a3182c37cb1152d0cfd21')}, text='LLM Variants and Meta\\'s Open Source Before shedding light on four major trends, I\\'d share the latest Meta\\'s Llama 2 and Code Llama. Meta\\'s Llama 2 represents a sophisticated evolution in LLMs. This suite spans models pretrained and fine-tuned across a parameter spectrum of 7 billion to 70 billion. A specialized derivative, Llama 2-Chat, has been engineered explicitly for dialogue-centric applications. Benchmarking revealed Llama 2\\'s superior performance over most extant open-source chat models. Human-centric evaluations, focusing on safety and utility metrics, positioned Llama 2-Chat as a potential contender against proprietary, closed-source counterparts. The development trajectory of Llama 2 emphasized rigorous fine-tuning methodologies. Meta\\'s transparent delineation of these processes aims to catalyze community-driven advancements in LLMs, underscoring a commitment to collaborative and responsible AI development. Code Llama is built on top of Llama 2 and is available in three models: Code Llama, the foundational code model;Codel Llama - Python specialized for Python;and Code Llama - Instruct, which is fine-tuned for understanding natural language instructions. Based on its benchmark testing, Code Llama outperformed state-of-the-art publicly available LLMs (except GPT-4) on code tasks. Llama 2, Llama 2-Chat, and Code Llama are key steps in LLM development but still have a way to go compared to GPT-4. Meta\\'s open access and commitment to improving these models promise transparent and faster LLM progress in the future. Please refer to the LLM and Llama variants below: From LLMs to Multimodal LLMs, like OpenAI\\'s ChatGPT (GPT-3.5), primarily focus on understanding and generating human language. They\\'ve been instrumental in tasks like text generation, translation, and even creative writing. However, their scope is limited to text. Enter multimodal models like GPT-4. These are a new breed of AI models that can understand and generate not just text, but also images, sounds, and potentially other types of data. The term \"multimodal\" refers to their ability to process multiple modes or', start_char_idx=0, end_char_idx=2117, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n')"
|
390 |
]
|
391 |
},
|
392 |
"execution_count": 12,
|
|
|
502 |
"Node ID\t f707756065d1f788b41fb97fcef81979e1fd241dbfa4034a24bec8e57b648482\n",
|
503 |
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
|
504 |
"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",
|
505 |
+
"Score\t 0.7121413582808603\n",
|
506 |
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n",
|
507 |
"Node ID\t 636f98cf8754c3a4759da02aa11a3f2aa7cdeb848a4980ec99300ece4a2e92fd\n",
|
508 |
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
|
509 |
"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",
|
510 |
+
"Score\t 0.7046432574807696\n",
|
511 |
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"
|
512 |
]
|
513 |
}
|
|
|
574 |
"name": "stderr",
|
575 |
"output_type": "stream",
|
576 |
"text": [
|
577 |
+
"100%|ββββββββββ| 108/108 [05:21<00:00, 2.98s/it]\n"
|
578 |
]
|
579 |
}
|
580 |
],
|
|
|
582 |
"from llama_index.core.evaluation import generate_question_context_pairs\n",
|
583 |
"from llama_index.llms.openai import OpenAI\n",
|
584 |
"\n",
|
585 |
+
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
|
586 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
587 |
" nodes,\n",
|
588 |
" llm=llm,\n",
|
|
|
661 |
"output_type": "stream",
|
662 |
"text": [
|
663 |
" Retriever Name Hit Rate MRR\n",
|
664 |
+
"0 Retriever top_2 0.678208 0.568228\n",
|
665 |
+
" Retriever Name Hit Rate MRR\n",
|
666 |
+
"0 Retriever top_4 0.814664 0.60981\n",
|
667 |
" Retriever Name Hit Rate MRR\n",
|
668 |
+
"0 Retriever top_6 0.863544 0.618635\n",
|
669 |
" Retriever Name Hit Rate MRR\n",
|
670 |
+
"0 Retriever top_8 0.885947 0.622066\n",
|
671 |
+
" Retriever Name Hit Rate MRR\n",
|
672 |
+
"0 Retriever top_10 0.912424 0.624946\n"
|
673 |
]
|
674 |
}
|
675 |
],
|
|
|
694 |
"\n",
|
695 |
"Here, we evaluate the answer generated by the LLM. Is the answer using the correct context? Is the answer faithful to the context? Is the answer relevant to the question?\n",
|
696 |
"\n",
|
697 |
+
"An LLM will answer these questions, more specifically `gpt-4o`.\n",
|
698 |
"\n",
|
699 |
"**`FaithfulnessEvaluator`**\n",
|
700 |
"Evaluates if the answer is faithful to the retrieved contexts (in other words, whether there's an hallucination).\n",
|
|
|
715 |
"name": "stdout",
|
716 |
"output_type": "stream",
|
717 |
"text": [
|
718 |
+
"top_2 faithfulness_score: 0.9\n",
|
719 |
+
"top_2 relevancy_score: 0.95\n",
|
720 |
+
"top_4 faithfulness_score: 0.85\n",
|
721 |
+
"top_4 relevancy_score: 1.0\n",
|
722 |
+
"top_6 faithfulness_score: 0.95\n",
|
723 |
"top_6 relevancy_score: 0.95\n",
|
724 |
+
"top_8 faithfulness_score: 0.95\n",
|
725 |
+
"top_8 relevancy_score: 0.95\n",
|
726 |
+
"top_10 faithfulness_score: 1.0\n",
|
727 |
+
"top_10 relevancy_score: 0.9\n"
|
728 |
]
|
729 |
}
|
730 |
],
|
|
|
732 |
"from llama_index.core.evaluation import RelevancyEvaluator, FaithfulnessEvaluator, BatchEvalRunner\n",
|
733 |
"from llama_index.llms.openai import OpenAI\n",
|
734 |
"\n",
|
735 |
+
"llm_gpt4 = OpenAI(temperature=0, model=\"gpt-4o\")\n",
|
736 |
"\n",
|
737 |
"faithfulness_evaluator = FaithfulnessEvaluator(llm=llm_gpt4)\n",
|
738 |
"relevancy_evaluator = RelevancyEvaluator(llm=llm_gpt4)\n",
|
notebooks/07-RAG_Improve_Chunking.ipynb
CHANGED
@@ -45,7 +45,7 @@
|
|
45 |
"import os\n",
|
46 |
"\n",
|
47 |
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
|
48 |
-
"os.environ[\"OPENAI_API_KEY\"] = \"
|
49 |
]
|
50 |
},
|
51 |
{
|
@@ -82,7 +82,7 @@
|
|
82 |
"source": [
|
83 |
"from llama_index.llms.openai import OpenAI\n",
|
84 |
"\n",
|
85 |
-
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo
|
86 |
]
|
87 |
},
|
88 |
{
|
@@ -758,7 +758,7 @@
|
|
758 |
"\n",
|
759 |
"index_no_metadata = VectorStoreIndex(\n",
|
760 |
" nodes=nodes_no_meta,\n",
|
761 |
-
" service_context=ServiceContext.from_defaults(llm=OpenAI(model=\"gpt-3.5-turbo
|
762 |
")"
|
763 |
]
|
764 |
},
|
@@ -876,7 +876,7 @@
|
|
876 |
"# Create questions for each segment. These questions will be used to\n",
|
877 |
"# assess whether the retriever can accurately identify and return the\n",
|
878 |
"# corresponding segment when queried.\n",
|
879 |
-
"llm = OpenAI(model=\"gpt-3.5-turbo
|
880 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
881 |
" nodes,\n",
|
882 |
" llm=llm,\n",
|
@@ -1035,7 +1035,7 @@
|
|
1035 |
" query_engine = index.as_query_engine(similarity_top_k=i)\n",
|
1036 |
"\n",
|
1037 |
" # While we use GPT3.5-Turbo to answer questions, we can use GPT4 to evaluate the answers.\n",
|
1038 |
-
" llm_gpt4 = OpenAI(temperature=0, model=\"gpt-
|
1039 |
" service_context_gpt4 = ServiceContext.from_defaults(llm=llm_gpt4)\n",
|
1040 |
"\n",
|
1041 |
" faithfulness_evaluator = FaithfulnessEvaluator(service_context=service_context_gpt4)\n",
|
|
|
45 |
"import os\n",
|
46 |
"\n",
|
47 |
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
|
48 |
+
"os.environ[\"OPENAI_API_KEY\"] = \"<YOUR_OPENAI_KEY>\""
|
49 |
]
|
50 |
},
|
51 |
{
|
|
|
82 |
"source": [
|
83 |
"from llama_index.llms.openai import OpenAI\n",
|
84 |
"\n",
|
85 |
+
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
86 |
]
|
87 |
},
|
88 |
{
|
|
|
758 |
"\n",
|
759 |
"index_no_metadata = VectorStoreIndex(\n",
|
760 |
" nodes=nodes_no_meta,\n",
|
761 |
+
" service_context=ServiceContext.from_defaults(llm=OpenAI(model=\"gpt-3.5-turbo\")),\n",
|
762 |
")"
|
763 |
]
|
764 |
},
|
|
|
876 |
"# Create questions for each segment. These questions will be used to\n",
|
877 |
"# assess whether the retriever can accurately identify and return the\n",
|
878 |
"# corresponding segment when queried.\n",
|
879 |
+
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
|
880 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
881 |
" nodes,\n",
|
882 |
" llm=llm,\n",
|
|
|
1035 |
" query_engine = index.as_query_engine(similarity_top_k=i)\n",
|
1036 |
"\n",
|
1037 |
" # While we use GPT3.5-Turbo to answer questions, we can use GPT4 to evaluate the answers.\n",
|
1038 |
+
" llm_gpt4 = OpenAI(temperature=0, model=\"gpt-4o\")\n",
|
1039 |
" service_context_gpt4 = ServiceContext.from_defaults(llm=llm_gpt4)\n",
|
1040 |
"\n",
|
1041 |
" faithfulness_evaluator = FaithfulnessEvaluator(service_context=service_context_gpt4)\n",
|
notebooks/08-Finetune_Embedding.ipynb
CHANGED
@@ -259,7 +259,7 @@
|
|
259 |
"from llama_index.llms.openai import OpenAI\n",
|
260 |
"\n",
|
261 |
"# Load the OpenAI API with the \"gpt-3.5-turbo\" model\n",
|
262 |
-
"llm = OpenAI(model=\"gpt-3.5-turbo
|
263 |
"\n",
|
264 |
"# Generate questions for each chunk.\n",
|
265 |
"TRAIN_DATASET = generate_qa_embedding_pairs(TRAIN_NODEs, llm=llm)\n",
|
|
|
259 |
"from llama_index.llms.openai import OpenAI\n",
|
260 |
"\n",
|
261 |
"# Load the OpenAI API with the \"gpt-3.5-turbo\" model\n",
|
262 |
+
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
|
263 |
"\n",
|
264 |
"# Generate questions for each chunk.\n",
|
265 |
"TRAIN_DATASET = generate_qa_embedding_pairs(TRAIN_NODEs, llm=llm)\n",
|
notebooks/09-Better_Embedding_Model.ipynb
CHANGED
@@ -92,7 +92,7 @@
|
|
92 |
"source": [
|
93 |
"from llama_index.llms.openai import OpenAI\n",
|
94 |
"\n",
|
95 |
-
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo
|
96 |
]
|
97 |
},
|
98 |
{
|
@@ -665,7 +665,7 @@
|
|
665 |
"# Create questions for each segment. These questions will be used to\n",
|
666 |
"# assess whether the retriever can accurately identify and return the\n",
|
667 |
"# corresponding segment when queried.\n",
|
668 |
-
"llm = OpenAI(model=\"gpt-3.5-turbo
|
669 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
670 |
" nodes,\n",
|
671 |
" llm=llm,\n",
|
@@ -824,7 +824,7 @@
|
|
824 |
" query_engine = index.as_query_engine(similarity_top_k=i)\n",
|
825 |
"\n",
|
826 |
" # While we use GPT3.5-Turbo to answer questions, we can use GPT4 to evaluate the answers.\n",
|
827 |
-
" llm_gpt4 = OpenAI(temperature=0, model=\"gpt-
|
828 |
" service_context_gpt4 = ServiceContext.from_defaults(llm=llm_gpt4)\n",
|
829 |
"\n",
|
830 |
" faithfulness_evaluator = FaithfulnessEvaluator(service_context=service_context_gpt4)\n",
|
|
|
92 |
"source": [
|
93 |
"from llama_index.llms.openai import OpenAI\n",
|
94 |
"\n",
|
95 |
+
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
96 |
]
|
97 |
},
|
98 |
{
|
|
|
665 |
"# Create questions for each segment. These questions will be used to\n",
|
666 |
"# assess whether the retriever can accurately identify and return the\n",
|
667 |
"# corresponding segment when queried.\n",
|
668 |
+
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
|
669 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
670 |
" nodes,\n",
|
671 |
" llm=llm,\n",
|
|
|
824 |
" query_engine = index.as_query_engine(similarity_top_k=i)\n",
|
825 |
"\n",
|
826 |
" # While we use GPT3.5-Turbo to answer questions, we can use GPT4 to evaluate the answers.\n",
|
827 |
+
" llm_gpt4 = OpenAI(temperature=0, model=\"gpt-4o\")\n",
|
828 |
" service_context_gpt4 = ServiceContext.from_defaults(llm=llm_gpt4)\n",
|
829 |
"\n",
|
830 |
" faithfulness_evaluator = FaithfulnessEvaluator(service_context=service_context_gpt4)\n",
|
notebooks/10-Adding_Reranking.ipynb
CHANGED
@@ -93,7 +93,7 @@
|
|
93 |
"source": [
|
94 |
"from llama_index.llms.openai import OpenAI\n",
|
95 |
"\n",
|
96 |
-
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo
|
97 |
]
|
98 |
},
|
99 |
{
|
@@ -617,7 +617,7 @@
|
|
617 |
"# Create questions for each segment. These questions will be used to\n",
|
618 |
"# assess whether the retriever can accurately identify and return the\n",
|
619 |
"# corresponding segment when queried.\n",
|
620 |
-
"llm = OpenAI(model=\"gpt-3.5-turbo
|
621 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
622 |
" nodes,\n",
|
623 |
" llm=llm,\n",
|
|
|
93 |
"source": [
|
94 |
"from llama_index.llms.openai import OpenAI\n",
|
95 |
"\n",
|
96 |
+
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
97 |
]
|
98 |
},
|
99 |
{
|
|
|
617 |
"# Create questions for each segment. These questions will be used to\n",
|
618 |
"# assess whether the retriever can accurately identify and return the\n",
|
619 |
"# corresponding segment when queried.\n",
|
620 |
+
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
|
621 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
622 |
" nodes,\n",
|
623 |
" llm=llm,\n",
|
notebooks/11-Adding_Hybrid_Search.ipynb
CHANGED
@@ -91,7 +91,7 @@
|
|
91 |
"source": [
|
92 |
"from llama_index.llms.openai import OpenAI\n",
|
93 |
"\n",
|
94 |
-
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo
|
95 |
]
|
96 |
},
|
97 |
{
|
@@ -807,7 +807,7 @@
|
|
807 |
"# Create questions for each segment. These questions will be used to\n",
|
808 |
"# assess whether the retriever can accurately identify and return the\n",
|
809 |
"# corresponding segment when queried.\n",
|
810 |
-
"llm = OpenAI(model=\"gpt-3.5-turbo
|
811 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
812 |
" nodes,\n",
|
813 |
" llm=llm,\n",
|
|
|
91 |
"source": [
|
92 |
"from llama_index.llms.openai import OpenAI\n",
|
93 |
"\n",
|
94 |
+
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
95 |
]
|
96 |
},
|
97 |
{
|
|
|
807 |
"# Create questions for each segment. These questions will be used to\n",
|
808 |
"# assess whether the retriever can accurately identify and return the\n",
|
809 |
"# corresponding segment when queried.\n",
|
810 |
+
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
|
811 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
812 |
" nodes,\n",
|
813 |
" llm=llm,\n",
|
notebooks/12-Improve_Query.ipynb
CHANGED
@@ -91,7 +91,7 @@
|
|
91 |
"source": [
|
92 |
"from llama_index.llms.openai import OpenAI\n",
|
93 |
"\n",
|
94 |
-
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo
|
95 |
]
|
96 |
},
|
97 |
{
|
@@ -501,7 +501,7 @@
|
|
501 |
"source": [
|
502 |
"from llama_index.core import ServiceContext\n",
|
503 |
"\n",
|
504 |
-
"gpt4 = OpenAI(temperature=0, model=\"gpt-
|
505 |
"service_context_gpt4 = ServiceContext.from_defaults(llm=gpt4)"
|
506 |
]
|
507 |
},
|
@@ -766,7 +766,7 @@
|
|
766 |
"from llama_index.core.indices.query.query_transform.base import StepDecomposeQueryTransform\n",
|
767 |
"from llama_index.core.query_engine.multistep_query_engine import MultiStepQueryEngine\n",
|
768 |
"\n",
|
769 |
-
"gpt3 = OpenAI(temperature=0, model=\"gpt-3.5-turbo
|
770 |
"service_context_gpt3 = ServiceContext.from_defaults(llm=gpt3)\n",
|
771 |
"\n",
|
772 |
"step_decompose_transform_gpt3 = StepDecomposeQueryTransform(llm=gpt3, verbose=True)\n",
|
|
|
91 |
"source": [
|
92 |
"from llama_index.llms.openai import OpenAI\n",
|
93 |
"\n",
|
94 |
+
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
95 |
]
|
96 |
},
|
97 |
{
|
|
|
501 |
"source": [
|
502 |
"from llama_index.core import ServiceContext\n",
|
503 |
"\n",
|
504 |
+
"gpt4 = OpenAI(temperature=0, model=\"gpt-4o\")\n",
|
505 |
"service_context_gpt4 = ServiceContext.from_defaults(llm=gpt4)"
|
506 |
]
|
507 |
},
|
|
|
766 |
"from llama_index.core.indices.query.query_transform.base import StepDecomposeQueryTransform\n",
|
767 |
"from llama_index.core.query_engine.multistep_query_engine import MultiStepQueryEngine\n",
|
768 |
"\n",
|
769 |
+
"gpt3 = OpenAI(temperature=0, model=\"gpt-3.5-turbo\")\n",
|
770 |
"service_context_gpt3 = ServiceContext.from_defaults(llm=gpt3)\n",
|
771 |
"\n",
|
772 |
"step_decompose_transform_gpt3 = StepDecomposeQueryTransform(llm=gpt3, verbose=True)\n",
|
notebooks/13-Adding_Router.ipynb
CHANGED
@@ -45,7 +45,7 @@
|
|
45 |
"import os\n",
|
46 |
"\n",
|
47 |
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
|
48 |
-
"os.environ[\"OPENAI_API_KEY\"] = \"
|
49 |
]
|
50 |
},
|
51 |
{
|
@@ -81,7 +81,7 @@
|
|
81 |
"source": [
|
82 |
"from llama_index.llms.openai import OpenAI\n",
|
83 |
"\n",
|
84 |
-
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo
|
85 |
]
|
86 |
},
|
87 |
{
|
@@ -405,7 +405,7 @@
|
|
405 |
"source": [
|
406 |
"from llama_index.llms.openai import OpenAI\n",
|
407 |
"\n",
|
408 |
-
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo
|
409 |
]
|
410 |
},
|
411 |
{
|
|
|
45 |
"import os\n",
|
46 |
"\n",
|
47 |
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
|
48 |
+
"os.environ[\"OPENAI_API_KEY\"] = \"<YOUR_OPENAI_KEY>\""
|
49 |
]
|
50 |
},
|
51 |
{
|
|
|
81 |
"source": [
|
82 |
"from llama_index.llms.openai import OpenAI\n",
|
83 |
"\n",
|
84 |
+
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
85 |
]
|
86 |
},
|
87 |
{
|
|
|
405 |
"source": [
|
406 |
"from llama_index.llms.openai import OpenAI\n",
|
407 |
"\n",
|
408 |
+
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
409 |
]
|
410 |
},
|
411 |
{
|
notebooks/14-Adding_Chat.ipynb
CHANGED
@@ -91,7 +91,7 @@
|
|
91 |
"source": [
|
92 |
"from llama_index.llms.openai import OpenAI\n",
|
93 |
"\n",
|
94 |
-
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo
|
95 |
]
|
96 |
},
|
97 |
{
|
@@ -740,7 +740,7 @@
|
|
740 |
"outputs": [],
|
741 |
"source": [
|
742 |
"# Define GPT-4 model that will be used by the chat_engine to improve the query.\n",
|
743 |
-
"gpt4 = OpenAI(temperature=0.9, model=\"gpt-
|
744 |
]
|
745 |
},
|
746 |
{
|
|
|
91 |
"source": [
|
92 |
"from llama_index.llms.openai import OpenAI\n",
|
93 |
"\n",
|
94 |
+
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
95 |
]
|
96 |
},
|
97 |
{
|
|
|
740 |
"outputs": [],
|
741 |
"source": [
|
742 |
"# Define GPT-4 model that will be used by the chat_engine to improve the query.\n",
|
743 |
+
"gpt4 = OpenAI(temperature=0.9, model=\"gpt-4o\")"
|
744 |
]
|
745 |
},
|
746 |
{
|
notebooks/15-Use_OpenSource_Models.ipynb
CHANGED
@@ -782,7 +782,7 @@
|
|
782 |
"# Create questions for each segment. These questions will be used to\n",
|
783 |
"# assess whether the retriever can accurately identify and return the\n",
|
784 |
"# corresponding segment when queried.\n",
|
785 |
-
"llm = OpenAI(model=\"gpt-3.5-turbo
|
786 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
787 |
" nodes,\n",
|
788 |
" llm=llm,\n",
|
|
|
782 |
"# Create questions for each segment. These questions will be used to\n",
|
783 |
"# assess whether the retriever can accurately identify and return the\n",
|
784 |
"# corresponding segment when queried.\n",
|
785 |
+
"llm = OpenAI(model=\"gpt-3.5-turbo\")\n",
|
786 |
"rag_eval_dataset = generate_question_context_pairs(\n",
|
787 |
" nodes,\n",
|
788 |
" llm=llm,\n",
|
notebooks/17-Using_LLMs_to_rank_chunks_as_the_Judge.ipynb
CHANGED
@@ -1,26 +1,10 @@
|
|
1 |
{
|
2 |
-
"nbformat": 4,
|
3 |
-
"nbformat_minor": 0,
|
4 |
-
"metadata": {
|
5 |
-
"colab": {
|
6 |
-
"provenance": [],
|
7 |
-
"authorship_tag": "ABX9TyMhd0xkjZD3StMhSoQIPv+w",
|
8 |
-
"include_colab_link": true
|
9 |
-
},
|
10 |
-
"kernelspec": {
|
11 |
-
"name": "python3",
|
12 |
-
"display_name": "Python 3"
|
13 |
-
},
|
14 |
-
"language_info": {
|
15 |
-
"name": "python"
|
16 |
-
}
|
17 |
-
},
|
18 |
"cells": [
|
19 |
{
|
20 |
"cell_type": "markdown",
|
21 |
"metadata": {
|
22 |
-
"
|
23 |
-
"
|
24 |
},
|
25 |
"source": [
|
26 |
"<a href=\"https://colab.research.google.com/github/towardsai/ai-tutor-rag-system/blob/main/notebooks/17-Using_LLMs_to_rank_chunks_as_the_Judge.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
@@ -28,27 +12,27 @@
|
|
28 |
},
|
29 |
{
|
30 |
"cell_type": "markdown",
|
31 |
-
"source": [
|
32 |
-
"# Install Packages and Setup Variables"
|
33 |
-
],
|
34 |
"metadata": {
|
35 |
"id": "0FbELaf7TrW7"
|
36 |
-
}
|
|
|
|
|
|
|
37 |
},
|
38 |
{
|
39 |
"cell_type": "code",
|
40 |
"execution_count": null,
|
41 |
"metadata": {
|
42 |
-
"id": "Yubz8AanRRSW",
|
43 |
"colab": {
|
44 |
"base_uri": "https://localhost:8080/"
|
45 |
},
|
|
|
46 |
"outputId": "2487c4fd-0fb5-4894-ffe6-c747f4adb952"
|
47 |
},
|
48 |
"outputs": [
|
49 |
{
|
50 |
-
"output_type": "stream",
|
51 |
"name": "stdout",
|
|
|
52 |
"text": [
|
53 |
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m226.7/226.7 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
54 |
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m11.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
@@ -106,51 +90,56 @@
|
|
106 |
},
|
107 |
{
|
108 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
109 |
"source": [
|
110 |
"import os\n",
|
111 |
"\n",
|
112 |
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
|
113 |
"os.environ[\"OPENAI_API_KEY\"] = \"[OPENAI_API_KEY]\""
|
114 |
-
]
|
115 |
-
"metadata": {
|
116 |
-
"id": "xLXFuRW-TpUu"
|
117 |
-
},
|
118 |
-
"execution_count": null,
|
119 |
-
"outputs": []
|
120 |
},
|
121 |
{
|
122 |
"cell_type": "markdown",
|
123 |
-
"source": [
|
124 |
-
"# Load a Model"
|
125 |
-
],
|
126 |
"metadata": {
|
127 |
"id": "r6GCYYqqTuMc"
|
128 |
-
}
|
|
|
|
|
|
|
129 |
},
|
130 |
{
|
131 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
132 |
"source": [
|
133 |
"from llama_index.llms.openai import OpenAI\n",
|
134 |
"\n",
|
135 |
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
136 |
-
]
|
137 |
-
"metadata": {
|
138 |
-
"id": "pupJpdZaTu5m"
|
139 |
-
},
|
140 |
-
"execution_count": null,
|
141 |
-
"outputs": []
|
142 |
},
|
143 |
{
|
144 |
"cell_type": "markdown",
|
145 |
-
"source": [
|
146 |
-
"# Create a Vector Store"
|
147 |
-
],
|
148 |
"metadata": {
|
149 |
"id": "gaKYO-KrTwsn"
|
150 |
-
}
|
|
|
|
|
|
|
151 |
},
|
152 |
{
|
153 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
154 |
"source": [
|
155 |
"import chromadb\n",
|
156 |
"\n",
|
@@ -158,71 +147,63 @@
|
|
158 |
"# chromadb.EphemeralClient saves data in-memory.\n",
|
159 |
"chroma_client = chromadb.PersistentClient(path=\"./mini-llama-articles\")\n",
|
160 |
"chroma_collection = chroma_client.create_collection(\"mini-llama-articles\")"
|
161 |
-
]
|
162 |
-
"metadata": {
|
163 |
-
"id": "npCqCZSPZKR0"
|
164 |
-
},
|
165 |
-
"execution_count": null,
|
166 |
-
"outputs": []
|
167 |
},
|
168 |
{
|
169 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
170 |
"source": [
|
171 |
"from llama_index.vector_stores.chroma import ChromaVectorStore\n",
|
172 |
"\n",
|
173 |
"# Define a storage context object using the created vector database.\n",
|
174 |
"vector_store = ChromaVectorStore(chroma_collection=chroma_collection)"
|
175 |
-
]
|
176 |
-
"metadata": {
|
177 |
-
"id": "dG9eKSVrZMs1"
|
178 |
-
},
|
179 |
-
"execution_count": null,
|
180 |
-
"outputs": []
|
181 |
},
|
182 |
{
|
183 |
"cell_type": "markdown",
|
184 |
-
"source": [
|
185 |
-
"# Load the Dataset (CSV)"
|
186 |
-
],
|
187 |
"metadata": {
|
188 |
"id": "HmiFENBdZMAk"
|
189 |
-
}
|
|
|
|
|
|
|
190 |
},
|
191 |
{
|
192 |
"cell_type": "markdown",
|
193 |
-
"source": [
|
194 |
-
"## Download"
|
195 |
-
],
|
196 |
"metadata": {
|
197 |
"id": "X-20isiTZRIa"
|
198 |
-
}
|
|
|
|
|
|
|
199 |
},
|
200 |
{
|
201 |
"cell_type": "markdown",
|
202 |
-
"source": [
|
203 |
-
"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."
|
204 |
-
],
|
205 |
"metadata": {
|
206 |
"id": "-lWKX814ZURc"
|
207 |
-
}
|
|
|
|
|
|
|
208 |
},
|
209 |
{
|
210 |
"cell_type": "code",
|
211 |
-
"
|
212 |
-
"!wget https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles.csv"
|
213 |
-
],
|
214 |
"metadata": {
|
215 |
-
"id": "fmlEL849ZPrH",
|
216 |
"colab": {
|
217 |
"base_uri": "https://localhost:8080/"
|
218 |
},
|
|
|
219 |
"outputId": "63039988-ab7a-4ecf-deb0-d9510628ecb8"
|
220 |
},
|
221 |
-
"execution_count": null,
|
222 |
"outputs": [
|
223 |
{
|
224 |
-
"output_type": "stream",
|
225 |
"name": "stdout",
|
|
|
226 |
"text": [
|
227 |
"--2024-04-30 18:37:36-- https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles.csv\n",
|
228 |
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.111.133, ...\n",
|
@@ -237,19 +218,27 @@
|
|
237 |
"\n"
|
238 |
]
|
239 |
}
|
|
|
|
|
|
|
240 |
]
|
241 |
},
|
242 |
{
|
243 |
"cell_type": "markdown",
|
244 |
-
"source": [
|
245 |
-
"# Read File"
|
246 |
-
],
|
247 |
"metadata": {
|
248 |
"id": "r9PL_eiTZW7y"
|
249 |
-
}
|
|
|
|
|
|
|
250 |
},
|
251 |
{
|
252 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
253 |
"source": [
|
254 |
"import csv\n",
|
255 |
"\n",
|
@@ -265,47 +254,47 @@
|
|
265 |
"\n",
|
266 |
"# The number of characters in the dataset.\n",
|
267 |
"len( rows )"
|
268 |
-
]
|
269 |
-
"metadata": {
|
270 |
-
"id": "x5IwXJi8ZQGh"
|
271 |
-
},
|
272 |
-
"execution_count": null,
|
273 |
-
"outputs": []
|
274 |
},
|
275 |
{
|
276 |
"cell_type": "markdown",
|
277 |
-
"source": [
|
278 |
-
"# Convert to Document obj"
|
279 |
-
],
|
280 |
"metadata": {
|
281 |
"id": "ktYUZzzSZaDW"
|
282 |
-
}
|
|
|
|
|
|
|
283 |
},
|
284 |
{
|
285 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
286 |
"source": [
|
287 |
"from llama_index.core.schema import Document\n",
|
288 |
"\n",
|
289 |
"# Convert the chunks to Document objects so the LlamaIndex framework can process them.\n",
|
290 |
"documents = [Document(text=row[1], metadata={\"title\": row[0], \"url\": row[2], \"source_name\": row[3]}) for row in rows]"
|
291 |
-
]
|
292 |
-
"metadata": {
|
293 |
-
"id": "oO10Q-UyZQEB"
|
294 |
-
},
|
295 |
-
"execution_count": null,
|
296 |
-
"outputs": []
|
297 |
},
|
298 |
{
|
299 |
"cell_type": "markdown",
|
300 |
-
"source": [
|
301 |
-
"# Transforming"
|
302 |
-
],
|
303 |
"metadata": {
|
304 |
"id": "0PnovZ0tZdAT"
|
305 |
-
}
|
|
|
|
|
|
|
306 |
},
|
307 |
{
|
308 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
309 |
"source": [
|
310 |
"from llama_index.core.node_parser import TokenTextSplitter\n",
|
311 |
"\n",
|
@@ -314,15 +303,15 @@
|
|
314 |
"text_splitter = TokenTextSplitter(\n",
|
315 |
" separator=\" \", chunk_size=512, chunk_overlap=128\n",
|
316 |
")"
|
317 |
-
]
|
318 |
-
"metadata": {
|
319 |
-
"id": "wzOQZH6VZQBm"
|
320 |
-
},
|
321 |
-
"execution_count": null,
|
322 |
-
"outputs": []
|
323 |
},
|
324 |
{
|
325 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
326 |
"source": [
|
327 |
"from llama_index.core.extractors import (\n",
|
328 |
" SummaryExtractor,\n",
|
@@ -347,71 +336,63 @@
|
|
347 |
"\n",
|
348 |
"# Run the transformation pipeline.\n",
|
349 |
"nodes = pipeline.run(documents=documents, show_progress=True);"
|
350 |
-
]
|
351 |
-
"metadata": {
|
352 |
-
"id": "l6UP7M_rZeXS"
|
353 |
-
},
|
354 |
-
"execution_count": null,
|
355 |
-
"outputs": []
|
356 |
},
|
357 |
{
|
358 |
"cell_type": "code",
|
359 |
-
"
|
360 |
-
"len( nodes )"
|
361 |
-
],
|
362 |
"metadata": {
|
363 |
"id": "GcUUhs88ZeUs"
|
364 |
},
|
365 |
-
"
|
366 |
-
"
|
|
|
|
|
367 |
},
|
368 |
{
|
369 |
"cell_type": "code",
|
370 |
-
"
|
371 |
-
"# Compress the vector store directory to a zip file to be able to download and use later.\n",
|
372 |
-
"!zip -r vectorstore.zip mini-llama-articles"
|
373 |
-
],
|
374 |
"metadata": {
|
375 |
"id": "B_P8Cil-ZeQM"
|
376 |
},
|
377 |
-
"
|
378 |
-
"
|
|
|
|
|
|
|
379 |
},
|
380 |
{
|
381 |
"cell_type": "markdown",
|
382 |
-
"source": [
|
383 |
-
"# Load Indexes"
|
384 |
-
],
|
385 |
"metadata": {
|
386 |
"id": "YSGHsZMMZj4E"
|
387 |
-
}
|
|
|
|
|
|
|
388 |
},
|
389 |
{
|
390 |
"cell_type": "markdown",
|
391 |
-
"source": [
|
392 |
-
"If you have already uploaded the zip file for the vector store checkpoint, please uncomment the code in the following cell block to extract its contents. After doing so, you will be able to load the dataset from local storage."
|
393 |
-
],
|
394 |
"metadata": {
|
395 |
"id": "J81Yvj0AZlvK"
|
396 |
-
}
|
|
|
|
|
|
|
397 |
},
|
398 |
{
|
399 |
"cell_type": "code",
|
400 |
-
"
|
401 |
-
"# !unzip vectorstore.zip"
|
402 |
-
],
|
403 |
"metadata": {
|
404 |
-
"id": "M8iaOOGyZeNp",
|
405 |
"colab": {
|
406 |
"base_uri": "https://localhost:8080/"
|
407 |
},
|
|
|
408 |
"outputId": "6a117a0b-161a-4889-daf6-baf94ae00d2a"
|
409 |
},
|
410 |
-
"execution_count": null,
|
411 |
"outputs": [
|
412 |
{
|
413 |
-
"output_type": "stream",
|
414 |
"name": "stdout",
|
|
|
415 |
"text": [
|
416 |
"Archive: vectorstore.zip\n",
|
417 |
" creating: mini-llama-articles/\n",
|
@@ -423,60 +404,68 @@
|
|
423 |
" inflating: mini-llama-articles/chroma.sqlite3 \n"
|
424 |
]
|
425 |
}
|
|
|
|
|
|
|
426 |
]
|
427 |
},
|
428 |
{
|
429 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
430 |
"source": [
|
431 |
"# Load the vector store from the local storage.\n",
|
432 |
"db = chromadb.PersistentClient(path=\"./mini-llama-articles\")\n",
|
433 |
"chroma_collection = db.get_or_create_collection(\"mini-llama-articles\")\n",
|
434 |
"vector_store = ChromaVectorStore(chroma_collection=chroma_collection)"
|
435 |
-
]
|
436 |
-
"metadata": {
|
437 |
-
"id": "6tzS_EKPZeLS"
|
438 |
-
},
|
439 |
-
"execution_count": null,
|
440 |
-
"outputs": []
|
441 |
},
|
442 |
{
|
443 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
444 |
"source": [
|
445 |
"from llama_index.core import VectorStoreIndex\n",
|
446 |
"\n",
|
447 |
"# Create the index based on the vector store.\n",
|
448 |
"index = VectorStoreIndex.from_vector_store(vector_store)"
|
449 |
-
]
|
450 |
-
"metadata": {
|
451 |
-
"id": "0T6FL7J3ZrNK"
|
452 |
-
},
|
453 |
-
"execution_count": null,
|
454 |
-
"outputs": []
|
455 |
},
|
456 |
{
|
457 |
"cell_type": "markdown",
|
458 |
-
"source": [
|
459 |
-
"# RankGPT"
|
460 |
-
],
|
461 |
"metadata": {
|
462 |
"id": "w2XBkzNwLle5"
|
463 |
-
}
|
|
|
|
|
|
|
464 |
},
|
465 |
{
|
466 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
467 |
"source": [
|
468 |
"from llama_index.core.postprocessor.rankGPT_rerank import RankGPTRerank\n",
|
469 |
"\n",
|
470 |
"rankGPT = RankGPTRerank(top_n=3, llm=OpenAI(model=\"gpt-3.5-turbo\"))"
|
471 |
-
]
|
472 |
-
"metadata": {
|
473 |
-
"id": "_it2CxTtLmHT"
|
474 |
-
},
|
475 |
-
"execution_count": null,
|
476 |
-
"outputs": []
|
477 |
},
|
478 |
{
|
479 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
480 |
"source": [
|
481 |
"# Define a query engine that is responsible for retrieving related pieces of text,\n",
|
482 |
"# and using a LLM to formulate the final answer.\n",
|
@@ -487,18 +476,11 @@
|
|
487 |
")\n",
|
488 |
"\n",
|
489 |
"res = query_engine.query(\"How many parameters LLaMA2 model has?\")"
|
490 |
-
]
|
491 |
-
"metadata": {
|
492 |
-
"id": "YA3M9m9CL6AJ"
|
493 |
-
},
|
494 |
-
"execution_count": null,
|
495 |
-
"outputs": []
|
496 |
},
|
497 |
{
|
498 |
"cell_type": "code",
|
499 |
-
"
|
500 |
-
"res.response"
|
501 |
-
],
|
502 |
"metadata": {
|
503 |
"colab": {
|
504 |
"base_uri": "https://localhost:8080/",
|
@@ -507,34 +489,28 @@
|
|
507 |
"id": "wgyjv9e6MCVm",
|
508 |
"outputId": "70723d5e-9d16-4123-884b-0d65cd91a405"
|
509 |
},
|
510 |
-
"execution_count": null,
|
511 |
"outputs": [
|
512 |
{
|
513 |
-
"output_type": "execute_result",
|
514 |
"data": {
|
515 |
-
"text/plain": [
|
516 |
-
"'The Llama 2 model has four different parameter sizes: 7 billion, 13 billion, 34 billion, and 70 billion.'"
|
517 |
-
],
|
518 |
"application/vnd.google.colaboratory.intrinsic+json": {
|
519 |
"type": "string"
|
520 |
-
}
|
|
|
|
|
|
|
521 |
},
|
|
|
522 |
"metadata": {},
|
523 |
-
"
|
524 |
}
|
|
|
|
|
|
|
525 |
]
|
526 |
},
|
527 |
{
|
528 |
"cell_type": "code",
|
529 |
-
"
|
530 |
-
"# Show the retrieved nodes\n",
|
531 |
-
"for src in res.source_nodes:\n",
|
532 |
-
" print(\"Node ID\\t\", src.node_id)\n",
|
533 |
-
" print(\"Title\\t\", src.metadata['title'])\n",
|
534 |
-
" print(\"Text\\t\", src.text)\n",
|
535 |
-
" print(\"Score\\t\", src.score)\n",
|
536 |
-
" print(\"-_\"*20)"
|
537 |
-
],
|
538 |
"metadata": {
|
539 |
"colab": {
|
540 |
"base_uri": "https://localhost:8080/"
|
@@ -542,11 +518,10 @@
|
|
542 |
"id": "wUhOlwWcMEUT",
|
543 |
"outputId": "eae3754b-5cb8-4c5d-d739-c42c9686006d"
|
544 |
},
|
545 |
-
"execution_count": null,
|
546 |
"outputs": [
|
547 |
{
|
548 |
-
"output_type": "stream",
|
549 |
"name": "stdout",
|
|
|
550 |
"text": [
|
551 |
"Node ID\t d6f533e5-fef8-469c-a313-def19fd38efe\n",
|
552 |
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
|
@@ -565,37 +540,51 @@
|
|
565 |
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"
|
566 |
]
|
567 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
568 |
]
|
569 |
},
|
570 |
{
|
571 |
"cell_type": "markdown",
|
572 |
-
"source": [
|
573 |
-
"# Custom Postprocessor"
|
574 |
-
],
|
575 |
"metadata": {
|
576 |
"id": "5mcAcZqhQluE"
|
577 |
-
}
|
|
|
|
|
|
|
578 |
},
|
579 |
{
|
580 |
"cell_type": "markdown",
|
581 |
-
"source": [
|
582 |
-
"## The `Judger` Function"
|
583 |
-
],
|
584 |
"metadata": {
|
585 |
"id": "7v7vmJblQrN6"
|
586 |
-
}
|
|
|
|
|
|
|
587 |
},
|
588 |
{
|
589 |
"cell_type": "markdown",
|
590 |
-
"source": [
|
591 |
-
"The following function will query GPT-4 to retrieve the top three nodes that has highest similarity to the asked question."
|
592 |
-
],
|
593 |
"metadata": {
|
594 |
"id": "6k8IKlN9QvU7"
|
595 |
-
}
|
|
|
|
|
|
|
596 |
},
|
597 |
{
|
598 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
599 |
"source": [
|
600 |
"from pydantic import BaseModel\n",
|
601 |
"from llama_index.llms.openai import OpenAI\n",
|
@@ -634,39 +623,39 @@
|
|
634 |
" )\n",
|
635 |
"\n",
|
636 |
" # Define the an instance of GPT-4 and send the request\n",
|
637 |
-
" llm = OpenAI(model=\"gpt-
|
638 |
" ordered_nodes = llm.structured_predict(\n",
|
639 |
" OrderedNodes, prompt_tmpl, nodes_list=the_nodes, user_query=query\n",
|
640 |
" )\n",
|
641 |
"\n",
|
642 |
" return ordered_nodes"
|
643 |
-
]
|
644 |
-
"metadata": {
|
645 |
-
"id": "WhtJ1OeF9L3G"
|
646 |
-
},
|
647 |
-
"execution_count": null,
|
648 |
-
"outputs": []
|
649 |
},
|
650 |
{
|
651 |
"cell_type": "markdown",
|
652 |
-
"source": [
|
653 |
-
"## Define Postprocessor"
|
654 |
-
],
|
655 |
"metadata": {
|
656 |
"id": "Q5f1GrBKZprO"
|
657 |
-
}
|
|
|
|
|
|
|
658 |
},
|
659 |
{
|
660 |
"cell_type": "markdown",
|
661 |
-
"source": [
|
662 |
-
"The following class will use the `judger` function to rank the nodes, and filter them based on the ranks."
|
663 |
-
],
|
664 |
"metadata": {
|
665 |
"id": "yZujUJTvQ6Yu"
|
666 |
-
}
|
|
|
|
|
|
|
667 |
},
|
668 |
{
|
669 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
670 |
"source": [
|
671 |
"from typing import (\n",
|
672 |
" List,\n",
|
@@ -698,35 +687,35 @@
|
|
698 |
" final_nodes.append( item )\n",
|
699 |
"\n",
|
700 |
" return final_nodes"
|
701 |
-
]
|
702 |
-
"metadata": {
|
703 |
-
"id": "-QtyuC8fZun0"
|
704 |
-
},
|
705 |
-
"execution_count": null,
|
706 |
-
"outputs": []
|
707 |
},
|
708 |
{
|
709 |
"cell_type": "code",
|
710 |
-
"
|
711 |
-
"judge = OpenaiAsJudgePostprocessor()"
|
712 |
-
],
|
713 |
"metadata": {
|
714 |
"id": "jk-lqYlYLipi"
|
715 |
},
|
716 |
-
"
|
717 |
-
"
|
|
|
|
|
718 |
},
|
719 |
{
|
720 |
"cell_type": "markdown",
|
721 |
-
"source": [
|
722 |
-
"## Query Engine with Postprocessor"
|
723 |
-
],
|
724 |
"metadata": {
|
725 |
"id": "cgtsvxR7SflP"
|
726 |
-
}
|
|
|
|
|
|
|
727 |
},
|
728 |
{
|
729 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
730 |
"source": [
|
731 |
"# Define a query engine that is responsible for retrieving related pieces of text,\n",
|
732 |
"# and using a LLM to formulate the final answer.\n",
|
@@ -737,18 +726,11 @@
|
|
737 |
")\n",
|
738 |
"\n",
|
739 |
"res = query_engine.query(\"How many parameters LLaMA2 model has?\")"
|
740 |
-
]
|
741 |
-
"metadata": {
|
742 |
-
"id": "1Hh3RLCeLfXZ"
|
743 |
-
},
|
744 |
-
"execution_count": null,
|
745 |
-
"outputs": []
|
746 |
},
|
747 |
{
|
748 |
"cell_type": "code",
|
749 |
-
"
|
750 |
-
"res.response"
|
751 |
-
],
|
752 |
"metadata": {
|
753 |
"colab": {
|
754 |
"base_uri": "https://localhost:8080/",
|
@@ -757,46 +739,39 @@
|
|
757 |
"id": "zmZv0EIyF0wG",
|
758 |
"outputId": "7ff1b3bf-1b5f-4985-ea0d-3048d94c8da1"
|
759 |
},
|
760 |
-
"execution_count": null,
|
761 |
"outputs": [
|
762 |
{
|
763 |
-
"output_type": "execute_result",
|
764 |
"data": {
|
765 |
-
"text/plain": [
|
766 |
-
"'The Llama 2 model is available in four different sizes: 7 billion, 13 billion, 34 billion, and 70 billion parameters.'"
|
767 |
-
],
|
768 |
"application/vnd.google.colaboratory.intrinsic+json": {
|
769 |
"type": "string"
|
770 |
-
}
|
|
|
|
|
|
|
771 |
},
|
|
|
772 |
"metadata": {},
|
773 |
-
"
|
774 |
}
|
|
|
|
|
|
|
775 |
]
|
776 |
},
|
777 |
{
|
778 |
"cell_type": "code",
|
779 |
-
"
|
780 |
-
"# Show the retrieved nodes\n",
|
781 |
-
"for src in res.source_nodes:\n",
|
782 |
-
" print(\"Node ID\\t\", src.node_id)\n",
|
783 |
-
" print(\"Title\\t\", src.metadata['title'])\n",
|
784 |
-
" print(\"Text\\t\", src.text)\n",
|
785 |
-
" print(\"Score\\t\", src.score)\n",
|
786 |
-
" print(\"-_\"*20)"
|
787 |
-
],
|
788 |
"metadata": {
|
789 |
-
"id": "bBMaG6yaZzjA",
|
790 |
"colab": {
|
791 |
"base_uri": "https://localhost:8080/"
|
792 |
},
|
|
|
793 |
"outputId": "8a173ef7-e66f-4f9b-a979-c88a17028ef0"
|
794 |
},
|
795 |
-
"execution_count": null,
|
796 |
"outputs": [
|
797 |
{
|
798 |
-
"output_type": "stream",
|
799 |
"name": "stdout",
|
|
|
800 |
"text": [
|
801 |
"Node ID\t d6f533e5-fef8-469c-a313-def19fd38efe\n",
|
802 |
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
|
@@ -815,16 +790,41 @@
|
|
815 |
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"
|
816 |
]
|
817 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
818 |
]
|
819 |
},
|
820 |
{
|
821 |
"cell_type": "code",
|
822 |
-
"
|
823 |
"metadata": {
|
824 |
"id": "J7sIPpFFTep3"
|
825 |
},
|
826 |
-
"
|
827 |
-
"
|
828 |
}
|
829 |
-
]
|
830 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "markdown",
|
5 |
"metadata": {
|
6 |
+
"colab_type": "text",
|
7 |
+
"id": "view-in-github"
|
8 |
},
|
9 |
"source": [
|
10 |
"<a href=\"https://colab.research.google.com/github/towardsai/ai-tutor-rag-system/blob/main/notebooks/17-Using_LLMs_to_rank_chunks_as_the_Judge.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "markdown",
|
|
|
|
|
|
|
15 |
"metadata": {
|
16 |
"id": "0FbELaf7TrW7"
|
17 |
+
},
|
18 |
+
"source": [
|
19 |
+
"# Install Packages and Setup Variables"
|
20 |
+
]
|
21 |
},
|
22 |
{
|
23 |
"cell_type": "code",
|
24 |
"execution_count": null,
|
25 |
"metadata": {
|
|
|
26 |
"colab": {
|
27 |
"base_uri": "https://localhost:8080/"
|
28 |
},
|
29 |
+
"id": "Yubz8AanRRSW",
|
30 |
"outputId": "2487c4fd-0fb5-4894-ffe6-c747f4adb952"
|
31 |
},
|
32 |
"outputs": [
|
33 |
{
|
|
|
34 |
"name": "stdout",
|
35 |
+
"output_type": "stream",
|
36 |
"text": [
|
37 |
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m226.7/226.7 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
38 |
"\u001b[2K \u001b[90mββββββββββββββββββββββββββββββββββββββββ\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m11.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
|
|
90 |
},
|
91 |
{
|
92 |
"cell_type": "code",
|
93 |
+
"execution_count": null,
|
94 |
+
"metadata": {
|
95 |
+
"id": "xLXFuRW-TpUu"
|
96 |
+
},
|
97 |
+
"outputs": [],
|
98 |
"source": [
|
99 |
"import os\n",
|
100 |
"\n",
|
101 |
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
|
102 |
"os.environ[\"OPENAI_API_KEY\"] = \"[OPENAI_API_KEY]\""
|
103 |
+
]
|
|
|
|
|
|
|
|
|
|
|
104 |
},
|
105 |
{
|
106 |
"cell_type": "markdown",
|
|
|
|
|
|
|
107 |
"metadata": {
|
108 |
"id": "r6GCYYqqTuMc"
|
109 |
+
},
|
110 |
+
"source": [
|
111 |
+
"# Load a Model"
|
112 |
+
]
|
113 |
},
|
114 |
{
|
115 |
"cell_type": "code",
|
116 |
+
"execution_count": null,
|
117 |
+
"metadata": {
|
118 |
+
"id": "pupJpdZaTu5m"
|
119 |
+
},
|
120 |
+
"outputs": [],
|
121 |
"source": [
|
122 |
"from llama_index.llms.openai import OpenAI\n",
|
123 |
"\n",
|
124 |
"llm = OpenAI(temperature=0.9, model=\"gpt-3.5-turbo\", max_tokens=512)"
|
125 |
+
]
|
|
|
|
|
|
|
|
|
|
|
126 |
},
|
127 |
{
|
128 |
"cell_type": "markdown",
|
|
|
|
|
|
|
129 |
"metadata": {
|
130 |
"id": "gaKYO-KrTwsn"
|
131 |
+
},
|
132 |
+
"source": [
|
133 |
+
"# Create a Vector Store"
|
134 |
+
]
|
135 |
},
|
136 |
{
|
137 |
"cell_type": "code",
|
138 |
+
"execution_count": null,
|
139 |
+
"metadata": {
|
140 |
+
"id": "npCqCZSPZKR0"
|
141 |
+
},
|
142 |
+
"outputs": [],
|
143 |
"source": [
|
144 |
"import chromadb\n",
|
145 |
"\n",
|
|
|
147 |
"# chromadb.EphemeralClient saves data in-memory.\n",
|
148 |
"chroma_client = chromadb.PersistentClient(path=\"./mini-llama-articles\")\n",
|
149 |
"chroma_collection = chroma_client.create_collection(\"mini-llama-articles\")"
|
150 |
+
]
|
|
|
|
|
|
|
|
|
|
|
151 |
},
|
152 |
{
|
153 |
"cell_type": "code",
|
154 |
+
"execution_count": null,
|
155 |
+
"metadata": {
|
156 |
+
"id": "dG9eKSVrZMs1"
|
157 |
+
},
|
158 |
+
"outputs": [],
|
159 |
"source": [
|
160 |
"from llama_index.vector_stores.chroma import ChromaVectorStore\n",
|
161 |
"\n",
|
162 |
"# Define a storage context object using the created vector database.\n",
|
163 |
"vector_store = ChromaVectorStore(chroma_collection=chroma_collection)"
|
164 |
+
]
|
|
|
|
|
|
|
|
|
|
|
165 |
},
|
166 |
{
|
167 |
"cell_type": "markdown",
|
|
|
|
|
|
|
168 |
"metadata": {
|
169 |
"id": "HmiFENBdZMAk"
|
170 |
+
},
|
171 |
+
"source": [
|
172 |
+
"# Load the Dataset (CSV)"
|
173 |
+
]
|
174 |
},
|
175 |
{
|
176 |
"cell_type": "markdown",
|
|
|
|
|
|
|
177 |
"metadata": {
|
178 |
"id": "X-20isiTZRIa"
|
179 |
+
},
|
180 |
+
"source": [
|
181 |
+
"## Download"
|
182 |
+
]
|
183 |
},
|
184 |
{
|
185 |
"cell_type": "markdown",
|
|
|
|
|
|
|
186 |
"metadata": {
|
187 |
"id": "-lWKX814ZURc"
|
188 |
+
},
|
189 |
+
"source": [
|
190 |
+
"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."
|
191 |
+
]
|
192 |
},
|
193 |
{
|
194 |
"cell_type": "code",
|
195 |
+
"execution_count": null,
|
|
|
|
|
196 |
"metadata": {
|
|
|
197 |
"colab": {
|
198 |
"base_uri": "https://localhost:8080/"
|
199 |
},
|
200 |
+
"id": "fmlEL849ZPrH",
|
201 |
"outputId": "63039988-ab7a-4ecf-deb0-d9510628ecb8"
|
202 |
},
|
|
|
203 |
"outputs": [
|
204 |
{
|
|
|
205 |
"name": "stdout",
|
206 |
+
"output_type": "stream",
|
207 |
"text": [
|
208 |
"--2024-04-30 18:37:36-- https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles.csv\n",
|
209 |
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.111.133, ...\n",
|
|
|
218 |
"\n"
|
219 |
]
|
220 |
}
|
221 |
+
],
|
222 |
+
"source": [
|
223 |
+
"!wget https://raw.githubusercontent.com/AlaFalaki/tutorial_notebooks/main/data/mini-llama-articles.csv"
|
224 |
]
|
225 |
},
|
226 |
{
|
227 |
"cell_type": "markdown",
|
|
|
|
|
|
|
228 |
"metadata": {
|
229 |
"id": "r9PL_eiTZW7y"
|
230 |
+
},
|
231 |
+
"source": [
|
232 |
+
"# Read File"
|
233 |
+
]
|
234 |
},
|
235 |
{
|
236 |
"cell_type": "code",
|
237 |
+
"execution_count": null,
|
238 |
+
"metadata": {
|
239 |
+
"id": "x5IwXJi8ZQGh"
|
240 |
+
},
|
241 |
+
"outputs": [],
|
242 |
"source": [
|
243 |
"import csv\n",
|
244 |
"\n",
|
|
|
254 |
"\n",
|
255 |
"# The number of characters in the dataset.\n",
|
256 |
"len( rows )"
|
257 |
+
]
|
|
|
|
|
|
|
|
|
|
|
258 |
},
|
259 |
{
|
260 |
"cell_type": "markdown",
|
|
|
|
|
|
|
261 |
"metadata": {
|
262 |
"id": "ktYUZzzSZaDW"
|
263 |
+
},
|
264 |
+
"source": [
|
265 |
+
"# Convert to Document obj"
|
266 |
+
]
|
267 |
},
|
268 |
{
|
269 |
"cell_type": "code",
|
270 |
+
"execution_count": null,
|
271 |
+
"metadata": {
|
272 |
+
"id": "oO10Q-UyZQEB"
|
273 |
+
},
|
274 |
+
"outputs": [],
|
275 |
"source": [
|
276 |
"from llama_index.core.schema import Document\n",
|
277 |
"\n",
|
278 |
"# Convert the chunks to Document objects so the LlamaIndex framework can process them.\n",
|
279 |
"documents = [Document(text=row[1], metadata={\"title\": row[0], \"url\": row[2], \"source_name\": row[3]}) for row in rows]"
|
280 |
+
]
|
|
|
|
|
|
|
|
|
|
|
281 |
},
|
282 |
{
|
283 |
"cell_type": "markdown",
|
|
|
|
|
|
|
284 |
"metadata": {
|
285 |
"id": "0PnovZ0tZdAT"
|
286 |
+
},
|
287 |
+
"source": [
|
288 |
+
"# Transforming"
|
289 |
+
]
|
290 |
},
|
291 |
{
|
292 |
"cell_type": "code",
|
293 |
+
"execution_count": null,
|
294 |
+
"metadata": {
|
295 |
+
"id": "wzOQZH6VZQBm"
|
296 |
+
},
|
297 |
+
"outputs": [],
|
298 |
"source": [
|
299 |
"from llama_index.core.node_parser import TokenTextSplitter\n",
|
300 |
"\n",
|
|
|
303 |
"text_splitter = TokenTextSplitter(\n",
|
304 |
" separator=\" \", chunk_size=512, chunk_overlap=128\n",
|
305 |
")"
|
306 |
+
]
|
|
|
|
|
|
|
|
|
|
|
307 |
},
|
308 |
{
|
309 |
"cell_type": "code",
|
310 |
+
"execution_count": null,
|
311 |
+
"metadata": {
|
312 |
+
"id": "l6UP7M_rZeXS"
|
313 |
+
},
|
314 |
+
"outputs": [],
|
315 |
"source": [
|
316 |
"from llama_index.core.extractors import (\n",
|
317 |
" SummaryExtractor,\n",
|
|
|
336 |
"\n",
|
337 |
"# Run the transformation pipeline.\n",
|
338 |
"nodes = pipeline.run(documents=documents, show_progress=True);"
|
339 |
+
]
|
|
|
|
|
|
|
|
|
|
|
340 |
},
|
341 |
{
|
342 |
"cell_type": "code",
|
343 |
+
"execution_count": null,
|
|
|
|
|
344 |
"metadata": {
|
345 |
"id": "GcUUhs88ZeUs"
|
346 |
},
|
347 |
+
"outputs": [],
|
348 |
+
"source": [
|
349 |
+
"len( nodes )"
|
350 |
+
]
|
351 |
},
|
352 |
{
|
353 |
"cell_type": "code",
|
354 |
+
"execution_count": null,
|
|
|
|
|
|
|
355 |
"metadata": {
|
356 |
"id": "B_P8Cil-ZeQM"
|
357 |
},
|
358 |
+
"outputs": [],
|
359 |
+
"source": [
|
360 |
+
"# Compress the vector store directory to a zip file to be able to download and use later.\n",
|
361 |
+
"!zip -r vectorstore.zip mini-llama-articles"
|
362 |
+
]
|
363 |
},
|
364 |
{
|
365 |
"cell_type": "markdown",
|
|
|
|
|
|
|
366 |
"metadata": {
|
367 |
"id": "YSGHsZMMZj4E"
|
368 |
+
},
|
369 |
+
"source": [
|
370 |
+
"# Load Indexes"
|
371 |
+
]
|
372 |
},
|
373 |
{
|
374 |
"cell_type": "markdown",
|
|
|
|
|
|
|
375 |
"metadata": {
|
376 |
"id": "J81Yvj0AZlvK"
|
377 |
+
},
|
378 |
+
"source": [
|
379 |
+
"If you have already uploaded the zip file for the vector store checkpoint, please uncomment the code in the following cell block to extract its contents. After doing so, you will be able to load the dataset from local storage."
|
380 |
+
]
|
381 |
},
|
382 |
{
|
383 |
"cell_type": "code",
|
384 |
+
"execution_count": null,
|
|
|
|
|
385 |
"metadata": {
|
|
|
386 |
"colab": {
|
387 |
"base_uri": "https://localhost:8080/"
|
388 |
},
|
389 |
+
"id": "M8iaOOGyZeNp",
|
390 |
"outputId": "6a117a0b-161a-4889-daf6-baf94ae00d2a"
|
391 |
},
|
|
|
392 |
"outputs": [
|
393 |
{
|
|
|
394 |
"name": "stdout",
|
395 |
+
"output_type": "stream",
|
396 |
"text": [
|
397 |
"Archive: vectorstore.zip\n",
|
398 |
" creating: mini-llama-articles/\n",
|
|
|
404 |
" inflating: mini-llama-articles/chroma.sqlite3 \n"
|
405 |
]
|
406 |
}
|
407 |
+
],
|
408 |
+
"source": [
|
409 |
+
"# !unzip vectorstore.zip"
|
410 |
]
|
411 |
},
|
412 |
{
|
413 |
"cell_type": "code",
|
414 |
+
"execution_count": null,
|
415 |
+
"metadata": {
|
416 |
+
"id": "6tzS_EKPZeLS"
|
417 |
+
},
|
418 |
+
"outputs": [],
|
419 |
"source": [
|
420 |
"# Load the vector store from the local storage.\n",
|
421 |
"db = chromadb.PersistentClient(path=\"./mini-llama-articles\")\n",
|
422 |
"chroma_collection = db.get_or_create_collection(\"mini-llama-articles\")\n",
|
423 |
"vector_store = ChromaVectorStore(chroma_collection=chroma_collection)"
|
424 |
+
]
|
|
|
|
|
|
|
|
|
|
|
425 |
},
|
426 |
{
|
427 |
"cell_type": "code",
|
428 |
+
"execution_count": null,
|
429 |
+
"metadata": {
|
430 |
+
"id": "0T6FL7J3ZrNK"
|
431 |
+
},
|
432 |
+
"outputs": [],
|
433 |
"source": [
|
434 |
"from llama_index.core import VectorStoreIndex\n",
|
435 |
"\n",
|
436 |
"# Create the index based on the vector store.\n",
|
437 |
"index = VectorStoreIndex.from_vector_store(vector_store)"
|
438 |
+
]
|
|
|
|
|
|
|
|
|
|
|
439 |
},
|
440 |
{
|
441 |
"cell_type": "markdown",
|
|
|
|
|
|
|
442 |
"metadata": {
|
443 |
"id": "w2XBkzNwLle5"
|
444 |
+
},
|
445 |
+
"source": [
|
446 |
+
"# RankGPT"
|
447 |
+
]
|
448 |
},
|
449 |
{
|
450 |
"cell_type": "code",
|
451 |
+
"execution_count": null,
|
452 |
+
"metadata": {
|
453 |
+
"id": "_it2CxTtLmHT"
|
454 |
+
},
|
455 |
+
"outputs": [],
|
456 |
"source": [
|
457 |
"from llama_index.core.postprocessor.rankGPT_rerank import RankGPTRerank\n",
|
458 |
"\n",
|
459 |
"rankGPT = RankGPTRerank(top_n=3, llm=OpenAI(model=\"gpt-3.5-turbo\"))"
|
460 |
+
]
|
|
|
|
|
|
|
|
|
|
|
461 |
},
|
462 |
{
|
463 |
"cell_type": "code",
|
464 |
+
"execution_count": null,
|
465 |
+
"metadata": {
|
466 |
+
"id": "YA3M9m9CL6AJ"
|
467 |
+
},
|
468 |
+
"outputs": [],
|
469 |
"source": [
|
470 |
"# Define a query engine that is responsible for retrieving related pieces of text,\n",
|
471 |
"# and using a LLM to formulate the final answer.\n",
|
|
|
476 |
")\n",
|
477 |
"\n",
|
478 |
"res = query_engine.query(\"How many parameters LLaMA2 model has?\")"
|
479 |
+
]
|
|
|
|
|
|
|
|
|
|
|
480 |
},
|
481 |
{
|
482 |
"cell_type": "code",
|
483 |
+
"execution_count": null,
|
|
|
|
|
484 |
"metadata": {
|
485 |
"colab": {
|
486 |
"base_uri": "https://localhost:8080/",
|
|
|
489 |
"id": "wgyjv9e6MCVm",
|
490 |
"outputId": "70723d5e-9d16-4123-884b-0d65cd91a405"
|
491 |
},
|
|
|
492 |
"outputs": [
|
493 |
{
|
|
|
494 |
"data": {
|
|
|
|
|
|
|
495 |
"application/vnd.google.colaboratory.intrinsic+json": {
|
496 |
"type": "string"
|
497 |
+
},
|
498 |
+
"text/plain": [
|
499 |
+
"'The Llama 2 model has four different parameter sizes: 7 billion, 13 billion, 34 billion, and 70 billion.'"
|
500 |
+
]
|
501 |
},
|
502 |
+
"execution_count": 12,
|
503 |
"metadata": {},
|
504 |
+
"output_type": "execute_result"
|
505 |
}
|
506 |
+
],
|
507 |
+
"source": [
|
508 |
+
"res.response"
|
509 |
]
|
510 |
},
|
511 |
{
|
512 |
"cell_type": "code",
|
513 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
514 |
"metadata": {
|
515 |
"colab": {
|
516 |
"base_uri": "https://localhost:8080/"
|
|
|
518 |
"id": "wUhOlwWcMEUT",
|
519 |
"outputId": "eae3754b-5cb8-4c5d-d739-c42c9686006d"
|
520 |
},
|
|
|
521 |
"outputs": [
|
522 |
{
|
|
|
523 |
"name": "stdout",
|
524 |
+
"output_type": "stream",
|
525 |
"text": [
|
526 |
"Node ID\t d6f533e5-fef8-469c-a313-def19fd38efe\n",
|
527 |
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
|
|
|
540 |
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"
|
541 |
]
|
542 |
}
|
543 |
+
],
|
544 |
+
"source": [
|
545 |
+
"# Show the retrieved nodes\n",
|
546 |
+
"for src in res.source_nodes:\n",
|
547 |
+
" print(\"Node ID\\t\", src.node_id)\n",
|
548 |
+
" print(\"Title\\t\", src.metadata['title'])\n",
|
549 |
+
" print(\"Text\\t\", src.text)\n",
|
550 |
+
" print(\"Score\\t\", src.score)\n",
|
551 |
+
" print(\"-_\"*20)"
|
552 |
]
|
553 |
},
|
554 |
{
|
555 |
"cell_type": "markdown",
|
|
|
|
|
|
|
556 |
"metadata": {
|
557 |
"id": "5mcAcZqhQluE"
|
558 |
+
},
|
559 |
+
"source": [
|
560 |
+
"# Custom Postprocessor"
|
561 |
+
]
|
562 |
},
|
563 |
{
|
564 |
"cell_type": "markdown",
|
|
|
|
|
|
|
565 |
"metadata": {
|
566 |
"id": "7v7vmJblQrN6"
|
567 |
+
},
|
568 |
+
"source": [
|
569 |
+
"## The `Judger` Function"
|
570 |
+
]
|
571 |
},
|
572 |
{
|
573 |
"cell_type": "markdown",
|
|
|
|
|
|
|
574 |
"metadata": {
|
575 |
"id": "6k8IKlN9QvU7"
|
576 |
+
},
|
577 |
+
"source": [
|
578 |
+
"The following function will query GPT-4 to retrieve the top three nodes that has highest similarity to the asked question."
|
579 |
+
]
|
580 |
},
|
581 |
{
|
582 |
"cell_type": "code",
|
583 |
+
"execution_count": null,
|
584 |
+
"metadata": {
|
585 |
+
"id": "WhtJ1OeF9L3G"
|
586 |
+
},
|
587 |
+
"outputs": [],
|
588 |
"source": [
|
589 |
"from pydantic import BaseModel\n",
|
590 |
"from llama_index.llms.openai import OpenAI\n",
|
|
|
623 |
" )\n",
|
624 |
"\n",
|
625 |
" # Define the an instance of GPT-4 and send the request\n",
|
626 |
+
" llm = OpenAI(model=\"gpt-4o\")\n",
|
627 |
" ordered_nodes = llm.structured_predict(\n",
|
628 |
" OrderedNodes, prompt_tmpl, nodes_list=the_nodes, user_query=query\n",
|
629 |
" )\n",
|
630 |
"\n",
|
631 |
" return ordered_nodes"
|
632 |
+
]
|
|
|
|
|
|
|
|
|
|
|
633 |
},
|
634 |
{
|
635 |
"cell_type": "markdown",
|
|
|
|
|
|
|
636 |
"metadata": {
|
637 |
"id": "Q5f1GrBKZprO"
|
638 |
+
},
|
639 |
+
"source": [
|
640 |
+
"## Define Postprocessor"
|
641 |
+
]
|
642 |
},
|
643 |
{
|
644 |
"cell_type": "markdown",
|
|
|
|
|
|
|
645 |
"metadata": {
|
646 |
"id": "yZujUJTvQ6Yu"
|
647 |
+
},
|
648 |
+
"source": [
|
649 |
+
"The following class will use the `judger` function to rank the nodes, and filter them based on the ranks."
|
650 |
+
]
|
651 |
},
|
652 |
{
|
653 |
"cell_type": "code",
|
654 |
+
"execution_count": null,
|
655 |
+
"metadata": {
|
656 |
+
"id": "-QtyuC8fZun0"
|
657 |
+
},
|
658 |
+
"outputs": [],
|
659 |
"source": [
|
660 |
"from typing import (\n",
|
661 |
" List,\n",
|
|
|
687 |
" final_nodes.append( item )\n",
|
688 |
"\n",
|
689 |
" return final_nodes"
|
690 |
+
]
|
|
|
|
|
|
|
|
|
|
|
691 |
},
|
692 |
{
|
693 |
"cell_type": "code",
|
694 |
+
"execution_count": null,
|
|
|
|
|
695 |
"metadata": {
|
696 |
"id": "jk-lqYlYLipi"
|
697 |
},
|
698 |
+
"outputs": [],
|
699 |
+
"source": [
|
700 |
+
"judge = OpenaiAsJudgePostprocessor()"
|
701 |
+
]
|
702 |
},
|
703 |
{
|
704 |
"cell_type": "markdown",
|
|
|
|
|
|
|
705 |
"metadata": {
|
706 |
"id": "cgtsvxR7SflP"
|
707 |
+
},
|
708 |
+
"source": [
|
709 |
+
"## Query Engine with Postprocessor"
|
710 |
+
]
|
711 |
},
|
712 |
{
|
713 |
"cell_type": "code",
|
714 |
+
"execution_count": null,
|
715 |
+
"metadata": {
|
716 |
+
"id": "1Hh3RLCeLfXZ"
|
717 |
+
},
|
718 |
+
"outputs": [],
|
719 |
"source": [
|
720 |
"# Define a query engine that is responsible for retrieving related pieces of text,\n",
|
721 |
"# and using a LLM to formulate the final answer.\n",
|
|
|
726 |
")\n",
|
727 |
"\n",
|
728 |
"res = query_engine.query(\"How many parameters LLaMA2 model has?\")"
|
729 |
+
]
|
|
|
|
|
|
|
|
|
|
|
730 |
},
|
731 |
{
|
732 |
"cell_type": "code",
|
733 |
+
"execution_count": null,
|
|
|
|
|
734 |
"metadata": {
|
735 |
"colab": {
|
736 |
"base_uri": "https://localhost:8080/",
|
|
|
739 |
"id": "zmZv0EIyF0wG",
|
740 |
"outputId": "7ff1b3bf-1b5f-4985-ea0d-3048d94c8da1"
|
741 |
},
|
|
|
742 |
"outputs": [
|
743 |
{
|
|
|
744 |
"data": {
|
|
|
|
|
|
|
745 |
"application/vnd.google.colaboratory.intrinsic+json": {
|
746 |
"type": "string"
|
747 |
+
},
|
748 |
+
"text/plain": [
|
749 |
+
"'The Llama 2 model is available in four different sizes: 7 billion, 13 billion, 34 billion, and 70 billion parameters.'"
|
750 |
+
]
|
751 |
},
|
752 |
+
"execution_count": 29,
|
753 |
"metadata": {},
|
754 |
+
"output_type": "execute_result"
|
755 |
}
|
756 |
+
],
|
757 |
+
"source": [
|
758 |
+
"res.response"
|
759 |
]
|
760 |
},
|
761 |
{
|
762 |
"cell_type": "code",
|
763 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
764 |
"metadata": {
|
|
|
765 |
"colab": {
|
766 |
"base_uri": "https://localhost:8080/"
|
767 |
},
|
768 |
+
"id": "bBMaG6yaZzjA",
|
769 |
"outputId": "8a173ef7-e66f-4f9b-a979-c88a17028ef0"
|
770 |
},
|
|
|
771 |
"outputs": [
|
772 |
{
|
|
|
773 |
"name": "stdout",
|
774 |
+
"output_type": "stream",
|
775 |
"text": [
|
776 |
"Node ID\t d6f533e5-fef8-469c-a313-def19fd38efe\n",
|
777 |
"Title\t Meta's Llama 2: Revolutionizing Open Source Language Models for Commercial Use\n",
|
|
|
790 |
"-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n"
|
791 |
]
|
792 |
}
|
793 |
+
],
|
794 |
+
"source": [
|
795 |
+
"# Show the retrieved nodes\n",
|
796 |
+
"for src in res.source_nodes:\n",
|
797 |
+
" print(\"Node ID\\t\", src.node_id)\n",
|
798 |
+
" print(\"Title\\t\", src.metadata['title'])\n",
|
799 |
+
" print(\"Text\\t\", src.text)\n",
|
800 |
+
" print(\"Score\\t\", src.score)\n",
|
801 |
+
" print(\"-_\"*20)"
|
802 |
]
|
803 |
},
|
804 |
{
|
805 |
"cell_type": "code",
|
806 |
+
"execution_count": null,
|
807 |
"metadata": {
|
808 |
"id": "J7sIPpFFTep3"
|
809 |
},
|
810 |
+
"outputs": [],
|
811 |
+
"source": []
|
812 |
}
|
813 |
+
],
|
814 |
+
"metadata": {
|
815 |
+
"colab": {
|
816 |
+
"authorship_tag": "ABX9TyMhd0xkjZD3StMhSoQIPv+w",
|
817 |
+
"include_colab_link": true,
|
818 |
+
"provenance": []
|
819 |
+
},
|
820 |
+
"kernelspec": {
|
821 |
+
"display_name": "Python 3",
|
822 |
+
"name": "python3"
|
823 |
+
},
|
824 |
+
"language_info": {
|
825 |
+
"name": "python"
|
826 |
+
}
|
827 |
+
},
|
828 |
+
"nbformat": 4,
|
829 |
+
"nbformat_minor": 0
|
830 |
+
}
|
scripts/basic_tutor.py
CHANGED
@@ -26,7 +26,7 @@ def ask_ai_tutor(question):
|
|
26 |
|
27 |
# Call the OpenAI API
|
28 |
response = client.chat.completions.create(
|
29 |
-
model="gpt-3.5-turbo
|
30 |
messages=[
|
31 |
{"role": "system", "content": system_prompt},
|
32 |
{"role": "user", "content": prompt},
|
|
|
26 |
|
27 |
# Call the OpenAI API
|
28 |
response = client.chat.completions.create(
|
29 |
+
model="gpt-3.5-turbo",
|
30 |
messages=[
|
31 |
{"role": "system", "content": system_prompt},
|
32 |
{"role": "user", "content": prompt},
|
scripts/call_openai.py
CHANGED
@@ -16,7 +16,7 @@ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
16 |
def api_function_call(
|
17 |
system_message,
|
18 |
query: str,
|
19 |
-
model: str = "gpt-
|
20 |
response_model=None,
|
21 |
max_retries: int = 0,
|
22 |
stream: bool = False,
|
|
|
16 |
def api_function_call(
|
17 |
system_message,
|
18 |
query: str,
|
19 |
+
model: str = "gpt-4o",
|
20 |
response_model=None,
|
21 |
max_retries: int = 0,
|
22 |
stream: bool = False,
|
scripts/create_db.ipynb
CHANGED
@@ -158,7 +158,7 @@
|
|
158 |
"source": [
|
159 |
"from llama_index.llms.openai import OpenAI\n",
|
160 |
"\n",
|
161 |
-
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo
|
162 |
"query_engine = index.as_query_engine(llm=llm, similarity_top_k=5, embed_model=embeds)"
|
163 |
]
|
164 |
},
|
@@ -252,7 +252,7 @@
|
|
252 |
" condition=FilterCondition.OR,\n",
|
253 |
")\n",
|
254 |
"\n",
|
255 |
-
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo
|
256 |
"embeds = OpenAIEmbedding(model=\"text-embedding-3-large\", mode=\"text_search\")\n",
|
257 |
"# query_engine = index.as_query_engine(\n",
|
258 |
"# llm=llm, similarity_top_k=5, embed_model=embeds, verbose=True, streaming=True, filters=filters\n",
|
|
|
158 |
"source": [
|
159 |
"from llama_index.llms.openai import OpenAI\n",
|
160 |
"\n",
|
161 |
+
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo\", max_tokens=None)\n",
|
162 |
"query_engine = index.as_query_engine(llm=llm, similarity_top_k=5, embed_model=embeds)"
|
163 |
]
|
164 |
},
|
|
|
252 |
" condition=FilterCondition.OR,\n",
|
253 |
")\n",
|
254 |
"\n",
|
255 |
+
"llm = OpenAI(temperature=0, model=\"gpt-3.5-turbo\", max_tokens=None)\n",
|
256 |
"embeds = OpenAIEmbedding(model=\"text-embedding-3-large\", mode=\"text_search\")\n",
|
257 |
"# query_engine = index.as_query_engine(\n",
|
258 |
"# llm=llm, similarity_top_k=5, embed_model=embeds, verbose=True, streaming=True, filters=filters\n",
|
scripts/gradio-ui.py
CHANGED
@@ -81,7 +81,7 @@ vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
|
|
81 |
index = VectorStoreIndex.from_vector_store(vector_store=vector_store)
|
82 |
|
83 |
# Initialize OpenAI models
|
84 |
-
llm = OpenAI(temperature=0, model="gpt-3.5-turbo
|
85 |
# embeds = OpenAIEmbedding(model="text-embedding-3-large", mode="text_search")
|
86 |
embeds = OpenAIEmbedding(model="text-embedding-3-large", mode="similarity")
|
87 |
|
|
|
81 |
index = VectorStoreIndex.from_vector_store(vector_store=vector_store)
|
82 |
|
83 |
# Initialize OpenAI models
|
84 |
+
llm = OpenAI(temperature=0, model="gpt-3.5-turbo", max_tokens=None)
|
85 |
# embeds = OpenAIEmbedding(model="text-embedding-3-large", mode="text_search")
|
86 |
embeds = OpenAIEmbedding(model="text-embedding-3-large", mode="similarity")
|
87 |
|