In the process of power transmission and distribution, non-technical losses are usually caused by users' abnormal power consumption behavior. It will not only affect the dispatch and operation of the distribution network, bring hidden dangers to the security of the power grid, but also damage the operating costs of power companies and disrupt the operation of the power market. Aiming at users' abnormal electricity consumption behavior, this paper proposes a model based on particle swarm optimization and long-short term memory with the attention mechanism (PSO-Attention-LSTM). Firstly, according to the actual electricity theft behavior, six typical electricity theft modes are summarized, and 4 composite modes are obtained by combining them, so as to comprehensively test the detection performance of the model for various electricity theft behaviors. Secondly, a detection model based on PSO-Attention-LSTM is proposed, and the model is built using the TensorFlow framework. The model uses the attention mechanism to give different weights to the hidden state of LSTM, which reduces the loss of historical information, strengthens important information and suppresses useless information. Use PSO to solve the difficult problem of model parameter selection, and optimize the hyperparameters to improve the model performance. Finally, the data set of the University of Massachusetts was used for simulation and compared with convolutional neural network-long short term memory (CNN-LSTM), attention mechanism-based long short term memory (Attention-LSTM), LSTM, gated recurrent unit (GRU), support vector regression (SVR), random forest (RF) and linear regression (LR) to verify the effectiveness and accuracy of the method used in this article. In this paper, Matlab software is used to analyze and visualize the detection result data.