تنظيم صفحاتك في مجموعات يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
في وقت سابق، واجهت التصنيف الثنائي التي يمكنها الاختيار من بين اثنين من الخيارات المحتملة، مثل:
يُرجى اعتبار رسالة إلكترونية معيّنة رسالة غير مرغوب فيها أو ليست رسالة غير مرغوب فيها.
يكون ورم معين ورمًا خبيثًا أو حميدًا.
في هذا القسم، سنتقصى التصنيف متعدد الفئات التي يمكنها الاختيار من بين الاحتمالات المتعددة. على سبيل المثال:
هل هذا الكلب بيغل أم كلب صيد باسات أم كلب دموي؟
هل هذه الزهرة هي زهرة سيبيريا أم سوسن هولندي أم سوسن علم أزرق؟ أو السوسن القزم ذو اللحية؟
هل هذه الطائرة من طراز Boeing 747 أو Airbus 320 أو Boeing 777 أو Embraer 190؟
هل هذه صورة لتفاحة أو دب أو حلوى أو كلب أو بيضة؟
بعض المشاكل الواقعية المتعددة الفئات تتطلب الاختيار من بين الملايين من فئات منفصلة. فعلى سبيل المثال، بالنظر إلى التصنيف متعدد الفئات النموذج الذي يمكنه تحديد صورة أي شيء تقريبًا.
يفصّل هذا القسم المتغيرين الرئيسيين للتصنيف متعدد الفئات:
توفّر دالة واحد مقابل الكل طريقة لاستخدام التصنيف الثنائي. لسلسلة من التنبؤات بنعم أو لا عبر التصنيفات المحتملة المتعددة.
بناءً على مشكلة التصنيف مع ن من الحلول الممكنة، يمكن حساب واحد مقابل الكل أن يتألف الحل من مصنِّفات ثنائية منفصلة عن N — أي مُصنِّف ثنائي منفصل لكل نتيجة محتملة. أثناء التدريب، يقوم النموذج بتشغيل من خلال سلسلة من المصنِّفات الثنائية، مع تطبيق المصنِّفات الثنائية لحل نزُل سؤال التصنيف.
فعلى سبيل المثال، إذا كانت صورة قطعة فاكهة واحدة، وهي أربعة قد يتم تدريب أدوات تعرّف مختلفة، يجيب كل منها بنعم أو لا مختلفة السؤال:
هل هذه الصورة تفاحة؟
هل هذه الصورة برتقالية؟
هل هذه الصورة موزة؟
هل هذه الصورة عنب؟
توضح الصورة التالية كيفية عمل ذلك عمليًا.
الشكل 7. صورة كمثرى يتم تمريرها كمدخل إلى أربعة أشكال المصنِّفات الثنائية. يحتوي النموذج الأول والثاني والرابع (التنبؤ ما إذا كانت الصورة عبارة عن تفاحة أو برتقال أو عنب على التوالي) للتنبؤ بالفئة السالبة. أما النموذج الثالث (التنبؤ بما إذا كان أو لا تكون الصورة على شكل كمثرى) تتوقّع الفئة الموجبة.
ويكون هذا المنهج معقولاً إلى حد ما عندما يتجمع العدد الإجمالي للفئات صغيرة، لكنها تصبح غير فعالة بشكل متزايد مع زيادة يرتفع.
يمكننا إنشاء نموذج أكثر فعالية مقارنةً بالكل. بشبكة عصبية عميقة تمثل فيها كل عقدة ناتج الصف. توضح الصورة التالية هذا الأسلوب.
الشكل 8. يتم تنفيذ نفس مهام التصنيف واحد مقابل الكل باستخدام نموذج الشبكة العصبية. يتم تطبيق دالة التفعيل السيني على الناتج وكل قيمة ناتج من احتمالية أن يكون المدخل الصورة هي فاكهة محددة. يتنبأ هذا النموذج بأن هناك 84% احتمال أن تكون الصورة كمثرى، واحتمال بنسبة 7% أن تكون الصورة عنب
واحد مقابل واحد (softmax)
ربما لاحظت أن قيم الاحتمالات في طبقة الإخراج للشكل 8 لا مجموعها 1.0 (أو 100٪). (في الواقع، يبلغ مجموعها 1.43). في منظور واحد مقابل الكل منهجًا، تُحدد احتمالية كل مجموعة ثنائية من النتائج بشكل مستقل عن جميع المجموعات الأخرى. أي أننا نحدد احتمالية من "apple" مقابل "not apple" دون مراعاة احتمالية خيارات الفواكه: "البرتقال" أو "الكمثرى" أو "العنب".
ولكن ماذا لو أردنا التنبؤ باحتمالات كل فاكهة بالنسبة إلى بعضها البعض؟ في هذه الحالة، بدلًا من التنبؤ بكلمة apple مقابل "not" apple"، نريد التنبؤ بـ "apple" مقابل "البرتقالي" مقابل "الكمثرى" مقابل "العنب". يُطلق على هذا النوع من التصنيفات المتعددة الفئات اسم تصنيف واحد مقابل واحد.
يمكننا تنفيذ تصنيف واحد مقابل واحد باستخدام نفس النوع من التجميع العصبوني بنية الشبكة المستخدمة في التصنيف "واحد مقابل الكل"، مع تغيير رئيسي واحد. نحتاج إلى تطبيق تحويل مختلف على طبقة الإخراج.
معامل واحد مقابل الكل، طبقنا دالة التفعيل السيني على كل ناتج العقدة بشكل مستقل، مما أدى إلى ظهور قيمة ناتج بين 0 و1 لكل منهما ولكن لم يضمن جمع هذه القيم مع 1 بالضبط.
بالنسبة إلى معامل واحد مقابل واحد، يمكننا بدلاً من ذلك تطبيق دالة تُسمى softmax، وهي الاحتمالات العشرية لكل فئة في مشكلة متعددة الفئات، بحيث جمع جميع الاحتمالات ما يصل إلى 1.0. هذا القيد الإضافي يساعد التطبيق على التواصل بشكل أسرع مما لو كان ممكنًا.
لاحظ أن هذه المعادلة توسع بشكل أساسي معادلة لوجستية الانحدار إلى فئات متعددة.
تعيد الصورة التالية تطبيق التصنيف واحد مقابل الكل متعدد الفئات مهمة كمهمة مقارنة واحدة. لاحظ أنه من أجل تنفيذ softmax، فإن البيانات الطبقة التي تسبق طبقة الإخراج مباشرةً (تسمى طبقة softmax) يجب أن تحتوي نفس عدد العقد الموجودة في طبقة المخرجات.
الشكل 9. تنفيذ الشبكة العصبية للتصنيف واحد مقابل واحد، باستخدام طبقة softmax. تمثل كل قيمة ناتج احتمالية الصورة المدخلة هي الفاكهة المحددة وليست أيًا من الفواكه الثلاث الأخرى (مجموع جميع الاحتمالات إلى 1.0). يتنبأ هذا النموذج بأن هناك 63% احتمال أن تكون الصورة كمثرى.
خيارات Softmax
ضع في الاعتبار خيارات softmax التالية:
تمثّل سمة Full softmax تجربة softmax التي نناقشها. أي، تحسب softmax الاحتمالية لكل فئة محتملة.
تعني أخذ العينات المرشّح أنّ حملة softmax تحسب الاحتمالية. لجميع التصنيفات الموجبة ولكن فقط لعينة عشوائية من أو تصنيفات سلبية. على سبيل المثال، إذا كنا مهتمين بتحديد سواء كانت صورة الإدخال عبارة عن بيغل أو كلب دموي، فليس علينا تقدم الاحتمالات لكل مثال لغير الكلاب.
تكون softmax الكاملة رخيصة نوعًا ما عندما يكون عدد الفئات صغيرًا ولكنها تصبح باهظة الثمن عند زيادة عدد الفصول. يمكن أن يؤدي أخذ عينات المرشح إلى تحسين الكفاءة في المشكلات التي لها وعدد الصفوف الدراسية.
تصنيف واحد مقابل تصنيفات متعددة
تفترض Softmax أن كل مثال هو عضو في فئة واحدة بالضبط. ومع ذلك، يمكن أن تكون بعض الأمثلة عضوًا في صفوف متعددة في الوقت نفسه. في ما يلي أمثلة على ذلك:
لا يجوز لك استخدام softmax.
فينبغي عليك الاعتماد على الانحدار اللوجستي المتعدد.
على سبيل المثال، يفترض نموذج واحد مقابل واحد في الشكل 9 أعلاه أن كل إدخال ستصوِّر نوعًا واحدًا بالضبط من الفاكهة: تفاحة أو برتقال أو كمثرى أو عنب ومع ذلك، إذا كانت صورة تم إدخالها قد تحتوي على أنواع متعددة من الفاكهة، من التفاح والبرتقال - سيتعين عليك استخدام خدمات لوجستية متعددة عمليات التحويل بدلاً من ذلك.
تاريخ التعديل الأخير: 2024-08-16 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-08-16 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis document explores multi-class classification models, which predict from multiple possibilities instead of just two, like binary classification models.\u003c/p\u003e\n"],["\u003cp\u003eMulti-class classification can be achieved through two main approaches: one-vs.-all and one-vs.-one (softmax).\u003c/p\u003e\n"],["\u003cp\u003eOne-vs.-all uses multiple binary classifiers, one for each possible outcome, to determine the probability of each class independently.\u003c/p\u003e\n"],["\u003cp\u003eOne-vs.-one (softmax) predicts probabilities of each class relative to all other classes, ensuring all probabilities sum to 1 using the softmax function.\u003c/p\u003e\n"],["\u003cp\u003eSoftmax is efficient for fewer classes but can become computationally expensive with many classes; candidate sampling offers an alternative for increased efficiency.\u003c/p\u003e\n"]]],[],null,["Earlier, you encountered\n[**binary classification**](/machine-learning/glossary#binary-classification)\nmodels that could pick between one of *two* possible choices, such as whether:\n\n- A given email is spam or not spam.\n- A given tumor is malignant or benign.\n\nIn this section, we'll investigate\n[**multi-class classification**](/machine-learning/glossary#multi-class)\nmodels, which can pick from *multiple* possibilities. For example:\n\n- Is this dog a beagle, a basset hound, or a bloodhound?\n- Is this flower a Siberian Iris, Dutch Iris, Blue Flag Iris, or Dwarf Bearded Iris?\n- Is that plane a Boeing 747, Airbus 320, Boeing 777, or Embraer 190?\n- Is this an image of an apple, bear, candy, dog, or egg?\n\nSome real-world multi-class problems entail choosing from *millions*\nof separate classes. For example, consider a multi-class classification\nmodel that can identify the image of just about anything.\n\nThis section details the two main variants of multi-class classification:\n\n- [**one-vs.-all**](/machine-learning/glossary#one-vs.-all)\n- **one-vs.-one** , which is usually known as [**softmax**](/machine-learning/glossary#softmax)\n\nOne versus all\n\n*One-vs.-all* provides a way to use binary classification\nfor a series of yes or no predictions across multiple possible labels.\n\nGiven a classification problem with N possible solutions, a one-vs.-all\nsolution consists of N separate binary classifiers---one binary\nclassifier for each possible outcome. During training, the model runs\nthrough a sequence of binary classifiers, training each to answer a separate\nclassification question.\n\nFor example, given a picture of a piece of fruit, four\ndifferent recognizers might be trained, each answering a different yes/no\nquestion:\n\n1. Is this image an apple?\n2. Is this image an orange?\n3. Is this image a banana?\n4. Is this image a grape?\n\nThe following image illustrates how this works in practice.\n**Figure 7. An image of a pear being passed as input to four different\nbinary classifiers. The first, second, and fourth models (predicting\nwhether or not the image is an apple, orange, or grape, respectively)\npredict the negative class. The third model (predicting whether or not\nthe image is a pear) predicts the positive class.** For more on how binary classifiers make predictions (setting a classification threshold to convert numerical model output into a positive or negative label), see the [Classification](/machine-learning/crash-course/classification) module.\n\nThis approach is fairly reasonable when the total number of classes\nis small, but becomes increasingly inefficient as the number of classes\nrises.\n\nWe can create a significantly more efficient one-vs.-all model\nwith a deep neural network in which each output node represents a different\nclass. The following image illustrates this approach.\n**Figure 8. The same one-vs.-all classification tasks accomplished using a\nneural net model. A sigmoid activation function is applied to the output\nlayer, and each output value represents the probability that the input\nimage is a specified fruit. This model predicts that there is a 84%\nchance that the image is a pear, and a 7% chance that the image is a\ngrape.**\n\nOne versus one (softmax)\n\nYou may have noticed that the probability values in the output layer of Figure 8\ndon't sum to 1.0 (or 100%). (In fact, they sum to 1.43.) In a one-vs.-all\napproach, the probability of each binary set of outcomes is determined\nindependently of all the other sets. That is, we're determining the probability\nof \"apple\" versus \"not apple\" without considering the likelihood of our other\nfruit options: \"orange\", \"pear\", or \"grape.\"\n\nBut what if we want to predict the probabilities of each fruit\nrelative to each other? In this case, instead of predicting \"apple\" versus \"not\napple\", we want to predict \"apple\" versus \"orange\" versus \"pear\" versus \"grape\".\nThis type of multi-class classification is called *one-vs.-one classification*.\n\nWe can implement a one-vs.-one classification using the same type of neural\nnetwork architecture used for one-vs.-all classification, with one key change.\nWe need to apply a different transform to the output layer.\n\nFor one-vs.-all, we applied the sigmoid activation function to each output\nnode independently, which resulted in an output value between 0 and 1 for each\nnode, but did not guarantee that these values summed to exactly 1.\n\nFor one-vs.-one, we can instead apply a function called *softmax*, which\nassigns decimal probabilities to each class in a multi-class problem such that\nall probabilities add up to 1.0. This additional constraint\nhelps training converge more quickly than it otherwise would.\n\nClick the plus icon to see the softmax equation. \nThe softmax equation is as follows: \n$$p(y = j\\|\\\\textbf{x}) = \\\\frac{e\\^{(\\\\textbf{w}_j\\^{T}\\\\textbf{x} + b_j)}}{\\\\sum_{k\\\\in K} {e\\^{(\\\\textbf{w}_k\\^{T}\\\\textbf{x} + b_k)}} }$$\n\nNote that this formula basically extends the formula for logistic\nregression into multiple classes.\n\nThe following image re-implements our one-vs.-all multi-class classification\ntask as a one-vs.-one task. Note that in order to perform softmax, the hidden\nlayer directly preceding the output layer (called the softmax layer) must have\nthe same number of nodes as the output layer.\n**Figure 9. Neural net implementation of one-vs.-one classification, using\na softmax layer. Each output value represents the probability that the\ninput image is the specified fruit and not any of the other three fruits\n(all probabilities sum to 1.0). This model predicts that there is a 63%\nchance that the image is a pear.**\n\nSoftmax options\n\nConsider the following variants of softmax:\n\n- **Full softmax** is the softmax we've been discussing; that is,\n softmax calculates a probability for every possible class.\n\n- **Candidate sampling** means that softmax calculates a probability\n for all the positive labels but only for a random sample of\n negative labels. For example, if we are interested in determining\n whether an input image is a beagle or a bloodhound, we don't have to\n provide probabilities for every non-doggy example.\n\nFull softmax is fairly cheap when the number of classes is small\nbut becomes prohibitively expensive when the number of classes climbs.\nCandidate sampling can improve efficiency in problems having a large\nnumber of classes.\n\nOne label versus many labels\n\nSoftmax assumes that each example is a member of exactly one class.\nSome examples, however, can simultaneously be a member of multiple classes.\nFor such examples:\n\n- You may not use softmax.\n- You must rely on multiple logistic regressions.\n\nFor example, the one-vs.-one model in Figure 9 above assumes that each input\nimage will depict exactly one type of fruit: an apple, an orange, a pear, or\na grape. However, if an input image might contain multiple types of fruit---a\nbowl of both apples and oranges---you'll have to use multiple logistic\nregressions instead.\n| **Key terms:**\n|\n| - [Binary classification](/machine-learning/glossary#binary-classification)\n| - [Multi class classification](/machine-learning/glossary#multi-class-classification)\n| - [One-vs.-all classification](/machine-learning/glossary#one-vs.-all)\n- [softmax (one-vs.-one classification)](/machine-learning/glossary#softmax) \n[Help Center](https://support.google.com/machinelearningeducation)"]]