sadit commited on
Commit
51e0c75
·
verified ·
1 Parent(s): f672783

Upload encode-wikipedia.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. encode-wikipedia.py +20 -0
encode-wikipedia.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import h5py as h5
2
+ import json
3
+ import pandas as pd
4
+ import torch
5
+ from sentence_transformers import SentenceTransformer
6
+
7
+ torch.set_num_threads(32)
8
+ modelname = 'sentence-transformers/all-MiniLM-L6-v2'
9
+ model = SentenceTransformer(modelname)
10
+ with open("wikipedia-text-20231101-en.txt") as f:
11
+ sentences = [json.loads(line) for line in f.readlines()]
12
+
13
+ embeddings = model.encode(sentences)
14
+
15
+ with h5.File("wikipedia-embeddings-20231101-en.h5", "w") as f:
16
+ f["emb"] = embeddings
17
+ f.attrs["model"] = modelname
18
+
19
+ #print(embeddings)
20
+