Automatic modulation classification (AMC) enables automated wireless spectrum anomaly detection, facilitating efficient spectrum enforcement. Deep neural networks (DNNs), characterized by multiple hidden layers with nonlinear activation functions that allow for learning higher-level patterns hidden in the data, have proven effective in various tasks, including AMC. However, existing DNN-based approaches often struggle with generalization—their performance degrades significantly when deployed under unseen conditions, such as varying signal-to-noise ratios (SNRs) distinct from their training environments. To address this limitation, we propose CTLAE, a supervised deep learning framework that integrates an auto-encoder architecture with contrastive learning. During training, CTLAE processes signal samples of the same modulation category but with diverse SNRs, explicitly guiding the model to discern noise-intensity discrepancies. Additionally, the model is tasked with reconstructing segmented and heavily masked signal data, further enhancing its robustness to noise variations. Experiments on radar and communication signal datasets validate CTLAE's superiority: it achieves at least 5% higher overall test accuracy compared to state-of-the-art baselines, demonstrating significant improvements in generalization.