مرحله 5: Hyperparameters را تنظیم کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
برای تعریف و آموزش مدل مجبور شدیم تعدادی فراپارامتر انتخاب کنیم. ما بر شهود، مثالها و توصیههای بهترین عمل تکیه کردیم. با این حال، اولین انتخاب ما از مقادیر فراپارامتر ممکن است بهترین نتایج را به همراه نداشته باشد. این فقط یک نقطه شروع خوب برای آموزش به ما می دهد. هر مشکلی متفاوت است و تنظیم این فراپارامترها به اصلاح مدل ما برای نمایش بهتر ویژگیهای مشکل در دست کمک میکند. بیایید نگاهی به برخی از هایپرپارامترهایی که استفاده کردیم و معنای تنظیم آنها را بیاندازیم:
تعداد لایه ها در مدل : تعداد لایه های یک شبکه عصبی نشانگر پیچیدگی آن است. در انتخاب این مقدار باید دقت کنیم. لایه های بیش از حد به مدل اجازه می دهد تا اطلاعات زیادی در مورد داده های آموزشی بیاموزد که باعث برازش بیش از حد می شود. لایه های بسیار کم می تواند توانایی یادگیری مدل را محدود کند و باعث عدم تناسب شود. برای مجموعه داده های طبقه بندی متن، ما با MLP های یک، دو و سه لایه آزمایش کردیم. مدل های دو لایه عملکرد خوبی داشتند و در برخی موارد بهتر از مدل های سه لایه بودند. به طور مشابه، ما sepCNN را با چهار و شش لایه امتحان کردیم و مدلهای چهار لایه عملکرد خوبی داشتند.
تعداد واحدها در هر لایه : واحدهای یک لایه باید اطلاعات مربوط به تبدیلی که یک لایه انجام میدهد را نگه دارند. برای لایه اول، این توسط تعدادی از ویژگی ها هدایت می شود. در لایههای بعدی، تعداد واحدها به انتخاب گسترش یا انقباض نمایش از لایه قبلی بستگی دارد. سعی کنید از دست رفتن اطلاعات بین لایه ها را به حداقل برسانید. ما مقادیر واحد را در محدوده [8, 16, 32, 64]
و 32/64 واحدها به خوبی کار کردند.
نرخ انحراف : از لایههای حذف در مدل برای منظمسازی استفاده میشود. آنها کسری از ورودی را به عنوان یک اقدام احتیاطی برای بیش از حد برازش تعریف می کنند. محدوده توصیه شده: 0.2-0.5.
نرخ یادگیری : این نرخی است که در آن وزن شبکه عصبی بین تکرارها تغییر می کند. سرعت یادگیری زیاد ممکن است باعث نوسانات بزرگ در وزنه ها شود و ما هرگز مقادیر بهینه آنها را پیدا نکنیم. نرخ یادگیری پایین خوب است، اما این مدل به تکرارهای بیشتری نیاز دارد تا همگرا شود. ایده خوبی است که مثلاً از 1e-4 شروع کنید. اگر تمرین بسیار کند است، این مقدار را افزایش دهید. اگر مدل شما در حال یادگیری نیست، سعی کنید میزان یادگیری را کاهش دهید.
چند فراپارامتر اضافی وجود دارد که ما تنظیم کردیم که مختص مدل sepCNN ما هستند:
اندازه هسته : اندازه پنجره کانولوشن. مقادیر توصیه شده: 3 یا 5.
ابعاد جاسازی : تعداد ابعادی که میخواهیم برای نشان دادن جاسازیهای کلمه استفاده کنیم—یعنی اندازه هر بردار کلمه. مقادیر توصیه شده: 50–300. در آزمایشهای خود، از جاسازیهای GloVe با 200 بعد با یک لایه تعبیهشده از پیش آموزشدیده استفاده کردیم.
با این هایپرپارامترها بازی کنید و ببینید چه چیزی بهتر عمل می کند. هنگامی که ابرپارامترهای با بهترین عملکرد را برای مورد استفاده خود انتخاب کردید، مدل شما آماده استقرار است.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eInitial hyperparameter choices provide a starting point for model training, but further tuning is crucial to optimize performance for specific text classification problems.\u003c/p\u003e\n"],["\u003cp\u003eThe number of layers in a neural network impacts its complexity, with two-layer MLPs and four-layer sepCNNs showing promising results in text classification.\u003c/p\u003e\n"],["\u003cp\u003eKey hyperparameters to adjust include the number of units per layer (32 or 64 performed well), dropout rate (0.2-0.5 recommended), and learning rate (start low and adjust based on training progress).\u003c/p\u003e\n"],["\u003cp\u003eFor sepCNN models, optimizing kernel size (3 or 5) and embedding dimensions (50-300) further enhances performance.\u003c/p\u003e\n"],["\u003cp\u003eExperimenting with different hyperparameter combinations is essential to achieve the best model performance for your specific use case before deployment.\u003c/p\u003e\n"]]],[],null,["# Step 5: Tune Hyperparameters\n\nWe had to choose a number of hyperparameters for defining and training the\nmodel. We relied on intuition, examples and best practice recommendations. Our\nfirst choice of hyperparameter values, however, may not yield the best results.\nIt only gives us a good starting point for training. Every problem is different\nand tuning these hyperparameters will help refine our model to better represent\nthe particularities of the problem at hand. Let's take a look at some of the\nhyperparameters we used and what it means to tune them:\n\n- **Number of layers in the model** : The number of layers in a neural network is\n an indicator of its complexity. We must be careful in choosing this value. Too\n many layers will allow the model to learn too much information about the\n training data, causing overfitting. Too few layers can limit the model's\n learning ability, causing underfitting. For text classification datasets, we\n experimented with one, two, and three-layer MLPs. Models with two layers\n performed well, and in some cases better than three-layer models. Similarly, we\n tried [sepCNN](https://developers.google.com/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)s\n with four and six layers, and the four-layer models performed well.\n\n- **Number of units per layer** : The units in a layer must hold the information\n for the transformation that a layer performs. For the first layer, this is\n driven by the number of features. In subsequent layers, the number of units\n depends on the choice of expanding or contracting the representation from the\n previous layer. Try to minimize the information loss between layers. We tried\n unit values in the range `[8, 16, 32, 64]`, and 32/64 units worked well.\n\n- **Dropout rate** : Dropout layers are used in the model for\n [regularization](https://developers.google.com/machine-learning/glossary/?utm_source=DevSite&utm_campaign=Text-Class-Guide&utm_medium=referral&utm_content=glossary&utm_term=dropout-regularization#dropout_regularization).\n They define the fraction of input to drop as a precaution for overfitting.\n Recommended range: 0.2--0.5.\n\n- **Learning rate**: This is the rate at which the neural network weights change\n between iterations. A large learning rate may cause large swings in the weights,\n and we may never find their optimal values. A low learning rate is good, but the\n model will take more iterations to converge. It is a good idea to start low, say\n at 1e-4. If the training is very slow, increase this value. If your model is not\n learning, try decreasing learning rate.\n\nThere are couple of additional hyperparameters we tuned that are specific to our\nsepCNN model:\n\n1. **Kernel size**: The size of the convolution window. Recommended values: 3 or\n 5.\n\n2. **Embedding dimensions**: The number of dimensions we want to use to represent\n word embeddings---i.e., the size of each word vector. Recommended values: 50--300.\n In our experiments, we used GloVe embeddings with 200 dimensions with a pre-\n trained embedding layer.\n\nPlay around with these hyperparameters and see what works best. Once you have\nchosen the best-performing hyperparameters for your use case, your model is\nready to be deployed."]]