Text processing method and device, equipment, readable storage medium and product
By using a deep reinforcement learning constraint to correct the SQL query statements generated by the language model under preset database metadata constraints, the problem of invalid statements generated by large language models is solved, and efficient and accurate query statement generation is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA TELECOM CLOUD TECH CO LTD
- Filing Date
- 2025-12-22
- Publication Date
- 2026-05-05
AI Technical Summary
In existing technologies, when using large language models to generate SQL query statements, invalid statements are easily generated, requiring repeated manual corrections, resulting in low efficiency in natural language recognition.
A pre-trained language model combined with a deep reinforcement learning constraint is used to generate query statements under the metadata constraints of a pre-set database. The generated query statements are dynamically corrected by reward values for grammatical correctness, pattern matching, and logical rationality to ensure accuracy.
It significantly improves the quality and efficiency of query statement generation, reduces the cost of manual intervention, avoids syntax errors and invalid field references, and ensures the compatibility of query statements with the database structure.
Smart Images

Figure CN121979907A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a text processing method, apparatus, device, readable storage medium, and product. Background Technology
[0002] Currently, the method of using a Large Language Model (LLM) to recognize statements and output corresponding SQL query statements is prone to generating invalid SQL statements, requiring repeated manual corrections, resulting in low efficiency in natural language recognition. Summary of the Invention
[0003] Therefore, it is necessary to provide a text processing method, apparatus, device, readable storage medium, and product that can improve the effectiveness of query statements in response to the above-mentioned technical problems.
[0004] Firstly, this application provides a text processing method, including:
[0005] Obtain the text to be recognized input by the user; the text to be recognized is a natural language statement;
[0006] The text to be identified is input into a pre-trained language model, and under the constraints of metadata in a preset database, the model outputs a query statement corresponding to the text to be identified. The language model determines the query statement based on the reward value generated by the deep reinforcement learning constraint. The query statement is an SQL statement.
[0007] Access the preset database based on the query statement and obtain the corresponding response result.
[0008] In one embodiment, the step of inputting the text to be recognized into a pre-trained language model and, under the constraints of metadata in a preset database, outputting a query statement corresponding to the text to be recognized includes:
[0009] Obtain the metadata of the preset database;
[0010] The text to be recognized is input into the language model, and multiple sentence fragments are gradually generated under the constraints of the metadata; during the generation of the sentence fragments, the deep reinforcement learning constraint is used to calculate the reward value of the language model.
[0011] When the reward value reaches a preset reward value threshold, the generation of the statement fragment ends, and the query statement is obtained based on the generated statement fragment.
[0012] In one embodiment, the reward value includes at least one of a grammatical correctness reward value, a pattern matching reward value, and a logically sound reward value.
[0013] In one embodiment, after calculating the reward value of the language model using the deep reinforcement learning constraint during the generation of the sentence fragment, the method further includes:
[0014] If the reward value does not reach the preset reward value threshold, the language model is retrained to achieve parameter tuning of the language model.
[0015] In one embodiment, the step of training the language model includes:
[0016] The sample metadata and multiple sample texts are input into the initial language model to gradually generate multiple sample sentence fragments corresponding to each sample text; during the generation of the sample sentence fragments, the deep reinforcement learning constraint is used to calculate the reward value of the language model;
[0017] When the reward value reaches the initial reward value threshold, the generation of sample sentence fragments corresponding to each sample text ends, and multiple sample query statements are obtained based on the generated sample sentence fragments.
[0018] When the sample query statement meets the preset requirements, the training of the language model ends, the trained language model is obtained, and the initial reward value threshold is used as the preset reward value threshold.
[0019] In one embodiment, after calculating the reward value of the language model using the deep reinforcement learning constraint during the generation of the sample sentence fragment, the method further includes:
[0020] When the sample query statement does not meet the preset requirements, the language model continues to be trained using the sample text and the sample metadata, and the initial reward value threshold is increased by a preset amount.
[0021] The initial reward value threshold is set as the preset reward value threshold until the sample query statement output by the language model meets the preset requirements.
[0022] Secondly, this application also provides a text processing apparatus, the apparatus comprising:
[0023] The acquisition module is used to acquire the text to be recognized input by the user; the text to be recognized is a natural language statement.
[0024] The output module is used to input the text to be recognized into a pre-trained language model and output the query statement corresponding to the text to be recognized; the language model determines the query statement based on the reward value generated by the deep reinforcement learning constraint; the query statement is an SQL statement.
[0025] The acquisition module is used to access a preset database based on the query statement and obtain the corresponding response result.
[0026] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above embodiments.
[0027] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the above embodiments.
[0028] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps in the above embodiments.
[0029] In the aforementioned text processing methods, apparatuses, devices, readable storage media, and products, the pre-trained language model, under the constraints of preset database metadata, can accurately associate requirements with data structures. Combined with the real-time guidance of deep reinforcement learning constraint generators, it avoids misinterpretation of requirements due to vague or non-standard user expressions, ensuring accurate conversion of query statements. By inputting metadata and the statement to be recognized into the language model together, the validity of the generated query statements can be guaranteed from the source, thereby significantly reducing the cost of manual intervention. Furthermore, through the reward value mechanism of deep reinforcement learning constraint generators, deviations can be dynamically corrected during the query statement generation process, preventing problems such as syntax errors and invalid field references, avoiding the generation of statements that deviate from the actual database structure, and improving the quality and efficiency of query statement generation. Attached Figure Description
[0030] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0031] Figure 1 This is a diagram illustrating the application environment of a text processing method in one embodiment.
[0032] Figure 2 This is a flowchart illustrating a text processing method in one embodiment;
[0033] Figure 3 This is a structural block diagram of a text processing device in one embodiment;
[0034] Figure 4 This is a structural block diagram of a text processing device in another embodiment;
[0035] Figure 5 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0037] The text processing method provided in this application embodiment can be applied to, for example, Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be integrated onto server 104, or it can be located in the cloud or on another network server.
[0038] Users can use terminal 102 to input text to be recognized on a preset interface. After receiving the input text, terminal 102 can send it to server 104. Server 104 uses a pre-trained language model stored in the data storage system to input the text and output a query statement corresponding to it. The language model determines the query statement based on the reward value generated by the deep reinforcement learning constraint. Finally, it accesses a preset database in the data storage system based on the query statement and obtains the corresponding response result. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, etc. Server 104 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0039] In one exemplary embodiment, such as Figure 2 As shown, a text processing method is provided, which can be applied to... Figure 1 Taking the server in the example, the explanation includes the following steps 202 to 208. Wherein:
[0040] Step 202: Obtain the text to be recognized input by the user; the text to be recognized is a natural language statement.
[0041] The text to be recognized refers to the query request corresponding to a natural language statement entered by the user in natural language form. As an example, the text to be recognized could be the natural language statement entered by the user on the front-end interface, "I want to query the database to find out who has the highest average score in the class this year."
[0042] In this embodiment, the terminal can receive and parse the text to be recognized by the user through a front-end interface or API interface, and then send it to the server.
[0043] Step 204: Input the text to be recognized into the pre-trained language model, and under the constraints of the metadata of the preset database, output the query statement corresponding to the text to be recognized; the language model determines the query statement based on the reward value generated by the deep reinforcement learning constraint.
[0044] A pre-trained language model refers to a large language model that has been pre-trained on a large number of sample texts and further fine-tuned on a specific task. The specific task may be a natural language to SQL (NL2SQL) task or a text-to-SQL (Text2SQL) task. Once trained, it can have the ability to understand natural language and generate structured query statements.
[0045] As an example, when the text to be recognized is the natural language statement "I want to query from the database who has the highest average score in the class this year", the corresponding query output by the language model could be, for example, the SQL statement select student_id from students where avg_scores =(select Max(avg_scores) from students).
[0046] The metadata of the default database may include, for example, table names, column names, data types, and relationships between tables.
[0047] A query statement refers to a machine-readable structured instruction used to access a pre-defined database, and is used to extract and filter the required data from the pre-defined database. The most common type is the Structured Query Language (SQL) statement.
[0048] Deep Reinforcement Learning (DRL) constraints are used to evaluate the intermediate or final results generated by a language model and calculate reward values to guide the language model to generate more accurate and reasonable outputs.
[0049] The reward value refers to a numerical value dynamically calculated by the deep reinforcement learning constraint based on multiple metrics, used to provide feedback and adjust the language model's generation strategy. For example, metrics may include grammatical correctness, pattern matching degree, and logical rationality, and correspondingly, the reward value may include at least one of the following: grammatical correctness reward value, pattern matching reward value, and logical rationality reward value.
[0050] In this embodiment, the server can use the text to be recognized and the metadata of the preset database as input to the language model. The metadata of the preset database can provide a data structure context for the language model, avoiding the generation of invalid statements that are detached from the actual database structure.
[0051] Furthermore, during the process of the language model generating query statements, the deep reinforcement learning constraint will monitor the generation action in real time. The generation action can, for example, instruct the language model to gradually generate multiple query fragments, i.e., SQL tokens, and calculate the reward value according to the preset reward function, and feed it back to the language model to adjust its subsequent generation behavior.
[0052] Step 206: Access the preset database based on the query statement and obtain the corresponding response results.
[0053] The default database refers to a relational database, such as MySQL or PostgreSQL, that is already configured in the server's data storage system. It can contain metadata such as table structure, column types, and primary and foreign key relationships.
[0054] The response result refers to the data result returned by the pre-defined database after executing the query statement, which meets the user's needs. It is usually presented in a structured form (such as tables or key-value pairs) and is the final feedback information corresponding to the user's input requirements.
[0055] In the aforementioned text processing method, the pre-trained language model, under the constraints of preset database metadata, can accurately associate requirements with data structures. Combined with the real-time guidance of the deep reinforcement learning constraint, it avoids misinterpretation of requirements due to vague or non-standard user expressions, ensuring accurate conversion of query statements. By inputting metadata and the statement to be recognized into the language model together, the validity of the generated query statements can be guaranteed from the source, thereby significantly reducing the cost of manual intervention. Furthermore, through the reward value mechanism of the deep reinforcement learning constraint, deviations can be dynamically corrected during the query statement generation process, preventing problems such as syntax errors and invalid field references, avoiding the generation of statements that deviate from the actual database structure, and improving the query statement generation instructions and efficiency.
[0056] In one embodiment, step 204 includes:
[0057] Retrieve metadata from the preset database;
[0058] The text to be recognized is input into the language model, and multiple sentence fragments are gradually generated under the constraints of metadata. During the generation of sentence fragments, a deep reinforcement learning constraint is used to calculate the reward value of the language model.
[0059] Once the reward value reaches the preset reward value threshold, the generation of the statement fragment ends, and the query statement is obtained based on the generated statement fragment.
[0060] In this embodiment, the server can input the text to be recognized along with the structured metadata into a pre-trained language model. The language model, based on the pre-training capability of the NL2SQL task and combined with the data structure context provided by the metadata, progressively generates sentence fragments in a token-by-token manner.
[0061] As an example, the language model first generates the first statement fragment "SELECT Product Name, SUM(Sales Amount) AS Total Sales Amount" based on the text to be recognized, combined with the information in the "Product Sales Table" in the metadata, which contains columns for "Product Name" and "Sales Amount". Then, based on the time range of "Third Quarter of 2024" and the data type of the "Sales Date" column, it generates the subsequent statement fragment "FROM Product Sales Table WHERE Sales Date BETWEEN '2024-07-01' AND '2024-09-30'". Finally, based on the grouping requirements of "Each Product", it generates the statement fragment "GROUP BY Product Name".
[0062] Throughout the generation process, metadata is always used for boundary constraints to ensure that the language model does not generate references to non-existent tables / columns and avoids generating statement fragments that do not conform to data types.
[0063] While the language model generates each sentence fragment, a deep reinforcement learning constraint simultaneously intervenes to evaluate and calculate the reward value according to preset multi-dimensional indicators.
[0064] As an example, a deep reinforcement learning constraint can first evaluate the syntactic correctness of a statement fragment, checking whether it conforms to SQL syntax rules, such as whether a valid column name follows "SELECT" and whether a valid conditional expression exists after "WHERE". If a syntactic error is found, the reward value is deducted. Second, it evaluates the metadata matching degree, verifying whether the table names and column names in the statement fragment exist in the metadata of the preset database, and whether the condition settings match the field data types. If there is a mismatch, the reward value is reduced. Finally, it evaluates the logical rationality of the statement fragment, combining the inter-table relationships and business constraints in the metadata to determine whether the statement fragment conforms to the business logic. If there is a logical contradiction, the reward value is further deducted. The deep reinforcement learning constraint can quantify the evaluation results of multiple dimensions into specific reward values. The quantification process may include, for example, setting a preset positive reward value to represent the compliance of the statement fragment and a preset negative reward value to represent the problem of the statement fragment, and feeding this feedback to the language model in real time.
[0065] After each sentence fragment generated by the language model and the corresponding reward value calculated by the deep reinforcement learning constraint, the server compares the currently accumulated reward value with a preset reward value threshold. If the reward value does not reach the preset reward value threshold, it indicates that the currently generated sentence fragment has compliance issues (such as grammatical flaws or metadata mismatches). The language model will adjust its generation strategy based on the reward value fed back by the deep reinforcement learning constraint. The adjustment process may include replacing invalid column names or correcting grammatical errors, before continuing to generate the next sentence fragment. If the reward value reaches the preset reward value threshold, and all generated sentence fragments can constitute a complete query logic, the sentence fragment generation process is terminated.
[0066] Subsequently, the server performs logical integration and format validation on all generated statement fragments to ensure smooth connection between fragments and no logical conflicts, ultimately forming a complete and executable query statement.
[0067] In the aforementioned text processing method, the pre-intervention and dynamic constraints of metadata ensure the compatibility of query statements with the preset database structure from the source. The metadata of the preset database provides the language model with clear data structure boundaries, preventing the model from generating query statements that are out of touch with the actual database environment, such as referencing invalid fields or mismatched table relationships. Furthermore, the language model can generate sentence fragments segment by segment and simultaneously receive evaluation from a deep reinforcement learning constraint. The deep reinforcement learning constraint calculates reward values through multiple dimensions, thereby promptly correcting grammatical errors, logical contradictions, and other issues in the sentence fragments, preventing the accumulation of errors from affecting the quality of the final sentence. This significantly improves the compliance and accuracy of the output statement. Combined with the comparison mechanism of the preset reward value threshold, the final output query statement not only meets the quality requirements but also efficiently connects to subsequent database access steps, providing key support for the automation and reliability of the overall text processing workflow.
[0068] In one embodiment, after calculating the reward value of the language model using a deep reinforcement learning constraint during the generation of the sentence fragment, the process further includes:
[0069] If the reward value does not reach the preset reward value threshold, the language model is retrained to achieve parameter tuning of the language model.
[0070] In this embodiment, after calculating the reward value of the query statement generated by the language model, the deep reinforcement learning constraint first compares the reward value with a preset reward value threshold. When it is determined that the reward value does not reach the preset reward value threshold, it can be considered that the currently generated query statement has obvious defects, such as syntax errors, references to non-existent database fields, or contradictions between logic and business requirements. At this time, the server will trigger the retraining process of the language model to optimize the generation strategy of the language model through targeted parameter tuning, so as to avoid the repeated generation of unqualified query statements.
[0071] As an example, the deep reinforcement learning constraint will backtrack to the detailed dimensional data of the current reward value calculation, including the reward score for grammatical correctness, the reward score for metadata matching, and the reward score for logical rationality, etc., to pinpoint the specific reasons for the low reward value of the query statement: for example, if the metadata matching score is extremely low, it may be considered that the language model has not accurately memorized the table column relationships of the preset database; if the grammatical correctness score is insufficient, it may be considered that the language model has a bias in its mastery of specific SQL syntax, etc. At the same time, the server will record the substandard statement fragments, the corresponding text to be identified, and metadata information, forming error samples and labeling the defect types, providing precise optimization directions for retraining.
[0072] The server can further integrate the generated error samples with historically accumulated similar defect samples to construct a targeted training dataset. This dataset not only includes the error fragments themselves, but also includes corresponding correction schemes and defect cause annotations, ensuring that the language model can clearly perceive the location of errors and optimization directions during training. At the same time, to avoid the language model overfitting to a single defect type, validated and qualified sentence fragment samples will be appropriately mixed in to maintain the balance of the training data.
[0073] The text processing method described above employs a closed-loop design involving reward threshold determination, targeted retraining, and parameter iterative optimization. This approach enables precise repair of model defects and capability iteration, preventing the recurrence of similar errors. When the reward value fails to reach the preset threshold, defect attribution analysis can pinpoint the root cause of the problem. Then, targeted retraining can be performed based on the targeted training dataset, fine-tuning only the model parameters related to the defects. This avoids the waste of resources from large-scale retraining while allowing the model to accurately compensate for its capability shortcomings.
[0074] In one embodiment, during each generation of sentence fragments by the language model, the deep reinforcement learning constraint can also correct the low reward value of a sentence fragment through a lightweight rollback mechanism after locating the specific reason. For example, when a sentence fragment has a misspelled column name, the deep reinforcement learning constraint can replace the column name with the column name that exists in the metadata through a lightweight rollback mechanism.
[0075] In one embodiment, the server can also verify the validity of the final generated query statement. If the server cannot successfully perform the access in the preset database based on the query statement, it triggers the language model to regenerate the query statement of the text to be recognized.
[0076] In one embodiment, the step of training the language model includes:
[0077] The sample metadata and multiple sample texts are input into the initial language model to gradually generate multiple sample sentence fragments corresponding to each sample text; during the generation of sample sentence fragments, a deep reinforcement learning constraint is used to calculate the reward value of the language model.
[0078] When the reward value reaches the initial reward value threshold, the generation of sample sentence fragments corresponding to each sample text ends, and multiple sample query statements are obtained based on the generated sample sentence fragments.
[0079] When the sample query statement meets the preset requirements, the training of the language model ends, the trained language model is obtained, and the initial reward value threshold is used as the preset reward value threshold.
[0080] Sample metadata refers to reference data used to train language models and simulate the actual database structure. Sample metadata can cover information such as table names, column names, data types, and relationships between tables.
[0081] Preset requirements refer to the standards set during the training phase to judge the quality of sample query statements and the model training effect. They can cover multiple dimensions such as effectiveness, accuracy, and generality. The model training is considered complete only when all sample query statements meet the requirements of the above dimensions.
[0082] The sample metadata can simulate database metadata in real-world application scenarios, covering the structural information of various mainstream databases, including table names, column names, data types, and inter-table relationships in different business scenarios, to ensure the diversity and representativeness of the sample metadata; multiple sample texts can cover different types of natural language query needs, including both basic queries and complex needs, while incorporating common input formats in real-world scenarios such as colloquial expressions and fuzzy time descriptions, to ensure the comprehensiveness of the training data.
[0083] Subsequently, the preprocessed sample metadata and sample text are input into the initial language model in a one-to-one or one-to-many correspondence. The initial model will understand user needs based on the sample text and, in combination with the data structure boundaries provided by the sample metadata, progressively generate sample sentence fragments in a token-by-token manner.
[0084] After each sample sentence fragment is generated, the deep reinforcement learning constraint immediately intervenes to evaluate it, calculating a reward value according to preset multi-dimensional indicators. The deep reinforcement learning constraint quantifies the multi-dimensional evaluation results into specific reward values and feeds them back to the initial language model in real time. The initial language model then adjusts the generation strategy of subsequent fragments based on the reward value: if the reward value is positive, it continues the current generation direction; if the reward value is negative, it corrects errors.
[0085] After the initial language model generates each sample sentence fragment and the deep reinforcement learning constraint calculates the reward value, the server compares the reward value of the current sample sentence fragment with the initial reward value threshold. If the reward value does not meet the threshold, the initial language model needs to adjust the strategy based on the feedback from the deep reinforcement learning constraint and continue to generate the next sample sentence fragment. If the reward value meets the threshold and the generated sample sentence fragment can constitute a complete query logic, the generation of the sample sentence fragment corresponding to that sample text is terminated.
[0086] Subsequently, all the generated sample sentence fragments were logically integrated and formatted, ultimately generating multiple sample query statements that correspond one-to-one with the multiple sample texts.
[0087] The server will verify each sample query statement one by one. If any sample query statement does not meet the preset requirements, it needs to return to the first step, supplement more targeted sample statements, and redo the sample statement fragment generation and reward value evaluation until all sample query statements meet the preset requirements.
[0088] The aforementioned text processing method allows sample metadata to simulate mainstream database structures and sample text to cover real-world query scenarios, enabling the initial language model to learn in an environment close to actual business needs and avoiding abstract training detached from the context. Simultaneously, the deep reinforcement learning constraint uses real-time reward value evaluation to ensure the initial language model establishes correct generation logic from the early stages of training, reducing later optimization costs. Furthermore, using an initial reward value threshold sets clear quality standards for sentence fragment generation, preventing the accumulation of fragment defects due to arbitrary generation, ensuring the trained model possesses stable practical value, and thus significantly improving the efficiency of model training and deployment.
[0089] In one embodiment, after calculating the reward value of the language model using a deep reinforcement learning constraint during the generation of sample sentence fragments, the process further includes:
[0090] If the sample query does not meet the preset requirements, continue to train the language model using sample text and sample metadata, and increase the initial reward value threshold according to the preset range.
[0091] The initial reward value threshold will be increased until the sample query statement output by the language model meets the preset requirements, at which point the preset reward value threshold will be used.
[0092] In this embodiment, the server analyzes each sample query statement that does not meet the preset requirements, combines the reward value data of the deep reinforcement learning constraint in the fragment generation stage, locates the specific defect type, and counts the proportion of each type of defect to determine the core optimization direction of this round of continuous training.
[0093] Subsequently, specific training samples are added for the identified defect types, and the supplemented sample text and sample metadata are input into the current language model to restart the generation of sentence fragments. The deep reinforcement learning constraint still calculates the reward value, and the weight of the evaluation dimensions related to the defect type is appropriately increased to strengthen the constraint on key defects.
[0094] After completing a round of targeted iterative training, the server will increase the initial reward value threshold by a preset amount, such as 0.05-0.1 each time, so as to force the language model to further optimize the generation strategy through higher quality standards.
[0095] The above text processing method introduces a dynamic reward threshold adjustment mechanism during model optimization. By dynamically increasing the initial reward threshold, a quality-driven mechanism is constructed to promote continuous optimization of the language model. Furthermore, a preset requirement is used as a necessary and sufficient condition for training termination, ensuring that the language model trained in the end can meet the predetermined quality standards. By establishing a gradual optimization path, the risk of the model getting stuck in a local optimum in the early stages of training due to reward sparsity is effectively prevented.
[0096] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0097] Based on the same inventive concept, this application also provides a text processing apparatus for implementing the text processing method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more text processing apparatus embodiments provided below can be found in the limitations of the text processing method described above, and will not be repeated here.
[0098] In one exemplary embodiment, such as Figure 3 As shown, a text processing device 300 is provided, comprising:
[0099] The acquisition module 301 is used to acquire the text to be recognized input by the user;
[0100] The first input module 302 is used to input the text to be recognized into a pre-trained language model and output the query statement corresponding to the text to be recognized; the language model determines the query statement based on the reward value generated by the deep reinforcement learning constraint.
[0101] The acquisition module 303 is used to access a preset database based on a query statement and obtain the corresponding response result.
[0102] In one embodiment, the first input module 302 is further configured to:
[0103] Retrieve metadata from the preset database;
[0104] The text to be recognized is input into the language model, and multiple sentence fragments are gradually generated under the constraints of metadata. During the generation of sentence fragments, a deep reinforcement learning constraint is used to calculate the reward value of the language model.
[0105] Once the reward value reaches the preset reward value threshold, the generation of the statement fragment ends, and the query statement is obtained based on the generated statement fragment.
[0106] In one embodiment, the reward value includes at least one of the following: a grammatical correctness reward value, a pattern matching reward value, and a logically sound reward value.
[0107] In one embodiment, the first input module 302 is further configured to:
[0108] If the reward value does not reach the preset reward value threshold, the language model is retrained to achieve parameter tuning of the language model.
[0109] like Figure 4 As shown, in one embodiment, the text processing device 300 further includes:
[0110] The second input module 304 is used to input sample metadata and multiple sample texts into the initial language model to gradually generate multiple sample sentence fragments corresponding to each sample text; during the generation of sample sentence fragments, a deep reinforcement learning constraint is used to calculate the reward value of the language model.
[0111] The generation module 305 is used to end the generation of sample sentence fragments corresponding to each sample text when the reward value reaches the initial reward value threshold, and to obtain multiple sample query statements based on the generated sample sentence fragments.
[0112] The determination module 306 is used to end the training of the language model when the sample query statement meets the preset requirements, obtain the trained language model, and use the initial reward value threshold as the preset reward value threshold.
[0113] In one embodiment, the generation module 305 is further configured to:
[0114] If the sample query does not meet the preset requirements, continue to train the language model using sample text and sample metadata, and increase the initial reward value threshold according to the preset range.
[0115] The initial reward value threshold will be increased until the sample query statement output by the language model meets the preset requirements, at which point the preset reward value threshold will be used.
[0116] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 5 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores business progress query data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When executed by the processor, the computer program implements a text processing method.
[0117] Those skilled in the art will understand that Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0118] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0119] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.
[0120] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0121] 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, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0122] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0123] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0124] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A text processing method, characterized in that, The method includes: Obtain the text to be recognized input by the user; the text to be recognized is a natural language statement; The text to be identified is input into a pre-trained language model, and under the constraints of metadata in a preset database, the model outputs a query statement corresponding to the text to be identified. The language model determines the query statement based on the reward value generated by the deep reinforcement learning constraint. The query statement is an SQL statement. Based on the query statement, access the preset database and obtain the corresponding response result.
2. The method according to claim 1, characterized in that, The step of inputting the text to be recognized into a pre-trained language model and, under the constraints of metadata in a preset database, outputting a query statement corresponding to the text to be recognized includes: Obtain the metadata of the preset database; The text to be recognized is input into the language model, and multiple sentence fragments are gradually generated under the constraints of the metadata; during the generation of the sentence fragments, the deep reinforcement learning constraint is used to calculate the reward value of the language model. When the reward value reaches a preset reward value threshold, the generation of the statement fragment ends, and the query statement is obtained based on the generated statement fragment.
3. The method according to claim 2, characterized in that, The reward value includes at least one of the following: grammatical correctness reward value, pattern matching reward value, and logical reasonableness reward value.
4. The method according to claim 2, characterized in that, After calculating the reward value of the language model using the deep reinforcement learning constraint during the generation of the sentence fragment, the process further includes: If the reward value does not reach the preset reward value threshold, the language model is retrained to achieve parameter tuning of the language model.
5. The method according to claim 2, characterized in that, The steps for training the language model include: The sample metadata and multiple sample texts are input into the initial language model to gradually generate multiple sample sentence fragments corresponding to each sample text; during the generation of the sample sentence fragments, the deep reinforcement learning constraint is used to calculate the reward value of the language model; When the reward value reaches the initial reward value threshold, the generation of sample sentence fragments corresponding to each sample text ends, and multiple sample query statements are obtained based on the generated sample sentence fragments. When the sample query statement meets the preset requirements, the training of the language model ends, the trained language model is obtained, and the initial reward value threshold is used as the preset reward value threshold.
6. The method according to claim 5, characterized in that, In the process of generating the sample sentence fragment, after calculating the reward value of the language model using the deep reinforcement learning constraint, the method further includes: When the sample query statement does not meet the preset requirements, the language model continues to be trained using the sample text and the sample metadata, and the initial reward value threshold is increased by a preset amount. The initial reward value threshold is set as the preset reward value threshold until the sample query statement output by the language model meets the preset requirements.
7. A text processing device, characterized in that, The device includes: The acquisition module is used to acquire the text to be recognized input by the user; the text to be recognized is a natural language statement. The output module is used to input the text to be recognized into a pre-trained language model and output the query statement corresponding to the text to be recognized; the language model determines the query statement based on the reward value generated by the deep reinforcement learning constraint; the query statement is an SQL statement. The acquisition module is used to access a preset database based on the query statement and obtain the corresponding response result.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.