Next Article in Journal
A Survey on Action Recognition: Multimodal Approaches, Ethical Considerations, and Feedback Mechanisms
Previous Article in Journal
Feasible-Region Aggregation of Distributed Multi-Energy Storage Based on Support Functions and Minkowski Sum
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Lightweight and Effective Coded-Slang Detection for Cyber-Drug Intelligence

1
Intelligent Policing Key Laboratory of Sichuan Province, Sichuan Police College, Luzhou 646000, China
2
Department of Criminal Investigation, Sichuan Police College, Luzhou 646000, China
*
Author to whom correspondence should be addressed.
Electronics 2026, 15(14), 3138; https://doi.org/10.3390/electronics15143138
Submission received: 10 May 2026 / Revised: 7 July 2026 / Accepted: 13 July 2026 / Published: 16 July 2026
(This article belongs to the Topic Applications of NLP, AI, and ML in Software Engineering)

Abstract

Drug-related criminal activities on social media increasingly employ rapidly evolving coded languages, including fruit substitutions, numeric homophones, and dialectal metaphors, to evade detection. This adversarial obfuscation causes large-scale deep learning models to suffer from severe computational overhead during edge deployment, while reducing their robustness against evolving coded expressions. To mitigate these challenges, we construct a dedicated dataset containing 10,000 drug-related coded text samples and propose an optimized, lightweight TextCNN-based framework. The framework normalizes lexical variants of codewords using a domain-specific dictionary and adaptive normalization functions, and extracts local semantic patterns from the word embedding layer through multi-scale convolutional kernels ( h { 3 , 4 , 5 } ) to capture crucial short-text semantics in parallel. Experimental results demonstrate that the proposed framework achieves an F1 score of 99.3% with only 0.22 M parameters, significantly outperforming baseline models. These findings indicate that models optimized for local n-gram patterns provide a highly cost-effective deployment solution while outperforming representative pre-trained language models in specialized adversarial digital forensics tasks.

1. Introduction

The rapid proliferation of social media platforms has fundamentally transformed the operational landscape of drug-related criminal activities [1,2,3,4,5]. In China, this trend is particularly concerning, as the widespread misuse of synthetic drugs has been linked to a growing number of violent incidents, posing severe threats to public safety and social stability [6]. Unlike traditional offline drug transactions, illicit activities on platforms such as Weibo, WeChat, and Xiaohongshu are concealed through drug slang, a form of drug-related coded language used to evade automated detection and law enforcement surveillance [7,8]. Common evasion strategies include euphemistic substitutions (e.g., fruits or animals), numeric homophones, and dialectal slang [9]. These strategies effectively circumvent platform-level keyword filtering and law enforcement surveillance. Consequently, a persistent gap is widening between criminal innovation and regulatory response.
This challenge is substantial on a global scale. The 2022 Annual Report of the European Monitoring Centre for Drugs and Drug Addiction (EMCDDA) highlights the rising prominence of social media in drug transactions [10]. Offenders are adopting more covert, intelligent, and diversified methods, significantly complicating investigative efforts. Similar trends exist in China, where drug slang evolves rapidly within online communities. As a result, static rule-based detection systems quickly become ineffective against the continuous emergence of new coded expressions [11].
First, rule-based systems rely on manually curated lexicons and pattern matching [12]. While interpretable and easy to deploy, they suffer from poor generalization and high maintenance costs when facing constantly evolving coded language. Second, early machine learning methods, such as support vector machines (SVM) and Naïve Bayes (NB), exhibit limited capacity to capture contextual nuances [13]. This is especially problematic given the extreme brevity and high lexical noise of social media text. More recently, deep learning architectures—including recurrent neural networks (RNNs), long short-term memory (LSTM) networks, and bidirectional encoder representations from transformers (BERT)—have demonstrated strong performance on general text classification benchmarks [14,15,16].
However, applying these advanced models directly to Chinese drug slang remains underexplored. This gap stems from two primary factors. First, there is a critical scarcity of domain-specific annotated datasets in Chinese. Second, social media drug slang possesses distinctive linguistic properties: extreme brevity, intentional semantic obfuscation, and rapid lexical turnover. Models designed for well-formed, resource-rich texts struggle to address these specific challenges [17,18].
Convolutional neural networks, particularly the TextCNN architecture proposed by Kim [19], offer a compelling solution for this low-resource setting. TextCNN applies parallel multi-scale convolutional filters over character- or word-level embeddings. This allows it to efficiently extract local n-gram semantic patterns from short, noisy texts. Crucially, it achieves this without relying on large-scale annotated corpora or extensive computational resources. Its architectural simplicity and strong empirical performance make it well-suited for real-time drug slang detection on Chinese social media platforms [20].
To address the identified limitations and bridge the existing research gap, this study makes the following contributions:
1.
Domain-specific dataset construction. We construct a dedicated corpus containing 10,000 annotated social media texts containing drug slang by integrating authentic judicial case files with continuous social media crawling. The authenticity and annotation consistency of the adversarial drug-slang samples are strictly ensured through double-blind annotation and Cohen’s Kappa verification.
2.
Low-resource detection framework. To address the challenges of polysemy and coexistence of benign and illicit usages of drug slang, we propose a collaborative detection framework that couples an expanded domain-specific dictionary with a word-level multi-scale convolutional neural network. This approach effectively captures core coded expressions and their local contextual patterns within highly noisy short texts.
3.
Systematic empirical evaluation. We benchmark our framework against both traditional statistical methods and compact Transformer models. Performance testing in a CPU-only edge-computing environment demonstrates that our lightweight model achieves an F1 score of 99.3%. It requires only 1.86 ms per sample while maintaining a compact model footprint, making it suitable for resource-constrained deployment.
The remainder of this paper is organized as follows. Section 2 reviews related work on text classification and drug-related content detection. Section 3 describes the dataset construction process and presents the proposed TextCNN-based methodology. Section 4 reports experimental results and comparative analysis. Section 5 concludes the paper and outlines directions for future research.

2. Related Work

The automatic detection of drug slang involves three core dimensions: the linguistic cognition of slang, social media content mining, and low-resource text classification. While existing research has made progress across these areas, systematic solutions tailored to low-resource Chinese social media settings remain scarce.

2.1. Linguistic Studies of Drug Slang

Understanding the linguistic patterns underlying drug slang is essential for building effective detection systems. Nahar et al. [3] reviewed drug slang from an interdisciplinary medico-linguistic perspective. They catalogued the types, origins, and evolution mechanisms of common drug terms, highlighting their highly covert nature and rapid rate of change. Sundaram et al. [6] conducted a systematic review of slang analytics on social media. They noted that slang is heavily context-dependent and spreads almost exclusively within closed communities rather than formal texts. This dynamic results in an acute scarcity of annotated corpora. Furthermore, Liu et al. [7] and Wu et al. [11] analyzed internet slang from a sentiment perspective. Liu et al. examined its persuasive effects in advertising, while Wu et al. constructed SlangSD, a sentiment lexicon for short texts. Collectively, these studies demonstrate that drug slang proliferates on Chinese social media via homophones, abbreviations, and coded expressions. Consequently, its low-resource nature and semantic ambiguity remain the primary obstacles to automated detection.

2.2. Word Embedding-Based Approaches

Word embedding methods represent the early dominant paradigm for slang detection. For instance, Holbrook et al. [8] applied Word2Vec to a Reddit corpus to construct semantic neighborhoods for drug slang. They identified candidate terms via vector similarity, achieving strong results in high-resource English settings. Gadusu and McGinty [12] systematically compared Word2Vec and BERT. They found that static word vectors struggle to disambiguate polysemous slang. Conversely, context-sensitive dynamic models offer clear advantages but demand extensive labeled data, causing performance to drop in low-resource scenarios. Shiozawa et al. [21] extended word co-occurrence statistics to dark web anchor texts. This approach partially alleviated the out-of-vocabulary problem. However, it relies on large-scale unlabelled corpora, which are extremely difficult to acquire from regulated Chinese social platforms. In summary, traditional word embedding methods face a fundamental data bottleneck in Chinese slang settings. Capturing local morphological features under limited annotation remains an open challenge.

2.3. Deep Learning in Slang Detection

The adoption of deep learning has substantially improved drug-related content detection. Hu et al. [17] proposed an ensemble framework to model drug abuse signals in sparse Twitter texts. This multi-model fusion enhanced robustness against noisy data, though it required higher data volumes. Tassone et al. [18] incorporated graph mining to model user relationships. This enriched the feature space, but graph-structural information is often inaccessible in anonymous online environments. Asim et al. [13] compared LSTM, CNN, and fine-tuned BERT on a Twitter dataset. They found that convolution-based models effectively extracted local n-gram features from short texts. Furthermore, CNNs exhibited more stable convergence than large pre-trained models under limited sample sizes. Similarly, Hossain et al. [22] validated the effectiveness of local feature modeling for political slang discovery. Among these architectures, TextCNN [19] has been widely validated for low-resource text classification. It applies parallel multi-scale convolutional filters to extract local semantic patterns and compresses them via global max-pooling. Building on these findings, this paper adopts TextCNN as the primary classification model. We adapt it specifically to character-level Chinese inputs and the unique morphological traits of drug slang, aiming for efficient detection in low-resource settings.

2.4. Large Language Models in Slang Detection

The rise of large language models (LLMs) offers new perspectives on slang understanding, but it also exposes clear limitations in low-resource scenarios. Sun et al. [23] evaluated mainstream LLMs on informal language tasks. They found that pre-trained models struggle with the contextual disambiguation of niche community slang. Carpenter et al. [24] validated LLM capabilities for English opioid slang. However, they noted that distributional biases in training corpora severely degrade performance on Chinese internet slang. Additionally, the SlangLLM framework proposed by Patel and Alsobeh [25] enables dynamic detection but demands substantial computational resources. This high overhead makes it unsuitable for real-time deployment. Compared to LLMs, lightweight discriminative models like TextCNN offer manageable training costs and lower inference latency. This makes them more suitable for practical drug slang monitoring in China.

2.5. Scarcity of Chinese Datasets

Data scarcity is the fundamental bottleneck constraining progress in Chinese drug slang detection. For English tasks, the SlangTrack dataset [26] provides an important benchmark for identifying slang usage. Unfortunately, no equivalent Chinese resource currently exists. Existing publicly available drug-related datasets predominantly originate from English platforms like Twitter, Reddit, and Instagram [27]. In contrast, labeled corpora from Chinese platforms (e.g., Weibo, WeChat) remain extremely scarce due to strict privacy protection and content regulation. This stark reality highlights the critical need for low-resource modeling methods. Consequently, it serves as the primary motivation for the dataset construction and model selection strategies adopted in this study.

2.6. Motivation and Core Problem Statement

Traditional keyword filtering can be readily bypassed through pinyin substitutions, homophonic variants, and fruit-based codewords. Meanwhile, although Transformer-based models and large language models have demonstrated strong performance on general text understanding tasks, their substantial computational requirements and inference latency limit their practicality for edge deployment in real-time monitoring systems. Therefore, the key challenge addressed in this study is to accurately detect drug slang in social media texts under limited computational resources while supporting real-time inference.

3. Method

3.1. Overview

Figure 1 illustrates the overall framework proposed in this study for detecting drug slang on social media platforms. As illustrated in Figure 1, the overall workflow consists of four primary stages:
Data Acquisition and Annotation: Raw text data are collected from mainstream Chinese social media platforms (e.g., Weibo, Douyin, Bilibili, and Xiaohongshu) using automated web scrapers. After noise reduction and data cleaning, the samples are manually annotated to distinguish illicit coded language from benign text, yielding a labeled dataset for subsequent experiments.
Feature Preprocessing: The annotated dataset is converted into structured feature representations for model training. This stage encompasses tokenization, stop-word removal, and the generation of dense word embeddings.
Model Construction and Training: An TextCNN-based classification framework is constructed. By applying multi-scale convolutional filters, the model extracts and aggregates local semantic features from the short, highly noisy texts characteristic of social media.
Performance Evaluation: The trained model is evaluated against established baseline methods using standard classification metrics.

3.2. Construction and Annotation of Drug Slang Corpus

This section describes the drug slang corpus construction process, including data sources, data preprocessing, data annotation, and statistical analysis. The resulting corpus is subsequently used for model training and evaluation. Figure 2 presents the workflow of the corpus construction process.

3.2.1. Data Sources

This study employs a multi-source data collection strategy to obtain text data containing drug slang through two complementary approaches. First, Python-based web crawlers are used to collect publicly available interactive content from mainstream social platforms. Representative crawled samples are shown in Table 1.
The collected data originate from three primary sources: (1) judicial documents obtained from the Supreme People’s Court Judgment Documents Network and drug-related case files released by the Ministry of Public Security, from which drug slang patterns are extracted; (2) official anti-drug documents, including government reports and bulletins issued by public security agencies, which are used to supplement the drug slang lexicon; and (3) publicly available drug-related posts collected from social media platforms such as Weibo, Douyin, and WeChat using Python-based web crawlers. After sensitive information filtering, these data are integrated to construct a continuously updated corpus for subsequent annotation and model training.
To augment the training data, this study automatically generated two categories of samples based on a drug slang lexicon: one category consists of sentences directly conveying hidden drug-related meanings (e.g., “A new batch of express tea has arrived”), and the other consists of benign-context sentences embedding drug slang terms into positive contexts (e.g., “Community outreach on new tea varieties to prevent fraud”). By randomly combining different grammatical structures and contextual scenarios, tens of thousands of generated texts (more than 5000 drug-related sentences and more than 5000 benign sentences) maintain linguistic naturalness while covering expressive variation across diverse real-world scenarios. Representative examples of sentences randomly generated from the code language lexicon are shown in Table 2.

3.2.2. Data Preprocessing

Raw text data collected from various sources often contains a large amount of noise and unstructured information that cannot be directly fed into a model for training. Therefore, a series of preprocessing operations must be applied to transform the raw data into standardized text corpora. The preprocessing pipeline consists of three main steps: text cleaning, word segmentation, and code-language-specific augmentation.
To ensures the statistical independence of the evaluation, a cross-set deduplication pipeline was integrated into the data preprocessing stage. Beyond exact string matching, we utilized Jaccard-similarity-based near-duplicate filtering across the entire corpus. This step semantic redundancies and guarantees that no identical or nearly-identical text variants cross the boundaries between the training and evaluation splits.
(1) Text Cleaning: Text cleaning is the first step of preprocessing, aimed at removing semantically irrelevant noise. Social media texts frequently contain URL links, HTML tags, emoticons, and various special symbols. Regular expressions are used to filter out such content: for example, pattern matching is applied to remove URLs beginning with http or www, topic hashtag symbols are removed while preserving the topic text, and various punctuation marks are eliminated. Since some emoticons may correspond to drug slang, they are converted to textual descriptions during cleaning to preserve potential semantic cues.
(2) Word Segmentation: Word segmentation is the process of dividing a continuous sequence of Chinese characters into word units with independent semantics, and can be formulated as a mapping from a character sequence to a word sequence. Let the raw text be represented as a character sequence:
C = ( c 1 , c 2 , , c i , , c m )
where c i denotes the i-th Chinese character. The goal of word segmentation is to convert this into a word sequence:
W = ( w 1 , w 2 , , w j , , w n )
where w j denotes a word composed of one or more consecutive characters. This process can be formally expressed as:
W base = Seg ( C , D )
where Seg ( · ) denotes the segmentation function and D is the segmentation dictionary. The Jieba tokenizer is employed to implement this mapping.
To address inaccurate segmentation of domain-specific vocabulary by general-purpose tokenizers, a domain-specific custom dictionary is introduced to extend the original dictionary:
D = D D drug
where D drug contains the set of drug slang terms (e.g., “liubing,” “zhurou,” “linghao jiaonang,” “xiaoqi,” etc.). Under the extended dictionary constraint, the segmentation function is updated to:
W * = Seg ( C , D )
Consequently, words satisfying w j D drug are kept intact during segmentation, thus avoiding semantic fragmentation and improving recognition accuracy for domain-specific expressions. The custom dictionary is built upon the code language lexicon collected in the preliminary phase and is continuously expanded and refined throughout the annotation process.
(3) Augmentation Processing: To address the problem of variant expressions of drug-related code language on social media (such as homophone substitution, pinyin abbreviations, and numeric encoding), this study introduces semantic normalization on top of the segmentation results, mapping non-standard expressions to canonical forms [28]. A code language mapping function is constructed:
W = Norm ( W * , M )
where W is the augmented word sequence. The mapping dictionary M transforms words one by one, defined as follows:
M ( w ) = m ( w ) if w dom ( M ) w otherwise
where dom ( M ) denotes the domain of the mapping dictionary and m ( w ) is the normalized expression corresponding to word w. For example, homophones or abbreviated forms are mapped to their standard code language equivalents. This process essentially implements a mapping from the original expression space to a canonical semantic space. Due to the polysemy and context-dependence of language, the mapping function is not strictly injective, and some words may carry semantic ambiguity. Nevertheless, in a statistical sense, this augmentation effectively improves the model’s ability to recognize variant code language expressions, particularly yielding significant improvement in recall.

3.2.3. Data Annotation

Data annotation is the key step in converting raw text into usable samples. Annotation quality directly affects model learning outcomes. This study adopts a binary annotation scheme, classifying sentences as either non-drug-related (labeled 0) or drug-related (labeled 1). To ensure annotation accuracy and consistency, three annotators with relevant backgrounds were organized to participate in the labeling process. The annotation workflow is as follows:
(1) Pre-annotation phase: A random sample of 200 instances is selected for pre-annotation. Inter-annotator agreement is calculated, disagreements are discussed, and consistent standards are established.
(2) Formal annotation phase: A double-blind annotation scheme is adopted, with each sample independently labeled by two annotators. Annotators do not communicate during the process to avoid mutual influence.
(3) Cross-review phase: Annotation results are compared; samples with consistent labels are directly accepted. For samples with inconsistent labels, a third senior annotator adjudicates to determine the final label.
To quantify the reliability of annotation results, this study uses Cohen’s Kappa coefficient to assess inter-annotator agreement. The Kappa coefficient is calculated as:
κ = P o P e 1 P e
where P o is the observed agreement rate (the proportion of samples labeled identically by both annotators), and  P e is the expected agreement rate (the proportion of agreement attributable to chance). The Kappa value typically ranges from 0 to 1: values above 0.75 indicate good agreement, values between 0.40 and 0.75 indicate moderate agreement, and values below 0.40 indicate poor agreement. The Kappa coefficients at each annotation stage in this study are shown in Table 3.
The Kappa coefficients for the pre-annotation and formal annotation stages are 0.82 and 0.91, respectively, indicating extremely high inter-annotator agreement and confirming the reliability of the annotation results. Sample annotations from the dataset are shown in Table 4.

3.3. Model Architecture

3.3.1. Model Overview

We proposes a domain-customized TextCNN framework tailored for drug slang detection. The overall model architecture is shown in Figure 3, comprising an embedding layer, a convolutional layer, a pooling layer, a fully connected layer, and an output layer. The input consists of preprocessed short social media texts, and the output is a probability distribution indicating whether the text belongs to the drug-related or non-drug-related category.
The text sequence is first mapped through the embedding layer into 100-dimensional dense vectors, forming a word vector matrix. Subsequently, convolutional kernels of three sizes (3, 4, and 5) slide in parallel over the matrix to extract local semantic features of varying lengths, generating multiple sets of feature maps. A global max-pooling operation is then applied to each set of feature maps to retain the most salient feature responses, and all pooling results are concatenated into a fixed-length feature vector. Finally, this vector undergoes nonlinear transformation through the fully connected layer and is passed through a Softmax function to produce the classification output. During training, the adaptive moment estimation (Adam) optimizer is used to update parameters, with the cross-entropy loss function employed to optimize the classification objective.

3.3.2. Input Layer and Embedding Layer

The input layer is responsible for receiving preprocessed sentence texts. Since neural networks require inputs of fixed dimensions, this study uniformly adjusts all text sequences to a length of 100 tokens. For sentences shorter than 100 tokens, zero-padding is applied at the end; for sentences longer than 100 tokens, only the first 100 tokens from the beginning are retained. This setting is based on statistical analysis of the dataset and is sufficient to cover the vast majority of short social media texts.
The embedding layer maps discrete word indices to continuous dense vectors. Suppose the input sentence contains n words ( n 100 ); the embedding layer converts it into a matrix E R n × d , where d is the word vector dimensionality, and the i-th row of the matrix corresponds to the d-dimensional vector representation of the i-th word in the sentence. This study sets the word vector dimensionality to d = 100 and initializes the embedding matrix using pretrained Word2Vec word vectors [29]. Pretrained word vectors provide the model with rich semantic priors, enabling basic language understanding ability from the early stages of training. During training, the embedding layer parameters are set to a fine-tunable state, allowing the word vectors to adaptively adjust toward the semantic space of the drug-related domain.

3.3.3. Convolutional Layer Design and Domain-Specific Adaptation

The convolutional layer is designed not only for local semantic feature extraction but also to capture the distinctive lexical variations characteristic of drug slang. To effectively capture the dynamic and context-dependent patterns of coded expressions, this study employs parallel multi-scale convolutional filters. Specifically, the kernel heights are configured to h { 3 , 4 , 5 } .
The architectural decision to employ this specific configuration is deeply rooted in the adversarial nature of Chinese drug slang. In online illicit markets, offenders deliberately utilize highly condensed, obfuscated terminology—ranging from two-character euphemisms (e.g., ice smoking, “pork”) to multi-character compound metaphors (e.g., Foxy Methoxy, “Spice pen”)—to circumvent static platform surveillance. During Chinese word segmentation, core two-character illicit phrases are frequently condensed into a single token. Consequently, setting the minimum kernel size to 3 serves as an optimal baseline: it captures not only the core illicit token itself but also its immediate syntactical context (e.g., surrounding verbs or prepositions). This three-token contextual information helps distinguish benign usage from illicit intent in noisy environments.
Concurrently, larger convolutional filters ( h = 4 and 5) are used to capture longer, syntactically complex semantic obfuscations. These extended receptive fields are adept at recognizing fragmented expressions or multi-word idioms where criminals deliberately insert noise characters to bypass rule-based detection. By operating these three kernel sizes in parallel, the framework dynamically learns n-gram representations across varying granularities, improving the model’s robustness to variations in the length and structure of drug slang expressions.
Formally, each of the three kernel sizes comprises 128 independent filters. Given that the width of each filter strictly corresponds to the word vector dimensionality d, the weight matrix of an individual kernel is defined as W R h × d . During the forward pass, each kernel slides vertically across the input embedding matrix, processing h consecutive word vectors per stride. This operation computes a localized feature value via a dot product, followed immediately by a ReLU non-linear activation. Ultimately, each kernel generates a feature map whose sequence length is jointly determined by the input text length and the specific kernel height, effectively mapping raw adversarial text into a dense semantic feature space.

3.3.4. Pooling Layer and Feature Fusion

The pooling layer performs dimensionality reduction on the feature vectors output by the convolutional layer, extracting the most representative features. This study employs a global max-pooling strategy, selecting the maximum value from the feature vector generated by each convolutional kernel as that kernel’s final output.
The core idea behind global max-pooling is that, for the drug slang recognition task, a key feature need only appear once in a sentence to support a judgment—its exact position is irrelevant. Regardless of whether “ice smoking” appears at the beginning, middle, or end of a sentence, it will be captured by the corresponding convolutional kernel, and the pooling layer retains its maximum activation value, thereby ensuring that critical information is not lost.
After the pooling layer, each convolutional kernel outputs a scalar value. With 128 kernels for each of the three sizes, a total of 384 scalar values are produced. These scalars are concatenated into a single feature vector that aggregates local semantic information at different granularities from the input sentence, providing a feature basis for subsequent classification.

3.3.5. Output Layer

The output layer consists of a fully connected layer and a Softmax classifier. The feature vector output by the pooling layer first undergoes nonlinear transformation and dimensionality compression through the fully connected layer. The fully connected layer has 128 neurons and uses the rectified linear unit (ReLU) activation function:
h = ReLU ( W fc v + b )
where W fc is the weight matrix and b is the bias term. v R 384 denotes the global maximum feature vector, which is obtained by concatenating the pooled outputs from 128 convolutional filters across three distinct scales.
To prevent overfitting, a Dropout mechanism is introduced after the fully connected layer. During training, Dropout randomly drops a fraction p of neuron outputs, forcing the model to avoid dependence on specific neurons. Dropout is active only during training; during inference, all neurons participate in computation.
The output layer applies the Softmax function to map the fully connected layer’s output into binary classification probabilities:
y ^ = Softmax ( W out h + b out )
The Softmax function is defined as Softmax ( z i ) = e z i / j e z j . The two output components correspond to the predicted probabilities for the non-drug-related (label 0) and drug-related (label 1) categories, respectively, and satisfy y ^ 0 + y ^ 1 = 1 . The final prediction is the category with the higher probability.

3.3.6. Model Training Settings

After annotation, the dataset is randomly shuffled and split into training, validation, and test sets in an 8:1:1 ratio. The training set is used for learning and updating model parameters; the validation set monitors model performance during training; the test set is used for final evaluation of model performance.
Model training uses the Adam optimizer with an initial learning rate of 0.001. Adam combines the concepts of momentum and adaptive learning rates, dynamically adjusting the learning rate of each parameter based on estimates of the first and second moments of the gradients. It offers the advantages of fast convergence and low sensitivity to hyperparameters.
The loss function is cross-entropy loss, defined as:
L = 1 N i = 1 N y i log p ^ i + ( 1 y i ) log ( 1 p ^ i )
where N is the batch size, y i is the true label of the i-th sample, and  p ^ i is the model’s predicted probability of the drug-related category. Cross-entropy loss effectively measures the discrepancy between the predicted probability distribution and the true label distribution.
The training batch size is set to 64, meaning 64 samples are processed simultaneously per iteration. The number of training epochs is set to 10. After each epoch, the loss and accuracy on the validation set are computed to monitor the training process. If validation performance ceases to improve, an early-stopping strategy is applied to prevent overfitting. The model with the best performance on the validation set is ultimately selected for evaluation on the test set. The main hyperparameters of this model are listed in Table 5.
Furthermore, to maintain strict lexical isolation, the custom narcotics code language lexicon and feature normalization rules were restricted entirely within the training loop. The tokenizer’s vocabulary was constructed solely from the training set. While the test set contains diverse slang variants to evaluate robust text recognition, any unseen tokens encountered during the evaluation phase were automatically masked using standard Out-of-Vocabulary (OOV) mechanisms (e.g., <UNK> mapping), thereby strictly blocking any lexical priors from leaking into the evaluation stage.

4. Experiments

This chapter provides an experimental validation of the TextCNN model using a custom-built dataset of drug-related slang. We evaluate the model’s performance through multi-dimensional metrics and conduct a comparative analysis against several baseline models. Furthermore, by performing an in-depth analysis of error cases and testing generalization capabilities, we offer a comprehensive examination of the model’s performance and inherent limitations in practical application scenarios.

4.1. Experimental Setup

4.1.1. Implementation Environment

All experiments were conducted under a unified hardware and software configuration to ensure fair and reproducible comparisons across models. The detailed environment specifications are summarized in Table 6.

4.1.2. Evaluation Metrics

Model performance was quantified using five standard evaluation metrics for binary text classification, computed from the four fundamental entries of the confusion matrix: true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN).
Accuracy measures the proportion of correctly classified samples over the entire test set:
Accuracy = T P + T N T P + F P + T N + F N
Precision measures the fraction of predicted positive samples that are truly positive, reflecting the reliability of positive predictions:
Precision = T P T P + F P
Recall measures the fraction of actual positive samples correctly identified by the model, reflecting coverage of the positive class:
Recall = T P T P + F N
F1-Score is the harmonic mean of precision and recall, providing a balanced measure of both correctness and completeness:
F 1 = 2 × Precision × Recall Precision + Recall
AUC (Area Under the ROC Curve) quantifies the model’s ability to discriminate between positive and negative samples across all classification thresholds. An AUC value approaching 1.0 indicates near-perfect rank-ordering performance.

4.1.3. Datasets Description and Partitioning

The dataset used in this study consists of 10,000 text samples, constructed using a seed-driven data augmentation strategy. Specifically, the foundational seed corpus includes 57 verified drug-related sentences and over 300 domain-specific slang terms. Based on these seeds, additional samples are generated through template-based construction and lexical perturbation, resulting in a corpus that covers diverse linguistic expressions.
To enhance the model’s ability to handle complex linguistic variations, the generated data incorporates multiple forms of expression, including direct references, metaphorical expressions, homophones, abbreviations, and numeric substitutions, thereby simulating the obfuscated communication patterns commonly observed in real-world scenarios.
Regarding label assignment, a binary classification scheme is adopted, where drug-related texts are labeled as 1 and non-drug-related texts as 0. All labels are inherited from the seed-driven generation process, ensuring consistency and uniform annotation rules.
To ensure experimental rigor and reproducibility, the dataset is randomly shuffled prior to splitting and divided into training, validation, and test sets in an 8:1:1 ratio. The detailed distribution is presented in Table 7.
Regarding the dataset partition (8:1:1), the split was strictly executed at the template and seed level (group splitting) rather than through random sentence-level sampling. Generated sentences sharing the same underlying syntactic framework or derived from the same real-world seed phrase were grouped together and allocated exclusively to a single split (Train, Val, or Test). This structural decoupling ensures that the test set evaluates the model’s genuine generalization capacity on entirely unseen sentence structures, effectively preventing templated leakage.

4.2. Performance Evaluation of TextCNN

4.2.1. Quantitative Results on Test Set

The trained TextCNN model was evaluated on the test set using a confusion matrix, from which accuracy, precision, recall, F1-score, and AUC were derived. Results are presented in Table 8.
As illustrated in Table 8, the TextCNN model demonstrates exceptional performance in the drug-related slang recognition task. The model achieved an Accuracy of 99.30%, indicating that only approximately 7 errors occurred out of 1000 test samples. Precision and Recall reached 0.9900 and 0.9960, underscoring the model’s high reliability in positive class prediction and its ability to capture the vast majority of actual drug-related instances. The F1-score, also recorded at 0.9930, signifies that the model maintains an optimal balance between precision and completeness. Furthermore, the AUC value of 0.9997—which significantly outperforms a random classifier—validates the model’s near-perfect discriminative capability in distinguishing between positive and negative samples. The confusion matrix for the model on the test set is presented in Figure 4.

4.2.2. Analysis of the Confusion Matrix

As demonstrated in the confusion matrix (Figure 4), the model produced only seven errors out of the 1000 test samples. Specifically, these consisted of five false positives and two false negatives. These findings are highly consistent with the performance metrics presented in Table 8.
The confusion matrix provides visual verification of the model’s strong discriminative capability for both drug-related slang and non-drug-related text. Furthermore, the error distribution is relatively uniform, indicating that the model does not exhibit a significant bias toward any specific category.

4.3. Comparative Analysis with Baseline Models

4.3.1. Performance Comparison on Classification Metrics

To evaluate the effectiveness of the proposed TextCNN model, we compare it with seven representative baseline models from two categories: traditional machine learning models, including Support Vector Machine (SVM) and Naive Bayes (NB), and widely used pre-trained language models, including BERT-Base-Chinese, Chinese-RoBERTa-wwm-ext, TinyBERT, MacBERT, and DistilBERT(DistilBERT-Base-Multilingual). To ensure a fair and reproducible comparison, all models were evaluated under identical experimental settings, including the same dataset split (random seed = 42; training/validation/test ratio of 8:1:1), evaluation metrics, and hardware/software environment. The detailed model configurations and training hyperparameters are summarized in Table 9.
To eliminate any performance bias stemming from stochastic weight initializations, all neural network models (TextCNN and PLMs) were re-evaluated across five independent experimental runs utilizing distinct random seeds (42, 100, 2026, 777, and 999). Traditional statistical models (SVM and Naive Bayes) were evaluated once because their optimization is deterministic given fixed input features. The reported results correspond to the mean performance over the five independent runs on the test set, as summarized in Table 10.
Among all evaluation metrics, recall is of primary importance for drug slang detection because missed detections may allow illicit content to evade subsequent intervention. TextCNN outperforms traditional machine learning models such as SVM and Naive Bayes by approximately 5.9 percentage points, and also holds a slight lead of 0.7 percentage points over the pre-trained models BERT-Base-Chinese and Chinese-RoBERTa-wwm-ext. Among the lightweight pre-trained models, TinyBERT delivers the metrics with an accuracy and F1-score of 0.9910. Crucially, it performs marginally lower than TextCNN yet consistently outperforms other pre-trained language models. This result can be attributed to the predominance of local lexical patterns inherent in our domain-specific dataset, which enables the convolutional filters in TextCNN to effectively capture discriminative local semantic features without relying on complex contextual reasoning. Furthermore, MacBERT and DistilBERT(DistilBERT-Base-Multilingual) yield comparable performance to BERT and RoBERTa, with all metrics hovering around 0.9890, without demonstrating a clear performance advantage. It is worth noting that although the SVM and Naive Bayes models achieve high precision (1.0000 and 0.9978, respectively), their recall is significantly lower, indicating a considerably higher risk of missed detections.
To more comprehensively compare the overall performance of each model, Figure 5 presents a multi-indicator radar chart for the five models. It can be clearly seen from the figure that the polygon of the TextCNN model occupies the largest area, leading in the three core indicators—accuracy, recall, and F1 score—thus demonstrating the best overall performance.TinyBERT closely follows in terms of overall performance, demonstrating outstanding competitiveness among the lightweight pre-trained language models. In contrast, although the SVM and Naïve Bayes models perform well in terms of precision, they show significant shortcomings in recall, with an apparent indentation in the polygon along this dimension. This reflects a serious issue of missed detections, rendering them unable to meet the practical requirement of avoiding false negatives is generally more important than reducing false positives in drug slang identification. The group of BERT-derived architectures, including BERT-Base-Chinese, Chinese-RoBERTa-wwm-ext, MacBERT, and DistilBERT(DistilBERT-Base-Multilingual), exhibits relatively balanced overall performance, yet their coverage areas are slightly smaller than that of TextCNN and TinyBERT, thereby confirming the overall performance of TextCNN in the task of identifying drug-related slang.
Hyperparameter Sensitivity Analysis of PLM Baselines. To further investigate model stability, we evaluated the sensitivity of the pre-trained language model (PLM) baselines to different learning rates. The results indicate that PLMs are considerably more sensitive to hyperparameter selection when fine-tuned on this low-resource, domain-specific dataset.
When the learning rate was increased to 5 × 10 4 , the F1-score of BERT-Base-Chinese decreased to 0.9830, suggesting unstable optimization during fine-tuning. Conversely, reducing the learning rate to 1 × 10 6 resulted in insufficient parameter updates, leading to severe underfitting and a dramatic drop in F1-score to 0.3349.
In contrast, the proposed TextCNN framework maps covert jargon into explicit atomic semantic units via domain lexicon boundaries. Optimized via a steady constant learning rate of 1 × 10 3 , our model maintains exceptional training equilibrium across different seed groupings, converging consistently with a negligible performance standard deviation ( Std = ± 0.0011 for F1-score). This stark contrast reinforces that for low-resource cybercrime linguistics where keyword clues outweigh long-range global context, a structurally compact convolutional filter array bypasses the optimization fragility and parameter tuning risks that commonly hinder heavy attention-based pre-trained architectures.

4.3.2. Analysis of False Negatives

To further evaluate the practical applicability of each model, Figure 6 compares the number of missed detections of each model on the test set. As shown in Figure 6, TextCNN incurs only 7 missed detections, achieving the lowest false negative rate among all models. TinyBERT follows closely with 9 missed instances—merely two more than TextCNN—significantly outperforming other base-level pre-trained models and demonstrating its ability to maintain a high recall rate while substantially compressing model volume. Notably, the four base-level models (BERT, RoBERTa, MacBERT, and DistilBERT-Base-Multilingual) yield identical results, each with 11 missed detections. In sharp contrast, traditional machine learning benchmarks exhibit considerably poorer performance: SVM and Naive Bayes fail to detect 31 and 32 instances, respectively, which is approximately 4.5 times higher than that of TextCNN. In the task of detecting drug-related coded language, Even a single missed detection of drug-related content may allow illicit information to evade subsequent monitoring and intervention. therefore, the number of missed detections serves as a core indicator for measuring the practicality of a model. While maintaining leading classification performance, TextCNN achieves the lowest miss rate, fully demonstrating its practical value for real-world deployment. In contrast, although SVM and Naïve Bayes perform well in terms of precision, their excessively high number of missed detections renders them unable to meet the practical requirements of the task.

4.3.3. Computational Efficiency and Deployment Costs

To rigorously validate the lightweight characteristics and real-world deployment viability of the proposed framework, we benchmarked the word-level TextCNN against both classical statistical models and representative compact Transformer baselines. All execution benchmarks were carried out on a uniform, single-core CPU environment to simulate low-resource edge settings. The comparison includes model parameters, storage footprint, single-sample inference latency, and throughput (queries per second, QPS), as summarized in Table 11.
As compiled in Table 11, the proposed architecture offers exhibits clear advantages. The word-level TextCNN comprises only 0.22 M parameters with a physical size of 0.84 MB, yielding a 52× reduction in model size compared with TinyBERT (43.59 MB) and more than two orders of magnitude compared with standard pre-trained architectures.
Regarding computational efficiency, the proposed model achieves 2698.02 queries per second on a consumer-grade CPU. This corresponds to approximately 3.7× the throughput of TinyBERT and 38.9× that of MacBERT. Combined with its strong classification performance, the proposed framework achieves an effective balance between detection accuracy and computational efficiency. Specifically, it attains an F1 score of 99.30%, outperforming TinyBERT by 0.20 percentage points while requiring only a fraction of the computational resources. These results indicate that the proposed framework provides accurate and efficient covert slang detection, making it well suited for deployment in resource-constrained edge environments, such as portable law enforcement devices and high-throughput network traffic inspection gateways.

4.3.4. Discussion on Model Characteristics

The performance of TextCNN in terms of identification accuracy, inference efficiency, and deployment costs—relative to BERT-Base-Chinese, Chinese-RoBERTa-wwm-ext, SVM, and Naive Bayes—stems from inherent differences in model architecture, data dependency, and task alignment.
Structural Architectural Analysis: TextCNN is based on a Convolutional Neural Network (CNN) architecture that utilizes multi-scale convolutional kernels to extract local n-gram features. This mechanism effectively captures representative keyword combinations and local patterns, which aligns well with the linguistic characteristics of drug-related coded language, such as word substitutions and fixed collocations.
Conversely, Transformer-based pre-trained models like BERT and RoBERTa [30] rely on multi-layer self-attention mechanisms to model long-range semantic relationships and global contextual dependencies. While these models excel in complex tasks like semantic reasoning and reading comprehension, such sophisticated modeling is not always critical for slang detection. In this specific task, complex semantic modeling may introduce redundant information or semantic noise, potentially weakening the model’s discriminative precision.
Data Dependency and Training Efficiency: Large-scale models like BERT and RoBERTa possess a massive number of parameters, requiring substantial annotated datasets and high-performance computational resources. When training samples are limited or when there is a significant domain discrepancy, these models are prone to overfitting or insufficient transfer learning. In contrast, TextCNN features a streamlined structure with fewer parameters. It converges rapidly and effectively learns task-specific features even when training data are limited, resulting in stable training and strong classification performance.
Comparison with Traditional Models: Traditional machine learning models, such as SVM and Naive Bayes, primarily rely on manually engineered features like term frequency or TF-IDF. These methods lack the capacity to characterize nuanced contextual semantic relationships, making it difficult for them to handle the metaphorical expressions and semantic deformations prevalent in drug-related jargon.
In conclusion, TextCNN successfully balances feature extraction capability with a lightweight structural design. It achieves a favorable balance between task adaptability, model complexity, and generalization performance. Consequently, in slang detection tasks dominated by local pattern recognition, TextCNN outperforms both large-scale pre-trained models and traditional shallow models. These disparities in efficiency and performance are the direct result of the specific structural characteristics and design objectives of each model.

4.3.5. Granularity Ablation: Word-, Character- and Subword-Level Tokenization

To justify the selection of word-level text processing under domain-specific lexicon constraints, an ablation study was conducted to compare the proposed word-level model against character-level and subword-level TextCNN variants. The character-level architecture inherently bypasses Out-of-Vocabulary (OOV) bottlenecks and exhibits high resilience against typographical permutations. However, within the highly ungrammatical and noisy contexts of social media communication, the absence of rigid word boundaries causes the model to misinterpret benign, accidental character co-occurrences as illicit keywords, yielding a lower F1 score of 99.00%. Subword-level tokenization, which dynamically balances characters and words, was also evaluated. Nonetheless, due to the scarcity of specialized domain-specific priors in public subword embeddings, it failed to capture the covert metaphorical semantics effectively. Ultimately, the word-level TextCNN equipped with the proposed domain-specific lexicon achieved the highest F1 score (99.30%) among the evaluated tokenization strategies. These results suggest that representing drug-related slang as complete lexical units through explicit domain-specific lexical boundaries provides more discriminative features than character- or subword-level tokenization, thereby improving detection performance while reducing false positives.

4.4. Ablation Study

To verify the individual contributions of the core components within the TextCNN model toward drug-related code word recognition, an ablation study was conducted utilizing the control variable method. Taking the fully configured model as the baseline benchmark, individual critical modules were either modified or removed sequentially, while strictly maintaining identical dataset partitioning rules, random seeds, training strategies, and hardware/software environments. This approach quantifies the practical impact of each component based on empirical performance fluctuations. A total of eight experimental configurations were established across three distinct dimensions: the preprocessing layer, the convolutional layer, and the embedding layer. The comparative results are summarized in Table 12.
Regarding the preprocessing module, when the custom tokenization dictionary is removed, the model’s F1-score falls by 0.52 percentage points, with the recall rate exhibiting the most pronounced decline. This suggests that domain-specific lexicons effectively prevent multi-character code words from being fragmented into broken tokens, thereby acting as a pivotal driver for maintaining recall capacity. Conversely, eliminating the code word normalization mapping yields overall metrics on par with the baseline, showing merely minor structural shifts—a microscopic dip in precision coupled with a slight elevation in recall. This indicates that this specific module primarily handles low-frequency variant samples, exerting a constrained influence on overall system metrics.
Among the hyperparameter spaces of the convolutional layer, the performance across the three sets of kernel sizes remains virtually indistinguishable. This observation validates the strong robustness of TextCNN toward convolutional kernel sizes under a word-level tokenization scheme, where the global max-pooling mechanism further dampens any redundant gains from extended sliding windows. In contrast, the number of feature filters exerts a more profound impact on overall performance; allocating 64 filters triggers a performance slide due to insufficient feature extraction capabilities, whereas scaling up to 256 filters induces over-fitting issues driven by an excessive parameter capacity. Consequently, 128 filters represents the optimal equilibrium point balancing empirical accuracy and model generalization.
In the embedding layer, substituting pre-trained vectors with randomly initialized embeddings yields evaluation metrics that fundamentally align with the baseline model, showing only subtle sub-metric fluctuations. This pattern occurs because the target task operates as a heavily keyword-driven binary classification framework. High-frequency code words can be directly mapped via literal surface features during supervised training, causing the semantic priors offered by pre-trained word embeddings to dilute against an overall performance ceiling that is already approaching its upper bound. Thus, the intrinsic value of pre-trained embeddings primarily manifests in accelerating training convergence and reinforcing generalization on low-frequency, long-tail samples.
In conclusion, the custom tokenization dictionary and the number of convolutional filters stand out as the most critical architectural components, exerting a statistically significant influence on model performance. The code word normalization mapping and pre-trained word embeddings primarily benefit edge-case scenarios; although their marginal utility on global metrics remains limited, they possess clear, specialized functional value. Lastly, the convolutional kernel size demonstrates a high degree of robustness under word-level inputs, yielding negligible performance variance upon tuning. The ablation results demonstrate the effectiveness of the proposed design choices in the TextCNN framework. Together, these components contribute to the strong performance of the model in drug-related slang detection.

4.5. Error Dissection and Case Study

To investigate the recognition boundaries of the proposed model and identify directions for future improvement, a qualitative analysis of misclassified samples from the test set was conducted. Despite the model’s strong overall performance, systematic examination of prediction errors reveals potential limitations in semantic understanding. Representative error cases are summarized in Table 13, categorized into four distinct error types.
The first error type is coded language recognition failure, characterized by false negatives in which the model fails to identify legitimate drug-related coded expressions. This typically occurs when certain slang terms appear infrequently in the training data or exhibit regional and temporal variation. For instance, the term “xiao hai”, a regionally specific drug alias, was not successfully identified, suggesting that low-frequency or geographically localized coded expressions remain a coverage challenge for the current model.
The second error type is context-induced misclassification, where the model incorrectly interprets ambiguous terms due to insufficient contextual reasoning. For example, “tin foil” appears in both legitimate culinary contexts and drug consumption scenarios; without broader contextual understanding, the model relies solely on local lexical features, leading to false positives. Similarly, “green” may refer to vegetables or cannabis depending on context, and the model tends to favor the drug-related interpretation in the absence of disambiguating cues.
The third error type is cultural and community-specific expression misunderstanding. Certain terms carry drug-related connotations only within specific subcultures or demographic groups. The term “school uniform”, for instance, may serve as coded drug language within particular communities but carries no such meaning in general usage. The model struggles to distinguish these context-dependent semantic shifts, resulting in over-generalization. The fourth error type is figurative and ironic language misinterpretation. The model lacks the capacity to recognize sarcasm, humor, or hyperbole, defaulting to literal interpretations. For example, the utterance “How many bones do you want, I have stock” carries an obvious humorous tone yet was classified as drug-related. Addressing this class of errors necessitates deeper pragmatic understanding, representing a promising direction for the integration of large pre-trained language models in future work.
Overall, the identified error patterns suggest that while TextCNN excels at local pattern recognition in short texts, its performance is constrained by limited contextual modeling capacity and sensitivity to low-frequency or culturally specific expressions. These findings provide concrete guidance for model refinement, including data augmentation for rare coded terms, context-aware feature integration, and the incorporation of pragmatic reasoning capabilities.

4.6. Generalization Analysis

4.6.1. Cross-Platform and Temporal Robustness

To evaluate the generalization capability and robustness of the proposed model under realistic application scenarios, two representative social media platforms were selected for cross-platform evaluation: Weibo, representative of short-text content, and WeChat Official Accounts, representative of long-form articles. Performance metrics for each platform are summarized in Table 14.
As shown in Table 14, the model maintains consistently high performance across both platforms, with accuracy differing by less than 0.1% between the two settings. On Weibo short texts, the model achieves an F1-score of 0.9983, while on WeChat long-form content, it attains an F1-score of 0.9978. This marginal performance gap suggests that the multi-scale convolutional feature extraction mechanism of TextCNN is effective not only at capturing concise coded expressions in short texts but also at localizing semantically relevant patterns within longer and more complex documents. These results demonstrate strong cross-platform generalization ability of the proposed approach.
Temporal Robustness Analysis. Given the dynamic and rapidly evolving nature of drug-related coded language on social media, a three-month longitudinal evaluation was conducted to examine temporal performance degradation. As illustrated in Figure 7, the model sustains strong performance during the first month, with an accuracy of approximately 0.998. However, a gradual decline is observed in subsequent months, with accuracy dropping to 0.986 in the second month and further to 0.963 by the third month.
This performance degradation is attributable to the inherent linguistic drift of drug-related coded expressions: criminal communities continuously coin new slang terms or reassign novel meanings to existing vocabulary, a phenomenon that the static training corpus is unable to anticipate. As the temporal gap between training data collection and deployment widens, the model’s coverage of emerging coded expressions diminishes accordingly. These findings highlight the necessity of periodic model retraining with updated data and suggest that incorporating online learning or continual learning mechanisms could be a promising direction for maintaining detection efficacy over time.

4.6.2. Zero-Shot Out-of-Vocabulary (OOV) Stress Test

To expose the model’s architectural boundaries against entirely unseen jargon types, a strict zero-shot out-of-vocabulary (OOV) test set was synthesized. We isolated 45 newly emerged narcotics slang terms across six lexical paradigms (e.g., noun hijacking, alphanumeric encodings, and food aliases) along with 20 benign daily control terms, generating a pristine testing block of 285 samples (225 positive, 60 negative) with zero training-loop overlap.
Under this absolute zero-shot isolation, the TextCNN maintains a perfect Precision of 1.0000, ensuring a zero false-positive rate on benign text. However, its Recall falls precipitously from the baseline 0.9960 down to 0.2578, dragging the total Accuracy down to 0.4140 (with an AUC of 0.8386). This acute performance plunge demonstrates that shallow neural architectures like TextCNN rely extensively on static lexical boundaries and verbatim collocations. While it can infer vague risk signals through surrounding structural indicators (e.g., transaction prompts like “purity” or “supply”), it cannot robustly decipher localized novel slang without explicit prior adaptation. These findings highlight an important limitation of lexicon-dependent TextCNN models when encountering previously unseen slang expressions, suggesting that continual learning or incremental model updating is necessary to maintain long-term detection performance.

4.7. Summary

This section presented a comprehensive experimental evaluation of the proposed TextCNN-based model for drug-related coded language detection. The model achieves an F1 score of 0.9930 on the test set, with an AUC of 0.9997, demonstrating strong and consistent detection performance. Comparative experiments against BERT-Base-Chinese, Chinese-RoBERTa-wwm-ext, SVM, and Naive Bayes confirm that TextCNN outperforms both large pre-trained language models and conventional machine learning baselines on this task, validating its suitability for short-text coded language recognition driven by local semantic pattern matching.
Error case analysis identifies four principal failure modes: (1) recognition failure for low-frequency or regionally specific coded terms; (2) context-induced misclassification of lexically ambiguous expressions; (3) difficulty in interpreting culturally or community-specific language; and (4) inability to recognize figurative, ironic, or humorous utterances. These findings provide concrete guidance for targeted model improvement in future work.
Generalization experiments across Weibo and WeChat platforms confirm that the model maintains stable performance in both short- and long-text scenarios, with a cross-platform accuracy difference of less than 0.1%. However, the longitudinal evaluation reveals a gradual performance decline over three months, attributable to the continuous linguistic evolution of drug-related coded expressions. This underscores the need for periodic model retraining and motivates future exploration of continual learning strategies to sustain long-term detection efficacy.

5. Conclusions

This study addressed the challenging problem of drug-related coded language detection on social media platforms by proposing a lightweight TextCNN-based intelligent detection framework. First, a dedicated dataset of 10,000 annotated samples was constructed integrating judicial documents, police case reports, multi-platform social media texts, and a lexicon-based augmentation strategy, achieving a high double-blind inter-annotator agreement of Kappa = 0.91. Second, a multi-scale TextCNN model featuring parallel convolutional filters (3, 4, 5) was designed to capture local n-gram semantic features with maintaining low parameter complexity and computational cost. Comprehensive experiments demonstrated that the proposed model achieves outstanding performance, with F1-score reaching 0.9930 (AUC = 0.9997), significantly outperforming heavy pre-trained language models like BERT and RoBERTa, as well as traditional machine learning baselines.
Despite its success, the model exhibits inherent limitations in handling low-frequency or regionally out-of-vocabulary (OOV) terms, complex pragmatic reasoning like irony, and performance degradation caused by dynamic language drift over time. Future work will focus on three directions: expanding the dataset via multi-platform crowdsourcing and dynamic lexicon updates; investigating hybrid architectures that fuse TextCNN’s local feature extraction with Transformer-based global semantics (such as BERT and ERNIE [31]) to enhance contextual reasoning; and developing online incremental learning mechanisms paired with periodic data refresh cycles to sustain long-term sensitivity to evolving coded expressions without full retraining.

Author Contributions

Conceptualization, T.L. and Y.D.; methodology, T.L.; software, X.Y.; validation, T.L., Y.D. and X.Y.; formal analysis, T.L.; investigation, X.Y.; resources, Y.D.; data curation, X.Y.; writing—original draft preparation, T.L.; writing—review and editing, T.L.; visualization, X.Y.; supervision, Y.D.; project administration, Y.D.; funding acquisition, Y.D. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by Key R&D Projects of Sichuan Science and Technology Program (Grant no. 2024YFFK0123), and was supported in part by Intelligent Policing Key Laboratory of Sichuan Province (No. ZNJW2025KFQN003), the Sichuan Police College Doctoral Research Start-up Fund Project (No. 2025XNBSQD04), and the Luzhou Science and Technology Plan Project (No. 2024JYJ028).

Data Availability Statement

The original contributions presented in this study are included in the article. Further inquiries can be directed to the corresponding authors.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Lin, S.Y.; Chien, S.Y.; Chen, Y.Z. Combating online malicious behavior: Integrating machine learning and deep learning methods for harmful news and toxic comments. Inf. Syst. Front. 2024. [Google Scholar] [CrossRef] [Scilit]
  2. Khan, U.; Khan, S.; Rizwan, A.; Atteia, G.; Jamjoom, M.M.; Samee, N.A. Aggression detection in social media from textual data using deep learning models. Appl. Sci. 2022, 12, 5083. [Google Scholar] [CrossRef] [Scilit]
  3. Nahar, S.; Any, O.H.; Afrin, M.; Laila, R. Understanding of drug addiction drug abuse and popular drug slang: A narrative review. J. Natl. Inst. Neurosci. Bangladesh 2022, 8, 84–89. [Google Scholar]
  4. Hu, C.; Yin, M.; Liu, B.; Li, X.; Ye, Y. Detection of illicit drug trafficking events on Instagram: A deep multimodal multilabel learning approach. In Proceedings of the 30th ACM International Conference on Information and Knowledge Management (CIKM 2021), Gold Coast, Australia, 1–5 November 2021; pp. 3838–3846. [Google Scholar]
  5. Mackey, T.K.; Kalyanam, J.; Katsuki, T.; Kuzmenko, E.; Gupta, R. Solution to detect, classify, and report illicit online marketing and sales of controlled substances via Twitter: Using machine learning and web forensics to combat digital opioid access. J. Med. Internet Res. 2018, 20, e10029. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  6. Sundaram, A.; Subramaniam, H.; Ab Hamid, S.H.; Nor, A.M. A systematic literature review on social media slang analytics in contemporary discourse. IEEE Access 2023, 11, 132457–132471. [Google Scholar] [CrossRef] [Scilit]
  7. Liu, S.; Gui, D.Y.; Zuo, Y.; Dai, Y. Good slang or bad slang? Embedding internet slang in persuasive advertising. Front. Psychol. 2019, 10, 1251. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  8. Holbrook, E.; Wiskur, B.; Nagykaldi, Z. Discovering drug slang on social media: A Word2Vec approach with Reddit data. arXiv 2024, arXiv:2405.01234. [Google Scholar]
  9. Deng, J.; Zhou, J.; Sun, H.; Zheng, C.; Mi, F.; Meng, H.; Huang, M. COLD: A benchmark for Chinese offensive language detection. In Proceedings of the Findings of the Association for Computational Linguistics: EMNLP 2022, Abu Dhabi, United Arab Emirates, 7–11 December 2022; pp. 3086–3100. [Google Scholar]
  10. Ren, R.; Zhao, J.; Sun, X.; Li, Q. NLP-based review for toxic comment detection tailored to the Chinese cyberspace. arXiv 2025, arXiv:2601.14721. [Google Scholar]
  11. Wu, L.; Morstatter, F.; Liu, H. SlangSD: Building, expanding and using a sentiment dictionary of slang words for short-text sentiment classification. Lang. Resour. Eval. 2018, 52, 839–852. [Google Scholar] [CrossRef] [Scilit]
  12. Gadusu, S.R.; McGinty, H. Semantic similarity for drug slang identification: A comparative analysis of Word2Vec and BERT. In Proceedings of the 13th Knowledge Capture Conference (K-CAP 2025), Austin, TX, USA, 2–4 December 2025; pp. 190–193. [Google Scholar]
  13. Asim, M.; Waqar, M.; Alam, I. A comparative analysis of deep learning methods for slang detection in Twitter data. Spectr. Eng. Sci. 2025, 3, 254–270. [Google Scholar]
  14. Minaee, S.; Kalchbrenner, N.; Cambria, E.; Nikzad, N.; Chenaghlu, M.; Gao, J. Deep learning-based text classification: A comprehensive review. ACM Comput. Surv. 2021, 54, 62. [Google Scholar] [CrossRef] [Scilit]
  15. Li, Q.; Peng, H.; Li, J.; Xia, C.; Yang, R.; Sun, L.; Yu, P.S.; He, L. A survey on text classification: From traditional to deep learning. ACM Trans. Intell. Syst. Technol. 2022, 13, 31. [Google Scholar] [CrossRef] [Scilit]
  16. Devlin, J.; Chang, M.W.; Lee, K.; Toutanova, K. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (NAACL-HLT 2019), Minneapolis, MN, USA, 2–7 June 2019; pp. 4171–4186. [Google Scholar]
  17. Hu, H.; Phan, N.; Geller, J.; Iezzi, S.; Vo, H.; Dou, D.; Chun, S.A. An ensemble deep learning model for drug abuse detection in sparse Twitter-sphere. In Proceedings of the MedInfo 2019, Lyon, France, 25–30 August 2019; pp. 163–167. [Google Scholar]
  18. Tassone, J.; Yan, P.; Simpson, M.; Mendhe, C.; Mago, V.; Choudhury, S. Utilizing deep learning and graph mining to identify drug use on Twitter data. BMC Med. Inform. Decis. Mak. 2020, 20, 304. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  19. Kim, Y. Convolutional neural networks for sentence classification. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP 2014), Doha, Qatar, 25–29 October 2014; pp. 1746–1751. [Google Scholar]
  20. Soni, S.; Chouhan, S.S.; Rathore, S.S. TextConvoNet: A convolutional neural network based architecture for text classification. Appl. Intell. 2023, 53, 14249–14268. [Google Scholar]
  21. Shiozawa, K.; Hayashi, H.; Akiyama, S.; Katsurai, M. Detecting slang on the dark web based on word co-occurrence relationships in anchor texts. In Proceedings of the 2026 40th International Conference on Information Networking (ICOIN 2026), Chiang Mai, Thailand, 14–16 January 2026; pp. 347–352. [Google Scholar]
  22. Hossain, N.; Tran, T.T.T.; Kautz, H. Discovering political slang in readers’ comments. In Proceedings of the 12th International AAAI Conference on Web and Social Media (ICWSM 2018), Stanford, CA, USA, 25–28 June 2018; pp. 596–599. [Google Scholar]
  23. Sun, Z.; Hu, Q.; Gupta, R.; Zemel, R.; Xu, Y. Toward informal language processing: Knowledge of slang in large language models. In Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (NAACL-HLT 2024), Mexico City, Mexico, 16–21 June 2024; pp. 1683–1701. [Google Scholar]
  24. Carpenter, K.A.; Samori, I.A.; Kiang, M.V.; Humphreys, K.; Lembke, A.; Eichstaedt, J.C.; Altman, R.B. Large language models can disambiguate opioid slang on social media. arXiv 2026, arXiv:2603.10313. [Google Scholar]
  25. Patel, L.; Alsobeh, A. SlangLLM: Dynamic detection and context/filtering of slang in NLP applications. In Proceedings of the 1st International Conference on Secure IoT, Assured and Trusted Computing (SATC 2025), Orlando, FL, USA, 18–20 May 2025; pp. 1–6. [Google Scholar]
  26. Aloraini, A.M.; Batista-Navarro, R.T.; Nenadic, G.; Schlegel, V. The SlangTrack dataset: Supporting the detection of words used in slang senses. In Proceedings of the 6th International Workshop on Computational Approaches to Language Change (LChange 2026), Gothenburg, Sweden, 22–23 May 2026; pp. 1–19. [Google Scholar]
  27. Hu, C.; Liu, B.; Ye, Y.; Li, X. Fine-grained classification of drug trafficking based on Instagram hashtags. Decis. Support Syst. 2023, 165, 113896. [Google Scholar] [CrossRef] [Scilit]
  28. Wei, J.; Zou, K. EDA: Easy data augmentation techniques for boosting performance on text classification tasks. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP 2019), Hong Kong, China, 3–7 November 2019; pp. 6383–6389. [Google Scholar]
  29. Mikolov, T.; Sutskever, I.; Chen, K.; Corrado, G.S.; Dean, J. Distributed representations of words and phrases and their compositionality. In Proceedings of the Advances in Neural Information Processing Systems (NeurIPS 2013), Lake Tahoe, NV, USA, 5–10 December 2013; pp. 3111–3119. [Google Scholar]
  30. Cui, Y.; Che, W.; Liu, T.; Qin, B.; Yang, Z.; Wang, S.; Hu, G. Pre-training with whole word masking for Chinese BERT. IEEE/ACM Trans. Audio Speech Lang. Process. 2021, 29, 3504–3514. [Google Scholar] [CrossRef] [Scilit]
  31. Zhang, Z.; Han, X.; Liu, Z.; Jiang, X.; Sun, M.; Liu, Q. ERNIE: Enhanced language representation with informative entities. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics (ACL 2019), Florence, Italy, 28 July–2 August 2019; pp. 1441–1451. [Google Scholar]
Figure 1. Architecture of the proposed drug slang detection framework.
Figure 1. Architecture of the proposed drug slang detection framework.
Electronics 15 03138 g001
Figure 2. Workflow of drug slang corpus construction.
Figure 2. Workflow of drug slang corpus construction.
Electronics 15 03138 g002
Figure 3. TextCNN model architecture.
Figure 3. TextCNN model architecture.
Electronics 15 03138 g003
Figure 4. Confusion matrix of the TextCNN model on the test set.
Figure 4. Confusion matrix of the TextCNN model on the test set.
Electronics 15 03138 g004
Figure 5. Radar chart of comprehensive performance.
Figure 5. Radar chart of comprehensive performance.
Electronics 15 03138 g005
Figure 6. Comparison of missed sample counts across models. * Best model.
Figure 6. Comparison of missed sample counts across models. * Best model.
Electronics 15 03138 g006
Figure 7. Performance trend chart of the model over three months.
Figure 7. Performance trend chart of the model over three months.
Electronics 15 03138 g007
Table 1. Representative examples of collected data.
Table 1. Representative examples of collected data.
Sentences Containing Drug Slang TermsSource (Account)
I’m a pilot, he’s a captain, she’s a farmer.WeChat Official Account (People’s Daily Online)
I’d like some dry pot, do you have any pork over there?WeChat Official Account (Capital University Youth Red Ribbon)
I’m the captain. I’ve grown some grass. Any friends want to be pilots?WeChat Official Account (Hubei Anti-Drug)
Electronic cigarettes, express delivery, high-altitude flight, no head rush, unconditional returns.WeChat Official Account (Hubei Anti-Drug)
I’m the captain, I still have fuel here, looking for a few pilots.Weibo (China Anti-Drug Online)
Do you have any “red wine” there?Weibo (Oriental Red People’s Procuratorate)
Newly arrived trousers with great cut, and top-grade red wine, welcome to try.Douyin (Xinjiang Anti-Drug)
Got some big meat—cold, hot, soft, hard, all kinds.Douyin (Yuelu Anti-Drug)
Want a late-night snack? Got some pork.Douyin (Guangzhou Anti-Drug)
Table 2. Representative sentences generated from the drug slang lexicon.
Table 2. Representative sentences generated from the drug slang lexicon.
Generated SentencesDrug Slang Terms
Have some “3-plus-1” tonight, let’s have fun.3-plus-1
My pigeons are great—dare to try?Pigeons
This batch of “US dollars” is top quality, want some tonight?US dollars
Want some G-water? Strong effects, give it a shot?G-water
Bro, the “meow-meow” stock is plentiful lately—try some?Meow-meow
This batch of “butterflies” is excellent—everyone try it.Butterflies
Tonight, try this “Lamborghini”—guaranteed satisfaction.Lamborghini
This batch of “Wuliangye” is absolutely top grade.Wuliangye
Changzhijin is a harmful substance.Changzhijin
Table 3. Cohen’s Kappa coefficients by annotation stage.
Table 3. Cohen’s Kappa coefficients by annotation stage.
Annotation StageKappa Coefficient
Pre-annotation0.82
Formal annotation0.91
Table 4. Sample sentence annotations from the dataset.
Table 4. Sample sentence annotations from the dataset.
SentenceLabel
Want some new excitement? The effects are pretty good.1
Coughed a couple of times this morning—mom and dad specially made cough syrup and brought it to school.0
Heard this batch of cough syrup is premium quality, want to try some?1
Bro, this batch of injections is way better than last time—let’s arrange for tonight.1
Went to the square today and saw the pigeons—they were so cute!0
Man, this “little white” is very pure, want some?1
Interested in tasting some “wind is tight”? I heard the flavor is pretty good.1
How does the convenience-store coffee I just grabbed taste like cough syrup? Awful.0
I’ve got fresh goods here, quality is beyond question—give it a try.1
Table 5. TextCNN model hyperparameters.
Table 5. TextCNN model hyperparameters.
ParameterValue
Maximum sequence length100
Word vector dimensionality100
Convolutional kernel sizes3, 4, 5
Number of kernels per size128
Pooling methodGlobal max-pooling
Fully connected layer neurons128
Dropout rate0.5
OptimizerAdam
Initial learning rate0.001
Loss functionCross-entropy loss
Batch size64
Number of training epochs10
Train:Val:Test split8:1:1
Table 6. Experimental environment configuration.
Table 6. Experimental environment configuration.
ConfigurationSpecification
Operating SystemUbuntu 20.04 LTS
CPUIntel Xeon Gold 5218 @ 2.30 GHz (Intel, Santa Clara, CA, USA)
GPUNVIDIA Tesla V100 32 GB (NVIDIA, Santa Clara, CA, USA)
Memory128 GB
Deep Learning FrameworkPyTorch 1.10.0
Python Version3.8.10
CUDA Version11.3
Table 7. Distribution of the experimental dataset.
Table 7. Distribution of the experimental dataset.
DatasetSample SizeProportion
Training Set800080%
Validation Set100010%
Test Set100010%
Table 8. Performance metrics of the TextCNN model on the test set.
Table 8. Performance metrics of the TextCNN model on the test set.
MetricValue
Accuracy0.9930
Precision0.9900
Recall0.9960
F1-Score0.9930
AUC0.9997
Table 9. Experimental configurations and hyperparameters of comparison models.
Table 9. Experimental configurations and hyperparameters of comparison models.
ModelMax
Length
Tokenizer & RepresentationOptimizerWeight
Decay
Batch
Size
Epochs
TextCNN100Jieba (Word)Adam0.016410
BERT-Base-Chinese512WordPiece (Subword)AdamW0.005165
Chinese-RoBERTa-wwm-ext512WordPiece (Subword)AdamW0.01165
TinyBERT512WordPiece (Char)AdamW0.01325
MacBERT512WordPiece (Char)AdamW0.01165
DistilBERT512WordPiece (Subword)AdamW0.01165
SVMJieba + TF-IDF (5000-dim)Single
Naive Bayes (NB)Jieba + TF-IDF (5000-dim)Single
Table 10. Performance comparison of different models on the test set.
Table 10. Performance comparison of different models on the test set.
ModelAccuracyPrecisionRecallF1 ScoreAUC
TextCNN0.99300.99000.99600.99300.9997
BERT-Base-Chinese0.98900.98920.98900.98900.9998
Chinese-RoBERTa-wwm-ext0.98900.98920.98900.98900.9998
SVM0.96901.00000.93740.96770.9907
Naive Bayes0.96800.99780.93740.96670.9920
TinyBERT0.99100.99100.99100.99100.9998
MacBERT0.98900.98920.98900.98900.9999
DistilBERT0.98900.98920.98900.98900.9998
Table 11. Quantitative comparison of computational efficiency and hardware deployment costs.
Table 11. Quantitative comparison of computational efficiency and hardware deployment costs.
 ModelParameters
(M)
Model Size
(MB)
Latency
(ms)
Throughput
(QPS)
BERT-Base-Chinese102.30390.2028.4266.04
Chinese-RoBERTa-wwm-ext102.30390.2034.6460.10
MacBERT102.30390.2029.6769.37
DistilBERT-Base-Multilingual135.33516.2714.63144.46
TinyBERT11.4243.593.76735.57
TextCNN (Ours)0.220.841.262698.02
SVM0.611.0625,885.97
Naive Bayes0.570.84115,475.58
Table 12. Performance comparison of TextCNN components in the ablation study.
Table 12. Performance comparison of TextCNN components in the ablation study.
ConfigurationAccuracyPrecisionRecallF1-ScoreAUC
TextCNN (full Configuration)0.99300.99000.99600.99300.9997
without Custom Tokenization Dictionary0.98800.99380.98180.98780.9997
Kernel Size [2, 3, 4]0.98700.98720.97780.98670.9997
Kernel Size [5, 6, 7]0.99000.98600.99390.98990.9997
Filter Number = 640.98800.99100.97980.98780.9998
Filter Number = 1280.99000.99390.98590.98990.9998
Filter Number = 2560.98800.99300.97980.98780.9997
Randomly Initialized Word Embeddings0.99100.99000.98790.99090.9998
Table 13. Error case analysis of the TextCNN model.
Table 13. Error case analysis of the TextCNN model.
Original TextTruePredError AnalysisError Type
I have some xiao hai here, want to try it?10Failure to recognize “xiao hai” as an explicit drug-related coded termCoded language recognition failure
This batch of tin foil heats up really well, let’s all try it together.01Tin foil is used in both normal cooking and drug consumption contexts; the model over-sensitively classifies a culinary reference as drug-relatedContext-induced misclassification
This green recipe is really simple and tastes great.01“green” may refer to vegetables (normal) or cannabis (drug); without sufficient context, the model favors the drug-related interpretationContext-induced misclassification
Want to try the newly arrived school uniform? Works great.01“School uniform” (jiao fu) may serve as drug-related coded language in specific subcultures but carries no such meaning here; the model over-generalizesCultural expression misunderstanding
How many bones do you want? I have stock.01The model lacks the capacity to recognize humor and irony, defaulting to a literal interpretation of the utteranceFigurative language misinterpretation
I have some cold stuff here, very pure. Coming or not?01Likely a hyperbolic description of a normal item, but the model interprets it as drug-related coded languageHyperbolic expression misinterpretation
Table 14. Model performance comparison across different platform content types.
Table 14. Model performance comparison across different platform content types.
Platform TypeAccuracyPrecisionRecallF1-Score
Weibo (short-text)0.99830.99820.99840.9983
WeChat Official Accounts (long-text)0.99780.99790.99770.9978
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Leng, T.; Dai, Y.; Yan, X. Lightweight and Effective Coded-Slang Detection for Cyber-Drug Intelligence. Electronics 2026, 15, 3138. https://doi.org/10.3390/electronics15143138

AMA Style

Leng T, Dai Y, Yan X. Lightweight and Effective Coded-Slang Detection for Cyber-Drug Intelligence. Electronics. 2026; 15(14):3138. https://doi.org/10.3390/electronics15143138

Chicago/Turabian Style

Leng, Tao, Yong Dai, and Xinyang Yan. 2026. "Lightweight and Effective Coded-Slang Detection for Cyber-Drug Intelligence" Electronics 15, no. 14: 3138. https://doi.org/10.3390/electronics15143138

APA Style

Leng, T., Dai, Y., & Yan, X. (2026). Lightweight and Effective Coded-Slang Detection for Cyber-Drug Intelligence. Electronics, 15(14), 3138. https://doi.org/10.3390/electronics15143138

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop