A large model-based traffic question and answer method, device and equipment
By semantically understanding the question text to generate triple information and converting it into structured instructions, the problem of irrelevant SQL statements output by large models is solved, achieving more accurate question-answering results.
Patent Information
- Application Number
- CN202511443851.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-10
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2045-10-10
AI Technical Summary
Due to the limitations of large-scale model training data, the output SQL statements are not related to the input natural language question text, which affects the question answering effect.
The question-answering model performs semantic understanding on the question text, generates triple information containing intent, entity, and constraints, and converts it into structured target instructions. The instruction parsing engine then generates SQL statements for question answering.
It improves the accuracy of generated SQL statements, thereby enhancing the effectiveness of question answering and solving the inaccuracy problem caused by insufficient understanding of the question text in traditional question answering.
Smart Images

Figure CN120929575B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, and in particular to a traffic question and answer method, device and equipment based on a large model. BACKGROUND
[0002] At present, with the technical upgrading brought by advanced large models such as ChatGPT and DeepSeek, large model technology has entered the stage of deep empowerment of vertical industries from the exploration of general capabilities, and has become the core engine driving the digital transformation of industries.
[0003] With the development of large models, large models are widely used in the field of natural language conversion to structured query language (NL2SQL). That is, the related technology directly inputs the natural language sentence into the large model, and the large model directly converts the natural language sentence into an SQL statement. However, due to the limitations of the training data of the large model, the SQL statement output by the large model may not be related to the input natural language sentence, and thus the reply generated based on the SQL statement output by the large model subsequently is inaccurate, affecting the question and answer effect. SUMMARY
[0004] The present application provides a traffic question and answer method, device and equipment based on a large model to improve the accuracy of generating SQL and thus improve the question and answer effect.
[0005] In a first aspect, the embodiments of the present application provide a traffic question and answer method based on a large model, which comprises:
[0006] processing the input question text using a question and answer model to generate a target instruction containing triple information of the question text; wherein the triple information includes intent, entity and corresponding constraint conditions;
[0007] calling an instruction parsing engine to process the target instruction to generate a first SQL statement for querying data corresponding to the intent, entity and corresponding constraint conditions;
[0008] According to the first SQL statement, querying the first target data corresponding to the intent, entity and corresponding constraint conditions in the knowledge base, and generating a reply text based on the first target data.
[0009] In a second aspect, the embodiments of the present application also provide a traffic question and answer device based on a large model, which comprises:
[0010] The processing module is configured to process input question text by using a question and answer model to generate a target instruction containing triple information of the question text; wherein the triple information includes an intent, an entity, and corresponding constraint conditions; and call an instruction analysis engine to process the target instruction to generate a first SQL statement for querying data corresponding to the intent, the entity, and the corresponding constraint conditions.
[0011] The question and answer module is configured to query first target data corresponding to the intent, the entity, and the corresponding constraint conditions in a knowledge base according to the first SQL statement, and generate a reply text based on the first target data.
[0012] In a third aspect, the embodiments of the present application further provide an electronic device, which comprises at least a processor and a memory, and the processor is configured to execute a computer program stored in the memory to implement the steps of the traffic question and answer method based on a large model.
[0013] In the embodiments of the present application, the question text is converted into a structured target instruction, so that the target instruction contains complete semantic information of the question text, and then a SQL statement is generated based on the structured target query instruction, so that the question and answer are performed based on the SQL statement, thereby solving the problem that the generated SQL statement is not related to the question text and the question and answer are not accurate and effective due to insufficient understanding of the question text in the traditional question and answer. BRIEF DESCRIPTION OF DRAWINGS
[0014] In order to more clearly illustrate the technical solutions of the present application, the following will briefly introduce the drawings needed in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.
[0015] Figure 1 A traffic question and answer process based on a large model is provided for the embodiments of the present application.
[0016] Figure 2 A semantic analysis label generation flowchart is provided for the embodiments of the present application.
[0017] Figure 3 A traffic management business domain index system schematic diagram is provided for the embodiments of the present application.
[0018] Figure 4 An intent and API template correspondence schematic diagram is provided for the embodiments of the present application.
[0019] Figure 5 A possible question and answer flowchart is provided for the embodiments of the present application.
[0020] Figure 6 Another possible question and answer flowchart provided for the embodiments of the present application;
[0021] Figure 7 A large model-based traffic question and answer device structure schematic diagram provided for the embodiments of the present application;
[0022] Figure 8 An electronic device structure schematic diagram provided for the embodiments of the present application. DETAILED DESCRIPTION
[0023] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application will be described in further detail below with reference to the drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of protection of the present application.
[0024] At present, with the technical upgrading brought by advanced large models such as ChatGPT and DeepSeek, large model technology has entered the stage of deep empowerment in vertical industries from the exploration of general capabilities, and has become the core engine driving the digital transformation of industries. Intelligent question and answer, intelligent question and number, etc. as typical application scenarios of large models, realize data query and analysis through natural language interaction, and significantly reduce the threshold for business personnel to use data.
[0025] Although intelligent question and answer and intelligent question and number are widely used, the existing technical route still has significant limitations. On the one hand, NL2SQL (the scheme is limited by the illusion problem of the large model, and the reliability of directly generating dynamic SQL statements is low. Practice shows that a general model needs to rely on massive field data fine-tuning to reach the basic usability standard, and the accuracy rate of complex queries such as multi-table association and nested clauses is less than 55%. On the other hand, although the commonly used alternative scheme NL2DSL can avoid part of the illusion risk, it is limited by the expression ability of DSL, for example, traditional DSL is difficult to support spatial relationships such as "near a school", event descriptions such as "mentioning a vehicle on fire" and other unstructured semantics, resulting in narrow application scenarios and poor scalability. These defects jointly restrict the deep analysis of complex semantics in the traffic management vertical field.
[0026] Based on this, in order to improve the accuracy of generated SQL and thus improve the question and answer effect, the embodiments of the present application provide a large model-based traffic question and answer method, device and equipment.
[0027] Figure 1 A large model-based traffic question and answer process schematic diagram provided for the embodiments of the present application, the process includes:
[0028] S101: adopt the question and answer model to process the input question text, and generate a target instruction containing the triple information of the question text; wherein the triple information includes intent, entity and corresponding constraint condition.
[0029] The traffic question and answer method based on a large model provided in the embodiments of the present application is applied to an electronic device, which can be a server, a PC or a terminal device, etc.
[0030] In the related art, the natural language question text is directly input into the large model, and the large model directly converts the natural language question text into a SQL statement. However, due to the limitation of the training data of the large model, the SQL statement output by the large model can be irrelevant to the input natural language question text, that is, the large model cannot accurately understand the semantic information of the natural language question text, resulting in that the output SQL statement is irrelevant to the question text, and further resulting in that the reply generated based on the SQL statement output by the large model is inaccurate, affecting the question and answer effect.
[0031] Compared with the related art, the embodiments of the present application design a structured intermediate layer, first perform semantic understanding on the question text to obtain triple information corresponding to the semantic information of the question text, then convert the triple information into a structured target instruction, and generate a first SQL statement based on the target instruction, so as to generate a reply text according to the first SQL statement.
[0032] In the embodiments of the present application, the question text is fully understood by the question and answer model, and the triple information is obtained, so that the structured target instruction generated subsequently carries the triple information, and then the SQL statement is generated based on the structured target query instruction, so as to perform question and answer based on the SQL statement, solving the problem that in the traditional question and answer, due to insufficient understanding of the question text, the generated SQL statement is irrelevant to the question text, and the question and answer is inaccurate and poor in effect.
[0033] In a possible implementation, the electronic device can receive a question text sent by another device; the electronic device can also receive voice information input by a user by using a voice receiver, and convert the voice information into text, and determine the converted text as the question text; the electronic device can also directly receive a question text input by a user through an external device such as a keyboard; the electronic device can also receive a question text input by a user through an APP, a WEB page or other software.
[0034] The question text can be a natural language text or other formats of text, which is not limited herein.
[0035] In the embodiments of the present application, a trained question and answer model is configured in the electronic device, and the question and answer model is used to convert the question text into a structured target instruction.
[0036] Specifically, the electronic device inputs the question text into a question and answer model, the question and answer model performs semantic understanding on the question text to obtain triple information corresponding to the question text, and then converts the triple information into a structured target instruction.
[0037] In a possible implementation, the question and answer model can be a neural network model with learning ability, such as CNN, BERT, etc.; the question and answer model can also be a large model, such as a large language model, a multi-modal large model, etc.
[0038] In the embodiment of the application, the triple information obtained by the question and answer model performing semantic understanding on the question text includes but is not limited to intent, entity and constraint condition. Among them, the entity in the triple information is an entity type corresponding to an entity contained in the question text, such as name, employee number, etc., and the constraint condition is a specific entity value contained in the question text, such as a specific name, a specific province, etc.
[0039] In the embodiment of the application, the structured target instruction uses a predefined JSON format, and the target instruction can be a data query instruction for querying data related to the triple information in the knowledge base. The template corresponding to the structured target instruction is pre-configured in the application, and the question and answer model can call the template and add the triple information to the corresponding position of the template to obtain the target instruction.
[0040] S102: calling an instruction parsing engine to process the target instruction to generate a first SQL statement for querying data corresponding to the intent, entity and corresponding constraint condition.
[0041] In the embodiment of the application, the electronic device is also pre-configured with an instruction parsing engine, which can parse the target instruction, obtain the triple information carried in the target instruction, and generate a first SQL statement for querying data corresponding to the intent, entity and corresponding constraint condition contained in the triple information based on the triple information.
[0042] In a possible implementation, the instruction parsing engine can determine the business domain corresponding to the current question and answer based on the intent carried in the target instruction; determine the database table to be queried based on the business domain; the instruction parsing engine can also determine the SQL statement template corresponding to the intent based on the intent; the instruction parsing engine adds the information of the database table, the entity and the constraint condition carried in the target instruction to the SQL template to obtain the first SQL statement.
[0043] For example, in the embodiment of the application, the traffic management domain data is divided into five core business domains of accident, police situation, vehicle, driver and violation, and a corresponding database table is designed for each business domain.
[0044] Specifically, the electronic device is pre-configured with a correspondence relationship among the intent, the business domain and the database table, and is also pre-configured with a correspondence relationship between the intent and the SQL template. The instruction parsing engine acquires the triple information carried in the target instruction, and determines, according to the pre-configured correspondence relationship among the intent, the business domain and the database table, the business domain corresponding to the intent carried in the triple information and the database table to be queried; the instruction parsing engine determines, according to the pre-configured correspondence relationship between the intent and the SQL template, the SQL template corresponding to the intent carried in the triple information; and the instruction parsing engine adds the entity and the constraint condition carried in the triple information and the information of the database table to be queried to the SQL template, to obtain a first SQL statement.
[0045] For example, the instruction parsing engine matches the pre-defined SQL template according to the intent type. For example, the query instruction corresponds to SELECT [field] FROM [table] WHERE [condition], the statistical instruction corresponds to SELECT COUNT ( ) FROM [table] WHERE [condition], and so on. The instruction parsing engine maps the triple to the SQL template in combination with the Schema information of the database table to be queried (such as the table structure, the field type, and the primary key / foreign key relationship). For example, the SELECT clause corresponds to the query field in the intent, such as "temperature" is mapped to SELECT temperature; the WHERE clause corresponds to the entity and the constraint condition, such as "Beijing" is mapped to WHERE location = 'Beijing', and "tomorrow" is mapped to WHERE date = '2025-09-23'.
[0046] S103: Querying, according to the first SQL statement, the first target data corresponding to the intent, the entity and the corresponding constraint condition in the knowledge base, and generating a reply text based on the first target data.
[0047] In the embodiment of the present application, after the electronic device obtains the first SQL statement based on the instruction parsing engine, the electronic device executes the first SQL statement, queries the first target data corresponding to the intent, the entity and the corresponding constraint condition in the knowledge base according to the first SQL statement, and generates a reply text based on the first target data.
[0048] In order to better perform data query and question answering, in the embodiment of the present application, the data saved in the knowledge base is pre-processed. The pre-processing includes at least one of business domain structured definition, hierarchical label system enhancement and index modeling.
[0049] Specifically, the business domain structured definition includes: constructing a database table according to a business domain, and saving the relationship between the business domain and the database table. Specifically, the traffic management domain data can be divided into five core business domains of accident, police situation, vehicle, driver and illegal, a standardized original database table structure is designed for each business domain, the field type, constraint and correlation relationship are established, and then the data is saved into the corresponding database table according to the table structure.
[0050] The storage form of data in a technical system (such as a database field, a code value) cannot be directly understood by business personnel, and business analysis requirements (such as “red light running” and “express delivery”) cannot be accurately matched to specific fields in the stored business table. This gap leads to inefficient intelligent questioning and data analysis, and distorted decision-making. To break down the gap between data and business semantics, the application upgrades fragmented data to computable business semantic units through a hierarchical label system enhancement, solving the defect that traditional data models cannot support complex semantic understanding.
[0051] Specifically, the hierarchical label system enhancement includes: according to the specific information of each data, a plurality of levels of labels are allocated to each data. The plurality of levels of labels include but are not limited to basic labels, derived labels, statistical labels and semantic analysis labels. Among them, the basic label is the database table field corresponding to the data, such as jurisdiction, accident time, etc.; the derived label is the classification or range to which the basic label belongs, which is obtained by converting the basic label based on rules, such as the basic label being accident time, the derived label can be quarterly label, annual label, etc.; the statistical label is generated by referring to other database tables and SQL calculation, carrying information of other database tables, such as the basic label being “engineering transport vehicle”, the corresponding statistical label can be “associated vehicle information table and accident personnel table”, etc.; the semantic analysis label is the text key information extracted from the text description corresponding to the data, such as identifying the “hospital surrounding” label from the case description.
[0052] Specifically, a four-level enhancement label system can be constructed according to the basic label (original field), the derived label (rule mapping), the statistical label (multi-table association calculation) and the semantic analysis label (NLP semantic extraction).
[0053] In one possible implementation, a large model can be used to process the text description corresponding to the data to obtain the semantic description label corresponding to the data.
[0054] Figure 2 The generation process diagram of the semantic analysis label provided by the embodiment of the application is as follows: Figure 2As shown, the process includes: obtaining an accident brief case text (i.e., a text description) corresponding to the data to be added, using a large model to extract features from the accident brief case text, and based on the extracted features, performing real-time tagging to obtain semantic tags (i.e., semantic parsing tags).
[0055] Index modeling is the process of converting business objectives into a quantifiable and structured index system. First, the dimension columns of the database table can be defined (define the analysis perspective, such as the time dimension quarter and the space dimension jurisdiction), and the measurement columns can be set (set quantifiable indicators such as the number of accidents and vehicle density), and then the index caliber is defined, and the large model is set with clear structured index calculation rules, which greatly improves the accuracy.
[0056] For example, the index caliber includes but is not limited to atomic indicators, derived indicators, and composite indicators.
[0057] Among them, the atomic indicator is the value corresponding to the basic label carried in the data, that is, the basic calculation unit, for example: the number of accidents = COUNT(incident ID)); the derived indicator is based on the atomic indicator composite operation, for example, the same period accident growth rate = (this period accident number - last period accident number) / last period accident number); the composite indicator is a multi-dimensional calculation, for example, the hospital accident ratio = hospital accident number / total accident number).
[0058] Figure 3 The traffic management business domain index system provided by the embodiments of the present application is shown in the figure. Figure 3 As shown, the "accident" field contains 4 major indicators and 53 dimensions, the 4 major indicators are the number of accidents, the number of injured, the number of deaths, and the property damage, and the 53 dimensions include the occurrence time: today / yesterday / last week, etc.; the "motor vehicle" field contains 4 major indicators and 30 dimensions, the 4 major indicators are motor vehicle ownership, registration, cancellation, and overdue non-scraping, and the 3 dimensions include statistical time: year / quarter / last month / week / day, etc.; the "driver" field contains 3 major indicators and 23 dimensions, the 3 major indicators are driver ownership, registration, and cancellation, and the 23 dimensions include statistical time: year / quarter / last month / week / day, etc.; the "running situation" field contains 7 major indicators and 14 dimensions, the 7 major indicators are traffic index, average speed, congestion mileage, flow, number of vehicles in transit, daily active vehicle number, and number of in and out of the city, and the 14 dimensions include statistical period: today / early peak / 9 o'clock / yesterday / this week, etc.; the "police case" field contains 3 major indicators and 22 dimensions, the 3 major indicators are the number of police cases, the length of time to police, and the length of time to police, and the 22 dimensions include time: year / quarter / last month / week / day / hour, etc.
[0059] In the embodiment of the present application, the electronic device integrates the field, label, and index triple data system, constructs a business domain wide table, and adds a natural language note to a key element (such as marking the label calculation logic of the “engineering transport vehicle” as “associating the vehicle_info table with the accident_person table and filtering vehicle_type ∈ {‘concrete truck’, ‘muck truck’}”), thereby supporting semantic understanding and automatic analysis of a large model.
[0060] Based on this, in the embodiment of the present application, the electronic device can query the first target data corresponding to the intent, entity, and corresponding constraint condition in the knowledge base according to the first SQL statement and the label and index corresponding to each data saved in the knowledge base, and generate a reply text based on the first target data.
[0061] Specifically, the electronic device determines the database table to be queried in the knowledge base according to the database table information carried in the first SQL statement, and determines the first target data corresponding to the entity and corresponding constraint condition according to the label information and index information corresponding to each data carried in the database table to be queried saved in the knowledge base, and generates a reply text based on the first target data.
[0062] In the embodiment of the present application, the problem text is converted into a structured target instruction, so that the target instruction contains complete semantic information of the problem text, and then a SQL statement is generated based on the structured target query instruction, so that the SQL statement is used for question answering, thereby solving the problem that the generated SQL statement is not related to the problem text in the traditional question answering due to insufficient understanding of the problem text, and the question answering is inaccurate and ineffective.
[0063] In order to improve the accuracy of generating SQL and further improve the question answering effect, on the basis of the above embodiment, in the embodiment of the present application, the question answering model includes a text encoder and a structure encoder.
[0064] The processing of the input problem text by the question answering model to generate a target instruction containing triple information of the target question includes:
[0065] The text encoder is used to process the problem text to obtain the triple information corresponding to the problem text;
[0066] The structure encoder is used to process the triple information to obtain the target instruction.
[0067] In the embodiment of the present application, the question answering model includes a text encoder and a structure encoder. The text encoder is used to perform semantic analysis on the problem text to obtain triple information corresponding to the problem text, and the structure encoder is used to obtain a structured target instruction based on the triple information corresponding to the problem text.
[0068] Specifically, the electronic device inputs the question text into a question and answer model, a text encoder of the question and answer model processes the question text to obtain triple information corresponding to the question text; the text encoder inputs the triple information as input into a structure encoding of the question and answer model, and a structure encoder processes the triple information to obtain a target instruction.
[0069] For example, the triple information of the question text Q can be represented as: Q = I, E, C; wherein I represents an intent, E represents an entity, and C represents a constraint condition.
[0070] In a possible implementation, the intent of the question text is one of a preconfigured intent set, which includes but is not limited to four categories of screening statistics, trend exploration, operation processing, and horizontal comparison; wherein the screening statistics include but are not limited to detail query, list screening, and count statistics; the trend exploration includes but is not limited to trend analysis, same period calculation, ring ratio calculation, and proportion analysis; the operation processing includes but is not limited to mean calculation, addition and subtraction calculation, and index comparison; and the horizontal comparison includes but is not limited to sorting statistics, TopN selection, and extreme value analysis.
[0071] The entity of the question text is at least one of a preconfigured entity set, which can be a field, a time range, etc. One or more entities are included in the triple information of one question text.
[0072] The constraint condition of the question text is at least one of a preconfigured constraint condition set, which can be a filtering condition, a sorting rule, etc. One or more constraint rules are included in the triple information of one question text.
[0073] For example, the triple information of the question text Q can be Q = TopN sorting, {accident amount, jurisdiction}, {time = 2024Q1, N = 5}. That is, the intent of the question text Q is TopN sorting, the entity of the question text Q is accident amount and jurisdiction, and the constraint condition of the question text Q is time = 2024Q1, N = 5.
[0074] In the embodiments of the present application, the structure encoder obtains the target instruction based on the triple information.
[0075] Wherein, the API instruction generation function can be defined as:
[0076]
[0077] Wherein, is the target instruction corresponding to the question text Q, I is the intent, E is the entity, and C is the constraint condition.
[0078] To improve the accuracy of generating SQL and further improve the question and answer effect, on the basis of the above embodiments, in the embodiment of the application, the adopting the text encoder to process the question text to obtain the triple information corresponding to the question text comprises:
[0079] Adopting the text encoder to perform intent recognition on the question text to obtain the intent of the question text;
[0080] Adopting the text encoder to perform entity recognition on the question text to obtain the entity contained in the question text;
[0081] Adopting the text encoder to perform constraint condition recognition on the question text to obtain the constraint condition contained in the question text;
[0082] Determine the intent, the entity and the constraint condition as the triple information.
[0083] In the embodiment of the application, the text encoder is adopted to perform intent recognition, entity recognition and constraint condition recognition on the question text to obtain the intent of the question text, the entity contained in the question text and the constraint condition. The text encoder takes the recognized intent, entity and constraint condition as triple information.
[0084] In a possible implementation, the text encoder can determine the intent corresponding to the question text by semantic classification; the text encoder can determine the entity corresponding to the question text by rule matching or entity detection; and the text encoder can determine the constraint condition corresponding to the question text by rule matching or constraint condition detection.
[0085] For example, the electronic device is preconfigured with an entity set and a constraint condition set. The text encoder can determine a candidate entity in the entity set contained in the question text according to the entity set, and take the candidate entity as the entity contained in the question text; and the text encoder can determine a candidate constraint condition in the constraint condition set contained in the question text according to the constraint condition set, and take the candidate constraint condition as the constraint condition contained in the question text.
[0086] To improve the accuracy of generating SQL and further improve the question and answer effect, on the basis of the above embodiments, in the embodiment of the application, the target instruction is an API instruction;
[0087] The adopting the structure encoder to process the triple information to obtain the target instruction comprises:
[0088] The structure encoder determines a target API instruction type corresponding to the intent of the question text according to a correspondence relationship between the configured intent and the API instruction type.
[0089] The structure encoder obtains an API template corresponding to the target API instruction type, and adds the intent of the question text, an entity contained in the question text and a corresponding entity value into the API template to obtain the API instruction.
[0090] In the embodiment of the application, the target instruction output by the structure encoder can be an API instruction.
[0091] In addition, in order to better reflect each intent, an API template corresponding to each intent is configured in advance, wherein one API template can correspond to one intent, or one API template can correspond to multiple intents.
[0092] In a possible implementation, the API instruction can be divided into a data query / filtering API instruction (getDetails), an index statistics API instruction (getIndices) and an index secondary statistics processing API instruction (getIndicesMeasure).
[0093] Figure 4 A correspondence relationship between the intents and the API templates provided in the embodiment of the application is shown in a schematic diagram as shown in the figure. Figure 4 As shown in the figure, the intents are divided into four categories, i.e., filtering statistics, trend exploration, operation processing and horizontal comparison; wherein the filtering statistics include but are not limited to detail query, list filtering and count statistics; the trend exploration includes but is not limited to trend analysis, same period calculation, period calculation and proportion analysis; the operation processing includes but is not limited to mean calculation, addition and subtraction calculation and index comparison; and the horizontal comparison includes but is not limited to sorting statistics, TopN selection and extreme value analysis.
[0094] The data query / filtering API instruction (getDetails) corresponds to the intents of detail query and list filtering; the index statistics API instruction (getIndices) corresponds to the intents of count statistics, same period calculation, period calculation, proportion analysis, sorting statistics and TopN selection; and the index secondary statistics processing API instruction (getIndicesMeasure) corresponds to the intents of mean calculation, addition and subtraction calculation, index comparison and extreme value analysis.
[0095] For example, the API template format definition corresponding to the index statistics API instruction is as follows:
[0096]
[0097] Among them, is the index statistics API instruction, For indicator generating functions (such as sum(x) -> "measureTypes": ["SUM"] ), For conditional compiling functions (such as time = 2024Q1 -> "time_range": ["2024-01-01", "2024-03-31"]).
[0098] Wherein, the structure encoder determines the indicator generating function corresponding to the entity carried in the triple information according to the entity; and the structure encoder determines the conditional compiling function corresponding to the constraint condition carried in the triple information according to the constraint condition.
[0099] For example, if the question text Q is the Top5 of bicycle accident quantities of each jurisdiction in 2024Q1, the API instruction A corresponding to the question text Q is:
[0100]
[0101] Wherein, endpoint: "getIndices" specifies that the API instruction type is getIndices; groupFields: ["jurisdiction"] defines the data grouping field as "jurisdiction"; metrics: ["accident number"] specifies the indicator to be counted as "accident number". That is, the query will calculate the number of accidents in each grouping (grouped by jurisdiction); startTime: "2024-01-01", endTime: "2024-03-31" sets the time range of the query, from January 1, 2024 to March 31, 2024, and the query will only return data within this time period; queryParams: [field: "accident type", mode: 6, value: "bicycle accident"] is used to further filter data; field: "accident type" indicates that the field to be filtered is "accident type"; mode: 6 represents the filtering mode; value: "bicycle accident" specifies the value to be filtered as "bicycle accident", that is, only data with "accident type" as "bicycle accident" is selected; orderParams: "accident number": "desc" defines the sorting method of the result, which is sorted in descending order (desc) according to the "accident number" field, that is, the grouping with the most accidents will be placed at the front; limit: 5 limits the number of returned results to 5, that is, only the first 5 data after filtering and sorting according to the above conditions are returned.
[0102]
[0103]
[0104]
[0105] Table 1
[0106] Table 1 is a format definition of the getIndices type API instruction provided by the embodiments of the present application, and a structure encoder can generate the getIndices type API instruction according to the format definition as shown in Table 1. The getIndices API instruction includes multiple parameters, which are respectively: a query token (sysCode), an index domain (indexDomain), a business domain (geoDim), an atomic index field (atomIndexes), a start time (startTime), an end time (endTime), an aggregation dimension (groupFields), a having condition (havingQueryParams), a sorting field (orderParams), a limited return record number (limitNum), whether a same period value is needed, a same period (samePeriod), whether a last period value is needed, a constraint condition (queryParams) including a column name (field), a filtering specific value (val) and an operator (mod).
[0107] In the table 1, each parameter is a mandatory item, and each parameter corresponds to an enumerated value. For example, sysCode is a mandatory item, which can be a system identifier such as hiface, hicon, hitraffic, etc.; indexDomain is a mandatory item, which can be trafficStatus, trafficSafe, etc.; geoDim is a mandatory item, where the index domain trafficStatus has the following business domains: crossing, section, area, line, city, inout; the index domain trafficSafe has the following business domains: veh, drv, acd, vio, pis; atomIndexes is a mandatory item, which can be accident amount, property loss, number of police cases, etc.; atomIndexes is a mandatory item, which can be accident amount, property loss, number of police cases, etc.; startTime is a mandatory item, which can be in the format of 2024-7-26 14:24:06; endTime is a mandatory item, which can be in the format of 2024-7-26 14:24:06; groupFields is not a mandatory item, which can be an array, etc.; havingQueryParams is a mandatory item, which has the same structure as queryParam; orderParams is not a mandatory item, which can be multiple, separated by English commas, and needs to specify whether to increment or decrement, where the default is to increment, which can be sgfssjdesc, xzqh, sgdd desc, etc.; limitNum is not a mandatory item, which defaults to 100000, and the maximum number of queries is TOP 100000; samePeriod is not a mandatory item, which can be any number from 0 to 5, where 0 means not to return the same period value, 1 means to return the same period value of the last week, 2 means to return the same period value of the last month, 3 means to return the same period value of the last quarter, 4 means to return the same period value of the last year, 5 means to return the same period value of yesterday, etc.; lastPeriod is not a mandatory item, which can be any number from 0 to 5 or 11, where 0 means not to return, 1 means the interval time is an integer week, 2 means the interval time is an integer month, 3 means the interval time is an integer quarter, 4 means the interval time is an integer year, 5 means the interval time is an integer day, and 11 means the interval time is the difference between the end time and the start time, etc.; mode can be a SQL operator or a semantic operator, where the SQL operator is any number from 0 to 10, 1 represents greater than, 2 represents greater than or equal to, 3 represents less than, 4 represents less than or equal to, 5 represents not equal to, 6 represents equal to, 7 represents like, 8 notlike, 9 represents in, multiple values separated by English |, 10 notin, multiple values separated by English |, and the semantic operator is delivered in the form of fixed semantic vocabulary, such as "located", "mentioned", "crepuscular".
[0108] In addition, the electronic device can also be configured with format definitions corresponding to other types of API instructions, and the structure encoder generates API instructions of each type according to the format definitions corresponding to the API instructions of each type.
[0109] To improve the accuracy of generating SQL and thus improve the question and answer effect, on the basis of the above embodiments, in the embodiments of the present application, the training process of the question and answer model includes:
[0110] Obtain a training sample, the training sample including a sample question text and corresponding sample triple information and sample instructions;
[0111] Process the sample question text using a text encoder of a question and answer model to be trained to obtain predicted triple information corresponding to the sample question text;
[0112] Process the predicted triple information using a structure encoder of the question and answer model to be trained to obtain predicted instructions;
[0113] Determine a text loss value according to the sample triple information and the predicted triple information;
[0114] Determine a structure loss value according to the sample instructions and the predicted instructions;
[0115] Determine a total loss value according to the text loss value and the structure loss value, and adjust parameters of the question and answer model to be trained according to the total loss value.
[0116] In the embodiments of the present application, the electronic device can jointly train the text encoder and the structure encoder of the question and answer model to realize end-to-end mapping of semantics to API; and adjust the parameters of the text encoder and the structure encoder by constructing a multi-task loss function.
[0117] For example, the architecture of the question and answer model can be:
[0118]
[0119] wherein Model represents the question and answer model, represents the text encoder, represents the question text, represents the structure encoder, represents the API specification.
[0120] Specifically, the electronic device obtains a training sample, the training sample including a sample question text, corresponding sample triple information and a sample instruction. The electronic device processes the sample question text by using a text encoder of a to-be-trained question and answer model to obtain predicted triple information corresponding to the sample question text; the electronic device processes the predicted triple information by using a structure encoder of the to-be-trained question and answer model to obtain a predicted instruction; the electronic device determines a text loss value according to the sample triple information and the predicted triple information; the electronic device determines a structure loss value according to the sample instruction and the predicted instruction; and the electronic device determines a total loss value according to the text loss value and the structure loss value, and adjusts parameters of the to-be-trained question and answer model according to the total loss value.
[0121] In a possible implementation, the electronic device can determine the text loss value according to a sample intent carried in the sample triple information and a probability of the sample question text belonging to each intent carried in the predicted triple information.
[0122] In another possible implementation, the electronic device can further determine the structure loss value according to whether each field generated by the structure encoder is an illegal field under the current intent.
[0123] For example, the text loss value satisfies the following formula:
[0124]
[0125] wherein, represents the text loss value, represents a one-hot encoding vector of the sample intent (for example, the "statistical proportion" corresponds to the i-th type), represents a probability of the text encoder predicting that the question text belongs to the i-th intent, and K is the total number of intent categories.
[0126] For example, the structure loss value satisfies the following formula:
[0127]
[0128] wherein, represents the structure loss value, F represents a set of all fields generated by the structure encoder model (for example, groupFields, metrics, etc.), represents a set of illegal fields under the current intent, I( ) represents an indicator function, for example, 1 for an illegal field, and 0 otherwise, represents an L2 norm penalty of the corresponding parameter of the illegal field.
[0129] For example, the total loss value satisfies the following formula:
[0130]
[0131] wherein, represents a total loss value, represents a text loss value, represents a structure loss value, and is a preset weight.
[0132] In order to improve the accuracy of generating SQL and further improve the question and answer effect, on the basis of the above embodiments, in the embodiments of the present application, before the calling instruction parsing engine processes the target instruction to generate the first SQL statement for querying the data corresponding to the intent, entity and corresponding constraint condition, the method further comprises:
[0133] According to each data label saved in the knowledge base, it is judged whether there is a target data label containing the constraint condition;
[0134] If the target data label exists, the subsequent process of calling the instruction parsing engine to process the target instruction to generate the first SQL statement for querying the data corresponding to the intent, entity and corresponding constraint condition is executed.
[0135] In the embodiments of the present application, in order to avoid the situation that the reply cannot be made, the electronic device will judge whether there is a target data label containing the constraint condition according to each data label saved in the knowledge base when calling the instruction parsing engine to process the target instruction to generate the first SQL statement for querying the data corresponding to the intent, entity and corresponding constraint condition.
[0136] If the electronic device determines that there is a target data label containing the constraint condition in the knowledge base, the electronic device determines that the relevant data for replying to the question text can be found directly in the knowledge base, and then the electronic device can execute the subsequent process of calling the instruction parsing engine to process the target instruction to generate the first SQL statement for querying the data corresponding to the intent, entity and corresponding constraint condition.
[0137] In addition, in a possible implementation, the electronic device can analyze whether the database table contains the data corresponding to the constraint condition through a semantic model such as a large language model. If the electronic device determines that the database table contains the data corresponding to the constraint condition based on the semantic model, the electronic device can execute the subsequent process of calling the instruction parsing engine to process the target instruction to generate the first SQL statement for querying the data corresponding to the intent, entity and corresponding constraint condition.
[0138] In order to improve the accuracy of generating SQL and further improve the question and answer effect, on the basis of the above embodiments, in the embodiments of the present application, the method further comprises:
[0139] If the target data label containing the constraint condition does not exist in the knowledge base, the instruction parsing engine is invoked to process the target instruction to generate a second SQL statement for querying data corresponding to the intent and the entity;
[0140] According to the second SQL statement, second target data corresponding to the intent and the entity is queried in the knowledge base, and a reply text is generated based on the second target data.
[0141] When the electronic device determines that the target data label containing the constraint condition does not exist in the knowledge base, the electronic device determines that the relevant data for replying to the question text cannot be directly found in the knowledge base.
[0142] The electronic device can invoke the instruction parsing engine to process the target instruction to generate a second SQL statement for querying data corresponding to the intent and the entity; according to the second SQL statement, second target data corresponding to the intent and the entity is queried in the knowledge base, and a reply text is generated based on the second target data.
[0143] In addition, in a possible implementation, the electronic device can analyze whether the database table contains data corresponding to the constraint condition through a semantic model such as a large language model. If the electronic device determines based on the semantic model that the database table does not contain data corresponding to the constraint condition, the electronic device can invoke the instruction parsing engine to process the target instruction to generate a second SQL statement for querying data corresponding to the intent and the entity.
[0144] In order to improve the accuracy of generating SQL and further improve the question and answer effect, on the basis of the above embodiments, in the embodiments of the present application, the second target data corresponding to the intent and the entity is queried in the knowledge base according to the second SQL statement, comprising:
[0145] According to the second SQL statement, each candidate data corresponding to the intent and the entity is obtained from the knowledge base;
[0146] According to a preset similarity algorithm, the similarity of each candidate data to the constraint condition is determined;
[0147] The candidate data corresponding to the similarity exceeding a preset similarity threshold is determined as the second target data.
[0148] In the embodiments of the present application, after the electronic device invokes the instruction parsing engine to process the target instruction to generate a second SQL statement for querying data corresponding to the intent and the entity, the electronic device corresponds to the second SQL statement.
[0149] Specifically, the electronic device obtains each candidate data corresponding to the intent and the entity from the knowledge base according to the second SQL statement; determines the similarity of each candidate data to the constraint condition respectively according to a preset similarity algorithm; and determines the candidate data corresponding to a similarity that exceeds a preset similarity threshold as the second target data.
[0150] The traditional SQL parsing engine has a "semantic processing bottleneck" and cannot parse complex semantics such as spatial relationships (such as "near a school") and event descriptions (such as "mentioning vehicle combustion").
[0151] Based on this, the embodiment of the application proposes a hybrid engine architecture, which realizes semantic collaborative computing through a three-layer fusion design. Specifically, the hybrid engine architecture includes a semantic operator execution model, a SQL calculation module, and a special operator interface module. The SQL calculation module can be the instruction parsing engine in the above embodiments.
[0152] The semantic operator execution model can call an LLM to process the semantic computing requirements of non-SQL logic in the API. The semantic operator execution module supports five types of complex semantics (spatial relationship, event description, time sequence evolution, text feature, and domain rule). The SQL calculation module is used to execute standard data filtering and aggregation, such as WHERE police case type = 'traffic accident' and GROUP BY month. The special interface operator module is used to encapsulate domain-specific computing logic (such as traffic congestion index and accident hotspot prediction).
[0153] Figure 5 A possible question and answer flowchart provided by the embodiment of the application is shown in FIG. 1. Figure 5 As shown in FIG. 1, the electronic device structures the API intent to obtain a structured API instruction as follows:
[0154] Data model: police case;
[0155] Data index: number of police cases;
[0156] Statistical period: 2025-05-01 00:00:00 to 2025-06-01 00:00:00;
[0157] Grouping dimension: month;
[0158] Analysis dimension:
[0159] Police case type, filtering condition: equal to, filtering value: traffic accident;
[0160] Intelligence description, filtering condition: contains, filtering value: vehicle combustion | self-ignition;
[0161] Sorting dimension: month, ascending order;
[0162] The electronic device inputs the structured API instruction into the hybrid computing engine, which performs query sub-task disassembly arrangement based on the structured API instruction, analyzes whether the vehicle burning | spontaneous combustion is mentioned in each police case description text based on the semantic operator execution module, obtains the candidate SQL statement based on the SQL calculation module, and finally generates the first SQL statement.
[0163] Figure 6 Another possible question and answer flowchart provided for the embodiments of the present application is that the electronic device fine-tunes the SET large model using the training data set to obtain a general way vertical domain large model (question and answer model) for NL2API institutional analysis, obtains the structured API instruction corresponding to the user question "Please analyze the number of traffic accident police cases involving vehicle burning and spontaneous combustion in the last quarter", and the API instruction is:
[0164] Data model: police case;
[0165] Data index: number of police cases;
[0166] Statistical period: 2025-05-01 00:00:00 to 2025-06-01 00:00:00;
[0167] Grouping dimension: month;
[0168] Analysis dimension:
[0169] Police case type, filtering condition: equal to, filtering value: traffic accident;
[0170] Intelligence description, filtering condition: contains, filtering value: vehicle burning | spontaneous combustion;
[0171] Sorting dimension: month, ascending;
[0172] The electronic device performs post-processing verification on the API instruction;
[0173] The verified API instruction is input into the hybrid computing engine, which performs query sub-task disassembly arrangement based on the structured API instruction, and obtains the first SQL statement based on the semantic operator execution module, the SQL calculation module and the external algorithm extension module.
[0174] On the basis of the above embodiments, the embodiments of the present application further provide a traffic question and answer device based on a large model. Figure 7 A traffic question and answer device based on a large model provided for the embodiments of the present application has a structure schematic diagram, which comprises:
[0175] The processing module 701 is configured to process input question text by using a question and answer model to generate a target instruction containing triple information of the question text; wherein the triple information includes an intent, an entity, and a corresponding constraint condition; and call an instruction analysis engine to process the target instruction to generate a first SQL statement for querying data corresponding to the intent, the entity, and the corresponding constraint condition.
[0176] The question and answer module 702 is configured to query first target data corresponding to the intent, the entity, and the corresponding constraint condition in a knowledge base according to the first SQL statement, and generate a reply text based on the first target data.
[0177] In a possible implementation, the question and answer model includes a text encoder and a structure encoder.
[0178] The processing module 701 is specifically configured to process the question text by using the text encoder to obtain the triple information corresponding to the question text; and process the triple information by using the structure encoder to obtain the target instruction.
[0179] In a possible implementation, the processing module 701 is specifically configured to perform intent recognition on the question text by using the text encoder to obtain an intent of the question text; perform entity recognition on the question text by using the text encoder to obtain an entity contained in the question text; perform constraint condition recognition on the question text by using the text encoder to obtain a constraint condition contained in the question text; and determine the intent, the entity, and the constraint condition as the triple information.
[0180] In a possible implementation, the target instruction is an API instruction.
[0181] The processing module 701 is specifically configured to call the structure encoder to determine a target API instruction type corresponding to the intent of the question text according to a configured correspondence between an intent and an API instruction type; call the structure encoder to obtain an API template corresponding to the target API instruction type configured, and add the intent of the question text, the entity contained in the question text, and a corresponding entity value to the API template to obtain the API instruction.
[0182] In a possible implementation, the apparatus further includes:
[0183] The training module 703 is configured to acquire training samples, the training samples including sample question texts, corresponding sample triple information and sample instructions; process the sample question texts by using a text encoder of a to-be-trained question and answer model to obtain predicted triple information corresponding to the sample question texts; process the predicted triple information by using a structure encoder of the to-be-trained question and answer model to obtain predicted instructions; determine a text loss value according to the sample triple information and the predicted triple information; determine a structure loss value according to the sample instructions and the predicted instructions; determine a total loss value according to the text loss value and the structure loss value, and adjust parameters of the to-be-trained question and answer model according to the total loss value.
[0184] In a possible implementation, the processing module 701 is further configured to determine, according to each data label stored in the knowledge base, whether there is a target data label containing the constraint condition; if the target data label exists, execute a process of calling the instruction parsing engine to process the target instruction to generate a first SQL statement for querying data corresponding to the intent, the entity and the corresponding constraint condition.
[0185] In a possible implementation, the processing module 701 is further configured to, if the target data label containing the constraint condition does not exist in the knowledge base, call the instruction parsing engine to process the target instruction to generate a second SQL statement for querying data corresponding to the intent and the entity; query a second target data corresponding to the intent and the entity in the knowledge base according to the second SQL statement, and generate a reply text based on the second target data.
[0186] In a possible implementation, the processing module 701 is specifically configured to acquire, according to the second SQL statement, each candidate data corresponding to the intent and the entity from the knowledge base; determine, according to a preset similarity algorithm, a similarity between each candidate data and the constraint condition; and determine, as the second target data, a candidate data corresponding to a similarity that exceeds a preset similarity threshold.
[0187] On the basis of the above-mentioned embodiments, the embodiments of the present application further provide an electronic device, Figure 8 A structural schematic diagram of an electronic device provided by the embodiments of the present application is shown in Figure 8 As shown, the electronic device includes a processor 801, a communication interface 802, a memory 803 and a communication bus 804, wherein the processor 801, the communication interface 802 and the memory 803 complete mutual communication through the communication bus 804.
[0188] The computer program stored in the memory 803, when executed by the processor 801, causes the processor 801 to perform the following steps:
[0189] The question and answer model is used to process the input question text to generate a target instruction containing triple information of the question text; wherein the triple information includes an intent, an entity, and a corresponding constraint condition;
[0190] The instruction parsing engine is called to process the target instruction to generate a first SQL statement for querying data corresponding to the intent, the entity, and the corresponding constraint condition;
[0191] According to the first SQL statement, the first target data corresponding to the intent, the entity, and the corresponding constraint condition is queried in the knowledge base, and a reply text is generated based on the first target data.
[0192] In a possible implementation, the question and answer model includes a text encoder and a structure encoder;
[0193] The question and answer model is used to process the input question text to generate a target instruction containing triple information of the question text; wherein the triple information includes an intent, an entity, and a corresponding constraint condition;
[0194] The text encoder is used to process the question text to obtain the triple information corresponding to the question text;
[0195] The structure encoder is used to process the triple information to obtain the target instruction.
[0196] In a possible implementation, the text encoder is used to process the question text to obtain the triple information corresponding to the question text, including:
[0197] The text encoder is used to perform intent recognition on the question text to obtain the intent of the question text;
[0198] The text encoder is used to perform entity recognition on the question text to obtain the entity contained in the question text;
[0199] The text encoder is used to perform constraint condition recognition on the question text to obtain the constraint condition contained in the question text;
[0200] The intent, the entity, and the constraint condition are determined as the triple information.
[0201] In a possible implementation, the target instruction is an API instruction;
[0202] The structure encoder is used to process the triple information to obtain the target instruction, including:
[0203] The structure encoder determines the target API instruction type corresponding to the intent of the question text according to the correspondence between the configured intent and the API instruction type;
[0204] The structure encoder obtains an API template corresponding to the target API instruction type configured, and adds the intent of the question text, the entity contained in the question text, and the corresponding entity value into the API template to obtain the API instruction.
[0205] In a possible implementation, the training process of the question and answer model includes:
[0206] obtaining a training sample, the training sample including a sample question text, corresponding sample triple information, and a sample instruction;
[0207] processing the sample question text by using a text encoder of a question and answer model to be trained to obtain predicted triple information corresponding to the sample question text;
[0208] processing the predicted triple information by using a structure encoder of the question and answer model to be trained to obtain a predicted instruction;
[0209] determining a text loss value according to the sample triple information and the predicted triple information;
[0210] determining a structure loss value according to the sample instruction and the predicted instruction;
[0211] determining a total loss value according to the text loss value and the structure loss value, and adjusting parameters of the question and answer model to be trained according to the total loss value.
[0212] In a possible implementation, before the calling instruction resolution engine processes the target instruction to generate the first SQL statement for querying data corresponding to the intent, entity, and corresponding constraint condition, the method further includes:
[0213] determining, according to each data label saved in a knowledge base, whether there is a target data label containing the constraint condition;
[0214] if the target data label exists, performing a subsequent process of the calling instruction resolution engine processing the target instruction to generate the first SQL statement for querying data corresponding to the intent, entity, and corresponding constraint condition.
[0215] In a possible implementation, the method further includes:
[0216] If the target data label containing the constraint condition does not exist in the knowledge base, the instruction resolution engine is invoked to process the target instruction to generate a second SQL statement for querying data corresponding to the intent and entity pair;
[0217] According to the second SQL statement, a second target data corresponding to the intent and the entity pair is queried in the knowledge base, and a reply text is generated based on the second target data.
[0218] In a possible implementation, the querying of the second target data corresponding to the intent and the entity pair in the knowledge base according to the second SQL statement includes:
[0219] According to the second SQL statement, each candidate data corresponding to the intent and the entity pair is obtained from the knowledge base;
[0220] According to a preset similarity algorithm, a similarity of each candidate data with the constraint condition is determined respectively;
[0221] The candidate data with a corresponding similarity exceeding a preset similarity threshold is determined as the second target data.
[0222] Since the principle of solving the problem of the above electronic device is similar to the traffic question and answer method based on a large model, the implementation of the above electronic device can refer to the embodiments of the method, and the repeated parts will not be described again.
[0223] The communication bus mentioned in the above electronic device can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or only one type of bus. The communication interface 802 is used for communication between the above electronic device and other devices. The memory can include a random access memory (RAM) and can also include a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory can also be at least one storage device located away from the aforementioned processor.
[0224] The processor can be a general processor, including a central processing unit, a network processor (NP), etc.; can also be a digital signal processing (DSP) processor, an application specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.
[0225] On the basis of the above-mentioned embodiments, the embodiment of the application further provides a computer readable storage medium, the computer readable storage medium storing a computer program executable by a processor, when the program runs on the processor, causing the processor to execute the following steps:
[0226] The question and answer model is used to process the input question text to generate a target instruction containing triple information of the question text; wherein the triple information includes an intent, an entity and a corresponding constraint condition;
[0227] The instruction parsing engine is called to process the target instruction to generate a first SQL statement for querying data corresponding to the intent, the entity and the corresponding constraint condition;
[0228] According to the first SQL statement, the first target data corresponding to the intent, the entity and the corresponding constraint condition is queried in a knowledge base, and a reply text is generated based on the first target data.
[0229] In a possible implementation, the question and answer model includes a text encoder and a structure encoder;
[0230] The question and answer model is used to process the input question text to generate a target instruction containing triple information of the question text; wherein the triple information includes an intent, an entity and a corresponding constraint condition;
[0231] The text encoder is used to process the question text to obtain the triple information corresponding to the question text;
[0232] The structure encoder is used to process the triple information to obtain the target instruction.
[0233] In a possible implementation, the question and answer model is used to process the input question text to generate a target instruction containing triple information of the question text; wherein the triple information includes an intent, an entity and a corresponding constraint condition;
[0234] The text encoder is used to perform intent recognition on the question text to obtain the intent of the question text;
[0235] The text encoder is used to perform entity recognition on the question text to obtain the entity contained in the question text;
[0236] The text encoder is used to identify constraint conditions in the question text, to obtain constraint conditions contained in the question text.
[0237] The intent, the entity, and the constraint condition are determined as the triple information.
[0238] In a possible implementation, the target instruction is an API instruction.
[0239] The structure encoder is configured to process the triple information to obtain the target instruction, and the processing includes:
[0240] The structure encoder determines a target API instruction type corresponding to the intent of the question text according to a configured correspondence between intents and API instruction types.
[0241] The structure encoder obtains an API template corresponding to the target API instruction type, and adds the intent of the question text, the entity contained in the question text, and the corresponding entity value into the API template to obtain the API instruction.
[0242] In a possible implementation, the training process of the question and answer model includes:
[0243] A training sample is obtained, and the training sample includes a sample question text, corresponding sample triple information, and a sample instruction.
[0244] A text encoder of a to-be-trained question and answer model is used to process the sample question text to obtain predicted triple information corresponding to the sample question text.
[0245] A structure encoder of the to-be-trained question and answer model is used to process the predicted triple information to obtain a predicted instruction.
[0246] According to the sample triple information and the predicted triple information, a text loss value is determined.
[0247] According to the sample instruction and the predicted instruction, a structure loss value is determined.
[0248] According to the text loss value and the structure loss value, a total loss value is determined, and parameters of the to-be-trained question and answer model are adjusted according to the total loss value.
[0249] In a possible implementation, before the calling instruction resolution engine processes the target instruction to generate a first SQL statement for querying data corresponding to the intent, the entity, and the corresponding constraint condition, the method further includes:
[0250] determine whether there is a target data label containing the constraint condition according to each data label stored in the knowledge base;
[0251] If the target data label exists, a subsequent calling instruction parsing engine is executed to process the target instruction, and a process of generating a first SQL statement for querying data corresponding to the intent, the entity, and the corresponding constraint condition is performed.
[0252] In a possible implementation, the method further includes:
[0253] If the target data label containing the constraint condition does not exist in the knowledge base, the instruction parsing engine is called to process the target instruction, and a second SQL statement for querying data corresponding to the intent and the entity is generated;
[0254] According to the second SQL statement, second target data corresponding to the intent and the entity is queried in the knowledge base, and a reply text is generated based on the second target data.
[0255] In a possible implementation, the querying, according to the second SQL statement, of the second target data corresponding to the intent and the entity in the knowledge base includes:
[0256] According to the second SQL statement, each candidate data corresponding to the intent and the entity is obtained from the knowledge base;
[0257] According to a preset similarity algorithm, a similarity of each candidate data to the constraint condition is determined;
[0258] A candidate data corresponding to a similarity that exceeds a preset similarity threshold is determined as the second target data.
[0259] Since the principle of solving the problem by the above computer-readable storage medium is similar to the traffic question and answer method based on a large model, the implementation of the above computer-readable storage medium can refer to the embodiments of the method, and the repeated parts will not be described herein.
[0260] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can be in the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can be in the form of a computer program product implemented on one or more computer usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer usable program code.
[0261] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flow or blocks Figure 1 one or more flow or blocks
[0262] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instructions which implement the function specified in the flowchart block or blocks. Figure 1 one or more flow or blocks Figure 1 one or more flow or blocks
[0263] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flow or blocks Figure 1 one or more flow or blocks
[0264] Obviously, numerous modifications and variations of the present application are possible in light of the above teachings. It is therefore to be understood that within the scope of the appended claims and their equivalents, the application can be practiced otherwise than as specifically described.
Claims
1. A large model-based traffic question and answer method, characterized by, The method comprises: adopting a question and answer model to process input question text to generate a target instruction containing triple information of the question text; wherein the triple information comprises an intent, an entity and a corresponding constraint condition; calling an instruction analysis engine to process the target instruction to generate a first SQL statement for querying data corresponding to the intent, entity and corresponding constraint condition; querying first target data corresponding to the intent, entity and corresponding constraint condition in a knowledge base according to the first SQL statement, and generating a reply text based on the first target data; wherein the calling of the instruction analysis engine to process the target instruction to generate a first SQL statement for querying data corresponding to the intent, entity and corresponding constraint condition comprises: determining a business domain corresponding to the current question and answer based on the intent carried in the target instruction; determining a database table to be queried based on the business domain; determining a SQL statement template corresponding to the intent based on the intent; adding information of the database table, the entity and the constraint condition carried in the target instruction to the SQL statement template to obtain the first SQL statement; wherein the question and answer model comprises a text encoder and a structure encoder; the adoption of the question and answer model to process the input question text to generate a target instruction containing triple information of the question text comprises: processing the question text using the text encoder to obtain the triple information corresponding to the question text; processing the triple information using the structure encoder to obtain the target instruction; wherein the target instruction is an API instruction; the processing of the triple information using the structure encoder to obtain the target instruction comprises: determining a target API instruction type corresponding to the intent of the question text according to a configured correspondence between intents and API instruction types using the structure encoder; obtaining an API template corresponding to the target API instruction type configured using the structure encoder, and adding the intent of the question text, the entity contained in the question text and the constraint condition contained in the question text to the API template to obtain the API instruction; wherein the API instruction comprises a data query / filtering API instruction, an index statistics API instruction and an index secondary statistics processing API instruction; the intent comprises filtering and statistics, trend exploration, operation processing and horizontal comparison.
2. The method of claim 1, wherein, the processing of the question text using the text encoder to obtain the triple information corresponding to the question text comprises: performing intent recognition on the question text using the text encoder to obtain the intent of the question text; performing entity recognition on the question text using the text encoder to obtain the entity contained in the question text; performing constraint condition recognition on the question text using the text encoder to obtain the constraint condition contained in the question text; determining the intent, the entity and the constraint condition as the triple information.
3. The method according to claim 1 or 2, characterized in that, the training process of the question and answer model comprises: Obtaining training samples, the training samples comprising sample question texts and corresponding sample triple information and sample instructions; Processing the sample question texts by using a text encoder of a to-be-trained question and answer model to obtain predicted triple information corresponding to the sample question texts; Processing the predicted triple information by using a structure encoder of the to-be-trained question and answer model to obtain predicted instructions; Determining a text loss value according to the sample triple information and the predicted triple information; Determining a structure loss value according to the sample instructions and the predicted instructions; Determining a total loss value according to the text loss value and the structure loss value, and adjusting parameters of the to-be-trained question and answer model according to the total loss value.
4. The method of claim 1, wherein, Before the calling instruction parsing engine processes the target instruction to generate the first SQL statement for querying data corresponding to the intent, the entity and the corresponding constraint condition, the method further comprises: According to each data label saved in the knowledge base, it is judged whether there is a target data label containing the constraint condition; If the target data label exists, the subsequent process of calling the instruction parsing engine to process the target instruction to generate the first SQL statement for querying data corresponding to the intent, the entity and the corresponding constraint condition is executed.
5. The method of claim 4, wherein, The method further comprises: If there is no target data label containing the constraint condition in the knowledge base, the instruction parsing engine is called to process the target instruction to generate a second SQL statement for querying data corresponding to the intent and the entity; According to the second SQL statement, the second target data corresponding to the intent and the entity is queried in the knowledge base, and a reply text is generated based on the second target data.
6. The method of claim 5, wherein, According to the second SQL statement, the second target data corresponding to the intent and the entity is queried in the knowledge base, and a reply text is generated based on the second target data. According to the second SQL statement, the second target data corresponding to the intent and the entity is queried in the knowledge base, and a reply text is generated based on the second target data. The device comprises: A processing module configured to process input question texts by using a question and answer model to generate target instructions containing triple information of the question texts, wherein the triple information comprises an intent, an entity and a corresponding constraint condition; and call an instruction parsing engine to process the target instructions to generate a first SQL statement for querying data corresponding to the intent, the entity and the corresponding constraint condition; 7.A large model-based traffic question and answer device, characterized by, A question and answer module configured to query first target data corresponding to the intent, the entity and the corresponding constraint condition in a knowledge base according to the first SQL statement, and generate a reply text based on the first target data. The processing module is specifically configured to determine a business domain corresponding to the current question and answer based on an intention carried in the target instruction; determine a database table to be queried based on the business domain; determine an SQL statement template corresponding to the intention based on the intention; and add information of the database table, an entity carried in the target instruction, and a constraint condition to the SQL statement template to obtain the first SQL statement. The question and answer model comprises a text encoder and a structure encoder. The processing module is specifically configured to process the question text by using the text encoder to obtain the triple information corresponding to the question text; and process the triple information by using the structure encoder to obtain the target instruction. The target instruction is an API instruction. The processing module is specifically configured to determine a target API instruction type corresponding to the intention of the question text according to a correspondence relationship between the configured intention and the API instruction type by using the structure encoder; obtain an API template corresponding to the target API instruction type by using the structure encoder, and add the intention of the question text, an entity contained in the question text, and a constraint condition contained in the question text to the API template to obtain the API instruction. The API instruction comprises a data query / filtering API instruction, an index statistics API instruction, and an index secondary statistics processing API instruction. The intention comprises filtering and statistics, trend exploration, operation processing, and horizontal comparison.
8. An electronic device, comprising: The electronic device at least comprises a processor and a memory, and the processor is used to execute a computer program stored in the memory to realize the steps of the traffic question and answer method based on a large model according to any one of claims 1-6.
Citation Information
Patent Citations
Intelligent number asking method for large model index query
CN120336360A
Intelligent handling of API queries
US20250284888A1