yahoo2010 commited on
Commit
bdace02
Β·
verified Β·
1 Parent(s): e7284a6

Upload 2 files

Browse files
Files changed (2) hide show
  1. explore_metadata.ipynb +341 -0
  2. metadata.jsonl +0 -0
explore_metadata.ipynb ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": 11,
23
+ "id": "fa5d8eb8",
24
+ "metadata": {},
25
+ "outputs": [
26
+ {
27
+ "name": "stdout",
28
+ "output_type": "stream",
29
+ "text": [
30
+ "==================================================\n",
31
+ "Task ID: 7b5377b0-3f38-4103-8ad2-90fe89864c04\n",
32
+ "Question: Find the value of x to the nearest tenth: Lx = (d/dx * (A * x-squared)) + 4-thousand'n'ninety-7 minus C\n",
33
+ "Where L is the last two digits of the year of the Venezuelan Declaration of Independence,\n",
34
+ "A is the number of colors in the TikTok logo as of July 2023, excluding black and white,\n",
35
+ "and C is the height of the average woman in the Philippines according to a July 2023 Business Insider article, rounded to the nearest whole centimeter\n",
36
+ "Level: 2\n",
37
+ "Final Answer: 563.9\n",
38
+ "Annotator Metadata: \n",
39
+ " β”œβ”€β”€ Steps: \n",
40
+ " β”‚ β”œβ”€β”€ 1. Googled Venezuelan Declaration of Independence, found it to be in 1811, thus L = 11\n",
41
+ " β”‚ β”œβ”€β”€ 2. Googled TikTok logo, found 4 colors, 2 of which are black and white, so A = 2\n",
42
+ " β”‚ β”œβ”€β”€ 3. Googled average height of woman in Philippines, found it to be 149.6cm, so C = 150\n",
43
+ " β”‚ β”œβ”€β”€ 4. Deciphered formula to mean 11x = (d/dx(2x^2)) + 4097 - 150\n",
44
+ " β”‚ β”œβ”€β”€ 5. Used simple calculus and algebra to solve the equation\n",
45
+ " β”œβ”€β”€ Number of steps: 5\n",
46
+ " β”œβ”€β”€ How long did this take?: 40 minutes\n",
47
+ " β”œβ”€β”€ Tools:\n",
48
+ " β”‚ β”œβ”€β”€ 1. A web browser\n",
49
+ " β”‚ β”œβ”€β”€ 2. A search engine\n",
50
+ " β”‚ β”œβ”€β”€ 3. A calculator\n",
51
+ " └── Number of tools: 3\n",
52
+ "==================================================\n"
53
+ ]
54
+ }
55
+ ],
56
+ "source": [
57
+ "import random\n",
58
+ "random_samples = random.sample(json_QA, 1)\n",
59
+ "for sample in random_samples:\n",
60
+ " print(\"=\" * 50)\n",
61
+ " print(f\"Task ID: {sample['task_id']}\")\n",
62
+ " print(f\"Question: {sample['Question']}\")\n",
63
+ " print(f\"Level: {sample['Level']}\")\n",
64
+ " print(f\"Final Answer: {sample['Final answer']}\")\n",
65
+ " print(f\"Annotator Metadata: \")\n",
66
+ " print(f\" β”œβ”€β”€ Steps: \")\n",
67
+ " for step in sample['Annotator Metadata']['Steps'].split('\\n'):\n",
68
+ " print(f\" β”‚ β”œβ”€β”€ {step}\")\n",
69
+ " print(f\" β”œβ”€β”€ Number of steps: {sample['Annotator Metadata']['Number of steps']}\")\n",
70
+ " print(f\" β”œβ”€β”€ How long did this take?: {sample['Annotator Metadata']['How long did this take?']}\")\n",
71
+ " print(f\" β”œβ”€β”€ Tools:\")\n",
72
+ " for tool in sample['Annotator Metadata']['Tools'].split('\\n'):\n",
73
+ " print(f\" β”‚ β”œβ”€β”€ {tool}\")\n",
74
+ " print(f\" └── Number of tools: {sample['Annotator Metadata']['Number of tools']}\")\n",
75
+ "print(\"=\" * 50)"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": 20,
81
+ "id": "05076516",
82
+ "metadata": {},
83
+ "outputs": [
84
+ {
85
+ "ename": "ModuleNotFoundError",
86
+ "evalue": "No module named 'supabase.client'",
87
+ "output_type": "error",
88
+ "traceback": [
89
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
90
+ "\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
91
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[20]\u001b[39m\u001b[32m, line 5\u001b[39m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mlangchain_huggingface\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m HuggingFaceEmbeddings\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mlangchain_community\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mvectorstores\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m SupabaseVectorStore\n\u001b[32m----> \u001b[39m\u001b[32m5\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01msupabase\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mclient\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m create_client, Client\n\u001b[32m 7\u001b[39m os.environ[\u001b[33m\"\u001b[39m\u001b[33mSUPABASE_URL\u001b[39m\u001b[33m\"\u001b[39m] = \u001b[33m\"\u001b[39m\u001b[33mhttps://hkjtumxnumguevndjfcj.supabase.co\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 8\u001b[39m os.environ[\u001b[33m\"\u001b[39m\u001b[33mSUPABASE_SERVICE_ROLE_KEY\u001b[39m\u001b[33m\"\u001b[39m] = \u001b[33m\"\u001b[39m\u001b[33meyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImhranR1bXhudW1ndWV2bmRqZmNqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDk1NjgxNTksImV4cCI6MjA2NTE0NDE1OX0.6qtTbevyd7l38ogJjecgDu0BIlUyDJpJ0Gqdogbt3DM\u001b[39m\u001b[33m\"\u001b[39m\n",
92
+ "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'supabase.client'"
93
+ ]
94
+ }
95
+ ],
96
+ "source": [
97
+ "import os\n",
98
+ "from dotenv import load_dotenv\n",
99
+ "from langchain_huggingface import HuggingFaceEmbeddings\n",
100
+ "from langchain_community.vectorstores import SupabaseVectorStore\n",
101
+ "from supabase.client import create_client, Client\n",
102
+ "\n",
103
+ "os.environ[\"SUPABASE_URL\"] = \"https://hkjtumxnumguevndjfcj.supabase.co\"\n",
104
+ "os.environ[\"SUPABASE_SERVICE_ROLE_KEY\"] = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImhranR1bXhudW1ndWV2bmRqZmNqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDk1NjgxNTksImV4cCI6MjA2NTE0NDE1OX0.6qtTbevyd7l38ogJjecgDu0BIlUyDJpJ0Gqdogbt3DM\"\n",
105
+ "\n",
106
+ "load_dotenv()\n",
107
+ "embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\") # dim=768\n",
108
+ "\n",
109
+ "supabase_url = os.environ.get(\"SUPABASE_URL\")\n",
110
+ "supabase_key = os.environ.get(\"SUPABASE_SERVICE_ROLE_KEY\")\n",
111
+ "supabase: Client = create_client(supabase_url, supabase_key)"
112
+ ]
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "execution_count": 20,
117
+ "id": "aa1402e3",
118
+ "metadata": {},
119
+ "outputs": [],
120
+ "source": [
121
+ "from langchain.schema import Document\n",
122
+ "docs = []\n",
123
+ "cnt = 0 \n",
124
+ "for sample in json_QA:\n",
125
+ " content = f\"Question : {sample['Question']}\\n\\nFinal answer : {sample['Final answer']}\"\n",
126
+ " doc = {\n",
127
+ " \"id\" : cnt,\n",
128
+ " \"content\" : content,\n",
129
+ " \"metadata\" : {\n",
130
+ " \"source\" : sample['task_id']\n",
131
+ " },\n",
132
+ " \"embedding\" : embeddings.embed_query(content),\n",
133
+ " }\n",
134
+ " docs.append(doc)\n",
135
+ " cnt += 1\n",
136
+ "\n",
137
+ "# upload the documents to the vector database\n",
138
+ "try:\n",
139
+ " response = (\n",
140
+ " supabase.table(\"documents2\")\n",
141
+ " .insert(docs)\n",
142
+ " .execute()\n",
143
+ " )\n",
144
+ "except Exception as exception:\n",
145
+ " print(\"Error inserting data into Supabase:\", exception)\n",
146
+ "\n",
147
+ "# # Save the documents (a list of dict) into a csv file, and manually upload it to Supabase\n",
148
+ "# import pandas as pd\n",
149
+ "# df = pd.DataFrame(docs)\n",
150
+ "# df.to_csv('supabase_docs.csv',index=False)"
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "execution_count": 41,
156
+ "id": "9aa7eb5e",
157
+ "metadata": {},
158
+ "outputs": [],
159
+ "source": [
160
+ "# add items to vector database\n",
161
+ "vector_store = SupabaseVectorStore(\n",
162
+ " client=supabase,\n",
163
+ " embedding= embeddings,\n",
164
+ " table_name=\"documents2\",\n",
165
+ " query_name=\"match_documents_2\",\n",
166
+ ")\n",
167
+ "retriever = vector_store.as_retriever()"
168
+ ]
169
+ },
170
+ {
171
+ "cell_type": "code",
172
+ "execution_count": 42,
173
+ "id": "9eecafd1",
174
+ "metadata": {},
175
+ "outputs": [],
176
+ "source": [
177
+ "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",
178
+ "# matched_docs = vector_store.similarity_search(query, k=2)\n",
179
+ "docs = retriever.invoke(query)"
180
+ ]
181
+ },
182
+ {
183
+ "cell_type": "code",
184
+ "execution_count": 43,
185
+ "id": "ff917840",
186
+ "metadata": {},
187
+ "outputs": [
188
+ {
189
+ "data": {
190
+ "text/plain": [
191
+ "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')"
192
+ ]
193
+ },
194
+ "execution_count": 43,
195
+ "metadata": {},
196
+ "output_type": "execute_result"
197
+ }
198
+ ],
199
+ "source": [
200
+ "docs[0]"
201
+ ]
202
+ },
203
+ {
204
+ "cell_type": "code",
205
+ "execution_count": 44,
206
+ "id": "01c8f337",
207
+ "metadata": {},
208
+ "outputs": [
209
+ {
210
+ "name": "stdout",
211
+ "output_type": "stream",
212
+ "text": [
213
+ "List of tools used in all samples:\n",
214
+ "Total number of tools used: 83\n",
215
+ " β”œβ”€β”€ web browser: 107\n",
216
+ " β”œβ”€β”€ image recognition tools (to identify and parse a figure with three axes): 1\n",
217
+ " β”œβ”€β”€ search engine: 101\n",
218
+ " β”œβ”€β”€ calculator: 34\n",
219
+ " β”œβ”€οΏ½οΏ½οΏ½ unlambda compiler (optional): 1\n",
220
+ " β”œβ”€β”€ a web browser.: 2\n",
221
+ " β”œβ”€β”€ a search engine.: 2\n",
222
+ " β”œβ”€β”€ a calculator.: 1\n",
223
+ " β”œβ”€β”€ microsoft excel: 5\n",
224
+ " β”œβ”€β”€ google search: 1\n",
225
+ " β”œβ”€β”€ ne: 9\n",
226
+ " β”œβ”€β”€ pdf access: 7\n",
227
+ " β”œβ”€β”€ file handling: 2\n",
228
+ " β”œβ”€β”€ python: 3\n",
229
+ " β”œβ”€β”€ image recognition tools: 12\n",
230
+ " β”œβ”€β”€ jsonld file access: 1\n",
231
+ " β”œβ”€β”€ video parsing: 1\n",
232
+ " β”œβ”€β”€ python compiler: 1\n",
233
+ " β”œβ”€β”€ video recognition tools: 3\n",
234
+ " β”œβ”€β”€ pdf viewer: 7\n",
235
+ " β”œβ”€β”€ microsoft excel / google sheets: 3\n",
236
+ " β”œβ”€β”€ word document access: 1\n",
237
+ " β”œβ”€β”€ tool to extract text from images: 1\n",
238
+ " β”œβ”€β”€ a word reversal tool / script: 1\n",
239
+ " β”œβ”€β”€ counter: 1\n",
240
+ " β”œβ”€β”€ excel: 3\n",
241
+ " β”œβ”€β”€ image recognition: 5\n",
242
+ " β”œβ”€β”€ color recognition: 3\n",
243
+ " β”œβ”€β”€ excel file access: 3\n",
244
+ " β”œβ”€β”€ xml file access: 1\n",
245
+ " β”œβ”€β”€ access to the internet archive, web.archive.org: 1\n",
246
+ " β”œβ”€β”€ text processing/diff tool: 1\n",
247
+ " β”œβ”€β”€ gif parsing tools: 1\n",
248
+ " β”œβ”€β”€ a web browser: 7\n",
249
+ " β”œβ”€β”€ a search engine: 7\n",
250
+ " β”œβ”€β”€ a speech-to-text tool: 2\n",
251
+ " β”œβ”€β”€ code/data analysis tools: 1\n",
252
+ " β”œβ”€β”€ audio capability: 2\n",
253
+ " β”œβ”€β”€ pdf reader: 1\n",
254
+ " β”œβ”€β”€ markdown: 1\n",
255
+ " β”œβ”€β”€ a calculator: 5\n",
256
+ " β”œβ”€β”€ access to wikipedia: 3\n",
257
+ " β”œβ”€β”€ image recognition/ocr: 3\n",
258
+ " β”œβ”€β”€ google translate access: 1\n",
259
+ " β”œβ”€β”€ ocr: 4\n",
260
+ " β”œβ”€β”€ bass note data: 1\n",
261
+ " β”œβ”€β”€ text editor: 1\n",
262
+ " β”œβ”€β”€ xlsx file access: 1\n",
263
+ " β”œβ”€β”€ powerpoint viewer: 1\n",
264
+ " β”œβ”€β”€ csv file access: 1\n",
265
+ " β”œβ”€β”€ calculator (or use excel): 1\n",
266
+ " β”œβ”€β”€ computer algebra system: 1\n",
267
+ " β”œβ”€β”€ video processing software: 1\n",
268
+ " β”œβ”€β”€ audio processing software: 1\n",
269
+ " β”œβ”€β”€ computer vision: 1\n",
270
+ " β”œβ”€β”€ google maps: 1\n",
271
+ " β”œβ”€β”€ access to excel files: 1\n",
272
+ " β”œβ”€β”€ calculator (or ability to count): 1\n",
273
+ " β”œβ”€β”€ a file interface: 3\n",
274
+ " β”œβ”€β”€ a python ide: 1\n",
275
+ " β”œβ”€β”€ spreadsheet editor: 1\n",
276
+ " β”œβ”€β”€ tools required: 1\n",
277
+ " β”œβ”€β”€ b browser: 1\n",
278
+ " β”œβ”€β”€ image recognition and processing tools: 1\n",
279
+ " β”œβ”€β”€ computer vision or ocr: 1\n",
280
+ " β”œβ”€β”€ c++ compiler: 1\n",
281
+ " β”œβ”€β”€ access to google maps: 1\n",
282
+ " β”œβ”€β”€ youtube player: 1\n",
283
+ " β”œβ”€β”€ natural language processor: 1\n",
284
+ " β”œβ”€β”€ graph interaction tools: 1\n",
285
+ " β”œβ”€β”€ bablyonian cuniform -> arabic legend: 1\n",
286
+ " β”œβ”€β”€ access to youtube: 1\n",
287
+ " β”œβ”€β”€ image search tools: 1\n",
288
+ " β”œβ”€β”€ calculator or counting function: 1\n",
289
+ " β”œβ”€β”€ a speech-to-text audio processing tool: 1\n",
290
+ " β”œβ”€β”€ access to academic journal websites: 1\n",
291
+ " β”œβ”€β”€ pdf reader/extracter: 1\n",
292
+ " β”œβ”€β”€ rubik's cube model: 1\n",
293
+ " β”œβ”€β”€ wikipedia: 1\n",
294
+ " β”œβ”€β”€ video capability: 1\n",
295
+ " β”œβ”€β”€ image processing tools: 1\n",
296
+ " β”œβ”€β”€ age recognition software: 1\n",
297
+ " β”œβ”€β”€ youtube: 1\n"
298
+ ]
299
+ }
300
+ ],
301
+ "source": [
302
+ "# list of the tools used in all the samples\n",
303
+ "from collections import Counter, OrderedDict\n",
304
+ "\n",
305
+ "tools = []\n",
306
+ "for sample in json_QA:\n",
307
+ " for tool in sample['Annotator Metadata']['Tools'].split('\\n'):\n",
308
+ " tool = tool[2:].strip().lower()\n",
309
+ " if tool.startswith(\"(\"):\n",
310
+ " tool = tool[11:].strip()\n",
311
+ " tools.append(tool)\n",
312
+ "tools_counter = OrderedDict(Counter(tools))\n",
313
+ "print(\"List of tools used in all samples:\")\n",
314
+ "print(\"Total number of tools used:\", len(tools_counter))\n",
315
+ "for tool, count in tools_counter.items():\n",
316
+ " print(f\" β”œβ”€β”€ {tool}: {count}\")"
317
+ ]
318
+ }
319
+ ],
320
+ "metadata": {
321
+ "kernelspec": {
322
+ "display_name": "Python 3",
323
+ "language": "python",
324
+ "name": "python3"
325
+ },
326
+ "language_info": {
327
+ "codemirror_mode": {
328
+ "name": "ipython",
329
+ "version": 3
330
+ },
331
+ "file_extension": ".py",
332
+ "mimetype": "text/x-python",
333
+ "name": "python",
334
+ "nbconvert_exporter": "python",
335
+ "pygments_lexer": "ipython3",
336
+ "version": "3.13.3"
337
+ }
338
+ },
339
+ "nbformat": 4,
340
+ "nbformat_minor": 5
341
+ }
metadata.jsonl ADDED
The diff for this file is too large to render. See raw diff