Because of the abrupt occurrence and severe consequences of slope disasters, the analysis of slope stability has always been a focal point in the field of slope disaster prevention. In previous studies, traditional methods were employed to analyze the stability of slopes, which not only require considerable temporal and manpower investments but also fail to effectively predict the development trends of slope stability, thereby posing challenges in slope disaster prevention. However, the emergence of data-driven approaches based on deep learning has forged a novel avenue for slope disaster prevention. Recently, a transformer model is proposed, which has an attention module to deeply learn the high dimensionality correlation between the properties of slopes and the stability of slopes. In this study, we have pioneered a novel approach to slope stability analysis, utilizing the transformer model for the first time. We have developed new computer code, curated a dataset consisting of 72,000 slope samples, and demonstrated the superior predictive capabilities of the transformer model in comparison to LSTM and Attention-LSTM models. Subsequently, we conducted further study on transformer-based multi-classification and regression models. Significantly, the regression model outperformed in predicting slope stability, reaching an impressive accuracy of 99.983%. The results indicate that the deep learning approach based on the transformer model has shown great potential and advantages as a novel method for slope stability analysis. Its high accuracy and short computation time will contribute to rapid on-site decision-making in geotechnical engineering applications.