임베딩의 유사성 측정
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이제 임베딩이 생성되었습니다. 감독 유사성 측정값은 이러한 임베딩을 사용하여 유사성을 측정하는 숫자를 반환합니다.
임베딩은 숫자 벡터입니다. 두 벡터 \(A = [a_1,a_2,...,a_n]\) 와 \(B = [b_1,b_2,...,b_n]\)의 유사성을 찾으려면 다음 세 가지 유사성 측정 중 하나를 선택합니다.
측정 | 의미 | 수식 |
유사성이 증가하면 이 측정값은... |
유클리드 거리 | 벡터의 끝점 사이의 거리 |
\(\sqrt{(a_1-b_1)^2+(a_2-b_2)^2+...+(a_N-b_N)^2}\) |
감소 |
코사인 | 벡터 간 각도 \(\theta\) 의 코사인 |
\(\frac{a^T b}{|a| \cdot |b|}\) |
증가 |
내적 | 코사인에 두 벡터의 길이를 곱한 값 |
\(a_1b_1+a_2b_2+...+a_nb_n\) \(=|a||b|cos(\theta)\) |
증가합니다. 벡터 길이도 함께 증가합니다. |
유사도 측정 선택
코사인과 달리 내적은 벡터 길이에 비례합니다.
이는 학습 세트에 매우 자주 등장하는 예시 (예: 인기 YouTube 동영상)에는 길이가 긴 임베딩 벡터가 있는 경향이 있기 때문에 중요합니다.
인기를 파악하려면 내적을 선택합니다. 하지만 인기 있는 예시가 유사성 측정항목을 왜곡할 수 있다는 위험이 있습니다. 이 왜곡을 보정하려면 길이를 지수 \(\alpha\ < 1\) 로 올려 내적을 \(|a|^{\alpha}|b|^{\alpha}\cos(\theta)\)로 계산할 수 있습니다.
벡터 길이가 유사성 측정값을 어떻게 변경하는지 더 잘 이해하려면 벡터 길이를 1로 정규화하고 세 측정값이 서로 비례하는 것을 확인합니다.
a와 b를 \(||a||=1\) 와 \(||b||=1\)로 정규화하면 다음 세 측정항목은 다음과 같이 관련이 있습니다.
- 유클리드 거리 = \(||a-b|| = \sqrt{||a||^2 + ||b||^2 - 2a^{T}b}
= \sqrt{2-2\cos(\theta_{ab})}\).
- 내적 = \( |a||b| \cos(\theta_{ab})
= 1\cdot1\cdot \cos(\theta_{ab}) = cos(\theta_{ab})\).
- 코사인 = \(\cos(\theta_{ab})\).
따라서 세 가지 유사성 측정항목은 모두 \(cos(\theta_{ab})\)에 비례하므로 동일합니다.
유사도 측정 검토
유사도 측정값은 다른 예시 쌍을 기준으로 한 예시 쌍 간의 유사성을 수치화합니다. 수동 및 감독의 두 가지 유형을 아래에서 비교해 보세요.
유형 | 만들기 방법 | 권장 | 영향 |
수동 | 지형지물 데이터를 수동으로 결합합니다. |
결합하기 쉬운 기능이 있는 소규모 데이터 세트 |
유사도 계산 결과에 대한 유용한 정보를 제공합니다. 지형지물 데이터가 변경되면 유사성 측정값을 수동으로 업데이트해야 합니다. |
감독 대상 | 감독 DNN에서 생성된 임베딩 간의 거리를 측정합니다. |
결합하기 어려운 기능이 있는 대규모 데이터 세트 |
결과에 대한 통계를 제공하지 않습니다. 하지만 DNN은 변화하는 지형지물 데이터에 자동으로 적응할 수 있습니다. |
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-02-25(UTC)
[null,null,["최종 업데이트: 2025-02-25(UTC)"],[[["\u003cp\u003eSupervised similarity measures leverage embeddings to quantify the similarity between data examples using Euclidean distance, cosine, or dot product.\u003c/p\u003e\n"],["\u003cp\u003eDot product incorporates vector length, reflecting popularity, while cosine similarity focuses solely on the angle between vectors, ignoring popularity.\u003c/p\u003e\n"],["\u003cp\u003eNormalizing vector lengths makes Euclidean distance, cosine, and dot product proportional, essentially measuring the same thing.\u003c/p\u003e\n"],["\u003cp\u003eSupervised similarity, using embeddings and a distance metric, is suitable for large, complex datasets, while manual similarity, relying on feature combinations, is better for small, straightforward datasets.\u003c/p\u003e\n"]]],[],null,["# Measuring similarity from embeddings\n\nYou now have embeddings for any pair of examples. A supervised similarity\nmeasure takes these embeddings and returns a number measuring their similarity.\nRemember that embeddings are vectors of numbers. To find the similarity between\ntwo vectors \\\\(A = \\[a_1,a_2,...,a_n\\]\\\\) and \\\\(B = \\[b_1,b_2,...,b_n\\]\\\\),\nchoose one of these three similarity measures:\n\n| Measure | Meaning | Formula | As similarity increases, this measure... |\n|--------------------|-----------------------------------------------|--------------------------------------------------------------|---------------------------------------------------|\n| Euclidean distance | Distance between ends of vectors | \\\\(\\\\sqrt{(a_1-b_1)\\^2+(a_2-b_2)\\^2+...+(a_N-b_N)\\^2}\\\\) | Decreases |\n| Cosine | Cosine of angle \\\\(\\\\theta\\\\) between vectors | \\\\(\\\\frac{a\\^T b}{\\|a\\| \\\\cdot \\|b\\|}\\\\) | Increases |\n| Dot product | Cosine multiplied by lengths of both vectors | \\\\(a_1b_1+a_2b_2+...+a_nb_n\\\\) \\\\(=\\|a\\|\\|b\\|cos(\\\\theta)\\\\) | Increases. Also increases with length of vectors. |\n\nChoosing a similarity measure\n-----------------------------\n\nIn contrast to the cosine, the dot product is proportional to the vector length.\nThis is important because examples that appear very frequently in the training\nset (for example, popular YouTube videos) tend to have embedding vectors with\nlarge lengths.\n\nIf you\nwant to capture popularity, then choose dot product. However, the risk is that\npopular examples may skew the similarity metric. To balance this skew, you can\nraise the length to an exponent \\\\(\\\\alpha\\\\ \\\u003c 1\\\\) to calculate the dot product\nas \\\\(\\|a\\|\\^{\\\\alpha}\\|b\\|\\^{\\\\alpha}\\\\cos(\\\\theta)\\\\).\n\nTo better understand how vector length changes the similarity measure, normalize\nthe vector lengths to 1 and notice that the three measures become proportional\nto each other. \nProof: Proportionality of Similarity Measures \nAfter normalizing a and b such that \\\\(\\|\\|a\\|\\|=1\\\\) and \\\\(\\|\\|b\\|\\|=1\\\\), these three measures are related as:\n\n- Euclidean distance = \\\\(\\|\\|a-b\\|\\| = \\\\sqrt{\\|\\|a\\|\\|\\^2 + \\|\\|b\\|\\|\\^2 - 2a\\^{T}b} = \\\\sqrt{2-2\\\\cos(\\\\theta_{ab})}\\\\).\n- Dot product = \\\\( \\|a\\|\\|b\\| \\\\cos(\\\\theta_{ab}) = 1\\\\cdot1\\\\cdot \\\\cos(\\\\theta_{ab}) = cos(\\\\theta_{ab})\\\\).\n- Cosine = \\\\(\\\\cos(\\\\theta_{ab})\\\\).\nThus, all three similarity measures are equivalent because they are proportional to \\\\(cos(\\\\theta_{ab})\\\\).\n\nReview of similarity measures\n-----------------------------\n\nA similarity measure quantifies the similarity between a pair of\nexamples, relative to other pairs of examples. The two types, manual and\nsupervised, are compared below:\n\n| Type | How to create | Best for | Implications |\n|------------|--------------------------------------------------------------------|-------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| Manual | Manually combine feature data. | Small datasets with features that are straightforward to combine. | Gives insight into results of similarity calculations. If feature data changes, you must manually update the similarity measure. |\n| Supervised | Measure distance between embeddings generated by a supervised DNN. | Large datasets with hard-to-combine features. | Gives no insight into results. However, a DNN can automatically adapt to changing feature data. |"]]