With the increasing globalization of supply chains, ensuring food safety has become more complex, necessitating advanced approaches for risk assessment. This study aims to review the transformative role of machine learning (ML) and deep learning (DL) in enabling intelligent food safety management by efficiently analyzing high-quality and nonlinear data. We systematically summarize recent advances in the application of ML and DL, focusing on key areas such as biotoxin detection, heavy metal contamination, analysis of pesticide and veterinary drug residues, and microbial risk prediction. While traditional algorithms including support vector machines and random forests demonstrate strong performance in classification and risk evaluation, unsupervised methods such as K-means and hierarchical cluster analysis facilitate pattern recognition in unlabeled datasets. Furthermore, novel DL architectures, such as convolutional neural networks, recurrent neural networks, and transformers, enable automated feature extraction and multimodal data integration, substantially improving detection accuracy and efficiency. In conclusion, we recommend future work to emphasize model interpretability, multi-modal data fusion, and integration into HACCP systems, thereby supporting intelligent, interpretable, and real-time food safety management.
Crop yield prediction is critical for agricultural decision making and food security. Traditional models struggle to capture the complex interactions among meteorological, soil, and agricultural factors. This study introduces Crossformer, a Transformer-based model with a Local Perception Unit (LPU) for local dependencies and a Cross-Window Attention Mechanism for global dependencies. Experiments on winter wheat, rice, and corn datasets show that Crossformer outperforms CNN, LSTM, and Transformer in Test Loss, R2, MSE, and MAE. For instance, on the corn dataset, Crossformer achieves a Test Loss of 0.0271 and an R2 of 0.9863, compared to 0.7999 and 0.1634 for LSTM, respectively, demonstrating a substantial improvement in predictive performance. Interpretability analysis highlights the importance of temperature and precipitation in yield prediction, aligning with agricultural insights. The results demonstrate Crossformer’s potential for precision agriculture.
Accurately modeling the nonlinear relationships between near-infrared (NIR) spectral signatures and biochemical traits in corn remains a major challenge. A key difficulty lies in capturing multi-scale contextual dependencies—ranging from local absorption peaks to global spectral patterns—that jointly determine quality constituents such as protein and oil. To address this, we propose SpecTran, a spectral Transformer network specifically designed for NIR regression. SpecTran integrates three key components: adaptive multi-scale patch embedding which extracts spectral features at multiple resolutions to capture both fine and coarse patterns, spectral-enhanced positional encoding which preserves wavelength order information more effectively than standard encoding, and hierarchical feature fusion for robust multi-task prediction. Evaluated on the public Eigenvector corn dataset, SpecTran had a performance across four key traits—moisture, starch, oil, and protein—with an average of 0.483. It reduced the RMSE by 11.2% for protein and 10.7% for oil compared to the best-performing baseline, which is the standard Transformer model. These results demonstrate SpecTran’s superior ability to model complex spectral dynamics while providing interpretable insights, offering a reliable framework for NIR-based agricultural quality assessment.