File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
12import sys
23import struct
34import json
4- from tqdm import tqdm
5+
6+ try :
7+ from tqdm import tqdm
8+ iterate = lambda i : tqdm (range (i ))
9+ except ModuleNotFoundError :
10+ print ("Warning: [tqdm] package is not available and you won't be able to see progress." , file = sys .stderr )
11+ iterate = range
12+
13+ dims = 96
14+ num_vectors = 9990000
15+
516
617def to_json (f ):
7- for i in tqdm ( range ( num_vectors )) :
18+ for i in iterate ( num_vectors ):
819 f .read (4 ) # in .fvecs format for each vector the first 4 bytes represent dim
920 vector = struct .unpack ('f' * dims , f .read (dims * 4 ))
1021
@@ -13,8 +24,9 @@ def to_json(f):
1324 print (json .dumps (record , ensure_ascii = False ))
1425
1526
16- dims = 96
17- num_vectors = 9990000
27+ if len (sys .argv ) != 2 :
28+ print (f"Error: No .fvecs file. Rerun using [{ sys .argv [0 ]} /path/to/deep10M.fvecs]." )
29+ sys .exit (1 )
1830
1931with open (sys .argv [1 ], 'rb' ) as f :
20- to_json (f )
32+ to_json (f )
You can’t perform that action at this time.
0 commit comments