Method and apparatus for generating regular expressions based on large language models
Generating regular expressions through large language models solves the problem of low accuracy of intention recognition in the existing technology, achieves fast and accurate intention recognition and response, and improves the user experience in scenarios such as smart customer service.
Patent Information
- Application Number
- CN202510487076.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-18
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2045-04-18
AI Technical Summary
In the prior art, intention recognition has low accuracy and low efficiency in scenarios such as intelligent customer service, and existing methods rely on dictionary matching or deep learning to meet actual needs.
A large language model is used to generate regular expressions, and by selecting candidate samples with the same intent tag in the sample library to form an intent document, extracting and clustering intent keywords, using the large language model to process the regular expression corresponding to the target intent tag, and storing it in the regular library to identify user question-and-answer intent.
It improves the efficiency and accuracy of intention recognition, can quickly identify user intentions and generate corresponding answers, and improves user experience and system response efficiency.
Smart Images

Figure CN120011524B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of machine learning technology, and in particular to a method and device for generating regular expressions based on a large language model. Background Art
[0002] With the advancement of computing and internet technologies, intent recognition is being applied in an increasing number of scenarios, primarily to understand user intent. For example, in intelligent customer service scenarios, intent recognition is widely used in customer service robots. By identifying the intent of user input, robots can quickly respond to user needs. Furthermore, the accuracy of intent recognition plays a crucial role in scenarios such as e-commerce intelligent customer service and virtual assistants. Most existing rule-based approaches to intent recognition rely on dictionary matching, which lacks flexibility. Traditional machine learning uses statistical feature classification, while deep learning (such as BERT and LSTM) improves accuracy by automatically capturing semantic meaning. While these implementations can achieve intent recognition, their accuracy is low and their efficiency is low in real-world business scenarios. Therefore, an effective solution is urgently needed to address these issues. Summary of the Invention
[0003] In light of this, embodiments of this specification provide a method for generating regular expressions based on a large language model. One or more embodiments of this specification also include a device for generating regular expressions based on a large language model, a data processing method, a data processing device, a computing device, a computer-readable storage medium, and a computer program product to address technical deficiencies in the prior art.
[0004] According to a first aspect of an embodiment of this specification, a method for generating a regular expression based on a large language model is provided, comprising:
[0005] Select candidate samples with the same intent label from the sample library to form multiple intent documents, wherein the candidate samples are formed based on text data and intent labels corresponding to the text data;
[0006] Extract the intent keywords corresponding to each intent document, and obtain the intent keyword set corresponding to the target intent label by clustering the intent keywords;
[0007] Using a large language model to process the intent keyword set according to the target prompt word, obtaining a regular expression corresponding to the target intent label;
[0008] The regular expression is stored in a regular library, wherein the regular expression stored in the regular library is used to identify the user's question-answering intention during the question-answering interaction stage.
[0009] According to a second aspect of the embodiments of this specification, a data processing method is provided, including:
[0010] Get the question text data submitted by the user;
[0011] Performing regular matching on the question text data using a regular expression stored in a regular library, wherein the regular expression stored in the regular library is constructed according to the above method;
[0012] Determine the target regular expression corresponding to the question text data according to the matching result, and use the intent label corresponding to the target regular expression as the intent label corresponding to the question text data;
[0013] Answer text data is generated based on the intention tag corresponding to the question text data and displayed to the user.
[0014] According to a third aspect of the embodiments of this specification, a regular expression generation device based on a large language model is provided, comprising:
[0015] A selection module is configured to select candidate samples with the same intent label from the sample library to form a plurality of intent documents, wherein the candidate samples are formed based on text data and intent labels corresponding to the text data;
[0016] An extraction module is configured to extract intent keywords corresponding to each intent document and obtain an intent keyword set corresponding to a target intent tag by clustering the intent keywords;
[0017] a processing module configured to process the set of intent keywords according to the target prompt word using a large language model to obtain a regular expression corresponding to the target intent label;
[0018] The storage module is configured to store the regular expression in a regular library, wherein the regular expression stored in the regular library is used to identify the user's question-answering intention during the question-answering interaction stage.
[0019] According to a fourth aspect of the embodiments of this specification, there is provided a data processing device, including:
[0020] An acquisition module is configured to acquire question text data submitted by a user;
[0021] A matching module is configured to perform regular matching on the question text data using regular expressions stored in a regular library, wherein the regular expressions stored in the regular library are constructed according to the above method;
[0022] a determination module configured to determine a target regular expression corresponding to the question text data according to the matching result, and use the intent tag corresponding to the target regular expression as the intent tag corresponding to the question text data;
[0023] The display module is configured to generate answer text data based on the intention label corresponding to the question text data and display it to the user.
[0024] According to a fifth aspect of the embodiments of this specification, there is provided a computing device, including:
[0025] memory and processor;
[0026] The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the above-mentioned regular expression generation method or data processing method based on a large language model are implemented.
[0027] According to the sixth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores computer-executable instructions. When the instructions are executed by a processor, the steps of the above-mentioned regular expression generation method or data processing method based on a large language model are implemented.
[0028] According to the seventh aspect of the embodiments of this specification, a computer program product is provided, including a computer program or instructions, which, when executed by a processor, implement the steps of the above-mentioned regular expression generation method or data processing method based on a large language model.
[0029] The regular expression generation method based on the large language model provided in this embodiment, in order to be able to construct a regular expression that can quickly and accurately identify the intent of text data, can first select candidate samples with the same intent label in the sample library to form multiple intent documents, wherein the candidate samples are based on the text data and the intent label corresponding to the text data; on this basis, the intent keywords corresponding to each intent document can be extracted, and by clustering the intent keywords, the intent keyword set corresponding to the target intent label can be obtained, so that the keywords expressing the intent information corresponding to the target intent label can be integrated together before the regular expression is constructed, so that the subsequent regular expression construction corresponding to the target intent label is more accurate. After that, the large language model can be used to process the intent keyword set according to the target prompt word, and the regular expression corresponding to the target intent label can be obtained according to the processing result; finally, the regular expression can be stored in the regular library, so that in the application stage, the regular expression stored in the regular library can be used to identify the user's question and answer intention in the question and answer interaction stage. Thereby effectively improving the efficiency and accuracy of intent recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 This is a flowchart of a method for generating a regular expression based on a large language model provided by one embodiment of this specification;
[0031] Figure 2 is a flow chart of a data processing method provided by one embodiment of this specification;
[0032] Figure 3 This is a schematic diagram of the structure of a regular expression generation device based on a large language model provided by an embodiment of this specification;
[0033] Figure 4 This is a schematic diagram of the structure of a data processing device provided by one embodiment of this specification;
[0034] Figure 5 This is a structural block diagram of a computing device provided by one embodiment of this specification. DETAILED DESCRIPTION
[0035] The following description sets forth many specific details to facilitate a thorough understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the scope of this specification. Therefore, this specification is not limited to the specific implementations disclosed below.
[0036] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a," "the," and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0037] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0038] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0039] First, the terms involved in one or more embodiments of this specification are explained.
[0040] Large language model technology is typically based on deep neural networks, particularly the Transformer architecture. Trained using massive amounts of data, it can learn complex language patterns and semantic relationships. Using a self-attention mechanism, large language models can capture complex relationships between words and extract semantic information at multiple levels, thereby understanding the deeper meaning of sentences. Large language models often have a very large number of parameters, but this is precisely what enables them to be context-aware and capable of expressing deep semantics.
[0041] Regular expression extraction tasks require identifying specific patterns or structures in text, often requiring in-depth semantic understanding and pattern matching. This is highly compatible with the characteristics of large language models, as they better capture the context and semantic relationships of text, providing greater flexibility and robustness than traditional regular expressions. Through their self-learning model, they can handle complex and variable inputs, possess strong generalization capabilities, and automate large-scale data processing, reducing manual intervention. Therefore, large language model technology is well-suited for regular expression extraction tasks.
[0042] This specification provides a method for generating regular expressions based on a large language model. One or more embodiments of this specification also involve a regular expression generation apparatus based on a large language model, a data processing method, a data processing apparatus, a computing device, a computer-readable storage medium, and a computer program product, each of which is described in detail in the following embodiments.
[0043] See also Figure 1 , Figure 1 A flowchart of a method for generating a regular expression based on a large language model according to an embodiment of the present specification is shown, which specifically includes the following steps.
[0044] Step S102 : selecting candidate samples with the same intent label from the sample library to form a plurality of intent documents, wherein the candidate samples are formed based on text data and intent labels corresponding to the text data.
[0045] The regular expression generation method based on a large language model provided in this embodiment can be applied to any scenario with intent recognition, such as intelligent customer service scenarios (by recognizing the intention of user input, the robot can quickly respond to user needs), e-commerce intelligent customer service scenarios (the intelligent customer service system automatically responds to questions by recognizing the user's intentions such as shopping and order inquiries, thereby reducing manual customer service costs and improving customer experience), virtual assistant scenarios (understanding user instructions through intent recognition to complete specific tasks. For example, when the user says "set an alarm" or "play music", the virtual assistant performs the corresponding operation through intent recognition), medical and health assistant scenarios (through voice or text input, users can consult health issues or make appointments with doctors, and medical assistants provide users with corresponding help through intent recognition, such as diagnosing symptoms, prescribing, or making appointments), etc.
[0046] This embodiment describes the application of the regular expression generation method based on a large language model in a virtual assistant scenario as an example. The descriptions of other scenarios can be found in the description of this embodiment, and this embodiment will not be elaborated here.
[0047] Specifically, the sample library refers to a database that stores candidate samples, where candidate samples are composed of text data and intent labels corresponding to the text data. Text data refers to the text for which intent recognition is required, and intent labels refer to the intent information corresponding to the text data. Accordingly, an intent document refers to a document composed of candidate samples with the same intent labels selected from the sample library. Selecting candidate samples with the same intent labels to construct an intent document ensures that the text data in the candidate samples contained in the intent document have the same intent, facilitating the subsequent construction of regular expressions for the intent corresponding to each intent document.
[0048] Based on this, in order to be able to construct a regular expression that can quickly and accurately identify the intent of text data, we can first select candidate samples with the same intent label in the sample library to form multiple intent documents, where the candidate samples are based on the text data and the intent label corresponding to the text data; on this basis, we can extract the intent keywords corresponding to each intent document, and by clustering the intent keywords, we can obtain the intent keyword set corresponding to the target intent label. This allows us to integrate the keywords that express the intent information corresponding to the target intent label before constructing the regular expression, making the subsequent construction of the regular expression corresponding to the target intent label more accurate. After that, we can use the large language model to process the intent keyword set according to the target prompt word, and obtain the regular expression corresponding to the target intent label based on the processing result; finally, we can store the regular expression in the regular library, so that in the application stage, we can use the regular expression stored in the regular library to identify the user's question and answer intent in the question and answer interaction stage. This effectively improves the efficiency and accuracy of intent recognition.
[0049] In one or more implementations of this embodiment, before the step of selecting candidate samples with the same intent label from the sample library to form multiple intent documents is performed, the following step is further included:
[0050] Acquire text data, and perform regular matching on the text data using the regular expressions stored in the regular library;
[0051] If the match is successful, determine the target regular expression corresponding to the text data; use the intent tag corresponding to the target regular expression as the intent tag corresponding to the text data, and perform a question-and-answer interaction task based on the intent tag corresponding to the text data.
[0052] In the event of a matching failure, the text data is input into the large language model for intent recognition to obtain the intent label corresponding to the text data; candidate samples are constructed based on the text data and the intent label corresponding to the text data, and the candidate samples are stored in the sample library.
[0053] Specifically, the target regular expression is the regular expression obtained by performing a regular match on the text data. Its corresponding intent label is the label that represents the intent information corresponding to the regular expression. If the text data matches the target regular expression, the intent label corresponding to the target regular expression represents the intent of the text data. Correspondingly, the question-and-answer interactive task is the task of answering the text data based on the intent label of the text data, which can be implemented using a large language model.
[0054] Based on this, before constructing a regular expression, the text data needs to be processed to determine whether the text data can be used to construct a regular expression corresponding to a new intent. Therefore, the text data can be obtained and the regular expressions stored in the regular library can be used to perform regular matching on the text data.
[0055] If the match is successful, it means that the regular expression corresponding to the intent of the text data has been stored in the regular library, so there is no need to use the text data to construct a new regular expression. Therefore, the target regular expression corresponding to the text data can be determined; the intent label corresponding to the target regular expression is used as the intent label corresponding to the text data, and the question-and-answer interaction task is performed based on the intent label corresponding to the text data.
[0056] In the event of a match failure, it means that the regular expression corresponding to the intent of the text data has not yet been constructed, so regular expression construction processing is required. This can be achieved in conjunction with a large language model. Specifically, the text data can be input into the large language model for intent recognition, and the intent label corresponding to the text data can be obtained based on the recognition result. After that, candidate samples are constructed based on the text data and the intent label corresponding to the text data, and the candidate samples are stored in the sample library. They can then be used to select candidate samples with the same intent label from the sample library to form an intent document, which is used to construct a regular expression for the specified intent and store it in the regular library for use in actual business scenarios.
[0057] For example, after obtaining the text data "Check today's weather", you can first use the regular expressions stored in the regular library to perform regular matching on the text data; if the match is successful, you can extract the target regular expression corresponding to the text data from the regular library. For example, if the regular expression is {r"(query|view|understand)(.*?)(today|tomorrow|the day after tomorrow)?(.*?)weather"}, this regular expression can match keywords such as "query", "view", "weather", and "today". The intention corresponding to this regular expression is "query today's weather", so it can be determined that the intention of "check today's weather" is "query today's weather", and the answer can be fed back to the text data based on the intention information.
[0058] If the match fails, it means that the intent of the text data cannot be identified through regular expressions. Therefore, the text data can be input into a large language model for intent recognition. The recognition result of the model determines that the intent corresponding to the text data is "query today's weather". Then, based on the text data "Check today's weather" and the intent "query today's weather", a candidate sample {Check today's weather - Query today's weather} can be constructed and stored in the sample library.
[0059] Furthermore, when regular expression construction is required, candidate samples with the same intent can be extracted from the sample library. By concatenating the candidate samples, intent documents corresponding to different intents can be obtained. For example, by selecting candidate samples with the intent of "Query today's weather" from the sample library, we can obtain {How is the weather today - Query today's weather}, {Is it sunny today - Query today's weather}, {Will it rain today - Query today's weather}... At this time, the candidate samples can be concatenated to obtain the intent document corresponding to the intent of "Query today's weather", that is, one document represents one intent. Similarly, after obtaining multiple documents corresponding to multiple intents, regular expressions corresponding to different intents can be constructed and stored in the regular library. This allows the virtual assistant to quickly identify user intent and perform question-and-answer operations when interacting with the user.
[0060] In summary, regular expressions are first used to match text data to determine whether the intent corresponding to the text data is recognized, so as to select different links for subsequent processing based on the recognition results, thereby making data processing more efficient and reasonable.
[0061] Step S104: extract the intent keywords corresponding to each intent document, and obtain the intent keyword set corresponding to the target intent tag by clustering the intent keywords.
[0062] Specifically, after extracting candidate samples with the same intent label from the sample library to form intent documents, in order to accurately construct the regular expression corresponding to each intent, the intent keywords corresponding to each intent document can be extracted, and the intent keywords can be clustered to achieve deduplication while improving keyword accuracy, thereby obtaining a set of intent keywords corresponding to the target intent label for subsequent use.
[0063] Among them, the intent keywords specifically refer to the keywords extracted from each intent document, and the intent keywords corresponding to each intent document come from different candidate samples in the intent document. Correspondingly, the target intent label specifically refers to the intent label corresponding to each intent document, and the intent keyword set is the intent keywords obtained after clustering the intent keywords contained in the intent document. For example, intent document a contains intent keywords a1, a2, a3 and a4, and its corresponding intent label is A. By clustering intent keywords a1, a2, a3 and a4, we can get the intent keyword set {a1, a2, a4} corresponding to intent label A.
[0064] In one or more implementations of this embodiment, determining the intent keyword corresponding to any one of the multiple intent documents includes:
[0065] Determine the intent document to be processed; use a keyword extraction algorithm to extract multiple initial intent keywords from the intent document to be processed; use a keyword deduplication algorithm to deduplicate the multiple initial intent keywords, and determine the intent keywords corresponding to the intent document to be processed based on the deduplication results.
[0066] Specifically, the "to-be-processed intent document" refers to any one of the multiple intent documents. Accordingly, the keyword extraction algorithm refers to the TF-IDF algorithm, and the initial intent keywords refer to the intent keywords extracted from the intent document that have not yet been deduplicated. Accordingly, the keyword deduplication algorithm refers to the MMR algorithm.
[0067] Based on this, when performing keyword extraction for any intent document, we can first determine the intent document to be processed, and then use the keyword extraction algorithm to extract multiple initial intent keywords from the intent document to be processed. After obtaining multiple initial intent keywords, we can use the keyword deduplication algorithm to deduplicate the multiple initial intent keywords, and then determine the intent keywords corresponding to the intent document to be processed based on the deduplication results for subsequent use.
[0068] In summary, by using keyword extraction algorithm and keyword deduplication algorithm to determine the intended keywords, not only can the accuracy of keyword extraction be guaranteed, but also the subsequent computing pressure caused by keyword redundancy can be avoided, thereby effectively improving the accuracy of regular expression construction.
[0069] In one or more implementations of this embodiment, the deduplication processing of the multiple initial intent keywords using a keyword deduplication algorithm, and determining the intent keyword corresponding to the intent document to be processed according to the deduplication processing result, includes:
[0070] Use a keyword deduplication algorithm to calculate the cosine similarity of the multiple initial intent keywords; determine the intent keywords to be deleted based on the cosine similarity calculation results, and delete the intent keywords to be deleted from the multiple initial intent keywords; based on the deletion results, use the remaining initial intent keywords as the intent keywords corresponding to the intent document to be processed.
[0071] Specifically, the intent keywords to be deleted specifically refer to the intent keywords that are repeated with other intent keywords in the multiple initial intent keywords.
[0072] Based on this, when using the keyword deduplication algorithm for deduplication processing, the keyword deduplication algorithm can be used to calculate the cosine similarity of multiple initial intent keywords; thereafter, the intent keywords to be deleted can be determined based on the cosine similarity calculation results, and the intent keywords to be deleted can be deleted from the multiple initial intent keywords, so that the remaining initial intent keywords can be used as the intent keywords corresponding to the intent document to be processed based on the deletion results for subsequent use.
[0073] In specific implementation, the TF-IDF algorithm is used to extract high-frequency keywords from the intent document, and keywords related to the intent tag corresponding to the intent document can be obtained. On this basis, the maximum marginal relevance (MMR) algorithm is used to filter the keywords to achieve the purpose of removing redundant and repeated keywords, thereby determining the intent keywords corresponding to each intent document and then performing subsequent regular expression construction.
[0074] It should be noted that the MMR algorithm can be implemented by the following formula (1) when performing deduplication processing:
[0075] (1)
[0076] Among them, S is the multiple initial intent keywords extracted by the TF-IDF algorithm. is the set of keywords that have been selected. For one of the multiple initial intent keywords, For the query (or target text, or text representation of intent category), For keywords and query The correlation between them is generally calculated using TF-IDF cosine similarity; For keywords With a selected keyword The similarity between them is usually calculated using cosine similarity. A weight parameter that controls relevance and diversity (usually set between 0.5 and 0.7).
[0077] It can be understood that the MMR algorithm is a greedy algorithm that continuously finds the keyword that maximizes the formula among multiple initial intent keywords. ,Right now , by using the keyword as the intent keyword corresponding to the intent document and performing subsequent intent keyword extraction processing. Once the number of keywords reaches the set threshold, or the similarity between the newly added keyword and the extracted intent keyword is too high, the keyword extraction operation can be stopped and subsequent processing can be carried out.
[0078] In summary, by calculating cosine similarity to remove duplicate keywords, we can ensure that the remaining keywords are unique and associated with the target intent label, making the subsequent regular expression construction more accurate.
[0079] In one or more implementations of this embodiment, determining the set of intent keywords corresponding to the target intent tag includes:
[0080] Determine multiple intent keywords to be clustered corresponding to the target intent label, wherein the multiple intent keywords to be clustered belong to the intent document corresponding to the target intent label; perform semantic recognition on the multiple intent keywords to be clustered respectively through a semantic recognition model to obtain a semantic vector corresponding to each intent keyword to be clustered; use a clustering algorithm to process the semantic vector corresponding to each intent keyword to be clustered, and construct an intent keyword set corresponding to the target intent label according to the processing result.
[0081] Specifically, the intent keywords to be clustered refer to the intent keywords extracted from any intent document, and these intent keywords are all associated with the target intent label. Accordingly, the semantic recognition model specifically constructs a model that corresponds to the semantic features of each intent keyword to be clustered, which can be implemented using the BERT model. Accordingly, the semantic vector represents the semantic features corresponding to each intent keyword to be clustered. Accordingly, the clustering algorithm can be implemented using K-means.
[0082] Based on this, when constructing an intent keyword set for the target intent tag corresponding to any intent document, we can first determine the multiple intent keywords to be clustered corresponding to the target intent tag, and the multiple intent keywords to be clustered belong to the intent document corresponding to the target intent tag; thereafter, in order to improve processing efficiency and accuracy, the semantic recognition model can be used to perform semantic recognition on the multiple intent keywords to be clustered separately to obtain the semantic vector corresponding to each intent keyword to be clustered; at this time, the clustering algorithm is used to process the semantic vector corresponding to each intent keyword to be clustered, and the intent keyword set corresponding to the target intent tag can be constructed according to the processing results.
[0083] In specific implementation, when constructing a semantic vector for each keyword to be clustered through the semantic recognition model, it can be expressed by the following formula (2):
[0084] (2)
[0085] The clustering process can be expressed by the following formula (3):
[0086] (3)
[0087] in, Represents the total An intention, Indicates a high-frequency keyword extracted from a document under a certain intention (serial number j). Indicates the high-frequency keyword clustering center under this intent recognition, Indicates the total set of keywords under intent j.
[0088] For example, after obtaining intent document a corresponding to intent label A and intent document b corresponding to intent label B, we can use the TF-IDF algorithm to extract high-frequency keywords from intent documents a and b. This can be understood as extracting high-frequency keywords that are specifically related to the intent labels, rather than keywords that are high-frequency in all documents. Based on the processing results, we determine that intent document a contains the keywords {a1, a2, a3…an}, and that intent document b contains the keywords {b1, b2, a3…bm}.
[0089] Furthermore, after obtaining the keywords corresponding to each intent document, the MMR algorithm can be used to deduplicate the keywords. The specific processing can be found in the above description. According to the processing results, the initial keyword set corresponding to intent label A is determined to be {a1, a2, a3, a5, a6, a7, a8}, and the initial keyword set corresponding to intent label B is determined to be {b1, b5, b6, b9, b11}.
[0090] Furthermore, using the pre-trained BERT model, we embed the keywords corresponding to each intent label into the semantic space. This yields the embedding vector for each keyword in the keyword set. We then use the K-means clustering algorithm to cluster keywords with the same semantics to obtain the keywords corresponding to the intent label. The keyword set corresponding to intent label A is determined to be {a6, a7, a8}, and the keyword set corresponding to intent label B is {b1, b5, b6}. We can then construct regular expressions for each intent label based on this keyword set.
[0091] In summary, the use of semantic recognition when clustering intent keywords can ensure that the final determined intent keywords have the same intent, thereby effectively improving the accuracy of regular expression construction.
[0092] Step S106: Process the intention keyword set according to the target prompt word using a large language model to obtain a regular expression corresponding to the target intention label.
[0093] Step S108: storing the regular expression in a regular library, wherein the regular expression stored in the regular library is used to identify the user's question-answering intention during the question-answering interaction stage.
[0094] Specifically, after obtaining the intent keyword set corresponding to the target intent label as mentioned above, in order to improve the efficiency of constructing regular expressions, the large language model can be used to process the intent keyword set according to the target prompt word, and then obtain the regular expression corresponding to the target intent label. After that, the regular expression can be stored in the regular library, so that the regular expression stored in the regular library can be used to identify the user's question and answer intention in the question and answer interaction stage.
[0095] The target prompt word refers to the prompt word configured after optimization using the prompt word optimization project, which enables the large language model to construct a regular expression corresponding to each intent tag based on the prompt word. Correspondingly, the regular expression library refers to a database that stores regular expressions corresponding to different intent tags.
[0096] In practical applications, when using a large language model to extract the regular expression corresponding to each intent tag based on the target prompt word, both white and black regular expressions can be extracted separately, thereby improving the relevance and accuracy of the regular expressions. White regular expressions can be used to match standard formats such as email addresses and ID numbers, while black regular expressions can be used to process unstructured data, such as log cleaning.
[0097] Continuing with the above example, after obtaining the keyword set {a6, a7, a8} corresponding to intent label A and the keyword set {b1, b5, b6} corresponding to intent label B, the large language model can be used to construct regular expressions for the keyword sets {a6, a7, a8} and {b1, b5, b6}, respectively, based on the target prompt. This yields the regular expressions corresponding to intent labels A and B, respectively. For example, if intent label A is "Query today's weather," the resulting regular expression is {r"(Query|View|Learn)(.*?)(Today|Tomorrow|The day after tomorrow)?(.*?)Weather"}. For another example, if intent label B is "Open calculator," the resulting regular expression is {r"(Open|Start|Run)(.*?)(Calculator|Calculator)"}. After storing these regular expressions in the regular expression library, if a user asks a question about intent label A or B during a Q&A session with the virtual assistant, the corresponding regular expression can be used to directly determine the user's intent and provide feedback on weather information or the calculator launch operation.
[0098] In one or more implementations of this embodiment, after the step of storing the regular expression in the regular expression library is performed, the following step is further included:
[0099] Matching text data with unrecognized intent in a text database with regular expressions stored in the regular expression library; and determining and deleting associated text data in the text database based on the matching result.
[0100] In addition, considering that regular expression construction requires the combination of a large amount of text data contained in the text database in order to complete the construction of regular expressions with a wider coverage, after each regular expression is constructed, in order to avoid redundant construction operations, that is, repeated regular expression construction, text data with unrecognized intent in the text database can also be matched with regular expressions stored in the regular library; thereby, the associated text data in the text database is determined and deleted according to the matching results, so as to reduce the data volume of the text database and improve the efficiency of regular expression construction.
[0101] In summary, in order to construct a regular expression that can quickly and accurately identify the intent of text data, we can first select candidate samples with the same intent label in the sample library to form multiple intent documents, where the candidate samples are based on the text data and the intent label corresponding to the text data; on this basis, we can extract the intent keywords corresponding to each intent document, and by clustering the intent keywords, we can obtain the intent keyword set corresponding to the target intent label, so that before the regular expression is constructed, the keywords that express the intent information corresponding to the target intent label can be integrated together, making the subsequent construction of the regular expression corresponding to the target intent label more accurate. After that, the large language model can be used to process the intent keyword set according to the target prompt word, and the regular expression corresponding to the target intent label can be obtained according to the processing result; finally, the regular expression can be stored in the regular library, so that in the application stage, the regular expression stored in the regular library can be used to identify the user's question and answer intent in the question and answer interaction stage. This effectively improves the efficiency and accuracy of intent recognition.
[0102] See also Figure 2 , Figure 2 A flow chart of a data processing method provided according to an embodiment of the present specification is shown, which specifically includes the following steps.
[0103] Step S202: Obtain question text data submitted by the user.
[0104] Step S204: performing regular matching on the question text data using the regular expressions stored in the regular library, wherein the regular expressions stored in the regular library are constructed according to the above method.
[0105] Step S206 , determining a target regular expression corresponding to the question text data according to the matching result, and using the intention tag corresponding to the target regular expression as the intention tag corresponding to the question text data.
[0106] Step S208: Generate answer text data based on the intention tag corresponding to the question text data, and display it to the user.
[0107] Specifically, question text data refers to the question text submitted by the user in the current business scenario, which includes but is not limited to e-commerce intelligent customer service scenarios (the intelligent customer service system automatically responds to questions by identifying the user's intentions such as shopping and order inquiries, thereby reducing the cost of manual customer service and improving the customer experience), virtual assistant scenarios (understanding the user's instructions through intent recognition to complete specific tasks. For example, the user says "set an alarm" or "play music", and the virtual assistant performs the corresponding operation through intent recognition), medical and health assistant scenarios (through voice or text input, users can consult health issues or make appointments with doctors, and medical assistants provide users with corresponding help through intent recognition, such as diagnosing symptoms, prescribing, or making appointments), etc.
[0108] Correspondingly, the answer text data specifically refers to the answer text displayed to the user based on the intent information after the intent of the question text data submitted by the user is recognized. In specific implementation, the answer text data can be generated by a large language model.
[0109] For example, in an intelligent customer service scenario, when receiving the question text "When will my order arrive" submitted by the user, the regular expression stored in the regular library constructed using the same method as above can be used to identify the intent of the question text, so as to determine the intention of the question text "When will my order arrive" as "querying the order delivery status" based on the regular matching results; on this basis, the order information of the user's purchased goods can be obtained, and the delivery status can be determined based on the order information, and the delivery status of the goods can be displayed to the user.
[0110] In summary, by using regular expressions stored in the regular library to quickly identify user intentions, the efficiency of handling user questions can be effectively improved, thereby improving the user experience.
[0111] Corresponding to the above method embodiment, this specification also provides an embodiment of a regular expression generation device based on a large language model, Figure 3 FIG1 shows a schematic diagram of a structure of a regular expression generation device based on a large language model provided by an embodiment of this specification. Figure 3 As shown, the device includes:
[0112] A selection module 302 is configured to select candidate samples with the same intent label from the sample library to form a plurality of intent documents, wherein the candidate samples are formed based on text data and the intent label corresponding to the text data;
[0113] Extraction module 304 is configured to extract intent keywords corresponding to each intent document, and obtain an intent keyword set corresponding to the target intent tag by clustering the intent keywords;
[0114] The processing module 306 is configured to process the set of intent keywords according to the target prompt word using a large language model to obtain a regular expression corresponding to the target intent label;
[0115] The storage module 308 is configured to store the regular expression in a regular library, wherein the regular expression stored in the regular library is used to identify the user's question-answering intention during the question-answering interaction stage.
[0116] In an optional embodiment, before the step of selecting candidate samples with the same intent label from the sample library to form multiple intent documents is performed, the step further includes:
[0117] Acquire text data and perform regular matching on the text data using the regular expressions stored in the regular library; if the match is successful, determine the target regular expression corresponding to the text data; use the intent tag corresponding to the target regular expression as the intent tag corresponding to the text data, and perform a question-and-answer interaction task based on the intent tag corresponding to the text data.
[0118] In an optional embodiment, when the matching fails, the method further includes:
[0119] The text data is input into the large language model for intent recognition to obtain the intent label corresponding to the text data; candidate samples are constructed based on the text data and the intent label corresponding to the text data, and the candidate samples are stored in the sample library.
[0120] In an optional embodiment, determining the intent keyword corresponding to any one of the plurality of intent documents includes:
[0121] Determine the intent document to be processed; use a keyword extraction algorithm to extract multiple initial intent keywords from the intent document to be processed; use a keyword deduplication algorithm to deduplicate the multiple initial intent keywords, and determine the intent keywords corresponding to the intent document to be processed based on the deduplication results.
[0122] In an optional embodiment, determining the set of intent keywords corresponding to the target intent tag includes:
[0123] Determine multiple intent keywords to be clustered corresponding to the target intent label, wherein the multiple intent keywords to be clustered belong to the intent document corresponding to the target intent label; perform semantic recognition on the multiple intent keywords to be clustered respectively through a semantic recognition model to obtain a semantic vector corresponding to each intent keyword to be clustered; use a clustering algorithm to process the semantic vector corresponding to each intent keyword to be clustered, and construct an intent keyword set corresponding to the target intent label according to the processing result.
[0124] In an optional embodiment, after the step of storing the regular expression in a regular expression library is performed, the method further includes:
[0125] Matching text data with unrecognized intent in the text database with regular expressions stored in the regular library; and determining and deleting associated text data in the text database based on the matching results.
[0126] In an optional embodiment, the method of performing deduplication processing on the multiple initial intent keywords using a keyword deduplication algorithm and determining the intent keyword corresponding to the intent document to be processed according to the deduplication processing result includes:
[0127] Use a keyword deduplication algorithm to calculate the cosine similarity of the multiple initial intent keywords; determine the intent keywords to be deleted based on the cosine similarity calculation results, and delete the intent keywords to be deleted from the multiple initial intent keywords; based on the deletion results, use the remaining initial intent keywords as the intent keywords corresponding to the intent document to be processed.
[0128] In summary, in order to construct a regular expression that can quickly and accurately identify the intent of text data, we can first select candidate samples with the same intent label in the sample library to form multiple intent documents, where the candidate samples are based on the text data and the intent label corresponding to the text data; on this basis, we can extract the intent keywords corresponding to each intent document, and by clustering the intent keywords, we can obtain the intent keyword set corresponding to the target intent label, so that before the regular expression is constructed, the keywords that express the intent information corresponding to the target intent label can be integrated together, making the subsequent construction of the regular expression corresponding to the target intent label more accurate. After that, the large language model can be used to process the intent keyword set according to the target prompt word, and the regular expression corresponding to the target intent label can be obtained according to the processing result; finally, the regular expression can be stored in the regular library, so that in the application stage, the regular expression stored in the regular library can be used to identify the user's question and answer intent in the question and answer interaction stage. This effectively improves the efficiency and accuracy of intent recognition.
[0129] The above is a schematic diagram of a large language model-based regular expression generation device according to this embodiment. It should be noted that the technical solution of this large language model-based regular expression generation device and the technical solution of the large language model-based regular expression generation method are based on the same concept. For details not described in detail in the technical solution of the large language model-based regular expression generation device, please refer to the description of the technical solution of the large language model-based regular expression generation method.
[0130] Corresponding to the above method embodiment, this specification also provides a data processing device embodiment, Figure 4 FIG1 shows a schematic diagram of the structure of a data processing device provided by an embodiment of this specification. Figure 4 As shown, the device includes:
[0131] The acquisition module 402 is configured to acquire question text data submitted by the user;
[0132] The matching module 404 is configured to perform regular matching on the question text data using the regular expressions stored in the regular library, wherein the regular expressions stored in the regular library are constructed according to the above method;
[0133] Determination module 406 is configured to determine a target regular expression corresponding to the question text data according to the matching result, and use the intent tag corresponding to the target regular expression as the intent tag corresponding to the question text data;
[0134] The display module 408 is configured to generate answer text data based on the intention tag corresponding to the question text data, and display the answer text data to the user.
[0135] In summary, by using regular expressions stored in the regular library to quickly identify user intentions, the efficiency of handling user questions can be effectively improved, thereby improving the user experience.
[0136] The above is a schematic diagram of a data processing device according to this embodiment. It should be noted that the technical solution of the data processing device and the technical solution of the above-mentioned data processing method are based on the same concept. For details not described in detail in the technical solution of the data processing device, please refer to the description of the technical solution of the above-mentioned data processing method.
[0137] Figure 5 The block diagram of a computing device 500 according to one embodiment of the present disclosure is shown. Components of the computing device 500 include, but are not limited to, a memory 510 and a processor 520. The processor 520 is connected to the memory 510 via a bus 530, and a database 550 is used to store data.
[0138] The computing device 500 also includes an access device 540 that enables the computing device 500 to communicate via one or more networks 560. Examples of such networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 540 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, or a near field communication (NFC) interface.
[0139] In one embodiment of the present specification, the above components of the computing device 500 and Figure 5 Other components not shown in the figure may also be connected to each other, for example, via a bus. Figure 5 The computing device structure block diagram shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art may add or replace other components as needed.
[0140] Computing device 500 can be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, personal digital assistant, laptop computer, notebook computer, netbook computer, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smartwatch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or personal computer (PC). Computing device 500 can also be a mobile or stationary server.
[0141] The processor 520 is configured to execute the following computer-executable instructions, which, when executed by the processor, implement the steps of the above-mentioned regular expression generation method or data processing method based on a large language model.
[0142] The above is a schematic diagram of a computing device according to this embodiment. It should be noted that the technical solution of this computing device is based on the same concept as the technical solution of the large language model-based regular expression generation method or data processing method. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the large language model-based regular expression generation method or data processing method.
[0143] An embodiment of the present specification further provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the steps of the above-mentioned regular expression generation method or data processing method based on a large language model.
[0144] The above is a schematic diagram of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium is based on the same concept as the technical solution of the large language model-based regular expression generation method or data processing method. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the large language model-based regular expression generation method or data processing method.
[0145] An embodiment of the present specification further provides a computer program product, including a computer program or instructions, which, when executed by a processor, implements the steps of the above-mentioned regular expression generation method or data processing method based on a large language model.
[0146] The above is a schematic diagram of a computer program product according to this embodiment. It should be noted that the technical solution of this computer program product is based on the same concept as the technical solution of the large language model-based regular expression generation method or data processing method. For details not described in detail in the technical solution of the computer program product, please refer to the description of the technical solution of the large language model-based regular expression generation method or data processing method.
[0147] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0148] The computer instructions include computer program code, which may be in source code form, object code form, executable file, or some intermediate form. The computer-readable medium may include any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal, and software distribution medium. It should be noted that the content of the computer-readable medium may be appropriately increased or decreased based on the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media does not include electric carrier signals and telecommunication signals.
[0149] It should be noted that for the aforementioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0150] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0151] The preferred embodiments disclosed above are intended only to help illustrate this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and variations are possible based on the content of the embodiments described herein. These embodiments are selected and described in detail in this specification to better explain the principles and practical applications of the embodiments, thereby enabling those skilled in the art to better understand and utilize this specification.
Claims
1. A regular expression generation method based on a large language model, characterized in that: include: Acquire text data and perform regular matching on the text data using regular expressions stored in a regular library. If the match fails, input the text data into a large language model for intent recognition to obtain an intent label corresponding to the text data; construct candidate samples based on the text data and the intent label corresponding to the text data, and store the candidate samples in a sample library; select candidate samples with the same intent label from the sample library and splice them into multiple intent documents, wherein the candidate samples are composed based on the text data and the intent label corresponding to the text data, and each intent document corresponds to one intent label; Extract the intent keywords corresponding to each intent document, and obtain the intent keyword set corresponding to the target intent label by clustering the intent keywords, wherein the intent keywords corresponding to each intent document come from different candidate samples constituting the intent document, and are determined by a keyword extraction algorithm and a keyword deduplication algorithm; determination of the intent keyword set corresponding to the target intent label includes: determining a plurality of intent keywords to be clustered corresponding to the target intent label, wherein the plurality of intent keywords to be clustered belong to the intent document corresponding to the target intent label; performing semantic recognition on the plurality of intent keywords to be clustered respectively through a semantic recognition model to obtain a semantic vector corresponding to each intent keyword to be clustered; processing the semantic vector corresponding to each intent keyword to be clustered by using a clustering algorithm, and constructing the intent keyword set corresponding to the target intent label according to the processing result; Using a large language model to process the set of intent keywords according to the target prompt words, obtaining a white regular expression and a black regular expression corresponding to the target intent label, wherein the white regular expression is used to match the standard format, and the black regular expression is used to process unstructured data; The white regular expression and the black regular expression are stored in a regular library, wherein the regular expressions stored in the regular library are used to identify the user's question-answering intention during the question-answering interaction stage.
2. The method for generating a regular expression based on a large language model according to claim 1, wherein: Also includes: If the match is successful, determining the target regular expression corresponding to the text data; The intent label corresponding to the target regular expression is used as the intent label corresponding to the text data, and a question-answering interaction task is performed based on the intent label corresponding to the text data.
3. The method for generating a regular expression based on a large language model according to claim 1, wherein: Determining the intent keyword corresponding to any one of the multiple intent documents includes: Identify the intent document to be processed; Extracting a plurality of initial intent keywords from the intent document to be processed using a keyword extraction algorithm; The multiple initial intent keywords are deduplicated using a keyword deduplication algorithm, and the intent keywords corresponding to the intent document to be processed are determined based on the deduplication results.
4. The method for generating a regular expression based on a large language model according to claim 1, wherein: After the step of storing the white regular expression and the black regular expression in the regular library is performed, the method further includes: Matching text data with unrecognized intent in the text database with regular expressions stored in the regular library; The associated text data is determined in the text database according to the matching result and deleted.
5. The method for generating regular expressions based on a large language model according to claim 1, wherein: The method of performing deduplication processing on the multiple initial intent keywords using a keyword deduplication algorithm and determining the intent keywords corresponding to the intent document to be processed according to the deduplication processing result includes: Calculating cosine similarity of the multiple initial intent keywords using a keyword deduplication algorithm; Determine the intended keyword to be deleted according to the cosine similarity calculation result, and delete the intended keyword to be deleted from the multiple initial intended keywords; According to the deletion result, the remaining initial intent keywords are used as the intent keywords corresponding to the intent document to be processed.
6. A data processing method, characterized in that: include: Get the question text data submitted by the user; Performing regular matching on the question text data using a regular expression stored in a regular library, wherein the regular expression stored in the regular library is constructed according to the method according to any one of claims 1 to 5; Determine the target regular expression corresponding to the question text data according to the matching result, and use the intent label corresponding to the target regular expression as the intent label corresponding to the question text data; Answer text data is generated based on the intention tag corresponding to the question text data and displayed to the user.
7. A regular expression generation device based on a large language model, characterized in that: include: The selection module is configured to obtain text data and perform regular matching on the text data using regular expressions stored in a regular library. If the matching fails, the text data is input into a large language model for intent recognition to obtain an intent label corresponding to the text data; candidate samples are constructed based on the text data and the intent label corresponding to the text data, and the candidate samples are stored in a sample library; candidate samples with the same intent label are selected from the sample library to form multiple intent documents, wherein the candidate samples are composed based on the text data and the intent label corresponding to the text data, and each intent document corresponds to one intent label; An extraction module is configured to extract the intent keywords corresponding to each intent document, and obtain the intent keyword set corresponding to the target intent label by clustering the intent keywords, wherein the intent keywords corresponding to each intent document come from different candidate samples constituting the intent document, and are determined based on a keyword extraction algorithm and a keyword deduplication algorithm; determination of the intent keyword set corresponding to the target intent label includes: determining a plurality of intent keywords to be clustered corresponding to the target intent label, wherein the plurality of intent keywords to be clustered belong to the intent document corresponding to the target intent label; performing semantic recognition on the plurality of intent keywords to be clustered respectively through a semantic recognition model to obtain a semantic vector corresponding to each intent keyword to be clustered; processing the semantic vector corresponding to each intent keyword to be clustered using a clustering algorithm, and constructing the intent keyword set corresponding to the target intent label according to the processing result; a processing module configured to process the set of intent keywords according to the target prompt word using a large language model to obtain a white regular expression and a black regular expression corresponding to the target intent label, wherein the white regular expression is used to match a standard format and the black regular expression is used to process unstructured data; The storage module is configured to store the white regular expression and the black regular expression in a regular library, wherein the regular expressions stored in the regular library are used to identify the user's question-answering intention during the question-answering interaction stage.
8. A data processing device, characterized in that: include: An acquisition module is configured to acquire question text data submitted by a user; A matching module, configured to perform regular matching on the question text data using a regular expression stored in a regular library, wherein the regular expression stored in the regular library is constructed according to the method according to any one of claims 1 to 5; a determination module configured to determine a target regular expression corresponding to the question text data according to the matching result, and use the intent tag corresponding to the target regular expression as the intent tag corresponding to the question text data; The display module is configured to generate answer text data based on the intention label corresponding to the question text data and display it to the user.
9. A computing device, characterized in that include: memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer-readable storage medium, characterized in that It stores computer-executable instructions, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 6.
11. A computer program product, characterized in that The method comprises a computer program or an instruction, which implements the steps of the method according to any one of claims 1 to 6 when the computer program or the instruction is executed by a processor.
Citation Information
Patent Citations
Text classification method of regular expression generated based on large language model
CN117556049A
Regular expression generation method and device, equipment and storage medium
CN118427406A