spaCy로 문서 유사도 계산하기
의미적 유사도는 여러 문장을 분석해 서로 얼마나 비슷한지 파악하는 과정이에요. 이번 연습에서는 주어진 문서에 대해 다른 문서들의 의미적 유사도를 계산해 볼 거예요. 목표는 canned dog food와 관련된 리뷰들을 분류하는 것입니다.
canned dog food 카테고리는 category에 저장되어 있어요. 다섯 개의 음식 리뷰 예제가 texts라는 리스트로 제공됩니다. en_core_web_md는 nlp로 로드되어 있어요.
이 연습은 강의의 일부입니다
spaCy로 배우는 자연어 처리
연습 안내
- 모든
texts에 대한Doc컨테이너로 이루어진documents리스트를 만드세요. category의Doc컨테이너를 생성해category_document로 저장하세요.documents를 순회하면서 각Doc컨테이너와category_document의 유사도 점수를 소수 셋째 자리까지 반올림해 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create a documents list containing Doc containers
documents = [____ for t in texts]
# Create a Doc container of the category
category = "canned dog food"
category_document = ____(____)
# Print similarity scores of each Doc container and the category_document
for i, doc in enumerate(documents):
print(f"Semantic similarity with document {i+1}:", round(doc.____(____), 3))