In the field of oil drilling, accurately predicting the Rate of Penetration (ROP) is of great significance for improving drilling efficiency and reducing costs. However, traditional prediction methods may not fully exploit the potential information in drilling data, and the existing machine learning prediction methods may suffer from insufficient prediction accuracy due to lack of full optimization of the model. To address this issue, this study proposes an end-to-end Bidirectional Long Short-Term Memory network (BiLSTM) incorporating the Self-Attention mechanism (SA). This method, based on data-driven foundations and the understanding of the relationships among various parameters through the Bingham equation, improves prediction accuracy, with a Root Mean Square Error (RMSE) of 0.309 and a coefficient of determination (R2) of 0.790 on the test set. In order to further optimize the BiLSTM-SA model, this paper proposes an improved Dung Beetle Optimizer algorithm (SODBO) tailored to practical needs. Based on the Dung Beetle Optimizer algorithm, SODBO uses Sobol sequences to initialize population positions and simultaneously integrates the Golden Sine algorithm and dynamic subtraction factors to enhance optimization capabilities. After using SODBO to optimize the BiLSTM-SA, the RMSE of the model's test results is reduced to 0.065, and the R2 is increased to 0.963, which is a significant improvement compared to the original model. In practical drilling applications, the optimized model demonstrates good prediction performance.