با مجموعهها، منظم بمانید ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
در این مرحله، ما مجموعه دادههای خود را جمعآوری کردهایم و بینشهایی در مورد ویژگیهای کلیدی دادههای خود به دست آوردهایم. در مرحله بعد، بر اساس معیارهایی که در مرحله 2 جمع آوری کردیم، باید به این فکر کنیم که از کدام مدل طبقه بندی استفاده کنیم. یعنی پرسیدن سوالاتی از قبیل:
چگونه داده های متنی را به الگوریتمی ارائه می کنید که انتظار ورودی عددی را دارد؟ (به این کار پیش پردازش داده و بردارسازی می گویند.)
از چه مدلی باید استفاده کنید؟
از چه پارامترهای پیکربندی باید برای مدل خود استفاده کنید؟
به لطف چندین دهه تحقیق، ما به مجموعه وسیعی از پیش پردازش داده ها و گزینه های پیکربندی مدل دسترسی داریم. با این حال، در دسترس بودن یک آرایه بسیار بزرگ از گزینه های قابل دوام برای انتخاب می تواند پیچیدگی و دامنه یک مشکل خاص را تا حد زیادی افزایش دهد. با توجه به اینکه بهترین گزینه ها ممکن است واضح نباشند، یک راه حل ساده لوحانه این است که همه گزینه های ممکن را به طور کامل امتحان کنید و برخی از انتخاب ها را از طریق شهود هرس کنید. با این حال، این بسیار گران خواهد بود.
در این راهنما، ما تلاش می کنیم تا فرآیند انتخاب یک مدل طبقه بندی متن را به طور قابل توجهی ساده کنیم. برای یک مجموعه داده معین، هدف ما یافتن الگوریتمی است که به حداکثر دقت نزدیک میشود و زمان محاسبات مورد نیاز برای آموزش را به حداقل میرساند. ما تعداد زیادی (~450 هزار) آزمایش را در مورد مشکلات انواع مختلف (به ویژه تجزیه و تحلیل احساسات و مشکلات طبقهبندی موضوع)، با استفاده از 12 مجموعه داده، به طور متناوب برای هر مجموعه داده بین تکنیکهای پیش پردازش دادههای مختلف و معماریهای مدل متفاوت انجام دادیم. این به ما کمک کرد تا پارامترهای مجموعه داده ای را شناسایی کنیم که بر انتخاب های بهینه تأثیر می گذارد.
الگوریتم انتخاب مدل و نمودار جریان زیر خلاصه ای از آزمایش ما است. اگر هنوز تمام اصطلاحات استفاده شده در آنها را متوجه نشده اید، نگران نباشید. بخش های بعدی این راهنما آنها را به طور عمیق توضیح می دهد.
الگوریتم آماده سازی داده و ساخت مدل
تعداد نمونه ها / تعداد کلمات در نسبت نمونه را محاسبه کنید.
اگر این نسبت کمتر از 1500 باشد، متن را به صورت n-گرم نشانه گذاری کنید و از یک مدل پرسپترون چند لایه ساده (MLP) برای طبقه بندی آنها استفاده کنید (شاخه سمت چپ در فلوچارت زیر):
نمونه ها را به کلمه n-gram تقسیم کنید. n-گرم ها را به بردار تبدیل کنید.
به اهمیت بردارها امتیاز دهید و سپس با استفاده از امتیازها، 20K برتر را انتخاب کنید.
یک مدل MLP بسازید.
اگر نسبت بزرگتر از 1500 باشد، متن را به صورت دنباله ای توکن کنید و از یک مدل sepCNN برای طبقه بندی آنها استفاده کنید (شاخه سمت راست در فلوچارت زیر):
نمونه ها را به کلمات تقسیم کنید. 20 هزار کلمه برتر را بر اساس فراوانی آنها انتخاب کنید.
نمونه ها را به بردارهای توالی کلمه تبدیل کنید.
اگر تعداد نمونهها/تعداد واژهها در نسبت نمونه کمتر از 15K باشد، استفاده از یک جاسازی از پیش آموزشدیده دقیق با مدل sepCNN احتمالاً بهترین نتایج را ارائه میدهد.
برای یافتن بهترین پیکربندی مدل برای مجموعه داده، عملکرد مدل را با مقادیر فراپارامترهای مختلف اندازه گیری کنید.
در فلوچارت زیر، کادرهای زرد رنگ فرآیندهای آماده سازی داده و مدل را نشان می دهند. جعبه های خاکستری و جعبه های سبز انتخاب هایی را که برای هر فرآیند در نظر گرفته ایم نشان می دهد. جعبه های سبز انتخاب پیشنهادی ما برای هر فرآیند را نشان می دهد.
شما می توانید از این نمودار جریان به عنوان نقطه شروع برای ساخت اولین آزمایش خود استفاده کنید، زیرا دقت خوبی در هزینه های محاسباتی کم به شما می دهد. سپس می توانید به بهبود مدل اولیه خود در تکرارهای بعدی ادامه دهید.
شکل 5: فلوچارت طبقه بندی متن
این فلوچارت به دو سوال کلیدی پاسخ می دهد:
از کدام الگوریتم یا مدل یادگیری استفاده کنید؟
چگونه باید داده ها را برای یادگیری موثر رابطه بین متن و برچسب آماده کنید؟
پاسخ به سؤال دوم بستگی به پاسخ سؤال اول دارد; روشی که ما دادهها را برای وارد کردن به یک مدل پیش پردازش میکنیم به مدلی که انتخاب میکنیم بستگی دارد. مدلها را میتوان به طور کلی به دو دسته طبقهبندی کرد: مدلهایی که از اطلاعات ترتیب کلمات استفاده میکنند (مدلهای توالی)، و مدلهایی که فقط متن را بهعنوان «کیسه» (مجموعهای) از کلمات میبینند (مدلهای n-gram). انواع مدلهای توالی شامل شبکههای عصبی کانولوشن (CNN)، شبکههای عصبی بازگشتی (RNN) و تغییرات آنهاست. انواع مدل های n-gram عبارتند از:
از آزمایشهایمان، مشاهده کردهایم که نسبت «تعداد نمونه» (S) به «تعداد کلمات در هر نمونه» (W) با اینکه کدام مدل خوب عمل میکند همبستگی دارد.
وقتی مقدار این نسبت کوچک است (<1500)، پرسپترون های چند لایه کوچکی که n-گرم را به عنوان ورودی می گیرند (که ما آن را گزینه A می نامیم) بهتر یا حداقل به خوبی مدل های توالی عمل می کنند. تعریف و درک MLPها ساده است و زمان محاسبه آنها بسیار کمتر از مدلهای توالی است. وقتی مقدار این نسبت بزرگ است (>= 1500)، از یک مدل توالی ( گزینه B ) استفاده کنید. در مراحل بعدی، میتوانید برای نوع مدلی که بر اساس نسبت نمونه/کلمات به نمونه انتخاب کردهاید، به زیربخشهای مربوطه (با برچسب A یا B ) بروید.
در مورد مجموعه داده بررسی IMDb ما، نسبت نمونه/کلمات به ازای نمونه ~144 است. این بدان معناست که ما یک مدل MLP ایجاد خواهیم کرد.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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"]],["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis guide simplifies selecting a text classification model by identifying the best-performing algorithm for a given dataset based on accuracy and training time.\u003c/p\u003e\n"],["\u003cp\u003eA flowchart and algorithm are provided to guide model selection, primarily focusing on two options: using a multi-layer perceptron (MLP) with n-grams for datasets with a low sample-to-words-per-sample ratio or a sequence model (sepCNN) for datasets with a high ratio.\u003c/p\u003e\n"],["\u003cp\u003eExtensive experimentation across various text classification problems and datasets informed the recommendations, emphasizing the sample-to-words-per-sample ratio as a key factor in model selection.\u003c/p\u003e\n"],["\u003cp\u003eWhile the guide aims for optimal accuracy with minimal computation, it may not always yield the absolute best results due to potential variations in dataset characteristics, goals, or the emergence of newer algorithms.\u003c/p\u003e\n"],["\u003cp\u003eUsers can utilize the flowchart as a starting point for model construction, iteratively refining the model based on their specific needs and dataset properties.\u003c/p\u003e\n"]]],[],null,["At this point, we have assembled our dataset and gained insights into the key\ncharacteristics of our data. Next, based on the metrics we gathered in\n[Step 2](/machine-learning/guides/text-classification/step-2), we should think\nabout which classification model we should use. This means asking questions\nsuch as:\n\n- How do you present the text data to an algorithm that expects numeric input? (This is called data preprocessing and vectorization.)\n- What type of model should you use?\n- What configuration parameters should you use for your model?\n\nThanks to decades of research, we have access to a large array of data\npreprocessing and model configuration options. However, the availability of a\nvery large array of viable options to choose from can greatly increase the\ncomplexity and scope of a particular problem. Given that the best\noptions might not be obvious, a naive solution would be to try every possible\noption exhaustively, pruning some choices through intuition. However, that would\nbe tremendously expensive.\n\nIn this guide, we attempt to significantly simplify the process of selecting a\ntext classification model. For a given dataset, our goal is to find the\nalgorithm that achieves close to maximum accuracy while minimizing computation\ntime required for training. We ran a large number (\\~450K) of experiments across\nproblems of different types (especially sentiment analysis and topic\nclassification problems), using 12 datasets, alternating for each dataset\nbetween different data preprocessing techniques and different model\narchitectures. This helped us identify dataset parameters that influence optimal\nchoices.\n\nThe model selection algorithm and flowchart below are a summary of our\nexperimentation. Don't worry if you don't understand all the terms used in them\nyet; the following sections of this guide will explain them in depth.\n\nAlgorithm for Data Preparation and Model Building\n\n1. Calculate the number of samples/number of words per sample ratio.\n2. If this ratio is less than 1500, tokenize the text as [n-grams](/machine-learning/glossary#n-gram) and use a simple multi-layer perceptron (MLP) model to classify them (left branch in the flowchart below):\n 1. Split the samples into word n-grams; convert the n-grams into vectors.\n 2. Score the importance of the vectors and then select the top 20K using the scores.\n 3. Build an MLP model.\n3. If the ratio is greater than 1500, tokenize the text as sequences and use a [sepCNN](/machine-learning/glossary?utm_source=DevSite&utm_campaign=Text-Class-Guide&utm_medium=referral&utm_content=glossary&utm_term=sepCNN#depthwise-separable-convolutional-neural-network-sepcnn) model to classify them (right branch in the flowchart below):\n 1. Split the samples into words; select the top 20K words based on their frequency.\n 2. Convert the samples into word sequence vectors.\n 3. If the original number of samples/number of words per sample ratio is less than 15K, using a fine-tuned pre-trained embedding with the sepCNN model will likely provide the best results.\n4. Measure the model performance with different hyperparameter values to find the best model configuration for the dataset.\n\nIn the flowchart below, the yellow boxes indicate data and model preparation\nprocesses. Grey boxes and green boxes indicate choices we considered for each\nprocess. Green boxes indicate our recommended choice for each process.\n\nYou can use this flowchart as a starting point to construct your first\nexperiment, as it will give you good accuracy at low computation costs. You can\nthen continue to improve on your initial model over the subsequent iterations.\n\n\n**Figure 5: Text classification flowchart**\n\nThis flowchart answers two key questions:\n\n1. Which learning algorithm or model should you use?\n2. How should you prepare the data to efficiently learn the relationship between text and label?\n\nThe answer to the second question depends on the answer to the first question;\nthe way we preprocess data to be fed into a model will depend on what model we\nchoose. Models can be broadly classified into two categories: those that use\nword ordering information (sequence models), and ones that just see text as\n\"bags\" (sets) of words (n-gram models). Types of sequence models include\nconvolutional neural networks (CNNs), recurrent neural networks (RNNs), and\ntheir variations. Types of n-gram models include:\n\n- [logistic regression](/machine-learning/glossary#logistic-regression)\n- [simple multi-layer perceptrons](https://wikipedia.org/wiki/Multilayer_perceptron) (MLPs, or fully-connected neural networks)\n- [gradient boosted trees](/machine-learning/glossary#gradient-boosted-decision-trees-gbt)\n- [support vector machines](/machine-learning/glossary#kernel-support-vector-machines-ksvms)\n\n**From our experiments, we have observed that the ratio of \"number of samples\"\n(S) to \"number of words per sample\" (W) correlates with which model performs\nwell.**\n\nWhen the value for this ratio is small (\\\u003c1500), small multi-layer perceptrons\nthat take n-grams as input (which we'll call **Option A** ) perform better or at\nleast as well as sequence models. MLPs are simple to define and understand, and\nthey take much less compute time than sequence models. When the value for this\nratio is large (\\\u003e= 1500), use a sequence model (**Option B** ). In the steps\nthat follow, you can skip to the relevant subsections (labeled **A** or **B**)\nfor the model type you chose based on the samples/words-per-sample ratio.\n\nIn the case of our IMDb review dataset, the samples/words-per-sample ratio is\n\\~144. This means that we will create a MLP model.\n| **Note** : When using the above flowchart, keep in mind that it may not necessarily lead you to the most optimal results for your problem, for several reasons: \n| - Your goal may be different. We optimized for the best accuracy that could be achieved in the shortest possible compute time. An alternate flow may produce a better result, say, when optimizing for [area under the curve (AUC)](https://developers.google.com/machine-learning/glossary#AUC). \n| - We picked typical and common algorithm choices. As the field continues to evolve, new cutting-edge algorithms and enhancements may be relevant to your data and may perform better. \n| - While we used several datasets to derive and validate the flowchart, there may be specific characteristics to your dataset that favor using an alternate flow."]]