Upload encode-yahoo-answers.py with huggingface_hub
Browse files- encode-yahoo-answers.py +39 -0
encode-yahoo-answers.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import h5py as h5
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import torch
|
| 6 |
+
import time
|
| 7 |
+
from sentence_transformers import SentenceTransformer
|
| 8 |
+
|
| 9 |
+
#torch.set_num_threads(32)
|
| 10 |
+
|
| 11 |
+
D = pd.read_parquet("yahoo-answers/question-answer-pair")
|
| 12 |
+
# title, article
|
| 13 |
+
modelname = 'sentence-transformers/all-MiniLM-L6-v2'
|
| 14 |
+
model = SentenceTransformer(modelname)
|
| 15 |
+
|
| 16 |
+
print(D.columns)
|
| 17 |
+
#print("embeddings title")
|
| 18 |
+
#embeddings = model.encode(D.title)
|
| 19 |
+
#
|
| 20 |
+
#with h5.File("ccnews.h5", "w") as f:
|
| 21 |
+
# f["title"] = embeddings
|
| 22 |
+
# f.attrs["model"] = modelname
|
| 23 |
+
|
| 24 |
+
print("computing embeddings")
|
| 25 |
+
st = time.time()
|
| 26 |
+
embeddings = model.encode(D.question)
|
| 27 |
+
|
| 28 |
+
print("finished in {}s".format(time.time() - st))
|
| 29 |
+
with h5.File("yahoo-question-answer.h5", "a") as f:
|
| 30 |
+
f["question"] = embeddings
|
| 31 |
+
f.attrs["model"] = modelname
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
st = time.time()
|
| 35 |
+
embeddings = model.encode(D.answer)
|
| 36 |
+
|
| 37 |
+
print("finished in {}s".format(time.time() - st))
|
| 38 |
+
with h5.File("yahoo-question-answer.h5", "a") as f:
|
| 39 |
+
f["answer"] = embeddings
|