아빠는 개발자

[NLP] jhgan 본문

NLP/HuggingFace

[NLP] jhgan

father6019 2025. 5. 5. 20:30
728x90
반응형

aqqle 에서 뭘 써야 할지.. 

 

from sentence_transformers import SentenceTransformer, util

# 1) 모델 로드
model = SentenceTransformer('jhgan/ko-sbert-sts')

# 2) 비교할 문장 리스트
sentences = [
    "오늘 날씨가 정말 좋네요.",
    "날씨가 맑아서 기분이 좋습니다."
]

# 3) 임베딩 생성 (Tensor 반환)
embeddings = model.encode(sentences, convert_to_tensor=True)

# 4) 코사인 유사도 계산
cos_sim = util.cos_sim(embeddings[0], embeddings[1])
print(f"Similarity score: {cos_sim.item():.4f}")

 

 

 

  • convert_to_tensor=True를 주면 PyTorch Tensor로 반환되어 바로 유사도 연산에 쓸 수 있음.
  • util.cos_sim 외에도 util.pytorch_cos_sim 등을 사용할 수 있음.

 

728x90
반응형

'NLP > HuggingFace' 카테고리의 다른 글

[NLP] jhgan vs snunlp vs upskyy  (0) 2025.05.05
[NLP] upskyy  (0) 2025.05.01
[NLP] snunlp  (0) 2025.05.01
[NLP] 가상환경 만들기 - conda  (0) 2025.05.01
[NLP] Hugging Face  (1) 2025.04.30