후보 생성 개요
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
후보 생성은 추천의 첫 번째 단계입니다. 쿼리가 주어지면
시스템에서 관련 후보 집합을 생성합니다. 다음 표에서는
일반적인 후보 생성 방법:
유형 | 정의 | 예 |
콘텐츠 기반 필터링 |
항목 간 유사성을 사용하여 상품을 추천합니다.
사용자가 좋아하는 것과 비슷하다고 볼 수 있습니다. |
사용자 A가 귀여운 고양이 동영상 2개를 보면 시스템에서 귀여운 동물 동영상을 해당 사용자에게 추천할 수 있습니다. |
협업 필터링 |
쿼리와 항목의 동시 유사성을 사용하여 추천을 제공합니다. |
사용자 A가 사용자 B와 비슷하고 사용자 B가 동영상 1을 좋아한다면
시스템은 동영상 1을 사용자 A에게 추천할 수 있습니다 (사용자 A가
동영상 1과 유사한 모든 동영상을 시청한 사용자). |
임베딩 공간
콘텐츠 기반 필터링과 협업 필터링 모두 각 항목과 각 쿼리를 매핑합니다.
일반적인 임베딩 공간에서 임베딩 벡터로 변환
\(E = \mathbb R^d\)일반적으로 임베딩 공간은 저차원이지만
(즉, \(d\) 이 코퍼스 크기보다 훨씬 작음) 디코더에서 데이터를 캡처하고
항목 또는 검색어 집합의 잠재 구조를
가지고 있기 때문입니다 유사한 상품(예: YouTube)
평소에 같은 사용자가 보는 동영상은
임베딩 레이어입니다. '가까움'의 개념 유사성 측정으로 정의됩니다
유사성 측정
유사성 측정은 \(s : E \times E \to \mathbb R\) 모델의
는 임베딩 쌍을 취해 유사성을 측정하는 스칼라를 반환합니다.
임베딩은 다음과 같이 후보 생성에 사용할 수 있습니다.
쿼리 임베딩 \(q \in E\)을 선택하면 시스템이 항목 임베딩을 찾음
\(x \in E\) 에 가까운 \(q\), 즉 임베딩이
유사성 \(s(q, x)\)이라고
가정해 보겠습니다
대부분의 추천 시스템은 유사성 정도를 판단하기 위해
다음 중 하나 이상에서
코사인
이것은 단순히 두 지점 사이의 각도의 코사인입니다.
벡터, \(s(q, x) = \cos(q, x)\)
내적
두 벡터의 내적은
\(s(q, x) = \langle q, x \rangle = \sum_{i = 1}^d q_i x_i\)
\(s(q, x) = \|x\| \|q\| \cos(q, x)\) (
각도를 기준의 곱으로 곱한 값입니다. 따라서 임베딩이
내적과 코사인이 일치하는 것입니다.
유클리드 거리
유클리드의 일반적인 거리입니다.
스페이스, \(s(q, x) = \|q - x\| = \left[ \sum_{i = 1}^d (q_i - x_i)^2\right]^{\frac{1}{2}}\)
거리가 짧을수록 유사성이 높아집니다. 참고로 임베딩이
제곱한 유클리드 거리는 내적과 일치함
(및 코사인)을 상수로
전달할 수 있습니다
case \(\frac{1}{2}\|q - x\|^2 = 1 - \langle q, x \rangle\).

유사성 측정 비교
오른쪽 그림의 예를 생각해 보세요. 검은색 벡터는
쿼리 임베딩입니다. 다른 세 개의 임베딩 벡터 (항목 A, 항목 B, 항목 C)
조합 항목을 나타냅니다. 사용된 유사성 측정에 따라
항목 순위가 다를 수 있습니다
이미지를 사용하여 세 가지
코사인, 내적, 유클리드 거리로 구성됩니다.
답안
어떠셨나요?
항목 A는 가장 큰 표준을 가지며
내적 항목 C는 쿼리와의 각도가 가장 작으므로
코사인 유사성에 따라 1위를 차지합니다. 항목 B는 실제로
쿼리에 가장 가까우므로 유클리드 거리가 선호됩니다.

유사성 측정항목은 무엇인가요?
코사인과 비교할 때 내적 유사성은 다음 질문에 민감합니다.
임베딩 표준입니다. 다시 말해서 표준 가중치의 표준이 커질수록
임베딩일수록 유사성이 더 높음 (예각을 갖는 항목의 경우)
추천될 가능성도 높아집니다 이는
권장사항:
학습 세트에 매우 자주 표시되는 항목 (예:
인기 있는 YouTube 동영상)은 규범이 큰 임베딩을 사용하는 경향이 있습니다.
인기도 정보를 캡처하는 것이 바람직하다면
내적을 선호합니다. 하지만 조심하지 않으면 인기 있는
항목이 추천의 대부분을 차지하게 될 수 있습니다. 실제로는
덜 강조하는 다른 유사성 측정값의 변형을 사용할 수 있음
가중치를 부여합니다. 예를 들어
\(s(q, x) = \|q\|^\alpha \|x\|^\alpha \cos(q, x)\)
일부 \(\alpha \in (0, 1)\).
매우 드물게 표시되는 항목은
Vertex AI Feature
Store에서 제공되는 따라서 큰 표준으로 초기화되면
관련성이 높은 상품보다 희귀 상품을 추천할 수도 있습니다. 이를 방지하려면
임베딩 초기화에 주의를 기울이고 적절한
살펴보겠습니다. 첫 번째 연습에서 이 문제를 자세히 살펴보겠습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-07-26(UTC)
[null,null,["최종 업데이트: 2024-07-26(UTC)"],[[["\u003cp\u003eCandidate generation, the initial step in recommendation, involves identifying a set of relevant items using approaches like content-based filtering (similarity between items) and collaborative filtering (similarity between users and items).\u003c/p\u003e\n"],["\u003cp\u003eBoth methods utilize embedding spaces to represent items and queries as vectors, where similar items are positioned closer to each other based on chosen similarity measures (cosine, dot product, or Euclidean distance).\u003c/p\u003e\n"],["\u003cp\u003eThe choice of similarity measure influences item ranking: dot product considers embedding norms (favoring frequent items), while cosine focuses on the angle between vectors (favoring items with high semantic similarity).\u003c/p\u003e\n"],["\u003cp\u003eEuclidean distance prioritizes items physically closest in the embedding space and is less sensitive to norm or frequency, offering a balance between popularity and relevance.\u003c/p\u003e\n"],["\u003cp\u003eUnderstanding the properties and biases of different similarity measures is crucial for building effective and unbiased recommendation systems.\u003c/p\u003e\n"]]],[],null,["# Candidate generation overview\n\nCandidate generation is the first stage of recommendation. Given a query, the\nsystem generates a set of relevant candidates. The following table shows two\ncommon candidate generation approaches:\n\n| Type | Definition | Example |\n|-----------------------------|------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **content-based filtering** | Uses *similarity between items* to recommend items similar to what the user likes. | If user A watches two cute cat videos, then the system can recommend cute animal videos to that user. |\n| **collaborative filtering** | Uses *similarities between queries and items simultaneously* to provide recommendations. | If user A is similar to user B, and user B likes video 1, then the system can recommend video 1 to user A (even if user A hasn't seen any videos similar to video 1). |\n\nEmbedding space\n---------------\n\nBoth content-based and collaborative filtering map each item and each query\n(or context) to an embedding vector in a common embedding space\n\\\\(E = \\\\mathbb R\\^d\\\\). Typically, the embedding space is low-dimensional\n(that is, \\\\(d\\\\) is much smaller than the size of the corpus), and captures\nsome latent structure of the item or query set. Similar items, such as YouTube\nvideos that are usually watched by the same user, end up close together in the\nembedding space. The notion of \"closeness\" is defined by a similarity measure.\n| **Extra Resource:** [projector.tensorflow.org](http://projector.tensorflow.org/) is an interactive tool to visualize embeddings.\n\nSimilarity measures\n-------------------\n\nA similarity measure is a function \\\\(s : E \\\\times E \\\\to \\\\mathbb R\\\\) that\ntakes a pair of embeddings and returns a scalar measuring their similarity.\nThe embeddings can be used for candidate generation as follows: given a\nquery embedding \\\\(q \\\\in E\\\\), the system looks for item embeddings\n\\\\(x \\\\in E\\\\) that are close to \\\\(q\\\\), that is, embeddings with high\nsimilarity \\\\(s(q, x)\\\\).\n\nTo determine the degree of similarity, most recommendation systems rely\non one or more of the following:\n\n- cosine\n- dot product\n- Euclidean distance\n\n### Cosine\n\nThis is simply the cosine of the angle between the two\nvectors, \\\\(s(q, x) = \\\\cos(q, x)\\\\)\n\n### Dot product\n\nThe dot product of two vectors is\n\\\\(s(q, x) = \\\\langle q, x \\\\rangle = \\\\sum_{i = 1}\\^d q_i x_i\\\\).\nIt is also given by \\\\(s(q, x) = \\\\\\|x\\\\\\| \\\\\\|q\\\\\\| \\\\cos(q, x)\\\\) (the cosine of the\nangle multiplied by the product of norms). Thus, if the embeddings are\nnormalized, then dot-product and cosine coincide.\n\n### Euclidean distance\n\nThis is the usual distance in Euclidean\nspace, \\\\(s(q, x) = \\\\\\|q - x\\\\\\| = \\\\left\\[ \\\\sum_{i = 1}\\^d (q_i - x_i)\\^2\\\\right\\]\\^{\\\\frac{1}{2}}\\\\).\nA smaller distance means higher similarity. Note that when the embeddings\nare normalized, the squared Euclidean distance coincides with dot-product\n(and cosine) up to a constant, since in that\ncase \\\\(\\\\frac{1}{2}\\\\\\|q - x\\\\\\|\\^2 = 1 - \\\\langle q, x \\\\rangle\\\\).\n\nComparing similarity measures\n-----------------------------\n\nConsider the example in the figure to the right. The black vector illustrates the\nquery embedding. The other three embedding vectors (Item A, Item B, Item C)\nrepresent candidate items. Depending on the similarity measure used, the\nranking of the items can be different.\n\nUsing the image, try to determine the item ranking using all three of the\nsimilarity measures: cosine, dot product, and Euclidean distance.\n\n#### Answer key\n\n**How did you do?**\n\nItem A has the largest norm, and is ranked higher according to the\ndot-product. Item C has the smallest angle with the query, and is thus\nranked first according to the cosine similarity. Item B is physically\nclosest to the query so Euclidean distance favors it.\n\nWhich similarity measure?\n-------------------------\n\nCompared to the cosine, the dot product similarity is sensitive to\nthe norm of the embedding. That is, the larger the norm of an\nembedding, the higher the similarity (for items with an acute angle)\nand the more likely the item is to be recommended. This can affect\nrecommendations as follows:\n\n- Items that appear very frequently in the training set (for example,\n popular YouTube videos) tend to have embeddings with large norms.\n If capturing popularity information is desirable, then you should\n prefer dot product. However, if you're not careful, the popular\n items may end up dominating the recommendations. In practice, you\n can use other variants of similarity measures that put less emphasis\n on the norm of the item. For example, define\n \\\\(s(q, x) = \\\\\\|q\\\\\\|\\^\\\\alpha \\\\\\|x\\\\\\|\\^\\\\alpha \\\\cos(q, x)\\\\) for\n some \\\\(\\\\alpha \\\\in (0, 1)\\\\).\n\n- Items that appear very rarely may not be updated frequently during\n training. Consequently, if they are initialized with a large norm, the\n system may recommend rare items over more relevant items. To avoid this\n problem, be careful about embedding initialization, and use appropriate\n regularization. We will detail this problem in the first exercise."]]