File size: 960 Bytes
f66e5f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import h5py as h5
import sys
import json
import pandas as pd
import torch
import time
from sentence_transformers import SentenceTransformer

#torch.set_num_threads(32)

D = pd.read_parquet("yahoo-answers/question-answer-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("computing embeddings")
st = time.time()
embeddings = model.encode(D.question)

print("finished in {}s".format(time.time() - st))
with h5.File("yahoo-question-answer.h5", "a") as f:
    f["question"] = embeddings
    f.attrs["model"] = modelname


st = time.time()
embeddings = model.encode(D.answer)

print("finished in {}s".format(time.time() - st))
with h5.File("yahoo-question-answer.h5", "a") as f:
    f["answer"] = embeddings