Upload encode-ccnews.py with huggingface_hub
Browse files- encode-ccnews.py +27 -0
encode-ccnews.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import h5py as h5
|
| 2 |
+
import json
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import torch
|
| 5 |
+
from sentence_transformers import SentenceTransformer
|
| 6 |
+
|
| 7 |
+
#torch.set_num_threads(32)
|
| 8 |
+
|
| 9 |
+
D = pd.read_parquet("ccnews/pair")
|
| 10 |
+
# title, article
|
| 11 |
+
modelname = 'sentence-transformers/all-MiniLM-L6-v2'
|
| 12 |
+
model = SentenceTransformer(modelname)
|
| 13 |
+
|
| 14 |
+
print(D.columns)
|
| 15 |
+
|
| 16 |
+
#print("embeddings title")
|
| 17 |
+
#embeddings = model.encode(D.title)
|
| 18 |
+
#
|
| 19 |
+
#with h5.File("ccnews.h5", "w") as f:
|
| 20 |
+
# f["title"] = embeddings
|
| 21 |
+
# f.attrs["model"] = modelname
|
| 22 |
+
|
| 23 |
+
print("embeddings article")
|
| 24 |
+
embeddings = model.encode(D.article)
|
| 25 |
+
|
| 26 |
+
with h5.File("ccnews.h5", "a") as f:
|
| 27 |
+
f["article"] = embeddings
|