TextEmbeddings / encode-ccnews.py
sadit's picture
Upload encode-ccnews.py with huggingface_hub
62d21b1 verified
raw
history blame contribute delete
609 Bytes
import h5py as h5
import json
import pandas as pd
import torch
from sentence_transformers import SentenceTransformer
#torch.set_num_threads(32)
D = pd.read_parquet("ccnews/pair")
# title, article
modelname = 'sentence-transformers/all-MiniLM-L6-v2'
model = SentenceTransformer(modelname)
print(D.columns)
#print("embeddings title")
#embeddings = model.encode(D.title)
#
#with h5.File("ccnews.h5", "w") as f:
# f["title"] = embeddings
# f.attrs["model"] = modelname
print("embeddings article")
embeddings = model.encode(D.article)
with h5.File("ccnews.h5", "a") as f:
f["article"] = embeddings