[null,null,["最后更新时间 (UTC):2024-07-26。"],[[["\u003cp\u003eThis page focuses on the training data and process for a softmax deep neural network recommendation system.\u003c/p\u003e\n"],["\u003cp\u003eNegative sampling is crucial to avoid "folding," where embeddings from different categories are incorrectly grouped together.\u003c/p\u003e\n"],["\u003cp\u003eNegative sampling involves training the model on both positive (relevant) and negative (irrelevant) examples.\u003c/p\u003e\n"],["\u003cp\u003eCompared to Matrix Factorization, softmax DNNs are more flexible but computationally expensive and susceptible to folding.\u003c/p\u003e\n"],["\u003cp\u003eWhile Matrix Factorization is better for large-scale applications, DNNs excel at capturing personalized preferences for recommendation tasks.\u003c/p\u003e\n"]]],[],null,["# Softmax training\n\nThe previous page explained how to incorporate a softmax layer into a deep\nneural network for a recommendation system. This page takes a closer look at the\ntraining data for this system.\n\nTraining data\n-------------\n\nThe softmax training data consists of the query features \\\\(x\\\\) and\na vector of items the user interacted with (represented as a\nprobability distribution \\\\(p\\\\)). These are marked in blue in\nthe following figure. The variables of the model are the weights\nin the different layers. These are marked as orange in the following\nfigure. The model is typically trained using any variant of\nstochastic gradient descent.\n\n### Negative sampling\n\nSince the loss function compares two probability vectors\n\\\\(p, \\\\hat p(x) \\\\in \\\\mathbb R\\^n\\\\) (the ground truth and\nthe output of the model, respectively), computing the\ngradient of the loss (for a single query \\\\(x\\\\)) can be\nprohibitively expensive if the corpus size \\\\(n\\\\) is too big.\n\nYou could set up a system to compute gradients only on the positive items\n(items that are active in the ground truth vector). However, if the system\nonly trains on positive pairs, the model may suffer from folding, as\nexplained below. \nFolding \nIn the following figure, assume that each color represents a different category of queries and items. Each query (represented as a square) only mostly interacts with the items (represented as a circle) of the same color. For example, consider each category to be a different language in YouTube. A typical user will mostly interact with videos of one given language.\n\nThe model may learn how to place the query/item embeddings of a given\ncolor relative to each other (correctly capturing similarity within that\ncolor), but embeddings from different colors may end up in the same region\nof the embedding space, by chance. This phenomenon, known\nas **folding**, can lead to spurious recommendations: at query time,\nthe model may incorrectly predict a high score for an item from a\ndifferent group.\n\n**Negative examples** are items labeled \"irrelevant\" to a given query.\nShowing the model negative examples during training teaches the model that\nembeddings of different groups should be pushed away from each other.\n\nInstead of using all items to compute the gradient (which can be too\nexpensive) or using only positive items (which makes the model prone to\nfolding), you can use negative sampling. More precisely, you compute an\napproximate gradient, using the following items:\n\n- All positive items (the ones that appear in the target label)\n- A sample of negative items (\\\\(j\\\\) in \\\\({1, ..., n}\\\\))\n\nThere are different strategies for sampling negatives:\n\n- You can sample uniformly.\n- You can give higher probability to items j with higher score \\\\(\\\\psi(x) . V_j\\\\). Intuitively, these are examples that contribute the most to the gradient); these examples are often called hard negatives.\n\n| **Extra resources:**\n|\n| - For a more comprehensive account of the technology, architecture, and models used in YouTube, see [Deep Neural Networks\n| for YouTube Recommendations](https://research.google.com/pubs/pub45530.html).\n| - See [Xin et al., Folding:\n| Why Good Models Sometimes Make Spurious Recommendations](https://dl.acm.org/citation.cfm?id=3109911) for more details on folding.\n| - To learn more about negative sampling, see [Bengio and Senecal,\n| Adaptive Importance Sampling to Accelerate Training of a Neural\n| Probabilistic Language Model.](https://ieeexplore.ieee.org/document/4443871/)\n\nOn matrix factorization versus softmax\n--------------------------------------\n\nDNN models solve many limitations of Matrix Factorization, but are typically\nmore expensive to train and query. The table below summarizes some of the\nimportant differences between the two models.\n\n| | Matrix Factorization | Softmax DNN |\n|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Query features | Not easy to include. | Can be included. |\n| Cold start | Does not easily handle out-of vocab queries or items. Some heuristics can be used (for example, for a new query, average embeddings of similar queries). | Easily handles new queries. |\n| Folding | Folding can be easily reduced by adjusting the unobserved weight in WALS. | Prone to folding. Need to use techniques such as negative sampling or gravity. |\n| Training scalability | Easily scalable to very large corpora (perhaps hundreds of millions items or more), but only if the input matrix is sparse. | Harder to scale to very large corpora. Some techniques can be used, such as hashing, negative sampling, etc. |\n| Serving scalability | Embeddings U, V are static, and a set of candidates can be pre-computed and stored. | Item embeddings V are static and can be stored. The query embedding usually needs to be computed at query time, making the model more expensive to serve. |\n\nIn summary:\n\n- Matrix factorization is usually the better choice for large corpora. It is easier to scale, cheaper to query, and less prone to folding.\n- DNN models can better capture personalized preferences, but are harder to train and more expensive to query. DNN models are preferable to matrix factorization for scoring because DNN models can use more features to better capture relevance. Also, it is usually acceptable for DNN models to fold, since you mostly care about ranking a pre-filtered set of candidates assumed to be relevant."]]