hotchpotch
commited on
Commit
•
0fb0a80
1
Parent(s):
4646a6d
Add script to generate all embeddings and update
Browse files- Generate.md +10 -5
- all_embs_to_faiss.py +18 -0
- embs_to_faiss.py +3 -7
Generate.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
|
6 |
```
|
7 |
python datasets_to_embs.py \
|
8 |
-
--target="data" \
|
9 |
--model_name="intfloat/multilingual-e5-small" \
|
10 |
--output_name="multilingual-e5-small-passage" \
|
11 |
--input_prefix="passage: "
|
@@ -20,7 +20,7 @@ python datasets_to_embs.py \
|
|
20 |
|
21 |
```
|
22 |
python datasets_to_embs.py \
|
23 |
-
--target="data" \
|
24 |
--model_name="intfloat/multilingual-e5-small" \
|
25 |
--output_name="multilingual-e5-small-query" \
|
26 |
--input_prefix="query: "
|
@@ -36,10 +36,15 @@ python datasets_to_embs.py \
|
|
36 |
|
37 |
```
|
38 |
python embs_to_faiss.py \
|
39 |
-
--target="data" \
|
40 |
-
--input_name="multilingual-e5-small-
|
41 |
--use_gpu
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
43 |
```
|
44 |
|
45 |
# XXX
|
|
|
5 |
|
6 |
```
|
7 |
python datasets_to_embs.py \
|
8 |
+
--target="data" \ # data or chunked
|
9 |
--model_name="intfloat/multilingual-e5-small" \
|
10 |
--output_name="multilingual-e5-small-passage" \
|
11 |
--input_prefix="passage: "
|
|
|
20 |
|
21 |
```
|
22 |
python datasets_to_embs.py \
|
23 |
+
--target="data" \ # data or chunked
|
24 |
--model_name="intfloat/multilingual-e5-small" \
|
25 |
--output_name="multilingual-e5-small-query" \
|
26 |
--input_prefix="query: "
|
|
|
36 |
|
37 |
```
|
38 |
python embs_to_faiss.py \
|
39 |
+
--target="data" \ # data or chunked
|
40 |
+
--input_name="multilingual-e5-small-passage" \
|
41 |
--use_gpu
|
42 |
+
```
|
43 |
+
|
44 |
+
### generate all by ./embs/
|
45 |
+
|
46 |
+
```
|
47 |
+
python all_embs_to_faiss.py --use_gpu
|
48 |
```
|
49 |
|
50 |
# XXX
|
all_embs_to_faiss.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
import sys
|
3 |
+
import os
|
4 |
+
|
5 |
+
all_args_str = ' '.join(sys.argv[1:])
|
6 |
+
|
7 |
+
target_pathes = list(Path("./embs/").glob("**/*.npz"))
|
8 |
+
target_pathes = list(map(lambda x: x.parent, target_pathes))
|
9 |
+
# unique
|
10 |
+
target_pathes = list(set(target_pathes))
|
11 |
+
|
12 |
+
for target_path in target_pathes:
|
13 |
+
name = target_path.parent.stem
|
14 |
+
target = target_path.stem
|
15 |
+
cmd = f"python embs_to_faiss.py -t {target} -i {name} {all_args_str}"
|
16 |
+
print(f"[run] {cmd}")
|
17 |
+
os.system(cmd)
|
18 |
+
print("")
|
embs_to_faiss.py
CHANGED
@@ -16,12 +16,6 @@ parser.add_argument(
|
|
16 |
help="target dataset, data or chunked",
|
17 |
)
|
18 |
|
19 |
-
parser.add_argument(
|
20 |
-
"-d",
|
21 |
-
"--debug",
|
22 |
-
action="store_true",
|
23 |
-
help="debug mode, use small dataset",
|
24 |
-
)
|
25 |
parser.add_argument(
|
26 |
"-i",
|
27 |
"--input_name",
|
@@ -174,7 +168,9 @@ for idx, npz_file in enumerate(input_embs_npz):
|
|
174 |
if idx == 0:
|
175 |
dim = embs.shape[1]
|
176 |
if faiss_config.nlist is None:
|
177 |
-
faiss_config.nlist = int(np.sqrt(len(embs) * len(input_embs_npz)))
|
|
|
|
|
178 |
print(f"faiss_config: {faiss_config}")
|
179 |
if args.use_gpu:
|
180 |
print("use gpu for faiss index")
|
|
|
16 |
help="target dataset, data or chunked",
|
17 |
)
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
parser.add_argument(
|
20 |
"-i",
|
21 |
"--input_name",
|
|
|
168 |
if idx == 0:
|
169 |
dim = embs.shape[1]
|
170 |
if faiss_config.nlist is None:
|
171 |
+
faiss_config.nlist = int(np.sqrt(len(embs) * (len(input_embs_npz)-1)))
|
172 |
+
if faiss_config.nlist < 1:
|
173 |
+
faiss_config.nlist = 100
|
174 |
print(f"faiss_config: {faiss_config}")
|
175 |
if args.use_gpu:
|
176 |
print("use gpu for faiss index")
|