Bước 5: Điều chỉnh siêu tham số
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Chúng tôi phải chọn một số siêu tham số để xác định và đào tạo
mô hình. Chúng tôi đã tin tưởng vào trực giác, ví dụ và các đề xuất phương pháp hay nhất. Tuy nhiên,
lựa chọn đầu tiên của chúng tôi về các giá trị siêu thông số có thể không mang lại kết quả tốt nhất.
Đó chỉ là cơ hội tuyệt vời để chúng tôi bắt đầu học. Mỗi vấn đề đều khác nhau và việc điều chỉnh các siêu tham số này sẽ giúp điều chỉnh mô hình của chúng tôi để thể hiện rõ hơn các đặc điểm cụ thể của vấn đề này. Hãy cùng xem một số siêu thông số mà chúng tôi sử dụng và ý nghĩa của việc điều chỉnh các thông số đó:
Số lớp trong mô hình: Số lớp trong mạng nơron là chỉ báo về độ phức tạp của mô hình đó. Chúng ta phải cẩn thận trong việc chọn giá trị này. Quá nhiều lớp sẽ cho phép mô hình tìm hiểu quá nhiều thông tin về dữ liệu huấn luyện, gây ra tình trạng quá mức. Quá ít lớp có thể hạn chế khả năng học tập của mô hình, dẫn đến tình trạng không phù hợp. Đối với các tập dữ liệu phân loại văn bản, chúng tôi
đã thử nghiệm với MLP một, hai và ba lớp. Mô hình có hai lớp hoạt động tốt và trong một số trường hợp tốt hơn mô hình ba lớp. Tương tự, chúng tôi
đã thử sepCNN
với 4 và 6 lớp và các mô hình 4 lớp hoạt động rất tốt.
Số lượng đơn vị mỗi lớp: Các đơn vị trong một lớp phải lưu giữ thông tin
để chuyển đổi mà một lớp thực hiện. Đối với lớp đầu tiên, điều này được thúc đẩy bởi số lượng tính năng. Trong các lớp tiếp theo, số lượng đơn vị
phụ thuộc vào việc chọn mở rộng hoặc thu gọn bản trình bày từ
lớp trước đó. Hãy cố gắng giảm thiểu việc mất thông tin giữa các lớp. Chúng tôi đã thử
các giá trị đơn vị trong phạm vi [8, 16, 32, 64]
và đơn vị 32/64 hoạt động tốt.
Tỷ lệ bỏ qua: Lớp bỏ qua được sử dụng trong mô hình để chuẩn hoá.
Mã này xác định tỷ lệ phần trăm dữ liệu đầu vào cần thả xuống để phòng ngừa tình trạng quá tải.
Phạm vi đề xuất: 0,2 – 0,5.
Tốc độ học tập: Đây là tỷ lệ mà trọng số mạng nơron thay đổi giữa các lần lặp. Mức độ học tập cao có thể tạo ra những biến động lớn về trọng số, và chúng ta có thể không bao giờ thấy những giá trị tối ưu của các biến thể này. Tỷ lệ học tập thấp là tốt, nhưng mô hình
sẽ cần nhiều lần lặp lại hơn để hội tụ. Bạn nên bắt đầu từ 1e-4, chẳng hạn như. Nếu quá trình đào tạo rất chậm, hãy tăng giá trị này. Nếu mô hình của bạn không học tập, hãy thử giảm tỷ lệ học tập.
Có một số siêu tham số bổ sung mà chúng tôi đã điều chỉnh dành riêng cho mô hình sepCNN của chúng tôi:
Kích thước hạt nhân: Kích thước của cửa sổ tích chập. Giá trị được đề xuất: 3 hoặc 5.
Thứ nguyên nhúng: Số thứ nguyên mà chúng ta muốn sử dụng để đại diện cho việc nhúng từ khóa, tức là kích thước của mỗi vectơ từ. Giá trị đề xuất: 50–300.
Trong các thử nghiệm, chúng tôi đã sử dụng tính năng nhúng GloVe có 200 thứ nguyên với một lớp nhúng được đào tạo trước.
Hãy thử tìm hiểu những siêu liên kết này để tìm ra cách hiệu quả nhất. Sau khi chọn các tham số có hiệu suất cao nhất trong trường hợp sử dụng của mình, bạn có thể triển khai mô hình của mình.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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."]]