Text command security detection method and device
By performing semantic structure analysis and risk assessment on the current text instruction, and combining it with the semantic consistency assessment of historical text instructions, this method solves the problem of poor detection results caused by focusing only on the semantic information of the current text instruction in existing technologies, and realizes the identification and detection of hidden risk instructions with incoherent contextual semantics.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XIAN UNIV OF POSTS & TELECOMM
- Filing Date
- 2026-04-08
- Publication Date
- 2026-07-10
AI Technical Summary
Existing technologies for text instruction security detection only focus on the semantic information of the current text instruction itself, resulting in poor detection performance and an inability to effectively identify hidden risk instructions with inconsistent contextual semantics.
The current text instruction is subjected to semantic structure analysis and risk assessment by a pre-trained text processing model. Semantic consistency assessment is performed by combining the semantic structure information of historical text instructions. Dynamic thresholds are calculated to comprehensively assess the security of the current text instruction.
It improves the accuracy of text command security detection, can identify hidden risk commands with inconsistent contextual semantics, and enhances detection performance.
Smart Images

Figure CN122366448A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information security technology, specifically to a method and apparatus for detecting text commands. Background Technology
[0002] With the widespread application of large language models in terminal interaction scenarios, the need for security detection of user-input text commands is becoming increasingly prominent. Current text command security detection solutions only focus on the semantic information of the text command itself, resulting in poor security detection performance. Summary of the Invention
[0003] This application provides a text instruction security detection method and apparatus, which can overcome the vulnerability of security detection based solely on the semantic information of the current text instruction itself, identify hidden risk instructions with inconsistent contextual semantics, and improve the text instruction security detection effect.
[0004] This application provides a text instruction security detection method, including:
[0005] Receive the current text instruction;
[0006] The current text instruction is subjected to semantic structure analysis and risk assessment by a pre-trained text processing model to obtain the current semantic structure information and risk assessment results of the current text instruction.
[0007] Obtain historical semantic structure information of historical text instructions, and based on the current semantic structure information and the historical semantic structure information, perform semantic consistency evaluation on the current text instructions and historical text instructions to obtain the current semantic consistency evaluation result;
[0008] Based on the risk assessment results and the current semantic consistency assessment results, the current text instruction is subjected to security detection to obtain the security detection results of the current text instruction.
[0009] Further, in the text instruction security detection method described above, the risk assessment result includes a risk probability, the current semantic consistency assessment result includes a current semantic consistency assessment score, and the step of performing security detection on the current text instruction based on the risk assessment result and the current semantic consistency assessment result to obtain the security detection result of the current text instruction includes:
[0010] Obtain the historical semantic consistency results corresponding to multiple historical text instructions, wherein the historical semantic consistency results include historical semantic consistency scores;
[0011] Calculate the mean and standard deviation of the multiple historical semantic consistency scores;
[0012] Calculate the dynamic threshold based on the mean and the standard deviation;
[0013] Based on the risk probability, the current semantic consistency score, and the dynamic threshold, the current text instruction is subjected to security detection to obtain the security detection result of the current text instruction.
[0014] Further, in the text instruction security detection method described above, the step of performing security detection on the current text instruction based on the risk probability, the current semantic consistency score, and the dynamic threshold to obtain the security detection result of the current text instruction includes:
[0015] If the risk probability is greater than the preset probability and the current semantic consistency score is less than the dynamic threshold, then the current text instruction is determined to be a risky text instruction.
[0016] If the risk probability is less than or equal to the preset probability, or the current semantic consistency score is greater than or equal to the dynamic threshold, then the current text instruction is determined to be a safe text instruction.
[0017] Furthermore, the text instruction security detection method described above further includes:
[0018] If the current text instruction is a safe text instruction, then the execution of the current text instruction is permitted;
[0019] If the current text instruction is a risky text instruction, then the current text instruction will not be executed.
[0020] Furthermore, the text instruction security detection method described above further includes:
[0021] If the current semantic structure information and risk assessment result of the current text instruction are obtained through a pre-trained text processing model within a preset time period, then the step of obtaining the historical semantic structure information of historical text instructions is executed.
[0022] If the current semantic structure information and risk assessment result of the current text instruction are not obtained through the pre-trained text processing model within the preset time period, the model inference is determined to have timed out, the execution of the current text instruction is allowed, and an identifier representing the model inference timeout is set for the current text instruction.
[0023] Furthermore, the text instruction security detection method described above further includes:
[0024] If the execution of the current text instruction is permitted, the instruction execution agent detects whether the current text instruction carries the identification information.
[0025] If the current text instruction does not carry the identification information, then the instruction execution agent executes the current text instruction according to the first execution strategy;
[0026] If the current text instruction carries the identification information, then the instruction execution agent executes the current text instruction according to the second execution strategy.
[0027] Furthermore, in the text instruction security detection method described above, the step of calculating the dynamic threshold based on the mean and the standard deviation includes:
[0028] The dynamic threshold is calculated using the following formula:
[0029]
[0030] in, Indicates a dynamic threshold. This represents the mean. This represents the configurable dynamic threshold coefficient. It represents the standard deviation.
[0031] Furthermore, in the text instruction security detection method described above, the text processing model includes an encoding module, a semantic structure analysis module, and a risk assessment module. The step of performing semantic structure analysis and risk assessment on the current text instruction using a pre-trained text processing model to obtain the current semantic structure information and risk assessment result of the current text instruction includes:
[0032] The current text instruction is encoded by the encoding module to obtain semantic features;
[0033] The semantic structure analysis module performs semantic structure analysis on the semantic features to obtain the semantic structure information of the current text instruction.
[0034] The risk assessment module performs risk assessment on the semantic features to obtain the risk assessment result of the current text instruction.
[0035] Furthermore, in the text instruction security detection method described above, the step of performing a semantic consistency assessment on the current text instruction and the historical text instructions based on the current semantic structure information and the historical semantic structure information to obtain the current semantic consistency assessment result includes:
[0036] When multiple historical text instructions exist, determine the semantic similarity between the current semantic structure information and each historical semantic structure information;
[0037] Weights are assigned to different historical text commands, and the weights decrease as the interval between the time the historical text command was received and the current time increases.
[0038] The semantic similarity and corresponding weights are used to perform weighted fusion to obtain the current semantic consistency evaluation result.
[0039] This application also provides a text instruction security detection method apparatus, including:
[0040] The text receiving module is used to receive the current text command;
[0041] The text processing module is used to perform semantic structure analysis and risk assessment on the current text instruction using a pre-trained text processing model, so as to obtain the current semantic structure information and risk assessment results of the current text instruction.
[0042] The semantic evaluation module is used to obtain the historical semantic structure information of historical text instructions, and to evaluate the semantic consistency between the current text instruction and the historical text instructions based on the current semantic structure information and the historical semantic structure information, so as to obtain the current semantic consistency evaluation result.
[0043] The text detection module is used to perform security detection on the current text instruction based on the risk assessment result and the current semantic consistency assessment result, and obtain the security detection result of the current text instruction.
[0044] The text instruction security detection method and apparatus provided in this application receive a current text instruction; perform semantic structure analysis and risk assessment on the current text instruction using a pre-trained text processing model to obtain the current semantic structure information and risk assessment result of the current text instruction; acquire the historical semantic structure information of historical text instructions, and perform semantic consistency assessment between the current text instruction and historical text instructions based on the current semantic structure information and the historical semantic structure information to obtain the current semantic consistency assessment result; and perform security detection on the current text instruction based on the risk assessment result and the current semantic consistency assessment result to obtain the security detection result of the current text instruction. When performing security detection on the current text instruction, in addition to considering the risk assessment, the method also combines historical semantic structure information to perform semantic consistency assessment between the current text instruction and historical text instructions. Combining the risk assessment result and the semantic consistency assessment result for comprehensive security detection of the current text instruction can compensate for the vulnerabilities of security detection based solely on the semantic information of the current text instruction itself, and can identify hidden risk instructions with inconsistent contextual semantics, thereby improving the effectiveness of text instruction security detection. Attached Figure Description
[0045] Figure 1 A flowchart illustrating the text instruction security detection method provided in this application embodiment;
[0046] Figure 2 A schematic diagram of the structure of a pre-trained text processing model provided in the embodiments of this application;
[0047] Figure 3 This is a schematic diagram of the structure of the text instruction security detection device provided in the embodiments of this application;
[0048] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0049] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0050] In this embodiment, the description will focus on a text command security detection device, which can be integrated into an electronic device with a storage unit and a microprocessor or similar device. This electronic device can be a computing-limited device such as a smart terminal, in-vehicle equipment, or an edge box.
[0051] Please see Figure 1 , Figure 1 This is a flowchart illustrating a text instruction security detection method provided in an embodiment of this application. The method includes:
[0052] In step 101, the current text instruction is received.
[0053] The current text instruction is a piece of natural language text that the user inputs into the electronic device, used to issue tasks, initiate questions and answers, or perform operations. For example, the current text instruction could be "open the car window".
[0054] The text command security detection device monitors the terminal interaction interface in real time through the text receiving module, capturing the original text string input by the user; performs basic cleaning processing on the original text string, including removing leading and trailing spaces and filtering special invalid characters; adds a receiving timestamp and session ID to the processed text, and caches it as the current text command to be inferred.
[0055] After caching the current text instruction, the text receiving module further performs preprocessing operations such as text cleaning, word segmentation, and uniform length truncation or padding to generate a token-id sequence and position code for the current text instruction. The token-id sequence and position code are then output to the text processing module of the text instruction security detection device in a zero-copy manner, avoiding data copying overhead and improving processing efficiency.
[0056] It should be noted that after natural language text is segmented, each smallest semantic unit (token) is assigned a predefined unique numerical number, forming an ordered string of numbers called a token-id sequence. The purpose of the token-id sequence is to convert human language, such as "open the car window," into a numerical sequence that the model can compute.
[0057] Positional encoding assigns a corresponding position vector to each position in the token-id sequence, identifying the order of each token in the text and enabling the model to perceive the text's word order and syntactic structure. The purpose of positional encoding is to tell the model which word comes first and which comes last, ensuring correct semantic structure analysis.
[0058] After completing text cleaning, word segmentation, and uniform length truncation or padding, the text receiving module generates a matching attention mask in addition to generating the token-id sequence and position encoding mentioned above. The attention mask is used to distinguish between valid semantic content in the text and placeholder characters that are not filled with uniform length, and to shield invalid placeholder data from interference with subsequent model inference. The three sets of preprocessed data are uniformly encapsulated and transmitted to the text processing module in a zero-copy manner.
[0059] To meet the need for real-time user input monitoring, the text receiving module runs as a user-space daemon and can be deployed on ARM SoC or x86 architecture edge device CPUs. The text receiving module employs a dedicated operation strategy to avoid resource contention with other business processes, keeping memory usage consistently below 20MB. For harsh operating environments such as automotive applications, the module is compatible with industrial-grade storage chips with an operating temperature range of -40℃ to 85℃, ensuring service stability in extreme scenarios such as immediate restart after vehicle shutdown and sudden temperature changes.
[0060] The text receiving module is written in C++ and statically compiled, featuring zero external dependencies and allowing direct embedding into system images for flashing and deployment. To ensure compatibility with various input channels such as voice assistants, in-vehicle systems, and customer service robots, the module provides three access interfaces: a WebSocket interface for browsers and mini-programs, a TCP interface for native applications, and a Unix Domain Socket interface for local inter-process communication. The module supports a maximum data frame length of 8KB, covering typical interaction scenarios involving five rounds of dialogue. Output data is uniformly encapsulated into a RawReq structure, packaging the user ID, historical dialogue array, and current dialogue statement in one go, facilitating zero-copy reading by downstream text processing modules.
[0061] - Regarding data verification and exception handling, if the text receiving module receives illegal UTF-8 encoded data, it immediately returns a 1001 error code to block invalid data from flowing into the subsequent processing flow; if the length of a single round of text exceeds 512 bytes, it automatically performs truncation processing and records the log to avoid abnormal model inference due to excessively long prompt words; if the receiving buffer overflows, the module only restarts the corresponding Socket connection, rather than restarting the entire service, to achieve automatic self-healing of local faults.
[0062] In step 102, the current text instruction is subjected to semantic structure analysis and risk assessment by a pre-trained text processing model to obtain the current semantic structure information and risk assessment results of the current text instruction.
[0063] The text processing module, as the core execution unit of this step, belongs to the same process and address space as the text receiving module. It eliminates the need for cross-process and cross-network data transmission, reducing data interaction overhead at the source. The text processing module directly receives three sets of complete standardized data output from the preprocessed text receiving module: a token-id sequence, a positional encoding, and an attention mask, completing the reception of all basic data. Then, following the model inference specifications, it inputs the standard input data required by the text processing model—the token-id sequence and the attention mask—into the pre-trained text processing model. The positional encoding is simultaneously embedded within the model to participate in semantic feature extraction calculations, eliminating the need for additional repetitive processing. Relying on the model's internal neural network inference logic, the module extracts the deep semantic structure features of the current text instruction, generating standardized and interpretable current semantic structure information. Simultaneously, it quantifies the security risk level of the current text instruction, obtaining the corresponding risk assessment result. The entire data flow is efficient and smooth, with no redundant processing steps, adapting to the low-latency requirements of edge scenarios. After obtaining the current semantic structure information and risk assessment results of the current text instruction, the text processing module can output the current semantic structure information and risk assessment results of the current text instruction to the semantic assessment module.
[0064] Data transmission between the text receiving module and the text processing module employs a proprietary method combining shared smart pointers (shared_ptr) and tensor data structures. This enables efficient transfer of read-only data directly in memory, completely bypassing external network transmission and system kernel scheduling, further reducing data interaction latency. Simultaneously, the text processing module internally reserves compilation and adaptation macros for a neural network processor (NPU), allowing for compilation and deployment with multiple edge computing-specific neural network processors. Compared to conventional central processing unit deployment methods, inference latency can be further reduced by approximately 30%, while ensuring seamless code portability across different chip hardware platforms, perfectly adapting to demanding edge computing scenarios such as automotive and embedded terminals.
[0065] To address the limited computing power and memory constraints of edge devices, the text processing module employs two core optimization technologies: dynamic quantization and computational graph node fusion. Model weight parameters are stored in 8-bit integer (INT8) format, significantly compressing the model size and reducing storage usage. Activation values are stored in 16-bit floating-point (FP16) format, balancing inference accuracy and computational efficiency. This effectively reduces computing power consumption and memory usage without significantly reducing the accuracy of semantic structure analysis and risk assessment. The model input node strictly matches the preprocessing output specification of the text receiving module, retaining only the two core necessary fields: the tag number sequence and the attention mask. This simplifies memory allocation logic and avoids redundant data consuming resources. The model output node is divided into two parallel paths, completing two outputs simultaneously through a single forward inference, completely avoiding the double latency overhead caused by splitting two independent models for inference. One path outputs a BIO tag sequence to represent the core semantics of "who did what to whom," intuitively reflecting the semantic roles and structural relationships of the text, i.e., the current semantic structure information of the preceding text. The other path directly outputs a risk probability score ranging from 0 to 1, which serves as a risk assessment result. The closer the value is to 1, the higher the risk of the current text instruction; the closer the value is to 0, the safer the current text instruction.
[0066] The text processing module employs a dual-task collaborative strategy, simultaneously outputting risk probability scores and semantic role annotation results. This ensures both the accuracy of security assessments and the traceability and interpretability of detection results, facilitating subsequent auditing and anomaly investigation. During module startup, the MD5 hash value of the model file is automatically verified. If the verification result is inconsistent, indicating a corrupted model file or version mismatch, the module immediately exits to prevent accuracy drift and misjudgments due to model anomalies. If a program anomaly occurs during model inference, the module automatically captures the anomaly information, forcibly sets the risk probability score to zero, and continues executing subsequent business processes. This avoids single-point failures causing system service interruptions, ensuring system stability and continuity.
[0067] In some embodiments, the text processing model includes an encoding module, a semantic structure analysis module, and a risk assessment module. The pre-trained text processing model performs semantic structure analysis and risk assessment on the current text instruction to obtain the current semantic structure information and risk assessment results of the current text instruction, including:
[0068] The current text instruction is encoded by the encoding module to obtain semantic features;
[0069] The semantic structure analysis module performs semantic structure analysis on the semantic features to obtain the semantic structure information of the current text instruction.
[0070] The risk assessment module performs risk assessment on the semantic features to obtain the risk assessment result of the current text instruction.
[0071] like Figure 2 As shown, the text processing model uses a lightweight pre-trained model as its backbone network. Two task heads are connected in parallel on top of this backbone network: a semantic role labeling head (SRL-Head), which uses a BIO labeled sequence output format to parse the predicate-argument structure of text instructions; and a risk classification head (Risk-Head), which outputs the risk probability of text instructions through a fully connected layer and a Softmax activation function. The overall architecture is clear and suitable for edge inference. The backbone network uses a 4-layer lightweight BERT-mini model optimized with knowledge distillation and 8-bit integer quantization. The input specification perfectly matches the preprocessed output, receiving only two sets of data: a labeled sequence and an attention mask, thus adapting to the computing power and memory limitations of edge devices. In this embodiment, the backbone network corresponds to the encoding module, the semantic role labeling head corresponds to the semantic structure analysis module, and the risk classification head, fully connected layer, and Softmax activation function correspond to the risk assessment module. The specific inference flow of this text processing model is as follows:
[0072] The encoding module encodes the standardized input data of the current text instruction. The input to the encoding module includes the labeled sequence of the current text instruction, an attention mask, and simultaneously incorporates the positional encoding of the current text instruction. This positional encoding helps to perceive the text's word order and syntactic structure, accurately extracting deep semantic features and removing redundant surface information. This provides a unified and complete feature foundation for subsequent parallel semantic structure analysis and risk assessment. The semantic structure analysis module specifically analyzes the semantic features output by the encoding module, using a BIO-labeled sequence output format to accurately analyze the predicate-argument structure of the instruction. This clarifies key semantic elements such as the core action, the object of operation, and the implementing entity, obtaining complete semantic structure information for the current text instruction. Finally, the risk assessment module processes the same semantic features, using a fully connected layer and a Softmax activation function to quantify the risk level of the text instruction, outputting a standardized risk probability in the range of 0 to 1 as the risk assessment result for the current text instruction.
[0073] During the reasoning process, the three sets of preprocessed data corresponding to the current text instruction—namely, the tag number sequence, the attention mask, and the positional encoding—are simultaneously input into the encoding module to complete fusion encoding and semantic feature extraction. The generated semantic features are then simultaneously distributed to the parallel semantic structure analysis module and risk assessment module to complete structure analysis and risk assessment, respectively. Finally, the two results are simultaneously output to the semantic assessment module of the text instruction security detection device, realizing parallel processing of dual tasks in a single round of reasoning. No valid data generated during preprocessing is missed throughout the process, ensuring the integrity and accuracy of semantic analysis and risk assessment.
[0074] To adapt to the performance limitations of edge devices, the text processing model is optimized for lightweight design using knowledge distillation technology. It employs a lightweight Transformer architecture with significantly reduced layers and parameter size as the backbone network. Its network layers, hidden dimensions, and number of attention heads are all far lower than those of conventional large models, resulting in a substantial reduction in inference computational power requirements. Simultaneously, it utilizes mixed-precision quantization compression technology, supporting multi-level integer mixed-precision quantization, reducing the model size by more than an order of magnitude compared to conventional large models, perfectly adapting to the storage and memory constraints of edge devices.
[0075] During model training, a multi-objective collaborative distillation strategy is employed to simultaneously minimize semantic role annotation loss, risk classification loss, and hidden layer difference loss between models. This enables simultaneous learning of both semantic structure parsing and risk assessment tasks, ensuring detection accuracy while maintaining lightweight design. The inference engine is implemented based on a lightweight inference framework, achieving millisecond-level latency with single-threaded, single-batch processing without consuming significant computing resources, thus adapting to the real-time detection needs of various edge devices.
[0076] In step 103, the historical semantic structure information of the historical text instructions is obtained, and the semantic consistency between the current text instructions and the historical text instructions is evaluated based on the current semantic structure information and the historical semantic structure information to obtain the current semantic consistency evaluation result.
[0077] After receiving the current semantic structure information, the semantic evaluation module retrieves the set of historical semantic structure information for all historical text commands within a preset window, based on the session ID of the current text command. Since the current text command and all historical text commands within the same dialogue belong to the same session and share the same session ID, and all historical text commands are stored in memory or the database associated with this session ID after processing, historical data within the same session and preset window can be retrieved by matching the session ID of the current text command. The preset window refers to a pre-defined range of recent historical dialogues used for semantic consistency comparison, designed to control computational load and memory usage while ensuring the accuracy of semantic coherence judgment. The semantic evaluation module performs a semantic consistency evaluation on the current text command and historical text commands based on the current and historical semantic structure information, obtaining the current semantic consistency evaluation result. During the detection of the current text instruction, the current semantic consistency evaluation result is the same as the current semantic consistency evaluation result corresponding to the current text instruction. When the next text instruction is received, during the detection of the next text instruction, the current text instruction becomes the historical text instruction, and the current semantic consistency evaluation result becomes the historical semantic consistency evaluation result corresponding to the historical text instruction. After obtaining the current semantic consistency evaluation result, the semantic evaluation module can output the current semantic consistency evaluation result to the text detection module.
[0078] In some embodiments, based on current semantic structure information and historical semantic structure information, a semantic consistency evaluation is performed on the current text instruction and historical text instructions to obtain the current semantic consistency evaluation result, including:
[0079] When multiple historical text instructions exist, determine the semantic similarity between the current semantic structure information and each historical semantic structure information.
[0080] Assign weights to different historical text commands, with the weights decreasing as the interval between the received time of the historical text command and the current time increases.
[0081] The semantic similarity is weighted and fused according to the corresponding weights to obtain the current semantic consistency evaluation result of the current text instruction.
[0082] The semantic evaluation module can map the current semantic structure information and each historical semantic structure information into dense vectors respectively. By calculating the cosine similarity between the vectors, the semantic similarity between the current semantic structure information and each historical semantic structure information can be obtained.
[0083] The semantic evaluation module is a pure in-memory computation unit, without creating new threads or performing disk I / O operations. It executes sequentially within the same thread as the text processing module, completely eliminating lock contention overhead. The semantic evaluation module relies on pre-calculated dialogue data from the text receiving module, avoiding the repeated encoding of historical text instructions.
[0084] The semantic evaluation module uses exponentially decaying weights, which are calculated using the following formula.
[0085]
[0086] in, Indicates the first The weight corresponding to the historical text instructions. This indicates the preset window size, which is the maximum number of historical text instruction rounds used for consistency evaluation. Represents the relative round index of historical text instructions, 1≤ ≤ . The larger the value, the closer the historical text instruction was received to the current time, and the higher the corresponding weight.
[0087] The distance between the received time of historical text commands and the current time is determined by the size of the interval between the received time of historical text commands and the current time. The larger the interval between the received time of historical text commands and the current time, the farther away the received time of historical text commands is from the current time. The smaller the interval between the received time of historical text commands and the current time, the closer the received time of historical text commands is to the current time.
[0088] For example, assuming N is 3, corresponding to historical text commands T1, T2, and T3, where the interval between the reception time of historical text command T1 and the current time is greater than the interval between the reception time of historical text command T2 and the current time, and the interval between the reception time of historical text command T2 and the current time is greater than the interval between the reception time of historical text command T3 and the current time, historical text command T1 is the previous round of text command, historical text command T2 is the previous round of text command T1, and historical text command T3 is the previous round of text command T2. Therefore, we can conclude that historical text command T1 is the 3rd round of historical text commands, historical text command T2 is the 2nd round of historical text commands, and historical text command T3 is the 1st round of historical text commands. The weight corresponding to historical text command T1 is greater than the weight corresponding to historical text command T2, and the weight corresponding to historical text command T2 is greater than the weight corresponding to historical text command T3. Furthermore, the weight corresponding to historical text command T1 is... The weight corresponding to the historical text instruction T2 is The weight corresponding to the historical text instruction T3 is .
[0089] After obtaining the semantic similarity and weights corresponding to historical text commands T1, T2, and T3, the semantic evaluation module multiplies the semantic similarity of historical text command T1 by its weight, the semantic similarity of historical text command T2 by its weight, and the semantic similarity of historical text command T3 by its weight. Then, all the product results are summed to obtain the semantic consistency evaluation score, which serves as the current semantic consistency evaluation result. This score, along with the risk evaluation result of the current text command, is output to the text detection module of the text command security detection device. The semantic similarity between the current semantic structure information and the historical semantic structure information of a certain historical text command is the semantic similarity corresponding to that historical text command.
[0090] In step 104, based on the risk assessment results and the current semantic consistency assessment results, the current text instruction is subjected to security detection to obtain the security detection result of the current text instruction.
[0091] After obtaining the risk assessment results and the current semantic consistency assessment results, the text detection module can perform security detection on the current text instruction based on the risk assessment results and the current semantic consistency assessment results, and obtain the security detection results of the current text instruction.
[0092] In some embodiments, the risk assessment result includes a risk probability, the current semantic consistency assessment result includes a current semantic consistency assessment score, and a security check is performed on the current text instruction based on the risk assessment result and the current semantic consistency assessment result to obtain the security check result of the current text instruction, including:
[0093] Obtain the historical semantic consistency results corresponding to multiple historical text instructions. The historical semantic consistency results include the historical semantic consistency score.
[0094] Calculate the mean and standard deviation of multiple historical semantic consistency scores;
[0095] Calculate the dynamic threshold based on the mean and standard deviation;
[0096] Based on the risk probability, the current semantic consistency score, and the dynamic threshold, a security check is performed on the current text instruction to obtain the security check result of the current text instruction.
[0097] As can be understood from the previous embodiments, the current semantic consistency score is the current semantic consistency evaluation result corresponding to the current text instruction. According to this execution logic, historical text instructions will also obtain corresponding historical semantic consistency scores during the historical detection process. In this embodiment, the mean and standard deviation of multiple historical semantic consistency scores can be calculated; a dynamic threshold can be calculated based on the mean and standard deviation; and a security detection is performed on the current text instruction based on the risk probability, the current semantic consistency score, and the dynamic threshold to obtain the security detection result of the current text instruction.
[0098] In some embodiments, calculating a dynamic threshold based on the mean and standard deviation includes:
[0099] The dynamic threshold is calculated using the following formula:
[0100]
[0101] in, Indicates a dynamic threshold. This represents the mean. This represents the configurable dynamic threshold coefficient. It represents the standard deviation.
[0102] Used to adjust the severity of dynamic thresholds. The larger the value, the higher the dynamic threshold, the stricter the judgment of semantic mutation, the more sensitive to abnormal instructions, and the higher the probability of interception; The smaller the value, the lower the dynamic threshold, the higher the tolerance, and the lower the probability of false blocking.
[0103] By adjusting according to application scenarios The size allows this method to adaptively switch between different security levels in scenarios such as smart terminals, vehicle-mounted equipment, and industrial control, improving its versatility and practicality.
[0104] In this embodiment, a dynamic threshold enables the system to adaptively adjust its sensitivity: it has a higher tolerance in noisy daytime environments and is more sensitive in quiet nighttime environments, without requiring manual parameter tuning. The output structure includes three fields: a consistency score field, a dynamic threshold field, and a decision reason field. The corresponding content clearly traces the basis for the interception decision, facilitating auditing and review.
[0105] The semantic evaluation module employs an adaptive mechanism with dynamic thresholds, effectively addressing the issues of high false positive rates during the day and high false negative rates at night. This allows the system to adapt to various devices such as mobile phones, in-vehicle systems, and edge boxes, eliminating the burden of maintaining multiple sets of parameters. Regarding anomaly handling, if historical dialogue vectors are missing, the text detection module automatically degenerates into a single-sentence verification mode. In this case, setting λ=0 allows the system to maintain basic operation.
[0106] In some embodiments, security checks are performed on the current text instruction based on risk probability, current semantic consistency score, and dynamic threshold to obtain the security check result of the current text instruction, including:
[0107] If the risk probability is greater than the preset probability and the current semantic consistency score is less than the dynamic threshold, then the current text instruction is determined to be a risky text instruction.
[0108] If the risk probability is less than or equal to the preset probability, or the current semantic consistency score is greater than or equal to the dynamic threshold, then the current text instruction is determined to be a safe text instruction.
[0109] Among them, risk probability is used to characterize the risk level of the current text instruction itself; the higher the risk probability, the higher the risk level of the current text instruction. Current semantic consistency score is used to characterize the degree of contextual fit between the current text instruction and historical text instructions; the higher the semantic consistency score, the more coherent and normal the contextual semantics. Risky text instructions can be those with high security risk and semantic incoherence or logical breaks with historical text instructions. Safe text instructions can be those with low security risk, or those with semantic coherence or smooth logic with historical text instructions.
[0110] For example, assuming a preset probability of 0.7 and a dynamic threshold of 0.3, if the risk probability is 0.8 and the current semantic consistency score is 0.2, then the current text instruction is determined to be a risky text instruction; if the risk probability is 0.6 and the current semantic consistency score is 0.4, then the current text instruction is determined to be a safe text instruction; if the risk probability is 0.8 and the current semantic consistency score is 0.4, then the current text instruction is determined to be a safe text instruction; if the risk probability is 0.6 and the current semantic consistency score is 0.2, then the current text instruction is determined to be a safe text instruction.
[0111] In some embodiments, the method further includes:
[0112] If the current text instruction is a safe text instruction, then the execution of the current text instruction is permitted;
[0113] If the current text instruction is a risky text instruction, then the current text instruction will not be executed.
[0114] Specifically, if the current text instruction is a secure text instruction, it will be forwarded to the downstream business execution engine or large model inference interface without tampering, such as the instruction execution agent; wait for the execution result and return to the terminal to display a normal interactive response; write to the release log to record the session ID, instruction content, consistency score, dynamic threshold, decision reason, and release time for easy auditing and review.
[0115] If the current text command is a risky text command, it will not be forwarded downstream, the execution link will be cut off directly, and inference and invocation operations will not be performed. A friendly rejection prompt can also be returned to the terminal, such as "The current text command has security risks and is not supported for execution at this time", without disclosing the underlying judgment parameters; a low-priority risk control label will be temporarily attached to the session, and secondary rate limiting can be linked for short-term high-frequency anomalies; high-risk interception logs will be archived separately, highlighting violation characteristics, semantic mutation indicators, and two-dimensional judgment values to support post-event source tracing and investigation.
[0116] In some embodiments, the method further includes:
[0117] If the current semantic structure information and risk assessment results of the current text instruction are obtained through the pre-trained text processing model within the preset time period, then the step of obtaining the historical semantic structure information corresponding to the historical text instruction is executed.
[0118] If the current semantic structure information and risk assessment results of the current text instruction are not obtained through the pre-trained text processing model within the preset time, the model inference is determined to have timed out, the current text instruction is allowed to be executed, and a flag indicating that the model inference has timed out is set for the current text instruction.
[0119] Specifically, if the current semantic structure information and risk assessment result of the current text instruction are obtained through the pre-trained text processing model within the preset time period, the aforementioned normal judgment process for risky and safe text instructions is executed. If the current semantic structure information and risk assessment result of the current text instruction are not obtained through the pre-trained text processing model within the preset time period, the model inference is determined to have timed out. The current inference process of the model can be actively interrupted to release computing resources, avoid unnecessary waiting, and directly determine that the current text instruction can be executed without performing the aforementioned normal judgment process for risky and safe text instructions. Furthermore, a unique identifier can be set for the current text instruction, allowing it to carry the identifier to indicate that the model inference has timed out.
[0120] In normal scenarios, after the text detection module starts a high-precision timer, it waits for the text processing model to return a result within a preset timeout threshold, and then outputs a decision normally. In abnormal scenarios, when the timer detects that the inference time has exceeded the timeout threshold and has not returned, the text detection module immediately calls the interrupt application programming interface to forcibly terminate the inference calculation and enters a degraded processing flow: it generates a release result containing the reason for the timeout protection, and records a system context snapshot for alarms and post-event analysis.
[0121] The text detection module uses a steady-state clock provided by the C++ standard library for nanosecond-level timing, ensuring absolute accuracy in timeout determination and guaranteeing the measurability and reproducibility of the preset delay. The timeout threshold is defined as a constant at compile time to avoid the risk of accidental modification by maintenance personnel when reading configuration files at runtime, and to prevent the threshold from being tampered with by malicious processes, thus ensuring the reliability of the fault-tolerant mechanism.
[0122] Once the processing time exceeds the set time limit, the inference session interruption interface is immediately invoked. This interface is a session-level interruption interface provided by the lightweight inference framework. After the call, the inference operation being executed will immediately throw an exception and terminate the computation. By actively canceling, CPU resources can be reclaimed in a timely manner, enabling services such as voice assistants to respond quickly and improving resource utilization efficiency. The degraded return result carries a timeout protection flag field, informing the upstream that this result is a pass under timeout protection rather than a miss. All operations are logged and traceable.
[0123] Local intra-process communication uses an intra-process transmission mode to publish results. This mode achieves zero-copy data transmission within the process; data resides in shared memory, eliminating the need for system calls and buffer copying. Remote communication uses an asynchronous message producer, caching messages in a local buffer before having them pushed in batches to the message broker node by a background input / output thread, ensuring that services such as voice assistants can maintain real-time, uninterrupted responsiveness.
[0124] When the asynchronous producer buffer is full or the message service is unavailable, messages will be automatically transferred to a local circular queue for temporary storage. This circular queue uses a pre-allocated structure to avoid dynamic memory allocation at runtime; audit logs are written to this queue first in this case, and retransmission is performed by a background thread after the network is restored.
[0125] In some embodiments, the method further includes:
[0126] If the execution of the current text instruction is permitted, the instruction execution agent will detect whether the current text instruction carries identification information.
[0127] If the current text instruction does not carry identification information, the instruction execution agent executes the current text instruction according to the first execution strategy;
[0128] If the current text instruction carries identification information, then the instruction execution agent executes the current text instruction according to the second execution strategy.
[0129] The instruction execution agent is a business execution unit used to execute text instructions, possessing the capabilities of instruction parsing, function scheduling, and execution control. It selects different execution strategies based on whether the current text instruction carries an indication of timeout for representation model inference: when the current text instruction does not carry this indication, a full-function execution strategy is adopted, fully executing all business logic corresponding to the instruction; when the current text instruction carries this indication, a degraded execution strategy is adopted, restricting high-risk, high-privilege operations, executing only basic security functions and outputting prompt information, thereby ensuring continuous system operation while improving execution security in abnormal scenarios.
[0130] Specifically, the instruction execution agent detects whether the current text instruction carries an indication of timeout inference in the representation model, and outputs the detection result of carrying or not carrying the indication information, which serves as the basis for selecting the execution strategy.
[0131] If the detection result does not carry identification information, the agent's first execution strategy is invoked, such as the full-function execution strategy with no functional limitations; the business logic is fully triggered according to the user's instructions, such as calling the large model to generate a complete response, executing file queries, data display, etc.; without any additional prompts, the complete execution result is returned to the terminal, and the user perceives no difference.
[0132] If the detection result indicates the presence of identification information, the agent's second execution strategy is invoked, such as a downgraded execution strategy. This strategy restricts high-risk, high-privilege operations, such as prohibiting data modification, prohibiting calls to system interfaces, and returning only basic information. It also executes only risk-free basic query content in the command, such as when a user asks "check the weather," only basic weather data is returned, without performing additional operations such as "save the weather to local storage." A standardized prompt is automatically generated, for example: "Due to a temporary system detection delay, the current text command has not completed full security verification. It has been downgraded to basic functionality. Please try again later for full service."
[0133] For example, assuming a preset duration of 500ms, and the current text command is "Check Beijing's weather tomorrow and save it to the desktop": Scenario 1 (no identifier): The model completes the detection in 400ms, with no model inference timeout identifier, so the agent executes normally, returning the weather + save to desktop, without any prompt; Scenario 2 (with identifier): The model times out in 600ms, with a model inference timeout identifier, so the agent only returns Beijing's weather tomorrow (downgraded execution), and prompts "The current command has not completed full security verification, and has been downgraded to basic query execution, and the file has not been saved yet."
[0134] To further illustrate the implementation methods and technical effects of this application, three typical edge computing scenarios are selected for explanation. In each scenario, the aforementioned text instruction security detection method is used to achieve low-latency, context-aware instruction security verification.
[0135] Scenario 1: Offline command filtering for smart terminal voice assistants
[0136] For offline voice assistants on terminal devices, command security filtering is completed locally on the device without network involvement, featuring low latency, low power consumption, small model size, and the ability to resist context-induced attacks.
[0137] The system uses a general-purpose ARM architecture processor with 2GB of RAM. The text detection module runs as a daemon process. It employs a lightweight semantic model, resulting in a quantized file size of less than 5MB; the sliding window size is N=5, and the dynamic threshold coefficient... =1.5, inference timeout threshold is 10s.
[0138] Users sequentially issue system settings, account operations, and data export commands. The system combines historical dialogues to perform semantic analysis, risk assessment, and contextual consistency checks on the current text commands, identifying and blocking combined high-risk operations. This solves the problem that traditional single-sentence detection cannot identify contextual risks. When excessive processor load causes inference timeouts, the system automatically downgrades the process and records the anomaly, ensuring continuous operation of voice services.
[0139] Scenario 2: Protection of Voice Interaction in Intelligent Connected Vehicle Cockpits
[0140] For in-vehicle cockpit voice interaction scenarios, safety verification is performed on vehicle control commands to meet automotive-grade environmental adaptability, functional safety, and deterministic latency requirements.
[0141] The device is deployed in a separate secure partition of the vehicle domain controller. Model parameters are stored in non-volatile memory and undergo integrity verification. The sliding window size is N=10, and the dynamic threshold coefficient is... =2.0, inference timeout threshold is 50ms.
[0142] Users sequentially issue commands for adjusting the in-vehicle environment, controlling windows, and controlling vehicle speed. The system identifies semantic shifts in the commands and dangerous driving intentions, and blocks the commands based on risk probability and contextual consistency, while also reporting a safety incident. In the event of inference timeout or module malfunction, the system automatically degrades its operation without affecting cockpit interaction, and simultaneously issues safety warnings.
[0143] Scenario 3: Industrial Internet Edge Control Command Verification
[0144] For edge control devices in industrial settings, it performs real-time security verification of natural language commands for device operation, and has the ability to perform high-precision semantic parsing and adapt to industrial scenarios.
[0145] The system is deployed on general-purpose industrial edge computing nodes, running as a containerized service and interfacing with upper-layer control systems through standard interfaces. The model is optimized based on industrial control corpus, with a sliding window size of N=3 and a dynamic threshold coefficient. =1.0, inference timeout threshold is 100ms.
[0146] Operators issue commands to start equipment and perform unauthorized tests. The system identifies high-risk operations that do not meet safety requirements and blocks them, outputting a structured safety event. When equipment resources are strained and testing times out, the system downgrades the operation and triggers a high-level alarm, maintaining safety monitoring capabilities while ensuring production continuity.
[0147] In this embodiment, the current text instruction is received; a pre-trained text processing model is used to perform semantic structure analysis and risk assessment on the current text instruction to obtain the current semantic structure information and risk assessment result of the current text instruction; historical semantic structure information corresponding to historical text instructions is obtained, and semantic consistency assessment is performed on the current text instruction and historical text instructions based on the current semantic structure information and historical semantic structure information to obtain the current semantic consistency assessment result; security detection is performed on the current text instruction based on the risk assessment result and the current semantic consistency assessment result to obtain the security detection result of the current text instruction. When performing security detection on the current text instruction, in addition to considering the risk assessment, historical semantic structure information is also combined to perform semantic consistency assessment on the current text instruction and historical text instructions. Combining the risk assessment result and the semantic consistency assessment result to perform comprehensive security detection on the current text instruction can make up for the vulnerability of security detection based solely on the semantic information of the current text instruction itself, and can identify hidden risk instructions with inconsistent contextual semantics, thereby improving the security detection effect of text instructions.
[0148] Furthermore, in this embodiment, the model size can be compressed to the MB level, significantly reducing the storage pressure and program distribution overhead of edge devices, adapting to various resource-constrained scenarios, and making the model lightweight with lower deployment costs. Millisecond-level inference can be achieved with a single thread, resulting in low latency and low resource consumption, meeting the high real-time requirements of voice interaction and vehicle control, with efficient and low-consumption inference and stronger real-time performance. Combining semantic structure parsing and dynamic threshold decision-making, it effectively identifies multi-round context-induced attacks, significantly reducing the false negative rate and false blocking rate, making context security detection more accurate. It can be quickly migrated between smart terminals, automotive-grade equipment, and industrial edge nodes simply by adjusting parameters, with a single architecture adaptable to multiple domains, demonstrating strong scenario adaptability and versatility. A built-in fault-tolerant degradation mechanism ensures continuous business operation even under extreme conditions such as high load, resource preemption, and operational anomalies, meeting high reliability requirements and enhancing system reliability and robustness. From semantic parsing and risk calculation to decision-making and degradation logic, all outputs are interpretable, facilitating security auditing, problem tracing, and compliance verification, with the entire process being traceable and interpretable. Internally, it adopts a zero-copy mechanism to achieve microsecond-level data interaction, and externally it supports general message protocols and can be horizontally scaled, balancing low latency and large-scale deployment capabilities. Inter-module communication is efficient and scalable.
[0149] The text command security detection device provided in this application is described below. The text command security detection device described below can be referred to in correspondence with the text command security detection method described above.
[0150] Please see Figure 3 , Figure 3 This is a schematic diagram of the text instruction security detection device provided in this application. The device includes:
[0151] Text receiving module 201 is used to receive the current text command;
[0152] The text processing module 202 is used to perform semantic structure analysis and risk assessment on the current text instruction using a pre-trained text processing model, so as to obtain the current semantic structure information and risk assessment results of the current text instruction.
[0153] The semantic evaluation module 203 is used to obtain the historical semantic structure information of historical text instructions, and to evaluate the semantic consistency between the current text instructions and historical text instructions based on the current semantic structure information and the historical semantic structure information, so as to obtain the current semantic consistency evaluation result.
[0154] The text detection module 204 is used to perform security detection on the current text instruction based on the risk assessment results and the current semantic consistency assessment results, and obtain the security detection results of the current text instruction.
[0155] In some embodiments, the risk assessment result includes a risk probability, the current semantic consistency assessment result includes a current semantic consistency assessment score, and the text detection module 204 is specifically used for:
[0156] Obtain the historical semantic consistency results corresponding to multiple historical text instructions. The historical semantic consistency results include the historical semantic consistency score.
[0157] Calculate the mean and standard deviation of multiple historical semantic consistency scores;
[0158] Calculate the dynamic threshold based on the mean and standard deviation;
[0159] Based on the risk probability, the current semantic consistency score, and the dynamic threshold, a security check is performed on the current text instruction to obtain the security check result of the current text instruction.
[0160] In some embodiments, the text detection module 204 is specifically used for:
[0161] If the risk probability is greater than the preset probability and the current semantic consistency score is less than the dynamic threshold, then the current text instruction is determined to be a risky text instruction.
[0162] If the risk probability is less than or equal to the preset probability, or the current semantic consistency score is greater than or equal to the dynamic threshold, then the current text instruction is determined to be a safe text instruction.
[0163] In some embodiments, the text detection module 204 is further configured to:
[0164] If the current text instruction is a safe text instruction, then the execution of the current text instruction is permitted;
[0165] If the current text instruction is a risky text instruction, then the current text instruction will not be executed.
[0166] In some embodiments, the semantic evaluation module 203 is specifically used to: obtain the current semantic structure information and risk assessment result of the current text instruction through a pre-trained text processing model within a preset time period, and obtain the historical semantic structure information of historical text instructions;
[0167] The text detection module 204 is also used to: if the current semantic structure information and risk assessment results of the current text instruction are not obtained through the pre-trained text processing model within a preset time period, determine that the model inference has timed out, allow the execution of the current text instruction, and set the identification information representing the model inference timeout for the current text instruction.
[0168] In some embodiments, the text detection module 204 is further configured to:
[0169] If the execution of the current text instruction is permitted, the instruction execution agent will detect whether the current text instruction carries identification information.
[0170] If the current text instruction does not carry identification information, the instruction execution agent executes the current text instruction according to the first execution strategy;
[0171] If the current text instruction carries identification information, then the instruction execution agent executes the current text instruction according to the second execution strategy.
[0172] In some embodiments, the text detection module 204 is specifically used for:
[0173] The dynamic threshold is calculated using the following formula:
[0174]
[0175] in, Indicates a dynamic threshold. This represents the mean. This represents the configurable dynamic threshold coefficient. It represents the standard deviation.
[0176] In some embodiments, the text processing model includes an encoding module, a semantic structure analysis module, and a risk assessment module. The text processing module 202 is specifically used for:
[0177] The current text instruction is encoded by the encoding module to obtain semantic features;
[0178] The semantic structure analysis module performs semantic structure analysis on the semantic features to obtain the semantic structure information of the current text instruction.
[0179] The risk assessment module performs risk assessment on the semantic features to obtain the risk assessment result of the current text instruction.
[0180] In some embodiments, the semantic evaluation module 203 is specifically used for:
[0181] When multiple historical text instructions exist, determine the semantic similarity between the current semantic structure information and each historical semantic structure information.
[0182] Assign weights to different historical text commands, with the weights decreasing as the interval between the received time of the historical text command and the current time increases.
[0183] The semantic similarity is weighted and fused according to the corresponding weights to obtain the current semantic consistency evaluation result.
[0184] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include a processor 310, a communications interface 320, a memory 330, and a communication bus 340. The processor 310, communications interface 320, and memory 330 communicate with each other via the communication bus 340. The processor 310 can call logical instructions stored in the memory 330 to execute the text instruction security detection methods provided by the aforementioned methods.
[0185] Furthermore, the logical instructions in the aforementioned memory 330 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0186] On the other hand, this application also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer is able to execute the text instruction security detection method provided by the above methods.
[0187] In another aspect, this application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the text instruction security detection methods provided by the above methods.
[0188] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0189] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of embodiments.
[0190] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A text instruction security detection method, characterized in that, include: Receive the current text instruction; The current text instruction is subjected to semantic structure analysis and risk assessment by a pre-trained text processing model to obtain the current semantic structure information and risk assessment results of the current text instruction. Obtain historical semantic structure information of historical text instructions, and based on the current semantic structure information and the historical semantic structure information, perform semantic consistency evaluation on the current text instructions and historical text instructions to obtain the current semantic consistency evaluation result; Based on the risk assessment results and the current semantic consistency assessment results, the current text instruction is subjected to security detection to obtain the security detection results of the current text instruction.
2. The text instruction security detection method according to claim 1, characterized in that, The risk assessment result includes a risk probability, and the current semantic consistency assessment result includes a current semantic consistency assessment score. The step of performing security checks on the current text instruction based on the risk assessment result and the current semantic consistency assessment result to obtain the security check result of the current text instruction includes: Obtain the historical semantic consistency results corresponding to multiple historical text instructions, wherein the historical semantic consistency results include historical semantic consistency scores; Calculate the mean and standard deviation of the multiple historical semantic consistency scores; Calculate the dynamic threshold based on the mean and the standard deviation; Based on the risk probability, the current semantic consistency score, and the dynamic threshold, the current text instruction is subjected to security detection to obtain the security detection result of the current text instruction.
3. The text instruction security detection method according to claim 2, characterized in that, The step of performing security detection on the current text instruction based on the risk probability, the current semantic consistency score, and the dynamic threshold to obtain the security detection result of the current text instruction includes: If the risk probability is greater than the preset probability and the current semantic consistency score is less than the dynamic threshold, then the current text instruction is determined to be a risky text instruction. If the risk probability is less than or equal to the preset probability, or the current semantic consistency score is greater than or equal to the dynamic threshold, then the current text instruction is determined to be a safe text instruction.
4. The text instruction security detection method according to claim 3, characterized in that, The method further includes: If the current text instruction is a safe text instruction, then the execution of the current text instruction is permitted; If the current text instruction is a risky text instruction, then the current text instruction will not be executed.
5. The text instruction security detection method according to claim 4, characterized in that, The method further includes: If the current semantic structure information and risk assessment result of the current text instruction are obtained through a pre-trained text processing model within a preset time period, then the step of obtaining the historical semantic structure information of historical text instructions is executed. If the current semantic structure information and risk assessment result of the current text instruction are not obtained through the pre-trained text processing model within the preset time period, the model inference is determined to have timed out, the execution of the current text instruction is allowed, and a flag indicating the model inference timeout is set for the current text instruction.
6. The text instruction security detection method according to claim 5, characterized in that, The method further includes: If the execution of the current text instruction is permitted, the instruction execution agent detects whether the current text instruction carries the identification information. If the current text instruction does not carry the identification information, then the instruction execution agent executes the current text instruction according to the first execution strategy; If the current text instruction carries the identification information, then the instruction execution agent executes the current text instruction according to the second execution strategy.
7. The text instruction security detection method according to any one of claims 2 to 6, characterized in that, The step of calculating the dynamic threshold based on the mean and the standard deviation includes: The dynamic threshold is calculated using the following formula: in, Indicates a dynamic threshold. This represents the mean. This represents the configurable dynamic threshold coefficient. It represents the standard deviation.
8. The text instruction security detection method according to claim 1, characterized in that, The text processing model includes an encoding module, a semantic structure analysis module, and a risk assessment module. The pre-trained text processing model performs semantic structure analysis and risk assessment on the current text instruction to obtain the current semantic structure information and risk assessment results of the current text instruction, including: The current text instruction is encoded by the encoding module to obtain semantic features; The semantic structure analysis module performs semantic structure analysis on the semantic features to obtain the semantic structure information of the current text instruction. The risk assessment module performs risk assessment on the semantic features to obtain the risk assessment result of the current text instruction.
9. The text instruction security detection method according to claim 1, characterized in that, The step of evaluating the semantic consistency between the current text instruction and the historical text instructions based on the current semantic structure information and the historical semantic structure information to obtain the current semantic consistency evaluation result includes: When multiple historical text instructions exist, determine the semantic similarity between the current semantic structure information and each historical semantic structure information; Weights are assigned to different historical text commands, and the weights decrease as the interval between the time the historical text command was received and the current time increases. The semantic similarity and corresponding weights are used to perform weighted fusion to obtain the current semantic consistency evaluation result.
10. A text command security detection device, characterized in that, include: The text receiving module is used to receive the current text command; The text processing module is used to perform semantic structure analysis and risk assessment on the current text instruction using a pre-trained text processing model, so as to obtain the current semantic structure information and risk assessment results of the current text instruction. The semantic evaluation module is used to obtain the historical semantic structure information of historical text instructions, and to evaluate the semantic consistency between the current text instruction and the historical text instructions based on the current semantic structure information and the historical semantic structure information, so as to obtain the current semantic consistency evaluation result. The text detection module is used to perform security detection on the current text instruction based on the risk assessment result and the current semantic consistency assessment result, and obtain the security detection result of the current text instruction.