How to evaluate my model using a graph and how to reduce overfitting?

3 次查看(过去 30 天)
Hello,
I have a DL model that is used to exract embeddings from raw data, | plot the loss vs itterations and I get a noisy signal when I modified the plot to be loss vs epochs, It becomes smoother as you see in the figure. is it the right way to plot training. I'm using contrastive loss and DL network with a fully connected layer as output layer with 64 neurons, I can't plot the accuracy vs epoch, can I!
Another question, how to improve performance of the model. As you see model is overfitting, I tried to use l2Regularization and even add dropout layers in the network and no improvements. Any advices!

回答(1 个)

Ruchika Parag
Ruchika Parag 2025-7-17
Hi @Ahmed, thank you for sharing the details. You're approaching this correctly, and the observations you've made are valid.
1. Loss per Epoch vs. Iteration: Plotting loss per epoch is generally recommended, especially when using contrastive loss, which often results in noisy per-iteration values. An epoch-wise plot provides a clearer view of overall training trends, which aligns with what you're seeing.
2. Accuracy with Contrastive Loss: Contrastive loss does not directly produce class predictions, so conventional accuracy metrics are not applicable. However, you can evaluate performance using:
  • k-NN accuracy in the learned embedding space.
  • A similarity threshold (e.g., Euclidean or cosine distance) to convert distances into binary classification (similar vs. dissimilar).
  • Alternative metrics such as precision/recall or ROC-AUC on pairwise comparisons.
3. Overfitting and Model PerformanceThe training loss decreasing while validation loss remains high suggests overfitting. In addition to L2 regularization and dropout, you may consider:
  • Data augmentation to increase variability.
  • Batch normalization to stabilize training.
  • Reducing network complexity, such as fewer layers or neurons.
  • Early stopping based on validation loss trends.
  • Balanced batch construction, ensuring diverse positive and negative pairs.
  • Embedding normalization, constraining output vectors to unit norm.
  • Temperature scaling, if using NT-Xent or similar, to adjust contrastive loss sensitivity.
These strategies can help improve generalization and training stability in contrastive learning setups. Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

产品


版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by