Spaces:
Sleeping
Sleeping
File size: 854 Bytes
628d1d2 5708eb0 628d1d2 5708eb0 628d1d2 5708eb0 628d1d2 |
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 |
import json
import numpy as np
from sentence_transformers import SentenceTransformer
# Load dữ liệu
with open("data/raw.json", "r", encoding="utf-8") as f:
data = json.load(f)
questions = [item["question"] for item in data]
answers = [item["answer"] for item in data]
# Load mô hình embedding
model = SentenceTransformer("pkshatech/GLuCoSE-base-ja")
# Tạo embedding cho câu hỏi và câu trả lời
question_embeddings = model.encode(questions, convert_to_numpy=True)
answer_embeddings = model.encode(answers, convert_to_numpy=True)
# Lưu embedding dưới dạng numpy array
np.save("data/question_embeddings.npy", question_embeddings)
np.save("data/answer_embeddings.npy", answer_embeddings)
# Lưu dữ liệu gốc
with open("data/qa_data.json", "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
|