تدريب Softmax
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
شرحت الصفحة السابقة كيفية دمج طبقة softmax في
الشبكة العصبية لنظام التوصية. تُلقي هذه الصفحة نظرة عن كثب على
بيانات التطبيق لهذا النظام.
بيانات التدريب
تتكون بيانات تدريب softmax من ميزات طلب البحث \(x\)
متجه من العناصر التي تفاعل معها المستخدم (يتم تمثيلها
توزيع الاحتمالية \(p\)). هذه علامات باللون الأزرق في
الشكل التالي. متغيرات النموذج هي معاملات الترجيح
في الطبقات المختلفة. تظهر هذه الألوان باللون البرتقالي في ما يلي
الشكل. يتم تدريب النموذج عادةً باستخدام أي صيغة
انحدار التدرج العشوائي.
أخذ العينات السلبي
بما أنّ دالة الخسارة تقارن متّجهَين للاحتمالية
\(p, \hat p(x) \in \mathbb R^n\) (الحقيقة الأساسية
ناتج النموذج، على التوالي)، وحساب
تدرج الخسارة (لطلب بحث واحد \(x\))
باهظة الثمن إذا كان حجم المجموعة \(n\) كبيرًا جدًا.
يمكنك إعداد نظام لحساب التدرجات على العناصر الموجبة فقط
(العناصر النشطة في خط متجه الحقيقة). ومع ذلك، إذا لم يتمكن
يتدرّب على الأزواج الموجبة فقط، فقد يعاني النموذج من الطي، حيث إن
الموضحة أدناه.

في الشكل التالي، افترض أن كل لون يمثل قيمة
وفئة طلبات البحث والعناصر. كل طلب بحث (يتم تمثيله في شكل مربع) فقط
ويتفاعل في الغالب مع العناصر (تمثلها دائرة) من نفس اللون.
على سبيل المثال، يمكنك اعتبار كل فئة لغة مختلفة في YouTube.
يتفاعل المستخدم العادي في الغالب مع مقاطع الفيديو بلغة واحدة.
قد يتعلم النموذج كيفية وضع تضمينات طلب البحث/العنصر لعنصر
لونًا نسبيًا مع بعضها البعض (التقاط التشابه داخل ذلك بشكل صحيح
اللون)، ولكن قد ينتهي الأمر بتضمين ألوان مختلفة في المنطقة نفسها
مساحة التضمين، عن طريق الصدفة. إن هذه الظاهرة
على أنّها قابلة للطي، إلى اقتراحات كاذبة: عند طلب البحث،
فقد يتنبأ النموذج عن طريق الخطأ بدرجة عالية لعنصر من
مجموعة مختلفة.
الأمثلة السلبية هي العناصر التي يتم تصنيفها على أنها "غير ملائمة" إلى استعلام معين.
يؤدي عرض الأمثلة السلبية للنموذج أثناء التدريب إلى تعليم النموذج الذي
يجب إبعاد تضمين المجموعات المختلفة عن بعضها البعض.
وبدلاً من استخدام كل العناصر لحساب التدرج (والذي قد يكون
مكلفة) أو استخدام عناصر إيجابية فقط (مما يجعل النموذج عرضة
قابلة للطي)، يمكنك استخدام العينات السالبة. وبشكل أكثر دقة، تقوم بحساب
تدرج تقريبي، باستخدام العناصر التالية:
- جميع العناصر الإيجابية (تلك التي تظهر في التصنيف المستهدف)
- نموذج من العناصر السلبية (\(j\) في \({1, …, n}\))
ثمة استراتيجيات مختلفة لأخذ العينات السلبية:
- يمكنك أخذ عينات موحَّدة.
- يمكنك إعطاء احتمالية أعلى للعناصر j ذات القيم الأعلى
الجودة \(\psi(x) . V_j\). ومن البديهي أن هذه أمثلة
التي تساهم بشكل أكبر في التدرج) غالبًا ما تكون هذه الأمثلة
تسمى السلبيات الصعبة.
تحليل المصفوفة إلى عواملها في مقابل softmax
تحل نماذج DNN العديد من قيود تحليل المصفوفة، ولكن عادةً ما
التدريب والاستعلام أكثر تكلفة. يلخص الجدول أدناه بعض
الاختلافات المهمة بين النموذجين.
|
تحليل المصفوفة |
شركة Softmax DNN |
ميزات طلبات البحث |
لا يسهل تضمينها. |
يمكن تضمينها. |
التشغيل البارد |
لا يسهل التعامل مع المصطلحات الخارجة عن المألوف
أو استعلامات أو عناصر. ويمكن استخدام بعض الأساليب الإرشادية (على سبيل المثال، لمعرفة
طلب بحث جديد، ومتوسط عدد التضمينات من طلبات بحث مماثلة). |
التعامل مع طلبات البحث الجديدة بسهولة: |
الطيّ |
يمكن تقليل إمكانية طيّ بسهولة
عن طريق ضبط الوزن غير المرصود في WALS. |
عرضة للطي بحاجة إلى استخدام
تقنيات مثل أخذ العينات السالب أو الجاذبية. |
قابلية تطوير التدريب |
قابلة للتوسع بسهولة إلى أحجام كبيرة جدًا
(ربما مئات الملايين من العناصر أو أكثر)، ولكن فقط إذا
مصفوفة الإدخال متناثرة. |
من الصعب التغيير إلى الحجم الكبير جدًا
المجموعات. ويمكن استخدام بعض الأساليب، مثل التجزئة،
وأخذ العينات السلبي، وما إلى ذلك. |
قابلية عرض الإعلانات |
عمليات التضمين U وV ثابتة،
ويمكن حساب مجموعة من العناصر المرشحة وتخزينها مسبقًا. |
تضمينات العنصر V ثابتة
ويمكن تخزينها.
يؤدي تضمين طلب البحث عادةً
إلى وقت الاستعلام، مما يجعل النموذج أكثر تكلفة
|
باختصار:
- عادةً ما يكون تحليل المصفوفة هو الخيار الأفضل للمجموعات الكبيرة.
فمن الأسهل توسيعه، وأرخص طلب البحث، وأقل عرضة للطي.
- يمكن لنماذج DNN التقاط الإعدادات المفضّلة المخصصة بشكل أفضل، إلا أنّها
تدريبه وأكثر تكلفة أكثر في الاستعلام. يُفضَّل استخدام نماذج DNN
إلى تحليل المصفوفة لتسجيل النقاط لأن نماذج DNN يمكن أن تستخدم
ميزات إضافية لتحديد مدى الصلة بالموضوع بشكل أفضل. أيضًا، من المعتاد
مقبولة لطي نماذج DNN، لأنك تهتم في الغالب
ترتيب مجموعة تمت تصفيتها مسبقًا من العناصر المرشحة التي يُفترض أن تكون ملائمة.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2024-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 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."]]