File size: 529 Bytes
51e0c75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import h5py as h5
import json
import pandas as pd
import torch
from sentence_transformers import SentenceTransformer

torch.set_num_threads(32)
modelname = 'sentence-transformers/all-MiniLM-L6-v2'
model = SentenceTransformer(modelname)
with open("wikipedia-text-20231101-en.txt") as f:
    sentences = [json.loads(line) for line in f.readlines()]

embeddings = model.encode(sentences)

with h5.File("wikipedia-embeddings-20231101-en.h5", "w") as f:
    f["emb"] = embeddings
    f.attrs["model"] = modelname

#print(embeddings)