rnrahate007 commited on
Commit
a195930
·
verified ·
1 Parent(s): 9aa5e8c

Create gaia_loader.py

Browse files
Files changed (1) hide show
  1. gaia_loader.py +65 -0
gaia_loader.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ from sentence_transformers import SentenceTransformer
3
+ import faiss
4
+ import numpy as np
5
+
6
+ print("Loading GAIA dataset...")
7
+
8
+ dataset = load_dataset(
9
+ "gaia-benchmark/GAIA",
10
+ "2023_level1",
11
+ split="validation"
12
+ )
13
+
14
+ print("Loading embedding model...")
15
+
16
+ embedder = SentenceTransformer(
17
+ "sentence-transformers/all-MiniLM-L6-v2"
18
+ )
19
+
20
+ questions = dataset["Question"]
21
+
22
+ embeddings = embedder.encode(
23
+ questions,
24
+ convert_to_numpy=True,
25
+ show_progress_bar=True
26
+ )
27
+
28
+ dimension = embeddings.shape[1]
29
+
30
+ index = faiss.IndexFlatL2(dimension)
31
+
32
+ index.add(embeddings)
33
+
34
+ print(f"Indexed {len(questions)} questions.")
35
+
36
+
37
+ def search_examples(query, k=3):
38
+
39
+ query_embedding = embedder.encode(
40
+ [query],
41
+ convert_to_numpy=True
42
+ )
43
+
44
+ distances, indices = index.search(
45
+ query_embedding,
46
+ k
47
+ )
48
+
49
+ examples = []
50
+
51
+ for idx in indices[0]:
52
+
53
+ row = dataset[int(idx)]
54
+
55
+ examples.append({
56
+
57
+ "question": row["Question"],
58
+
59
+ "answer": row.get("Final answer", ""),
60
+
61
+ "task_id": row["task_id"]
62
+
63
+ })
64
+
65
+ return examples