ขั้นตอนที่ 5: ปรับแต่งไฮเปอร์พารามิเตอร์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เราจะต้องเลือกไฮเปอร์พารามิเตอร์จํานวนหนึ่งสําหรับกําหนดและฝึกโมเดล เราอาศัยสัญชาตญาณ ตัวอย่าง และการแนะนําแนวทางปฏิบัติที่ดีที่สุด อย่างไรก็ตาม การเลือกค่าไฮเปอร์พารามิเตอร์ครั้งแรกของเรา อาจไม่ให้ผลลัพธ์ที่ดีที่สุด
การดําเนินการนี้เป็นเพียงจุดเริ่มต้นที่ดีสําหรับการฝึกอบรมของเรา แต่ละปัญหามีความแตกต่างกัน
การปรับแต่งไฮเปอร์พารามิเตอร์เหล่านี้จะช่วยปรับแต่งโมเดลของเราให้แสดงถึงความเจาะจงของปัญหาได้ดีขึ้น มาดูพารามิเตอร์บางส่วน
ที่เราใช้และการปรับแต่งกัน
จํานวนเลเยอร์ในโมเดล: จํานวนเลเยอร์ในโครงข่ายระบบประสาทเทียมเป็นตัวบ่งชี้ความซับซ้อน เราต้องเลือกค่านี้อย่างระมัดระวัง เลเยอร์มากเกินไปอาจทําให้โมเดลเรียนรู้ข้อมูลมากเกินไปเกี่ยวกับข้อมูลการฝึก ทําให้สร้างมากเกินไป เลเยอร์น้อยเกินไปอาจจํากัดความสามารถในการเรียนรู้ของโมเดล ทําให้ไม่พอดี สําหรับชุดข้อมูลการจัดประเภทข้อความ
เราได้ทดลองใช้ MLP 1, 2 และ 3 เลเยอร์ โมเดลที่มี 2 เลเยอร์จะทํางานได้ดี และในบางกรณีก็ดีกว่าโมเดล 3 เลเยอร์ ในทํานองเดียวกัน เราใช้ sepCNN กับ 4 และ 6 เลเยอร์ และโมเดล 4 ชั้นทํางานได้ดี
จํานวนหน่วยต่อเลเยอร์: หน่วยในเลเยอร์ต้องเก็บข้อมูลการเปลี่ยนรูปแบบที่เลเยอร์หนึ่งทําไว้ สําหรับเลเยอร์แรก จะเป็นไปตาม
จํานวนจุดสนใจ ในเลเยอร์ต่อมา จํานวนหน่วยจะขึ้นอยู่กับตัวเลือกในการขยายหรือย่องานนําเสนอจากเลเยอร์ก่อนหน้า พยายามลดการสูญเสียข้อมูลระหว่างเลเยอร์ให้เหลือน้อยที่สุด เราลองใช้ค่าหน่วยในช่วง [8, 16, 32, 64]
และหน่วย 32/64 ทํางานได้ดี
อัตราการออกจากไซต์: มีการใช้เลเยอร์เมนูแบบเลื่อนลงในโมเดลสําหรับการปรับให้สอดคล้องตามมาตรฐาน
ตัวแปรเหล่านี้ระบุเศษของข้อมูลที่ป้อนให้ลดลงเพื่อเป็นการป้องกันสถานการณ์มากเกินไป
ช่วงที่แนะนํา: 0.2–0.5
อัตราการเรียนรู้: คืออัตราที่น้ําหนักของโครงข่ายประสาทเปลี่ยนแปลงไประหว่างการปรับปรุง อัตราการเรียนรู้จํานวนมากอาจทําให้ค่าน้ําหนักเปลี่ยนแปลงไปมากและเราอาจไม่พบค่าที่เหมาะสมที่สุด อัตราการเรียนรู้ต่ําเป็นสิ่งที่ดี แต่โมเดลจะใช้การทําซ้ําซ้ําๆ เป็นความคิดที่ดีที่จะเริ่มต้นอย่างต่ํา เช่น 1-4 โมง หากการฝึกช้ามาก ให้เพิ่มค่านี้ หากโมเดลของคุณไม่ได้เรียนรู้
ให้ลองลดอัตราการเรียนรู้
มีพารามิเตอร์ไฮเปอร์พารามิเตอร์อีก 2 ตัวที่เราปรับแต่งมาเพื่อรูปแบบ sepCNN ของเราโดยเฉพาะ
ขนาดเคอร์เนล: ขนาดของหน้าต่างการปฏิวัติ ค่าที่แนะนําคือ 3 หรือ
5
มิติข้อมูลที่ฝัง: จํานวนมิติข้อมูลที่ต้องการใช้เพื่อแสดงถึงการฝังคํา กล่าวคือ ขนาดของเวกเตอร์คําแต่ละคํา ค่าที่แนะนําคือ 50–300
ในการทดสอบ เราใช้การฝัง GloVe ที่มีมิติข้อมูล 200 ชั้น พร้อมด้วยชั้นที่มีการฝังไว้ล่วงหน้า
ลองใช้พารามิเตอร์เหล่านี้เพื่อดูว่ารูปแบบใดได้ผลดีที่สุด เมื่อคุณเลือกไฮเปอร์พารามิเตอร์ที่ทํางานได้ดีที่สุดสําหรับกรณีการใช้งานของคุณแล้ว โมเดลก็จะพร้อมใช้งาน
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[null,null,["อัปเดตล่าสุด 2025-07-27 UTC"],[[["\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."]]