단어 벡터 유사도 측정하기
이번 레슨에서는 실제로 학습된 단어 벡터를 통해 단어 벡터의 강점을 살펴보겠습니다. 사용되는 벡터는 Stanford NLP group에서 공개한 단어 벡터 목록에서 가져온 것입니다. 단어 벡터는 일련의 수치로 이루어진 벡터입니다. 예를 들어,
dog = (0.31, 0.92, 0.13)
단어 벡터 간 거리는 쌍(pair-wise) 유사도 지표로 측정할 수 있습니다. 여기서는 sklearn.metrics.pairwise.cosine_similarity를 사용해 보겠습니다. 코사인 유사도는 두 벡터의 원소 수준 유사도가 높을수록 더 큰 값을, 낮을수록 더 작은 값을 반환합니다.
이 연습은 강의의 일부입니다
Keras로 배우는 Machine Translation
연습 안내
ndarray.size속성을 사용해cat_vector의 길이를 출력하세요.cosine_similarity를 사용해cat_vector와window_vector의 유사도를 계산해 출력하세요.cosine_similarity를 사용해cat_vector와dog_vector의 유사도를 계산해 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
from sklearn.metrics.pairwise import cosine_similarity
# Print the length of the cat_vector
print('Length of the cat_vector: ', ____.____)
# Compute and print the similarity between cat and window vectors
dist_cat_window = ____(____, window_vector)
print('Similarity(cat, window): ', ____)
# Compute and print the similarity between cat and dog vectors
print('Similarity(cat,dog): ', ____(____, ____))