TextEmbeddings / encode-wikipedia.py
sadit's picture
Upload encode-wikipedia.py with huggingface_hub
51e0c75 verified
raw
history blame contribute delete
529 Bytes
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)