With the popularity of social media networks, the emergence of undesirable texts seriously affects the online environment. Although the existing recognition methods can filter out most of the sensitive information, the recognition of sensitive words with variants is still deficient, on the one hand, an improved word extraction algorithm is designed, which adequately constructs and extends the sensitive word database. On the other hand for the recognition of bad text, in order to improve the recognition accuracy of bad text, this paper proposes TCMHA bad text detection model, which incorporates MultiHeadAttention on the basis of TextCNN model, which improves the recognition rate of sensitive words to a certain extent, and the experimental results prove the effectiveness of the deep learning method.