Natural language to SQL (Structured Query Language) conversion method and device applied to security industry, and storage medium

By utilizing knowledge graph matching and triplet analysis in the securities industry, the accuracy problem of natural language to SQL conversion methods in the securities industry has been solved, generating more reliable SQL statements.

CN121833757AActive Publication Date: 2026-04-10HUAAN SECURITIES CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUAAN SECURITIES CO LTD
Filing Date
2026-03-13
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Existing natural language to SQL methods are difficult to guarantee accuracy in the securities industry, especially when faced with complex and ever-changing natural language and massive securities industry data.

Method used

By receiving natural language data from the securities industry, the system uses a pre-defined knowledge graph to match the target sub-graph, extracts entities and relations from triples, matches original text fragments, filters relevant text fragments based on weight information, determines the table template, and generates SQL statements.

Benefits of technology

This improves the accuracy of natural language to SQL conversion methods in the securities industry, ensuring that the generated SQL statements are more reliable and accurate.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121833757A_ABST
    Figure CN121833757A_ABST
Patent Text Reader

Abstract

The invention discloses a natural language to SQL (Structured Query Language) method and device applied to the security industry and a storage medium, and relates to the technical field of natural language processing. The method comprises the following steps: firstly, matching a natural language with a knowledge graph to obtain a target sub-graph; then, all triads in the target sub-graph are extracted, original text fragments are obtained through matching from a natural language according to each triad, each triad can serve as a small unit of the text fragments to conduct semantic query, and therefore the original text fragments are obtained through matching from the natural language. According to the method, the natural language is partitioned by means of the triple in the target sub-graph, so that the most reasonable M text fragments can be screened out. Due to the fact that the determination process of the text fragment is reliable and reasonable, the table template determined according to the text fragment is more reliable, a more reliable table-form language can be obtained by filling the natural language into the table template, and finally a more accurate SQL statement can be obtained according to the table-form language.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application relates to the technical field of natural language processing, and in particular to a natural language to SQL method and device applied to the securities industry and a storage medium. BACKGROUND

[0002] Natural language to SQL (NL2SQL) technology is an important application in the field of natural language processing (NLP), which allows users to interact with databases through natural language and converts natural language queries into executable SQL query statements. In the data-driven era, enterprises and individuals need to extract valuable information from massive data. Natural language to SQL technology realizes direct dialogue between people and databases by converting natural language problems into SQL query statements, improving the efficiency of data analysis. Traditional SQL queries require users to have certain programming knowledge, which is a barrier for non-technical personnel. The emergence of NL2SQL technology breaks down this barrier, enabling ordinary users to easily perform data queries and analysis. Development of artificial intelligence technology: With the advancement of artificial intelligence technology, especially the development of deep learning models such as Transformer and BERT, natural language to SQL technology has been realized. These models learn to extract key information from natural language text through large corpus training and convert it into SQL query statements. However, in the securities industry, due to the complexity and diversity of natural language and the complexity of securities industry data, the accuracy of existing natural language to SQL methods is difficult to guarantee when facing securities industry data. Therefore, a more accurate natural language to SQL method needs to be proposed for the securities industry. SUMMARY

[0003] The application provides a natural language to SQL method and device applied to the securities industry and a storage medium, which is used to improve the accuracy of the natural language to SQL method.

[0004] The first aspect of the application discloses a natural language to SQL method applied to the securities industry, which comprises the following steps: receiving a natural language output by an operation object for securities industry data; matching the natural language with a preset knowledge graph to obtain a target sub-graph corresponding to the natural language; extracting all triplets in the target sub-graph, wherein any one of the triplets comprises two entities and a relationship between the two entities; for each of the triplets, matching an original text segment from the natural language according to the two entities in the triplet and the relationship between the two entities; Based on the original text segments corresponding to all the triples, determine the weight information corresponding to each original text segment; based on the weight information corresponding to each original text segment, filter out M relevant text segments; Based on the M related text fragments, a table template is determined; the natural language is filled into the table template to obtain a table formal language; wherein, the table formal language includes multiple table headers for indicating content attributes and table content corresponding to each table header; Based on the tabular form language, generate the corresponding SQL statement in the natural language.

[0005] As an optional implementation, in the first aspect of the present invention, generating the SQL statement corresponding to the natural language based on the tabular formal language includes: Expand the table content corresponding to each header of the tabular form language to obtain an expanded table; Based on the extended table, multiple initial SQL statements are generated, and the credibility parameter corresponding to each initial SQL statement is determined according to the number of times each initial SQL statement is repeated. From the multiple initial SQL statements, select the SQL statements to be confirmed, wherein the credibility parameter of the SQL statements to be confirmed is greater than or equal to the preset credibility threshold. If there is only one SQL statement to be confirmed, then the SQL statement to be confirmed is the SQL statement corresponding to the natural language.

[0006] As an optional implementation, in the first aspect of the invention, the step of matching the original text fragment from the natural language for each triple, based on the two entities in the triple and the relationship between the two entities, includes: For each triple, the two entities in the triple are expanded using a preset knowledge set of data to obtain multiple expanded entities; the relationship between the two entities in the triple is expanded to obtain multiple expanded relationships. For each triple, the original text fragment is obtained by matching all the extended entities and all the extended relations with the natural language.

[0007] As an optional implementation, in the first aspect of the invention, the step of matching the natural language with all the extended entities and all the extended relations for each triple to obtain the matched original text fragment includes: For each triple, multiple extended statements are constructed based on all extended entities and all extended relations; all extended statements are then matched with the natural language to obtain the matched original text fragments.

[0008] As an optional implementation, in the first aspect of the present invention, matching the natural language with a preset knowledge graph to obtain a target sub-graph corresponding to the natural language includes: The natural language is converted into a language vector in vector form; the language vector is matched with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language.

[0009] As an optional implementation, in the first aspect of the invention, the step of converting the natural language into a language vector in vector form includes: The natural language is divided into text blocks according to multiple preset text block granularity division rules to obtain multiple text block sequences; a sub-language vector is determined according to each text block sequence, and a language vector is obtained from all the sub-language vectors; And, the step of matching the language vector with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language includes: All the sub-language vectors are matched with a preset knowledge graph to obtain all associated entities; the knowledge graph is traversed to mine the relationships between all associated entities, and the target sub-graph corresponding to the natural language is obtained based on all the associated entities and the relationships between them.

[0010] As an optional implementation, in the first aspect of the present invention, determining the table template based on the M related text fragments includes: For each of the M related text fragments, determine the content attribute corresponding to each related text fragment, and match the corresponding table header for each content attribute; obtain a table template based on all the table headers.

[0011] A second aspect of this invention discloses a natural language to SQL converter for the securities industry, the converter comprising: The graph matching module is used to receive natural language output by the operation object for securities industry data; match the natural language with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language; The text matching module is used to extract all triples in the target sub-graph, wherein any triple includes two entities and a relationship between the two entities; for each triple, the original text fragment is obtained from the natural language based on the two entities and the relationship between the two entities in the triple; The table determination module is used to determine the weight information corresponding to each original text segment based on all the original text segments corresponding to the triples; to filter out M relevant text segments based on the weight information corresponding to each original text segment; and to determine a table template based on the M relevant text segments. The language conversion module is used to fill the natural language into a preset table template to obtain a tabular language; wherein, the tabular language includes multiple table headers for indicating content attributes and table content corresponding to each table header; The SQL generation module is used to generate SQL statements corresponding to the natural language based on the tabular form language.

[0012] As an optional implementation, in a second aspect of the present invention, the SQL generation module generates a specific operation method for generating the SQL statement corresponding to the natural language based on the tabular formal language, including: Expand the table content corresponding to each header of the tabular form language to obtain an expanded table; Based on the extended table, multiple initial SQL statements are generated, and the credibility parameter corresponding to each initial SQL statement is determined according to the number of times each initial SQL statement is repeated. From the multiple initial SQL statements, select the SQL statements to be confirmed, wherein the credibility parameter of the SQL statements to be confirmed is greater than or equal to the preset credibility threshold. If there is only one SQL statement to be confirmed, then the SQL statement to be confirmed is the SQL statement corresponding to the natural language.

[0013] As an optional implementation, in a second aspect of the invention, the text matching module, for each triple, obtains the original text fragment from the natural language based on the two entities in the triple and the relationship between the two entities, in the following specific operation: For each triple, the two entities in the triple are expanded using a preset knowledge set of data to obtain multiple expanded entities; the relationship between the two entities in the triple is expanded to obtain multiple expanded relationships. For each triple, the original text fragment is obtained by matching all the extended entities and all the extended relations with the natural language.

[0014] As an optional implementation, in a second aspect of the invention, the text matching module, for each of the triples, matches the natural language based on all the extended entities and all the extended relations to obtain the matched original text fragment. The specific operation includes: For each triple, multiple extended statements are constructed based on all extended entities and all extended relations; all extended statements are then matched with the natural language to obtain the matched original text fragments.

[0015] As an optional implementation, in a second aspect of the present invention, the specific operation method of the graph matching module matching the natural language with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language includes: The natural language is converted into a language vector in vector form; the language vector is matched with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language.

[0016] As an optional implementation, in a second aspect of the present invention, the specific operation method by which the graph matching module converts the natural language into a vector form of language vectors includes: The natural language is divided into text blocks according to multiple preset text block granularity division rules to obtain multiple text block sequences; a sub-language vector corresponding to each text block sequence is determined based on each text block sequence, and the natural language is obtained based on all the sub-language vectors; Furthermore, the specific operation method of the graph matching module matching the language vector with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language includes: All the sub-language vectors are matched with a preset knowledge graph to obtain all associated entities; the knowledge graph is traversed to mine the relationships between all associated entities, and an initial sub-graph corresponding to the natural language is obtained based on all the associated entities and the relationships between them.

[0017] As an optional implementation, in a second aspect of the invention, the table determination module determines the specific operation method of the table template based on the M related text fragments, including: For each of the M related text fragments, determine the content attribute corresponding to each related text fragment, and match the corresponding table header for each content attribute; obtain a table template based on all the table headers.

[0018] A third aspect of this invention discloses a natural language to SQL conversion system applied in the securities industry, the system comprising: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute some or all of the steps in the natural language to SQL method applied to the securities industry according to any of the first aspects of the present invention.

[0019] The fourth aspect of the present invention discloses a computer storage medium storing computer instructions, which, when invoked by a processor, are used to execute some or all of the steps in the natural language to SQL method applied to the securities industry as described in any of the first aspects of the present invention.

[0020] Compared with the prior art, the present invention has the following beneficial effects: This invention first matches natural language with a pre-defined knowledge graph to obtain a target sub-graph. This knowledge graph is generated based on securities industry data, and the target sub-graph is thus derived by combining the user's natural language with this securities industry data. Next, all triples in the target sub-graph are extracted, and based on the two entities and their relationship within each triple, original text fragments are matched from the natural language. Each triple includes two entities and their relationship; each triple can be used as a smaller unit of text fragment for semantic querying, thereby matching the original text fragments from the natural language. Then, based on the original text fragments corresponding to all triples, the weight information corresponding to each original text fragment is determined. Based on the weight information corresponding to each original text fragment, M relevant text fragments are selected. This invention uses triples in the target sub-graph to segment the natural language, thereby selecting the most reasonable M text fragments. Because the process of determining the text fragments is relatively reliable and reasonable, the table template determined based on the text fragments is also more reliable. Filling the table template with natural language also yields a more reliable tabular language, and ultimately, based on the tabular language, more accurate SQL statements can be obtained. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 This is a flowchart illustrating a natural language to SQL conversion method for the securities industry disclosed in an embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of a natural language to SQL converter for the securities industry disclosed in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a natural language to SQL system for the securities industry disclosed in an embodiment of the present invention. Detailed Implementation

[0023] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0024] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or end that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or ends.

[0025] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0026] This invention discloses a natural language to SQL conversion method, apparatus, and storage medium for use in the securities industry, which improves the accuracy of the natural language to SQL conversion method.

[0027] Example 1 Please see Figure 1 , Figure 1 This is a flowchart illustrating a natural language to SQL conversion method for the securities industry, as disclosed in an embodiment of the present invention. Figure 1 The described natural language to SQL conversion method for the securities industry can be applied to natural language to SQL conversion devices within the securities industry. These devices can be integrated into cloud servers or local servers. These servers can be used by securities companies or by other companies providing public services to the securities sector; the embodiments of this invention do not impose limitations. Figure 1 As shown, this natural language to SQL method applied to the securities industry can include the following operations: Step 101: Receive the natural language output of the operation object for securities industry data; match the natural language with the preset knowledge graph to obtain the target sub-graph corresponding to the natural language.

[0028] In this embodiment of the invention, natural language is used to perform various operations on securities industry data, such as basic business Q&A, basic database operation requirements, CRUD operations, multi-table joins, and partition creation. A knowledge graph is a structured database of entities and relationships; for example, it can be an "entity-relationship" vector library constructed by vectorizing entities and relationships for subsequent retrieval. Natural language is matched with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language.

[0029] The preset knowledge graph is a pre-defined knowledge graph for securities industry data, which can be obtained through the following methods: By collecting heterogeneous data from multiple sources, including business data, regulations, compliance clauses, and product information from the securities industry and within companies, a financial knowledge graph is constructed after cleaning, parsing, and structuring.

[0030] 1. Data Acquisition, Cleaning, and Heterogeneous Analysis To ensure the authority, comprehensiveness, and accuracy of the knowledge graph constructed subsequently, this embodiment of the invention collects data from multiple authoritative sources, mainly including: (1) compliance and system data: including regulations and policies issued by regulatory agencies such as the China Securities Regulatory Commission, the Shanghai Stock Exchange, the Shenzhen Stock Exchange, and the Beijing Stock Exchange, industry self-regulatory rules, and internal management systems of securities companies; (2) business data within securities companies: covering trading rules and risk level classifications for various securities products such as stocks, funds, and bonds, as well as business specifications for the entire process of account opening, trading entrustment, fund clearing, and customer service; (3) historical consultation scripts data within the company; (4) general financial knowledge data: covering explanations of securities industry terminology, basic theoretical knowledge, etc. All the above-mentioned collected data must undergo a strict cleaning process, including removing duplicate data, cleaning up invalid information (such as garbled characters, blank content, etc.), correcting various format errors, and relying on the knowledge of the expert team to identify and remove expired and obsolete data, and unifying the terminology expression standards.

[0031] Because the collected data covers various heterogeneous formats such as doc, docx, markdown, txt, jpg, png, pdf, and xlsx, and text formats such as docx and pdf may contain embedded images (such as business process diagrams, regulatory illustrations, etc.), this invention specifically designs the following to achieve unified data processing: Figure 3 The multi-source heterogeneous parsing process shown has the core objective of extracting effective content from various format data and embedded elements, while preserving the logical structure of the original content to the greatest extent possible (such as table associations, clause order, and text-image correspondence).

[0032] For text formats such as docx, markdown, and txt, the text content is directly extracted by parsing the original data structure of the file. Embedded images are analyzed using OCR algorithms to recognize valid text information, and a Visual-Language Model (VLM) is used to parse chart-type images, achieving alignment of text and images. For independent image formats such as jpg and png, the "OCR+VLM" approach is also used to extract text and analyze layout. For tabular data such as xlsx, the table headers and row / column relationships are parsed, converting the tabular data into standardized key-value pairs or triples, preserving the logical relationships between data. Through these multi-dimensional parsing methods, heterogeneous data is transformed into unified structured text, providing a standardized and consistent data foundation for subsequent knowledge graph construction.

[0033] Financial knowledge graph construction For standardized data after multi-source heterogeneous parsing, this embodiment of the invention first divides the original text into blocks based on punctuation rules. Then, it uses the locally deployed Qwen3-32B open-source large model to extract knowledge entities (such as product names, business processes, etc.) from the text blocks and mines the relationships between entities (such as "product-risk level", "process-preconditions", etc.). On this basis, it constructs entity communities through multi-level clustering algorithms, classifies and integrates similar entities (such as "trading units", "price limits", "trading commissions" related to stock products, etc.), and finally converts entities, relationships, communities, and corresponding descriptive information (generated by the large model) into structured data in tabular form, building the overall "skeleton" of the knowledge graph. At the same time, entities, relationships, and text blocks are vectorized to construct a dual vector library of "entity-relationship" and text blocks for subsequent retrieval.

[0034] Subsequently, entity relationship conflict detection and resolution technology is employed, using authoritative data sources such as regulatory laws and official systems as benchmarks. Cross-data source cross-validation resolves conflicts in the relationships of the same entity (e.g., contradictory relationships such as "Product A - Department - Wealth Management" and "Product A - Department - Retail Business"). Simultaneously, duplicate relationships are merged, redundant nodes are eliminated, and the graph structure is simplified, improving the graph's accuracy and usability. Finally, a bidirectional mapping relationship is established between knowledge graph nodes, edges, and original data documents, recording information sources and providing complete support for subsequent answer tracing.

[0035] The final financial knowledge graph comprehensively covers the entity connections and logical relationships across all scenarios of securities business, achieving the structured integration of scattered data.

[0036] Step 102: Extract all triples in the target subgraph. For each triple, the original text fragment is obtained by matching it from natural language based on the two entities in the triple and the relationship between the two entities.

[0037] In this embodiment of the invention, any triple includes two entities and the relationship between the two entities.

[0038] Obtaining original text fragments from natural language can be achieved using many existing technologies. However, the natural language provided by different users carries personalized characteristics, such as the use of non-standardized vocabulary, inaccurate grammar, and unconventional expressions. Therefore, directly using fixed text fragment extraction methods is difficult to guarantee reasonableness. To obtain more reasonable and reliable original text fragments, this embodiment of the invention extracts all triples in the initial subgraph. Any triple includes two entities and the relationship between the two entities. Each triple can be used as a smaller unit of text fragment for semantic querying, thereby obtaining the original text fragment from natural language.

[0039] Step 103: Determine the weight information corresponding to each original text segment based on the original text segments corresponding to all triples; filter out M relevant text segments based on the weight information corresponding to each original text segment.

[0040] In this embodiment of the invention, step 102 performs semantic matching for each triple to find its corresponding text fragment in natural language, thereby trying different segmentation strategies. First, the user question is comprehensively segmented to obtain the original text fragments corresponding to all triples.

[0041] Subsequently, in step 103 of this embodiment of the invention, the weight information corresponding to each original text segment is determined based on the original text segments corresponding to all triples; M relevant text segments are selected based on the weight information corresponding to each original text segment. For example, the weight is determined based on the frequency of occurrence of the text segments, and then the top-M relevant text segments are selected. Here, M is a positive integer, which can be determined by a pre-set method, or the number of original text segments whose weight information exceeds the confidence threshold can be obtained based on the weight information corresponding to each original text segment. This number is M.

[0042] This invention utilizes triples in the target sub-graph to segment natural language into blocks, thereby selecting the most reasonable M text segments, thus improving the rationality and reliability of text block segmentation of natural language.

[0043] Step 104: Based on M relevant text fragments, determine the table template; fill the table template with natural language to obtain the table form language.

[0044] In this embodiment of the invention, the table template is a method for breaking down and analyzing natural language. The table template can be set according to different features of natural language. For example, it can be established based on the grammatical function (subject, predicate, object, etc.) of each word in natural language; or it can be established based on the part of speech (verb, noun, adjective, etc.) of different words in natural language. The table template is pre-determined for data operations on securities industry data. The tabular language includes multiple headers indicating the operation object or content and the corresponding table content for each header. For example, the headers represent different grammatical functions or parts of speech, and the corresponding table content is the specific vocabulary. Through the tabular language, natural speech can be analyzed more systematically and accurately, which is beneficial for subsequent recognition and conversion operations.

[0045] In existing technologies, different table templates can be set for different operational purposes, thereby providing customized table templates. For example, different table templates can be set in advance based on basic business Q&A, basic database operation requirements, CRUD operations, multi-table joins, and partition creation. Before filling natural language into the table template, the operational purpose of the natural language is determined, and the corresponding table template is found.

[0046] However, existing table templates are predetermined, and their reliability is difficult to guarantee when faced with complex and ever-changing natural language. Therefore, in this embodiment of the invention, a table template is determined based on M related text fragments. For example, for the M related text fragments, the content attributes corresponding to each related text fragment are determined, and a corresponding table header is matched for each content attribute; the table template is obtained based on all the table headers.

[0047] Because the process of determining the text fragments is relatively reliable and reasonable, the table templates determined based on the text fragments are also more reliable.

[0048] Finally, natural language is filled into the table template to obtain the tabular form language. In this embodiment of the invention, the tabular form language includes multiple table headers for indicating content attributes and table content corresponding to each table header.

[0049] Step 105: Generate the corresponding SQL statement in natural language based on the tabular form language.

[0050] Those skilled in the art will understand that the conversion between tabular form language and SQL statements can be achieved using any statement conversion scheme.

[0051] As can be seen, this embodiment of the invention first matches natural language with a preset knowledge graph to obtain a target sub-graph. This knowledge graph is generated based on securities industry data, and thus the target sub-graph is also obtained by combining the user's natural language with the securities industry data. Then, all triples in the target sub-graph are extracted, and based on the two entities and the relationship between them in each triple, original text fragments are matched from the natural language. Any triple includes two entities and the relationship between them; each triple can be used as a smaller unit of text fragment for semantic querying, thereby matching original text fragments from the natural language. Then, based on the original text fragments corresponding to all triples, the weight information corresponding to each original text fragment is determined; based on the weight information corresponding to each original text fragment, M relevant text fragments are selected. This embodiment of the invention uses triples in the target sub-graph to segment the natural language, thereby selecting the most reasonable M text fragments. Since the process of determining text fragments is relatively reliable and reasonable, the table template determined based on the text fragments is also more reliable. Filling the table template with natural language can also yield a more reliable table form language, and finally, based on the table form language, a more accurate SQL statement can be obtained.

[0052] In an optional embodiment, generating the corresponding SQL statement in natural language based on the tabular formal language may include: Expand the table content corresponding to each header in the tabular form language to obtain an expanded table; Based on the expanded table, generate multiple initial SQL statements, and determine the confidence parameter corresponding to each initial SQL statement based on the number of times each initial SQL statement is repeated; Select SQL statements to be confirmed from multiple initial SQL statements. The credibility parameter of the SQL statement to be confirmed is greater than or equal to the preset credibility threshold. If there is only one SQL statement to be confirmed, then the SQL statement to be confirmed is the SQL statement corresponding to natural language.

[0053] In this optional embodiment, the optional extension methods include: (1) Synonym expansion method, including: Dictionary lookup method: Search for synonyms or near-synonyms of the term in a pre-defined securities industry dictionary; Contextual substitution method: Find synonyms or near-synonyms by combining them with the context of natural language; Root and affix method: Analyze the roots and affixes of words, and find words with the same or similar roots based on the meaning of the roots; Antonym method: First find the antonym of the word, then find the antonym of the antonym, which may lead to new synonyms; (2) Semantic expansion method, including: Hypernym / hyponym method: Find the hypernym and hyponym of a word to expand its semantic scope. The hypernym is a word with a broader meaning, while the hyponym is a word with a more specific and narrower meaning.

[0054] Semantic extension method: Based on the literal meaning of words, derive their metaphorical meaning, symbolic meaning, etc. Collocation expansion method: Analyze the words that are often collocated with a word to expand its meaning.

[0055] Lexical context method: By combining the context of the securities industry in which the term is used, we can understand its specific indicative connotation and thus expand its semantic meaning; (3) Vocabulary association Linking words: Expanding based on the connections between words, such as linking "ocean" to "ships," "navigation," and "marine life." Contextual Association: Imagine a specific scenario and think about the words that might be related to the given word in that scenario. For example, in the context of a "birthday party," words like "cake," "gift," and "balloon" might come to mind.

[0056] (4) Semantic discrimination method Comparative analysis method: Compare the word with other similar words to find the subtle differences between them, so as to understand and expand its meaning more accurately; Contextual analysis method: Analyze the meaning of a word in different contexts to see how it changes in different situations, thereby expanding its semantics.

[0057] In this optional embodiment, the expanded table does not simply transform a natural language statement into multiple statements that may indicate the same or similar meanings. Instead, it processes the original natural language statement by adding multiple table headers and corresponding expanded table contents for each header. This processing allows the expanded table to cover more semantic expressions. Then, based on the various semantic expressions contained in the expanded table, multiple initial SQL statements are generated using Natural Language to SQL (NL2SQL) technology, and the repetition count of each SQL statement is counted. The repetition count actually indicates the number of times the same semantic expression appears within the expanded table; the higher the repetition count, the more important the corresponding semantic expression. Therefore, the confidence parameter corresponding to each initial SQL statement can be determined based on the repetition count of each initial SQL statement.

[0058] The method for determining the credibility parameter is illustrated below: Based on the extended table, multiple derived statements corresponding to natural language are generated; for example, different meaning expressions can be formed based on the extended table through permutation and combination, and each meaning expression corresponds to a derived statement.

[0059] Input all derived statements into the pre-trained transformation model, obtain the initial SQL statement corresponding to each derived statement output by the transformation model, and count the number of repetitions of each initial SQL statement; The confidence parameter for each initial SQL statement is determined based on the number of times it is repeated. The confidence parameter for each initial SQL statement is proportional to the number of repetitions.

[0060] In this optional embodiment, whether the natural language used in the securities industry can be converted into a corresponding SQL statement also depends on the accuracy and convertibility of the natural language. If the confidence parameter of the initial SQL statement corresponding to the original language has multiple similar values ​​without extreme values, it indicates that the original natural language cannot be converted into an SQL statement due to ambiguity or other reasons. Therefore, when determining the final SQL statement, it is first necessary to filter out initial SQL statements with confidence parameters exceeding a certain value as SQL statements to be confirmed. If there is only one SQL statement to be confirmed, it means that there is a highly compatible SQL statement in the original natural language, and there are no other ambiguities. Therefore, it can be confirmed that the SQL statement to be confirmed is the SQL statement corresponding to the natural language.

[0061] In this optional embodiment, if the number of SQL statements to be confirmed is greater than or equal to 2, it indicates that there is more than one highly matched SQL statement in the original natural language, which may indicate ambiguity. In this case, it is determined that the natural language does not have a corresponding SQL statement, and the corresponding prompt information is output to the operation object.

[0062] As can be seen, this optional embodiment can process the original natural language statement by using multiple table headers and multiple extended table contents corresponding to each header. This processing allows the extended tables to cover more semantic expressions. Then, based on the various semantic expressions contained in the extended tables, multiple initial SQL statements are generated using Natural Language to SQL (NL2SQL) technology. The confidence parameter corresponding to each initial SQL statement is determined based on the number of repetitions of each initial SQL statement. When determining the final SQL statement, the initial SQL statements with confidence parameters exceeding a certain value are first filtered out as SQL statements to be confirmed. If there is only one SQL statement to be confirmed, it means that there is a highly matched SQL statement in the original natural language, and there are no other ambiguities. This can be confirmed as the SQL statement corresponding to the natural language. This improves the accuracy of natural language to SQL statement conversion in the securities industry.

[0063] In yet another alternative embodiment, the above-described conversion model can be obtained through the following scheme: Obtain the training dataset, which includes multiple initial instructions in natural language form and the target SQL statement corresponding to each initial instruction; For each initial instruction, a semantically equivalent derived instruction is generated based on that initial instruction. For example, for the same SQL query, multiple natural language expressions can be used. For instance, the query "get all fund accounts under the same customer name" can be expanded to "query all fund accounts under the same ID number" or "find all fund accounts of the same customer" to increase data diversity and help the model better understand semantics.

[0064] For each target SQL statement, various derived SQL statements with different structures are generated based on the target SQL statement. For example, based on the target SQL statement, more SQL statements with different structures are added, such as SQL statements containing complex joins (multi-table joins, nested joins), different types of aggregate functions (Sum, Count, Avg, etc.), subqueries, etc., so that the model can adapt to more complex query requirements.

[0065] Obtain the training instruction set, which includes all initial instructions and all derived instructions; Obtain a set of training SQL statements that match the training instruction set. The set of SQL statements includes all target SQL statements and all derived SQL statements. The initial conversion model is trained using a training instruction set and a set of training SQL statements that match the training instruction set, resulting in a trained conversion model. This model is used to convert between natural language and SQL statements, including outputting the corresponding SQL statement based on the input natural language and vice versa. Because the training dataset used by this conversion model includes a training instruction set and a set of training SQL statements that match the training instruction set, the conversion model can better understand semantics and adapt to more complex query requirements, thereby improving the accuracy of the conversion process.

[0066] In this optional embodiment, training a preset initial conversion model based on a training instruction set and a set of training SQL statements matching the training instruction set to obtain a trained conversion model may include: (1) Preprocessing: Clean and format the data of the training instruction set and the training SQL statement set that match the training instruction set, such as removing irrelevant characters, unifying the text format, and word segmentation, so that the model can better understand and learn.

[0067] (2) Model Construction: The model structure can be designed based on the Transformer architecture, and fine-tuned using the LLaMA-Factory open-source model fine-tuning framework to complete the model construction and optimization. Based on Multi-Query-Attention technology, more efficient inference speed and lower memory usage are achieved, thereby improving inference speed and response speed. Based on FlashAttention technology, the context length of the base model is extended, that is, the maximum length of the large model dialogue stage is increased, allowing for more rounds of dialogue.

[0068] (3) Initialize parameters: You can initialize the model parameters randomly, or use the parameters of the pre-trained model as a starting point. The latter helps to accelerate the training process and improve the performance of the final model.

[0069] (4) Loss function and optimization algorithm: Define an appropriate loss function (such as cross-entropy loss) and select a suitable optimization algorithm (such as Adam) to minimize the difference between the predicted output and the true label during training.

[0070] (5) Training process: The model is iteratively trained using a training instruction set and a set of training SQL statements that match the training instruction set. The predicted value is calculated through forward propagation, the loss is calculated according to the loss function, and the model parameters are updated through backpropagation. This process is repeated for multiple epochs until the model performance reaches the expected level or the loss value converges.

[0071] (6) Evaluation and tuning: Evaluate the model performance on an independent validation set and adjust hyperparameters (such as learning rate, batch size, etc.) based on the evaluation results to further optimize the model performance.

[0072] (7) Testing and deployment: After training is completed, the generalization ability of the model is further verified on the test set to ensure that it can generate high-quality dialogue responses on unseen data.

[0073] In the above embodiments, for the matching of the initial sub-graph and natural language, since natural language has user-personalized features, in order to further improve the accuracy of the matching between the initial sub-graph and natural language, in another optional embodiment, for each triple, based on the two entities in the triple and the relationship between the two entities, the original text fragment is matched from the natural language, which may include: For each triple, the two entities in the triple are expanded using a pre-defined knowledge set of data to obtain multiple expanded entities; the relationship between the two entities in the triple is expanded to obtain multiple expanded relationships. For each triple, match it against natural language based on all extended entities and all extended relations to obtain the matched original text fragment.

[0074] In this optional embodiment, both extended entities and extended relationships can be found in a pre-set extension library. For example, in the field of finance and securities, a knowledge base can be established in advance based on encyclopedic knowledge in the field of finance and securities, listing all different expressions of synonyms or the same concept, different expressions of the same operation, and different expressions of the same relationship, so that the knowledge base can be used to extend entities and relationships.

[0075] In this optional embodiment, the extended entities and extended relations can cover a wide range of expressions, and can also achieve good coverage for cases where standardized terms are not used, the grammar is inaccurate, or the expression is unconventional, thereby further improving the accuracy of matching between the initial subgraph and natural language.

[0076] In this optional embodiment, for each triple, matching the original text fragment with natural language based on all extended entities and all extended relations can include: For each triple, construct multiple extended statements based on all extended entities and all extended relations; use all extended statements to match natural language to obtain the matched original text fragments.

[0077] In this context, the triple is the basic unit of knowledge, with the format (head entity, relation, tail entity). For example: (account, belongs to, customer).

[0078] Expanding Entities / Relationships: To cope with the diversity of textual expressions, we cannot simply use "account" for matching; we must also consider its alternative names, abbreviations, synonyms, etc. (such as "account number" or "account number"). Relationships also need to be expanded (e.g., "belongs to" can be expanded to "open an account" or "own").

[0079] Expanded sentences: Combine a triple and all its extensions into multiple possible natural language sentence fragments using a certain language template.

[0080] Matching: Using these generated "expanded phrases" as patterns, scan the given natural language text to find the most similar text fragments.

[0081] In another optional embodiment, matching natural language with a preset knowledge graph to obtain a target sub-graph corresponding to the natural language may include: The natural language is converted into language vectors in vector form; the language vectors are then matched with a predefined knowledge graph to obtain the target sub-graph corresponding to the natural language.

[0082] In this optional embodiment, converting natural language into vector form involves transforming textual semantic information into numerical vectors, ensuring that semantically similar texts are close in distance within the vector space. The vector form is more advantageous for subsequent matching operations. For example, language vectors can be used to perform similarity matching with the "entity-relationship" vector library of a knowledge graph to locate associated entities; then, graph traversal algorithms (such as breadth-first search) can be used to mine direct and indirect relationships between entities, initially filtering out target sub-graphites containing entities, relationships, and community information.

[0083] In this optional embodiment, further optionally, converting natural language into language vectors in vector form may include: The natural language is divided into text blocks according to multiple preset text block granularity division rules, resulting in multiple text block sequences; the sub-language vector corresponding to each text block sequence is determined based on each text block sequence, and the language vector is obtained based on all sub-language vectors; Furthermore, matching language vectors with a pre-defined knowledge graph to obtain the target sub-graph corresponding to the natural language can include: Match all sub-language vectors with the preset knowledge graph to obtain all associated entities; traverse the knowledge graph to mine the relationships between all associated entities; and obtain the target sub-graph corresponding to the natural language based on all associated entities and the relationships between them.

[0084] In existing technologies, text blocks can be divided according to punctuation rules or according to a certain text block granularity. However, neither of these methods can guarantee the rationality of text block division. Therefore, this optional embodiment divides the user question into text blocks according to multiple preset text block granularity division rules, resulting in multiple text block sequences. All text block sequences will participate in subsequent data processing. Because the division of text blocks determines the accuracy and rationality of text semantic analysis, in some cases, text block sequences obtained using certain text block granularities are less rational and may lead to significant errors. Therefore, using multiple granularities for division can prevent semantic analysis deviations caused by using a single division rule or granularity.

[0085] As can be seen, in this optional embodiment, when it is uncertain which rule is most reasonable for text block segmentation, different text block granularity segmentation rules are used to segment the natural language into text blocks to prevent semantic omissions. Then, a sub-language vector corresponding to each text block sequence is determined, and a language vector is obtained from all sub-language vectors. In the subsequent target sub-graph determination process, all sub-language vectors are matched with a preset knowledge graph to achieve more comprehensive semantic coverage.

[0086] Example 2 Please see Figure 2 , Figure 2 This is a schematic diagram of the structure of a natural language to SQL converter for the securities industry, as disclosed in an embodiment of the present invention. Figure 2 As shown, the natural language to SQL converter for the securities industry may include: The graph matching module 201 is used to receive natural language output by the operation object for securities industry data; match the natural language with the preset knowledge graph to obtain the target sub-graph corresponding to the natural language; The text matching module 202 is used to extract all triples in the target subgraph, wherein any triple includes two entities and the relationship between the two entities; for each triple, the original text fragment is obtained by matching from natural language based on the two entities and the relationship between the two entities in the triple; The table determination module 203 is used to determine the weight information corresponding to each original text segment based on the original text segments corresponding to all triples; to filter out M relevant text segments based on the weight information corresponding to each original text segment; and to determine the table template based on the M relevant text segments. The language conversion module 204 is used to fill natural language into a preset table template to obtain tabular language; wherein, the tabular language includes multiple table headers for indicating content attributes and table content corresponding to each table header; SQL generation module 205 is used to generate SQL statements corresponding to natural language based on tabular form language.

[0087] In an optional embodiment, the SQL generation module 205 generates specific operation methods for SQL statements corresponding to natural language based on tabular form language, which may include: Expand the table content corresponding to each header in the tabular form language to obtain an expanded table; Based on the expanded table, generate multiple initial SQL statements, and determine the confidence parameter corresponding to each initial SQL statement based on the number of times each initial SQL statement is repeated; Select SQL statements to be confirmed from multiple initial SQL statements. The credibility parameter of the SQL statement to be confirmed is greater than or equal to the preset credibility threshold. If there is only one SQL statement to be confirmed, then the SQL statement to be confirmed is the SQL statement corresponding to natural language.

[0088] In another optional embodiment, the text matching module 202, for each triple, performs the following specific operations to match the original text fragment from natural language based on the two entities in the triple and the relationship between the two entities: For each triple, the two entities in the triple are expanded using a pre-defined knowledge set of data to obtain multiple expanded entities; the relationship between the two entities in the triple is expanded to obtain multiple expanded relationships. For each triple, match it against natural language based on all extended entities and all extended relations to obtain the matched original text fragment.

[0089] In another optional embodiment, the text matching module 202, for each triple, matches it against natural language based on all extended entities and all extended relations to obtain the matched original text fragment. This specific operation may include: For each triple, construct multiple extended statements based on all extended entities and all extended relations; use all extended statements to match natural language to obtain the matched original text fragments.

[0090] In another optional embodiment, the specific operation method of the graph matching module 201 matching natural language with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language may include: The natural language is converted into language vectors in vector form; the language vectors are then matched with a predefined knowledge graph to obtain the target sub-graph corresponding to the natural language.

[0091] In yet another optional embodiment, the specific operation by which the graph matching module 201 converts natural language into language vectors in vector form may include: The natural language is divided into text blocks according to multiple preset text block granularity division rules, resulting in multiple text block sequences; the sub-language vector corresponding to each text block sequence is determined based on each text block sequence, and the natural language is obtained based on all sub-language vectors; Furthermore, the specific operation method by which the graph matching module 201 matches language vectors with preset knowledge graphs to obtain the target sub-graph corresponding to the natural language may include: Match all sub-language vectors with the preset knowledge graph to obtain all associated entities; traverse the knowledge graph to mine the relationships between all associated entities, and obtain the initial sub-graph corresponding to the natural language based on all associated entities and the relationships between them.

[0092] In another optional embodiment, the table determination module 203 determines the specific operation method of the table template based on M related text fragments, which may include: For M related text fragments, determine the content attributes corresponding to each related text fragment, and match the corresponding table header for each content attribute; obtain the table template based on all table headers.

[0093] Example 3 Please see Figure 3 , Figure 3 This is a schematic diagram of the structure of a natural language to SQL conversion system for the securities industry, as disclosed in an embodiment of the present invention. This natural language to SQL conversion system for the securities industry may include: Memory 301 storing executable program code; Processor 302 coupled to memory 301; The processor 302 calls the executable program code stored in the memory 301 to execute some or all of the steps in any of the natural language to SQL methods applied to the securities industry in Embodiment 1 or Embodiment 2 of the present invention.

[0094] Example 4 This invention discloses a computer storage medium storing computer instructions. When executed by a processor, these computer instructions implement some or all of the steps in any of the natural language to SQL methods applied to the securities industry in Embodiment 1 of this invention.

[0095] The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0096] Through the detailed description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-Erasable Programmable Read-Only Memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.

[0097] Finally, it should be noted that the above embodiments are merely preferred embodiments of the present invention and are only used to illustrate the technical solutions of the present invention, not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A natural language to SQL conversion method applied to the securities industry, characterized in that, The method includes: Receive natural language output from the operation object for securities industry data; match the natural language with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language; Extract all triples from the target subgraph, wherein any triple includes two entities and a relationship between the two entities; For each triple, the original text fragment is obtained by matching the natural language based on the two entities in the triple and the relationship between the two entities; Based on the original text segments corresponding to all the triples, determine the weight information corresponding to each original text segment; based on the weight information corresponding to each original text segment, filter out M relevant text segments; Based on the M related text fragments, a table template is determined; the natural language is filled into the table template to obtain a table formal language; wherein, the table formal language includes multiple table headers for indicating content attributes and table content corresponding to each table header; Based on the tabular form language, generate the corresponding SQL statement in the natural language.

2. The natural language to SQL conversion method applied to the securities industry according to claim 1, characterized in that, The step of generating the corresponding SQL statement in natural language based on the tabular form language includes: Expand the table content corresponding to each header of the tabular form language to obtain an expanded table; Based on the extended table, multiple initial SQL statements are generated, and the credibility parameter corresponding to each initial SQL statement is determined according to the number of times each initial SQL statement is repeated. From the multiple initial SQL statements, select the SQL statements to be confirmed, wherein the credibility parameter of the SQL statements to be confirmed is greater than or equal to the preset credibility threshold. If there is only one SQL statement to be confirmed, then the SQL statement to be confirmed is the SQL statement corresponding to the natural language.

3. The natural language to SQL conversion method applied to the securities industry according to claim 1, characterized in that, For each triple, based on the two entities in the triple and the relationship between the two entities, the original text fragment is obtained from the natural language, including: For each triple, the two entities in the triple are expanded using a preset knowledge set of data to obtain multiple expanded entities; the relationship between the two entities in the triple is expanded to obtain multiple expanded relationships. For each triple, the original text fragment is obtained by matching all the extended entities and all the extended relations with the natural language.

4. The natural language to SQL conversion method applied to the securities industry according to claim 3, characterized in that, For each of the triples, the natural language is matched based on all the extended entities and all the extended relations to obtain the matched original text fragment, including: For each triple, multiple extended statements are constructed based on all extended entities and all extended relations; all extended statements are then matched with the natural language to obtain the matched original text fragments.

5. The natural language to SQL conversion method applied to the securities industry according to claim 1, characterized in that, The step of matching the natural language with a preset knowledge graph to obtain a target sub-graph corresponding to the natural language includes: The natural language is converted into a language vector in vector form; the language vector is matched with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language.

6. The natural language to SQL conversion method applied to the securities industry according to claim 5, characterized in that, The process of converting the natural language into a language vector in vector form includes: The natural language is divided into text blocks according to multiple preset text block granularity division rules to obtain multiple text block sequences; a sub-language vector is determined according to each text block sequence, and a language vector is obtained from all the sub-language vectors; And, the step of matching the language vector with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language includes: All the sub-language vectors are matched with a preset knowledge graph to obtain all associated entities; the knowledge graph is traversed to mine the relationships between all associated entities, and the target sub-graph corresponding to the natural language is obtained based on all the associated entities and the relationships between them.

7. The natural language to SQL conversion method applied to the securities industry according to claim 1, characterized in that, The step of determining the table template based on the M related text fragments includes: For each of the M related text fragments, determine the content attribute corresponding to each related text fragment, and match the corresponding table header for each content attribute; obtain a table template based on all the table headers.

8. A natural language to SQL converter for use in the securities industry, characterized in that, The device includes: The graph matching module is used to receive natural language output by the operation object for securities industry data; match the natural language with a preset knowledge graph to obtain the target sub-graph corresponding to the natural language; The text matching module is used to extract all triples in the target sub-graph, wherein any triple includes two entities and a relationship between the two entities; for each triple, the original text fragment is obtained from the natural language based on the two entities and the relationship between the two entities in the triple; The table determination module is used to determine the weight information corresponding to each original text segment based on all the original text segments corresponding to the triples; to filter out M relevant text segments based on the weight information corresponding to each original text segment; and to determine a table template based on the M relevant text segments. The language conversion module is used to fill the natural language into a preset table template to obtain a tabular language; wherein, the tabular language includes multiple table headers for indicating content attributes and table content corresponding to each table header; The SQL generation module is used to generate SQL statements corresponding to the natural language based on the tabular form language.

9. A natural language to SQL conversion system for the securities industry, characterized in that, The system includes: a memory storing executable program code; a processor coupled to the memory; the processor calling the executable program code stored in the memory to execute the natural language to SQL method for the securities industry as described in any one of claims 1-7.

10. A computer storage medium, characterized in that, The computer storage medium stores computer instructions, which, when executed by a processor, implement the natural language to SQL method for the securities industry as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Text index enhanced question and answer method and system based on knowledge graph

    CN117453851A

  • Retrieval enhancement generation-based retrieval method, product, equipment and medium

    CN119003795A

  • Data management method and device of security business management system, and storage medium

    CN120336351A

  • SQL (Structured Query Language) statement generation method and device based on natural language and medium

    CN120560649A

  • Multimodal fusion entity retrieval enhancement generation method and device

    CN121502017A