Accurate quantification of soil moisture is essential for understanding water and energy exchanges between the atmosphere and the Earth’s surface, as well as for agricultural applications. Predicting soil moisture content is vital for efficient water management, irrigation scheduling, and drought monitoring. Traditional forecasting methods, such as numerical regression models, often struggle due to various influencing factors and poor observation data quality. In contrast, deep learning algorithms, particularly recurrent and convolutional neural networks, show promise in predicting nonlinear data like soil moisture. This study focuses on shallow groundwater regions, using groundwater levels and meteorological data as features while coupling the Transformer model with other neural network structures. We investigate the potential of attention-based neural networks for soil moisture time series prediction. Our findings demonstrate that the Transformer model achieves an average R2 of 0.523 across different time lags, outperforming the LSTM model with an R2 of 0.485. The introduction of LSTM enhances the Transformer’s stability in handling temporal changes. Additionally, we verified the importance of groundwater for soil moisture prediction. This study introduces new methods for soil moisture prediction and offers new insights and recommendations for the development of artificial intelligence technology for soil moisture prediction.