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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 9,
|
6 |
+
"id": "a600d7fc",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import json \n",
|
11 |
+
"with open('metadata.jsonl', 'r') as f: \n",
|
12 |
+
" json_list = list(f)\n",
|
13 |
+
"\n",
|
14 |
+
"json_QA = []\n",
|
15 |
+
"for json_str in json_list: \n",
|
16 |
+
" json_data = json.loads(json_str)\n",
|
17 |
+
" json_QA.append(json_data)"
|
18 |
+
]
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"cell_type": "code",
|
22 |
+
"execution_count": 10,
|
23 |
+
"id": "fa5d8eb8",
|
24 |
+
"metadata": {},
|
25 |
+
"outputs": [
|
26 |
+
{
|
27 |
+
"name": "stdout",
|
28 |
+
"output_type": "stream",
|
29 |
+
"text": [
|
30 |
+
"==================================================\n",
|
31 |
+
"Task ID: d1af70ea-a9a4-421a-b9cc-94b5e02f1788\n",
|
32 |
+
"Question: As of the 2020 census, what was the population difference between the largest county seat and smallest county seat, by land area of the county seat, in Washington state? For population figures, please use the official data from data.census.gov. Please report the integer difference.\n",
|
33 |
+
"Level: 2\n",
|
34 |
+
"Final Answer: 736455\n",
|
35 |
+
"Annotator Metadata: \n",
|
36 |
+
" βββ Steps: \n",
|
37 |
+
" β βββ Step 1: Using a web browser, access a search engine and conduct a search, \"Washington cities by area\"\n",
|
38 |
+
" β βββ Step 2: Navigate to the second search result, https://en.wikipedia.org/wiki/List_of_municipalities_in_Washington\n",
|
39 |
+
" β βββ Step 3: Evaluate the page contents, finding the largest and smallest county seats by land area, Seattle and Cathlamet\n",
|
40 |
+
" β βββ Step 4: Using a web browser, navigate to https://data.census.gov/\n",
|
41 |
+
" β βββ Step 5: Using the website's search area, conduct a search, Seattle, Washington\n",
|
42 |
+
" β βββ Step 6: Record the reported 2020 Decennial Census population of Seattle, Washington, 737,015\n",
|
43 |
+
" β βββ Step 7: Using the website's search area, conduct a search, Cathlamet, Washington\n",
|
44 |
+
" β βββ Step 8: Record the reported 2020 Decennial Census population of Cathlamet, Washington, 560\n",
|
45 |
+
" β βββ Step 9: Using a calculator, find the difference in populations,\n",
|
46 |
+
" β βββ \n",
|
47 |
+
" β βββ 737,015 - 560\n",
|
48 |
+
" β βββ 736,455\n",
|
49 |
+
" β βββ Step 10: Report the correct answer to my user in the requested format, \"736,455\"\n",
|
50 |
+
" βββ Number of steps: 10\n",
|
51 |
+
" βββ How long did this take?: 5 minutes\n",
|
52 |
+
" βββ Tools:\n",
|
53 |
+
" β βββ 1. A web browser\n",
|
54 |
+
" β βββ 2. A search engine\n",
|
55 |
+
" β βββ 3. A calculator\n",
|
56 |
+
" βββ Number of tools: 3\n",
|
57 |
+
"==================================================\n"
|
58 |
+
]
|
59 |
+
}
|
60 |
+
],
|
61 |
+
"source": [
|
62 |
+
"import random\n",
|
63 |
+
"random_samples = random.sample(json_QA, 1)\n",
|
64 |
+
"for sample in random_samples:\n",
|
65 |
+
" print(\"=\" * 50)\n",
|
66 |
+
" print(f\"Task ID: {sample['task_id']}\")\n",
|
67 |
+
" print(f\"Question: {sample['Question']}\")\n",
|
68 |
+
" print(f\"Level: {sample['Level']}\")\n",
|
69 |
+
" print(f\"Final Answer: {sample['Final answer']}\")\n",
|
70 |
+
" print(f\"Annotator Metadata: \")\n",
|
71 |
+
" print(f\" βββ Steps: \")\n",
|
72 |
+
" for step in sample['Annotator Metadata']['Steps'].split('\\n'):\n",
|
73 |
+
" print(f\" β βββ {step}\")\n",
|
74 |
+
" print(f\" βββ Number of steps: {sample['Annotator Metadata']['Number of steps']}\")\n",
|
75 |
+
" print(f\" βββ How long did this take?: {sample['Annotator Metadata']['How long did this take?']}\")\n",
|
76 |
+
" print(f\" βββ Tools:\")\n",
|
77 |
+
" for tool in sample['Annotator Metadata']['Tools'].split('\\n'):\n",
|
78 |
+
" print(f\" β βββ {tool}\")\n",
|
79 |
+
" print(f\" βββ Number of tools: {sample['Annotator Metadata']['Number of tools']}\")\n",
|
80 |
+
"print(\"=\" * 50)"
|
81 |
+
]
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"cell_type": "code",
|
85 |
+
"execution_count": 11,
|
86 |
+
"id": "05076516",
|
87 |
+
"metadata": {},
|
88 |
+
"outputs": [],
|
89 |
+
"source": [
|
90 |
+
"import os\n",
|
91 |
+
"from dotenv import load_dotenv\n",
|
92 |
+
"from langchain_huggingface import HuggingFaceEmbeddings\n",
|
93 |
+
"from langchain_community.vectorstores import SupabaseVectorStore\n",
|
94 |
+
"from supabase.client import Client, create_client\n",
|
95 |
+
"\n",
|
96 |
+
"\n",
|
97 |
+
"load_dotenv()\n",
|
98 |
+
"embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\") # dim=768\n",
|
99 |
+
"\n",
|
100 |
+
"supabase_url = os.environ.get(\"SUPABASE_URL\")\n",
|
101 |
+
"supabase_key = os.environ.get(\"SUPABASE_SERVICE_ROLE_KEY\")\n",
|
102 |
+
"supabase: Client = create_client(supabase_url, supabase_key)"
|
103 |
+
]
|
104 |
+
},
|
105 |
+
{
|
106 |
+
"cell_type": "code",
|
107 |
+
"execution_count": 20,
|
108 |
+
"id": "aa1402e3",
|
109 |
+
"metadata": {},
|
110 |
+
"outputs": [],
|
111 |
+
"source": [
|
112 |
+
"from langchain.schema import Document\n",
|
113 |
+
"docs = []\n",
|
114 |
+
"cnt = 0 \n",
|
115 |
+
"for sample in json_QA:\n",
|
116 |
+
" content = f\"Question : {sample['Question']}\\n\\nFinal answer : {sample['Final answer']}\"\n",
|
117 |
+
" doc = {\n",
|
118 |
+
" \"id\" : cnt,\n",
|
119 |
+
" \"content\" : content,\n",
|
120 |
+
" \"metadata\" : {\n",
|
121 |
+
" \"source\" : sample['task_id']\n",
|
122 |
+
" },\n",
|
123 |
+
" \"embedding\" : embeddings.embed_query(content),\n",
|
124 |
+
" }\n",
|
125 |
+
" docs.append(doc)\n",
|
126 |
+
" cnt += 1\n",
|
127 |
+
"\n",
|
128 |
+
"# upload the documents to the vector database\n",
|
129 |
+
"try:\n",
|
130 |
+
" response = (\n",
|
131 |
+
" supabase.table(\"documents2\")\n",
|
132 |
+
" .insert(docs)\n",
|
133 |
+
" .execute()\n",
|
134 |
+
" )\n",
|
135 |
+
"except Exception as exception:\n",
|
136 |
+
" print(\"Error inserting data into Supabase:\", exception)\n",
|
137 |
+
"\n",
|
138 |
+
"# # Save the documents (a list of dict) into a csv file, and manually upload it to Supabase\n",
|
139 |
+
"# import pandas as pd\n",
|
140 |
+
"# df = pd.DataFrame(docs)\n",
|
141 |
+
"# df.to_csv('supabase_docs.csv',index=False)"
|
142 |
+
]
|
143 |
+
},
|
144 |
+
{
|
145 |
+
"cell_type": "code",
|
146 |
+
"execution_count": 41,
|
147 |
+
"id": "9aa7eb5e",
|
148 |
+
"metadata": {},
|
149 |
+
"outputs": [],
|
150 |
+
"source": [
|
151 |
+
"# add items to vector database\n",
|
152 |
+
"vector_store = SupabaseVectorStore(\n",
|
153 |
+
" client=supabase,\n",
|
154 |
+
" embedding= embeddings,\n",
|
155 |
+
" table_name=\"documents2\",\n",
|
156 |
+
" query_name=\"match_documents_2\",\n",
|
157 |
+
")\n",
|
158 |
+
"retriever = vector_store.as_retriever()"
|
159 |
+
]
|
160 |
+
},
|
161 |
+
{
|
162 |
+
"cell_type": "code",
|
163 |
+
"execution_count": 42,
|
164 |
+
"id": "9eecafd1",
|
165 |
+
"metadata": {},
|
166 |
+
"outputs": [],
|
167 |
+
"source": [
|
168 |
+
"query = \"On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?\"\n",
|
169 |
+
"# matched_docs = vector_store.similarity_search(query, k=2)\n",
|
170 |
+
"docs = retriever.invoke(query)"
|
171 |
+
]
|
172 |
+
},
|
173 |
+
{
|
174 |
+
"cell_type": "code",
|
175 |
+
"execution_count": 43,
|
176 |
+
"id": "ff917840",
|
177 |
+
"metadata": {},
|
178 |
+
"outputs": [
|
179 |
+
{
|
180 |
+
"data": {
|
181 |
+
"text/plain": [
|
182 |
+
"Document(metadata={'source': '840bfca7-4f7b-481a-8794-c560c340185d'}, page_content='Question : On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?\\n\\nFinal answer : 80GSFC21M0002')"
|
183 |
+
]
|
184 |
+
},
|
185 |
+
"execution_count": 43,
|
186 |
+
"metadata": {},
|
187 |
+
"output_type": "execute_result"
|
188 |
+
}
|
189 |
+
],
|
190 |
+
"source": [
|
191 |
+
"docs[0]"
|
192 |
+
]
|
193 |
+
},
|
194 |
+
{
|
195 |
+
"cell_type": "code",
|
196 |
+
"execution_count": 44,
|
197 |
+
"id": "01c8f337",
|
198 |
+
"metadata": {},
|
199 |
+
"outputs": [
|
200 |
+
{
|
201 |
+
"name": "stdout",
|
202 |
+
"output_type": "stream",
|
203 |
+
"text": [
|
204 |
+
"List of tools used in all samples:\n",
|
205 |
+
"Total number of tools used: 83\n",
|
206 |
+
" βββ web browser: 107\n",
|
207 |
+
" βββ image recognition tools (to identify and parse a figure with three axes): 1\n",
|
208 |
+
" βββ search engine: 101\n",
|
209 |
+
" βββ calculator: 34\n",
|
210 |
+
" βββ unlambda compiler (optional): 1\n",
|
211 |
+
" βββ a web browser.: 2\n",
|
212 |
+
" βββ a search engine.: 2\n",
|
213 |
+
" βββ a calculator.: 1\n",
|
214 |
+
" βββ microsoft excel: 5\n",
|
215 |
+
" βββ google search: 1\n",
|
216 |
+
" βββ ne: 9\n",
|
217 |
+
" βββ pdf access: 7\n",
|
218 |
+
" βββ file handling: 2\n",
|
219 |
+
" βββ python: 3\n",
|
220 |
+
" βββ image recognition tools: 12\n",
|
221 |
+
" βββ jsonld file access: 1\n",
|
222 |
+
" βββ video parsing: 1\n",
|
223 |
+
" βββ python compiler: 1\n",
|
224 |
+
" βββ video recognition tools: 3\n",
|
225 |
+
" βββ pdf viewer: 7\n",
|
226 |
+
" βββ microsoft excel / google sheets: 3\n",
|
227 |
+
" βββ word document access: 1\n",
|
228 |
+
" βββ tool to extract text from images: 1\n",
|
229 |
+
" βββ a word reversal tool / script: 1\n",
|
230 |
+
" βββ counter: 1\n",
|
231 |
+
" βββ excel: 3\n",
|
232 |
+
" βββ image recognition: 5\n",
|
233 |
+
" βββ color recognition: 3\n",
|
234 |
+
" βββ excel file access: 3\n",
|
235 |
+
" βββ xml file access: 1\n",
|
236 |
+
" βββ access to the internet archive, web.archive.org: 1\n",
|
237 |
+
" βββ text processing/diff tool: 1\n",
|
238 |
+
" βββ gif parsing tools: 1\n",
|
239 |
+
" βββ a web browser: 7\n",
|
240 |
+
" βββ a search engine: 7\n",
|
241 |
+
" βββ a speech-to-text tool: 2\n",
|
242 |
+
" βββ code/data analysis tools: 1\n",
|
243 |
+
" βββ audio capability: 2\n",
|
244 |
+
" βββ pdf reader: 1\n",
|
245 |
+
" βββ markdown: 1\n",
|
246 |
+
" βββ a calculator: 5\n",
|
247 |
+
" βββ access to wikipedia: 3\n",
|
248 |
+
" βββ image recognition/ocr: 3\n",
|
249 |
+
" βββ google translate access: 1\n",
|
250 |
+
" βββ ocr: 4\n",
|
251 |
+
" βββ bass note data: 1\n",
|
252 |
+
" βββ text editor: 1\n",
|
253 |
+
" βββ xlsx file access: 1\n",
|
254 |
+
" βββ powerpoint viewer: 1\n",
|
255 |
+
" βββ csv file access: 1\n",
|
256 |
+
" βββ calculator (or use excel): 1\n",
|
257 |
+
" βββ computer algebra system: 1\n",
|
258 |
+
" βββ video processing software: 1\n",
|
259 |
+
" βββ audio processing software: 1\n",
|
260 |
+
" βββ computer vision: 1\n",
|
261 |
+
" βββ google maps: 1\n",
|
262 |
+
" βββ access to excel files: 1\n",
|
263 |
+
" βββ calculator (or ability to count): 1\n",
|
264 |
+
" βββ a file interface: 3\n",
|
265 |
+
" βββ a python ide: 1\n",
|
266 |
+
" βββ spreadsheet editor: 1\n",
|
267 |
+
" βββ tools required: 1\n",
|
268 |
+
" βββ b browser: 1\n",
|
269 |
+
" βββ image recognition and processing tools: 1\n",
|
270 |
+
" βββ computer vision or ocr: 1\n",
|
271 |
+
" βββ c++ compiler: 1\n",
|
272 |
+
" βββ access to google maps: 1\n",
|
273 |
+
" βββ youtube player: 1\n",
|
274 |
+
" βββ natural language processor: 1\n",
|
275 |
+
" βββ graph interaction tools: 1\n",
|
276 |
+
" βββ bablyonian cuniform -> arabic legend: 1\n",
|
277 |
+
" βββ access to youtube: 1\n",
|
278 |
+
" βββ image search tools: 1\n",
|
279 |
+
" βββ calculator or counting function: 1\n",
|
280 |
+
" βββ a speech-to-text audio processing tool: 1\n",
|
281 |
+
" βββ access to academic journal websites: 1\n",
|
282 |
+
" βββ pdf reader/extracter: 1\n",
|
283 |
+
" βββ rubik's cube model: 1\n",
|
284 |
+
" βββ wikipedia: 1\n",
|
285 |
+
" βββ video capability: 1\n",
|
286 |
+
" βββ image processing tools: 1\n",
|
287 |
+
" βββ age recognition software: 1\n",
|
288 |
+
" βββ youtube: 1\n"
|
289 |
+
]
|
290 |
+
}
|
291 |
+
],
|
292 |
+
"source": [
|
293 |
+
"# list of the tools used in all the samples\n",
|
294 |
+
"from collections import Counter, OrderedDict\n",
|
295 |
+
"\n",
|
296 |
+
"tools = []\n",
|
297 |
+
"for sample in json_QA:\n",
|
298 |
+
" for tool in sample['Annotator Metadata']['Tools'].split('\\n'):\n",
|
299 |
+
" tool = tool[2:].strip().lower()\n",
|
300 |
+
" if tool.startswith(\"(\"):\n",
|
301 |
+
" tool = tool[11:].strip()\n",
|
302 |
+
" tools.append(tool)\n",
|
303 |
+
"tools_counter = OrderedDict(Counter(tools))\n",
|
304 |
+
"print(\"List of tools used in all samples:\")\n",
|
305 |
+
"print(\"Total number of tools used:\", len(tools_counter))\n",
|
306 |
+
"for tool, count in tools_counter.items():\n",
|
307 |
+
" print(f\" βββ {tool}: {count}\")"
|
308 |
+
]
|
309 |
+
}
|
310 |
+
],
|
311 |
+
"metadata": {
|
312 |
+
"kernelspec": {
|
313 |
+
"display_name": "env",
|
314 |
+
"language": "python",
|
315 |
+
"name": "python3"
|
316 |
+
},
|
317 |
+
"language_info": {
|
318 |
+
"codemirror_mode": {
|
319 |
+
"name": "ipython",
|
320 |
+
"version": 3
|
321 |
+
},
|
322 |
+
"file_extension": ".py",
|
323 |
+
"mimetype": "text/x-python",
|
324 |
+
"name": "python",
|
325 |
+
"nbconvert_exporter": "python",
|
326 |
+
"pygments_lexer": "ipython3",
|
327 |
+
"version": "3.11.9"
|
328 |
+
}
|
329 |
+
},
|
330 |
+
"nbformat": 4,
|
331 |
+
"nbformat_minor": 5
|
332 |
+
}
|