File size: 722 Bytes
748bd71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
import os
from gensim.models import KeyedVectors

MODEL_PATH_VEC = "ko.vec"

# 모델 로딩
if os.path.exists(MODEL_PATH_VEC):
    print("🔁 Word2Vec 텍스트 모델 로드 중...")
    model = KeyedVectors.load_word2vec_format(MODEL_PATH_VEC, binary=False)
    print("✅ Word2Vec 모델 로드 완료")
else:
    raise FileNotFoundError("❌ 'ko.vec' 파일을 찾을 수 없습니다.")

def embed_keywords(keywords: list[str]) -> np.ndarray:
    """
    키워드 리스트를 벡터로 변환하고 평균 벡터 반환
    """
    vectors = [model[word] for word in keywords if word in model]
    if not vectors:
        return np.zeros(model.vector_size)
    return np.mean(vectors, axis=0)