[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-07-26 (世界標準時間)。"],[[["\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 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\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\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\nCosine\n\nThis is simply the cosine of the angle between the two\nvectors, \\\\(s(q, x) = \\\\cos(q, x)\\\\)\n\nDot 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\nEuclidean 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\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\nAnswer 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\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."]]