A method for querying large models in resource-constrained environments

By pre -processing, syntax analysis, and semantic analysis of natural language query text, convert to structured knowledge and generate knowledge maps, solve the problem of low operating efficiency of large language models in the limited resource environment, and achieve efficient and accurate information query Essence

CN118313460BActive Publication Date: 2025-01-24BEIJING ZHONGSHURUIZHI TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410535935.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-30
Publication Date
2025-01-24
Estimated Expiration
2044-04-30

AI Technical Summary

Technical Problem

In resource-constrained environments, when deploying and running large pretrained language models for information query, the demand for computing resources and storage space is too high, making it difficult to efficiently run complex model operations.

Method used

By preparing the natural language query text of the user input, remove the words and stop words, perform syntax analysis and semantic analysis, identify the inquiry intent, and convert it into a structured knowledge to generate the knowledge map. Query.

Benefits of technology

It reduces the demand for computing resources and storage space, improves query efficiency, enhances adaptability and scalability, and provides users with efficient and accurate query services in resource-constrained environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118313460B_ABST
    Figure CN118313460B_ABST
Patent Text Reader

Abstract

This application proposes a method for querying using a large model in a resource-constrained environment, which pre-processes the natural language query text input by the user, removes word segmentation and stop words, and obtains a feature expression text; performs syntactic analysis and semantic parsing on the feature expression text to identify the query intent representation description; converts the query intent representation description into structured knowledge, and generates a knowledge graph based on the structured knowledge; generates reasoning logic used in information retrieval based on the knowledge graph; represents the object and intention of the user's query based on the reasoning logic to perform information query in the constructed knowledge base. The solution reduces the demand for computing resources and storage space, improves query efficiency, and enhances adaptability and scalability by reducing the amount of data processing, accurate intent recognition, structured query, and the use of knowledge graphs, providing strong technical support for users to perform efficient and accurate queries in resource-constrained environments.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of big data processing, and in particular to a method for querying using a large model in a resource-constrained environment. Background Art

[0002] With the rapid development of artificial intelligence technology, large pre-trained language models (such as the GPT series) have shown excellent performance in the field of natural language processing (NLP). These models have learned rich language representations by training on large-scale data sets, thus achieving breakthrough progress in various NLP tasks such as text classification, sentiment analysis, and machine translation.

[0003] As a key application area of ​​large-scale models, information query has the core advantage of being able to understand users' natural language queries and provide accurate information retrieval results. However, the deployment and operation of large-scale models require a large amount of computing resources and storage space, which is difficult to efficiently run complex model operations in resource-constrained environments such as mobile devices and embedded systems, where the processor computing power is limited. Summary of the invention

[0004] The purpose of this application is to propose a method for querying using a large model in a resource-constrained environment, so as to solve or alleviate the technical problems existing in the prior art.

[0005] A method for querying using a large model in a resource-constrained environment, comprising:

[0006] Obtaining a natural language query text input by a user, and preprocessing the natural language query text to remove participles and stop words therein, and obtaining a feature description text in the natural language query text;

[0007] Performing syntactic analysis and semantic parsing on the feature expression text to identify a representation description of the query intent in the natural language query text;

[0008] Convert the query intent representation description into structured knowledge, and generate a knowledge graph based on the structured knowledge;

[0009] Based on the knowledge graph, generate reasoning logic used in information retrieval;

[0010] The object and intention of the user's query are characterized based on the reasoning logic to perform information query in the constructed knowledge base.

[0011] Optionally, the acquiring of a natural language query text input by a user, and preprocessing the natural language query text to remove participles and stop words therein, and obtaining a feature description text in the natural language query text includes:

[0012] The large model calls the jieba library embedded therein to segment the natural language query text, and calls the customized word list in the HanLP library embedded therein to preprocess the natural language query text, remove the segmentation words and stop words therein, and obtain the feature description text in the natural language query text.

[0013] Optionally, the large model calls the jieba library embedded therein to segment the natural language query text, and calls a custom word list in the HanLP library embedded therein to pre-process the natural language query text, remove the segmentation words and stop words therein, and obtain the feature description text in the natural language query text, including:

[0014] The large model calls the jieba library embedded therein, uses Python's multi-threading to perform parallel segmentation on the natural language query text, assigns multiple segments to multi-process modules for parallel word segmentation, and calls the custom word list embedded in the HanLP library therein to update and iteratively match the results of the jieba word segmentation, so as to pre-process the natural language query text, remove the word segmentations and stop words therein, and obtain the feature description text in the natural language query text.

[0015] Optionally, the performing syntactic analysis and semantic parsing on the feature expression text to identify a representation description of the query intent in the natural language query text includes:

[0016] The large model calls the syntactic analyzer embedded therein to identify part-of-speech tags, dependency relations and syntactic structures, so as to perform syntactic analysis and semantic parsing on the feature description text, so as to determine the components in each sentence of the feature description text, and the semantic relations between the components;

[0017] According to the components and the semantic relationships between the components, a query intent representation description in the natural language query text is identified.

[0018] Optionally, the identifying the query intent representation description in the natural language query text according to the components and the semantic relationship between the components includes:

[0019] Generate a syntax tree according to the components and the semantic relations between the components;

[0020] According to the syntax tree, a query intent representation description in the natural language query text is identified.

[0021] Optionally, generating a syntax tree according to the components and semantic relationships between the components includes:

[0022] generating semantic role annotations according to the components and semantic relationships between the components;

[0023] The syntax tree is generated according to the semantic role labeling.

[0024] Optionally, generating semantic role labels according to the components and the semantic relationships between the components includes:

[0025] generating semantic argument data according to the components and semantic relations between the components;

[0026] framing the semantic argument data to generate a semantic framework;

[0027] The semantic framework is matched with a predefined semantic role list to generate semantic role annotations.

[0028] Optionally, generating the syntax tree according to the semantic role labeling includes:

[0029] According to the type of the semantic role annotation, construct a plurality of grammatical units and assign corresponding semantic labels;

[0030] Semantically merge the grammatical units based on the semantic tags to obtain syntactic tree node attributes;

[0031] The syntax tree is generated according to the syntax tree node attributes based on the semantic features and the syntax features of the syntax tree node attributes.

[0032] Optionally, identifying the query intent representation description in the natural language query text according to the syntax tree includes:

[0033] Locating a plurality of query slot features according to the syntax tree;

[0034] A joint semantic fusion analysis is performed on the plurality of query slot features to identify a representation description of the query intent in the natural language query text.

[0035] Optionally, locating a plurality of query slot features according to the syntax tree includes:

[0036] Performing structural analysis on the syntax tree to obtain a structured analysis result;

[0037] Performing context semantic fusion on the structured analysis results to locate multiple candidate query slot features;

[0038] Confidence analysis is performed on the multiple candidate query slot features to obtain confidence scores, so as to select some of the candidate query slot features as the located multiple query slot features according to the confidence scores.

[0039] Optionally, converting the query intent representation description into structured knowledge and generating a knowledge graph based on the structured knowledge includes:

[0040] Perform entity extraction, relationship extraction, and event extraction on the query intent representation description;

[0041] Generate a resource description framework based on the extracted entities, relationships, and events, and use it as structured knowledge;

[0042] The resource description framework is ontology constructed and semi-automatically semantically annotated to generate a knowledge graph.

[0043] Optionally, the ontology construction and semi-automatic semantic annotation of the resource description framework to generate a knowledge graph includes:

[0044] The entity parallel relationship similarity and entity hierarchical relationship are extracted from the resource description framework to construct an ontology and the constructed ontology is annotated with semantic roles to perform semi-automatic semantic annotation to generate a knowledge graph.

[0045] Optionally, the generating of reasoning logic used in information retrieval based on the knowledge graph includes:

[0046] Map the knowledge graph into the set TransE vector space to obtain the association vector between entity and semantics;

[0047] Performing cluster analysis on the association vectors between the entity and the semantics to obtain several intention item sets;

[0048] Calculate the similarity between any intention item set and each other intention item set, and merge the several intention item sets based on the similarity to obtain an intention logic cluster;

[0049] Based on the intention logic cluster, the reasoning logic used in information retrieval is generated.

[0050] Optionally, merging the plurality of intention item sets based on the similarity to obtain an intention logic cluster includes:

[0051] Calculate the mean of all the similarities to obtain the median similarity;

[0052] Based on the median similarity, determine the residual difference between the similarity between each intention item set and each other intention item set and the median similarity;

[0053] The residual is matched with a plurality of set residual ranges to group a plurality of intention items whose residuals are within the corresponding residual ranges into an intention logic cluster.

[0054] Optionally, characterizing the object and intention of the user's query based on the reasoning logic to perform information query in the constructed knowledge base includes:

[0055] Based on path reasoning calculus, converting the reasoning logic into a mapping path to the knowledge base;

[0056] Generate a structured query representation according to the mapping path;

[0057] According to the structured query representation, information query is performed in the constructed knowledge base.

[0058] Optionally, the converting the reasoning logic into a mapping path to the knowledge base based on the path reasoning calculation includes:

[0059] Obtaining the structure of the knowledge base, including its schema, entity types, attributes, and relationship types;

[0060] Based on the path reasoning calculus, a multi-hop relationship from the reasoning logic to the structure of the knowledge base is calculated to convert the reasoning logic into a mapping path to the knowledge base based on the multi-hop relationship.

[0061] Optionally, generating a structured query representation according to the mapping path includes:

[0062] Extracting static features and dynamic features in the mapping path, wherein the static features represent fixed entities and attributes in the query intent, and the dynamic features represent dynamically changing entities and attributes in the query intent;

[0063] Based on the query grammar and according to the static features and dynamic features, a structured query representation is generated.

[0064] Optionally, performing information query in the constructed knowledge base according to the structured query representation includes:

[0065] The structured query representation is matched with the edges and nodes of the knowledge base, and information query is performed in the constructed knowledge base. The edges represent entities in the knowledge base, and the edges represent the relationship between entities in the knowledge base, so that when performing the information query, the entities are first matched, and then based on the matched entities, the edges are matched to obtain the query results.

[0066] The present application provides a method for querying using a large model in a resource-constrained environment. By preprocessing the natural language query text input by the user and removing the segmentation and stop words, the amount of data that the model needs to process can be reduced, thereby reducing the consumption of computing resources. In addition, by identifying the query intent through syntactic analysis and semantic parsing, the user's information needs can be more accurately located, irrelevant calculations can be reduced, and query efficiency can be improved. Furthermore, converting the query intent into structured knowledge can make the query process more direct and efficient, because structured data queries are usually faster and consume less resources than unstructured text queries. Finally, the knowledge graph, as a structured semantic knowledge base, can significantly improve the speed and accuracy of information retrieval while reducing the direct dependence on large models. Moreover, generating reasoning logic can guide the query process, avoid unnecessary calculation branches, and thus reduce the demand for computing resources. In particular, by characterizing the object and intention of the user's query through reasoning logic, the query scope can be more accurately located, the search space can be reduced, and the query speed can be improved. In summary, the entire solution reduces the demand for computing resources and storage space, improves query efficiency, and enhances adaptability and scalability by reducing the amount of data processing, accurate intent recognition, structured queries, and the use of knowledge graphs, providing strong technical support for users to perform efficient and accurate queries in resource-constrained environments. BRIEF DESCRIPTION OF THE DRAWINGS

[0067] Hereinafter, some specific embodiments of the present application will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:

[0068] Figure 1 A flowchart of a method for querying using a large model in a resource-constrained environment according to an embodiment of the present application. DETAILED DESCRIPTION

[0069] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the embodiments of the present application should fall within the scope of protection of the embodiments of the present application.

[0070] The present application provides a method for querying using a large model in a resource-constrained environment, comprising: obtaining a natural language query text input by a user, and preprocessing the natural language query text to remove word segmentations and stop words therein to obtain a feature description text in the natural language query text; performing syntactic analysis and semantic parsing on the feature description text to identify a representation description of query intent in the natural language query text; converting the representation description of query intent into structured knowledge, and generating a knowledge graph based on the structured knowledge; generating reasoning logic used in information retrieval based on the knowledge graph; representing the object and intent of the user's query based on the reasoning logic to perform information query in a constructed knowledge base, thereby reducing the demand for computing resources and storage space, improving query efficiency, enhancing adaptability and scalability, and providing strong technical support for users to perform efficient and accurate queries in resource-constrained environments by reducing the amount of data processing, accurately identifying intent, and using structured queries and knowledge graphs.

[0071] Figure 1 This is a flow chart of a method for querying using a large model in a resource-constrained environment according to an embodiment of the present application. Figure 1 As shown, it includes:

[0072] S101, obtaining a natural language query text input by a user, and preprocessing the natural language query text to remove participles and stop words therein, to obtain a feature description text in the natural language query text;

[0073] S102, performing syntactic analysis and semantic parsing on the feature expression text to identify a representation description of the query intent in the natural language query text;

[0074] S103, converting the query intent representation description into structured knowledge, and generating a knowledge graph based on the structured knowledge;

[0075] S104, generating reasoning logic used in information retrieval based on the knowledge graph;

[0076] S105: Characterize the object and intention of the user's query based on the reasoning logic to perform information query in the constructed knowledge base.

[0077] Optionally, the acquiring of a natural language query text input by a user, and preprocessing the natural language query text to remove participles and stop words therein, and obtaining a feature description text in the natural language query text includes:

[0078] The large model calls the jieba library embedded therein to segment the natural language query text, and calls the customized word list in the HanLP library embedded therein to preprocess the natural language query text, remove the segmentation words and stop words therein, and obtain the feature description text in the natural language query text.

[0079] In this embodiment, by embedding the jieba library and the HanLP library into the large model, the integration of the tool is achieved, which means that the user does not need to install or configure these libraries separately, and can use them directly in the large model, thereby simplifying the use process and improving convenience. In addition, the jieba library is a widely used Chinese word segmentation tool, which can accurately segment Chinese text. Calling the jieba library for word segmentation in the large model can ensure the accuracy and reliability of the word segmentation results, and provide high-quality input for subsequent natural language processing tasks. In addition, by calling the custom word list in the HanLP library, stop words can be handled more flexibly. Stop words refer to words that do not contribute or contribute less to the text content in natural language processing, such as common function words, conjunctions, etc. By removing these stop words, the text can be further refined, and keywords and core information can be highlighted, thereby improving the efficiency of subsequent queries and processing. Furthermore, the text after word segmentation and stop word processing, that is, the feature description text, can more accurately reflect the intention and needs of the user's query, which helps to understand and parse the user's query more accurately in subsequent steps, such as syntactic analysis, semantic parsing, and reasoning logic generation, thereby improving the accuracy and relevance of the query results. Finally, by embedding the jieba library and HanLP library in the large model, the call and dependency of external libraries can be reduced, reducing the complexity and maintenance cost of the system. At the same time, since these libraries are embedded in the large model, the computing resources of the large model can be fully utilized to achieve efficient text preprocessing operations and improve the overall performance of the system.

[0080] The present application embodiment provides an exemplary code to show how to embed the jieba library and the HanLP library in a large model to pre-process the natural language query text input by the user:

[0081]

[0082]

[0083] In this sample code, the PreprocessingModule class containing the text preprocessing logic is defined, jieba is used for word segmentation and stop word removal, and then the MyLargeModel class is created. This class inherits from the LargeModel class in the large model library and embeds the PreprocessingModule instance in it. The preprocessing module is called through the process_query method in the MyLargeModel class to preprocess the query text.

[0084] Optionally, the large model calls the jieba library embedded therein to segment the natural language query text, and calls a custom word list in the HanLP library embedded therein to pre-process the natural language query text, remove the segmentation words and stop words therein, and obtain the feature description text in the natural language query text, including:

[0085] The large model calls the jieba library embedded therein, uses Python's multi-threading to perform parallel segmentation on the natural language query text, assigns multiple segments to multi-process modules for parallel word segmentation, and calls the custom word list embedded in the HanLP library therein to update and iteratively match the results of the jieba word segmentation, so as to pre-process the natural language query text, remove the word segmentations and stop words therein, and obtain the feature description text in the natural language query text.

[0086] In the present embodiment, by utilizing Python's multithreading and multi-process technology, natural language query text can be parallel segmented and parallel word segmentation, and this parallel processing mode can make full use of the computing resources of multi-core CPU, significantly reduce processing time, improve overall processing speed, and be particularly important for the query system that needs fast response. In addition, multithreading and multi-process technology enable the processing process to utilize system resources more efficiently, by dividing the task into multiple subtasks and assigning them to different threads or processes, it is possible to avoid the resource bottleneck that a single thread or process may appear when processing a large amount of data, thereby improving the throughput and performance of the entire system. In addition, jieba library, as a mature Chinese word segmentation tool, can accurately segment Chinese text, embed jieba library in a large model, and update iterative matching in conjunction with the self-defined word list in HanLP library, it is possible to further improve the accuracy of word segmentation, which helps to better capture the keywords and semantic information in the text, and provide more accurate data support for subsequent natural language processing tasks. Furthermore, by calling the custom word list in the HanLP library, stop words can be flexibly processed. Stop words are common noise words in natural language processing and contribute little to the text content. By removing these stop words, the text can be further refined to highlight keywords and core information. The use of custom word lists can be adjusted and optimized according to specific application scenarios to meet different needs. Finally, the text after multi-threaded and multi-process word segmentation and stop word processing, that is, the feature description text, can more accurately reflect the intention and needs of the user query. This effective feature extraction helps to more accurately understand and parse the user query in the subsequent steps, thereby improving the accuracy and relevance of the query results.

[0087] This application example provides an exemplary code to show how to use Python's multi-threading and multi-processing technology, combined with the jieba library embedded in the large model and the custom word list in the HanLP library, to pre-process the natural language query text:

[0088]

[0089]

[0090]

[0091] In this sample code, the MyLargeModel class inherits from the LargeModel class in the large model library. The MyLargeModel class contains the preprocess_query method, which uses multi-threading to perform text segmentation and word segmentation and multi-process to remove stop words in the word segmentation results. The method first checks whether jieba has been initialized, and if not, it initializes it, and then calls the preprocess_text function to perform the actual preprocessing work.

[0092] Optionally, the performing syntactic analysis and semantic parsing on the feature expression text to identify a representation description of the query intent in the natural language query text includes:

[0093] The large model calls the syntactic analyzer embedded therein to identify part-of-speech tags, dependency relations and syntactic structures, so as to perform syntactic analysis and semantic parsing on the feature description text, so as to determine the components in each sentence of the feature description text, and the semantic relations between the components;

[0094] According to the components and the semantic relationships between the components, a query intent representation description in the natural language query text is identified.

[0095] In this embodiment, the large model performs in-depth processing on the feature expression text through the built-in syntactic analyzer, identifies the part-of-speech tagging, dependency relationship and syntactic structure in the text, and this information provides a solid foundation for subsequent semantic analysis, so that the model can more accurately identify the key information and query intent in the query text. In addition, by performing syntactic analysis and semantic analysis on the feature expression text, the model can more accurately locate the key components in the query text and the semantic relationship between these components, which helps the model to better understand the user's query needs and provide more accurate and targeted responses or results accordingly. In addition, since the syntactic analyzer and semantic parser are embedded in the large model, the performance can be continuously improved as the model is trained and optimized, which enables the model to maintain a high recognition accuracy and stability when facing natural language queries of different types and complexities. Furthermore, for query texts containing multiple clauses, complex sentences or professional terms, syntactic analysis and semantic analysis can help the model better understand these complex structures, thereby achieving accurate processing of complex queries. Finally, by more accurately identifying the user's query intent, the model can provide users with more demand-oriented and personalized services, which helps improve user satisfaction and trust in the system, thereby improving the overall user experience.

[0096] This application example provides an exemplary code:

[0097]

[0098]

[0099] In this example code, the SyntaxAndSemanticParse class and the BigModel class are defined, wherein the SyntaxAndSemanticParser simulates the process of syntactic analysis and semantic parsing, and returns the simulated syntactic analysis results and semantic parsing results, which are query intent in this embodiment; the BigModel class contains the logic of preprocessing text, calls the SyntaxAndSemanticParser class to perform syntactic analysis and semantic parsing, and finally identifies the query intent based on the results of the semantic parsing.

[0100] Optionally, the identifying the query intent representation description in the natural language query text according to the components and the semantic relationship between the components includes:

[0101] Generate a syntax tree according to the components and the semantic relations between the components;

[0102] According to the syntax tree, a query intent representation description in the natural language query text is identified.

[0103] In this embodiment, the components and semantic relationships obtained through syntactic analysis can more accurately understand the structure and meaning of the query text, help to more accurately identify the user's query intent, and reduce misunderstandings and ambiguities. In addition, the syntax tree provides a hierarchical representation of the query text, so that the model can handle query texts of different complexity and structure. Even in the face of complex sentence structures and diverse expressions, the syntax tree can capture key semantic information, thereby enhancing the robustness of intent recognition. Furthermore, the process of generating a syntax tree makes the process of intent recognition more transparent and explainable. The syntax tree can clearly show the relationship between the various components in the query text, and how these relationships jointly affect the recognition of query intent, which is very helpful for debugging the model, understanding user queries, and improving system performance. At the same time, through the syntax tree, complex query texts containing multiple entities, relationships, and modifiers can be processed, and the model can identify the complex relationships between these components, thereby more accurately identifying complex query intent. Finally, the syntax tree-based intent recognition method does not rely on fixed templates or rules, but identifies intent by analyzing the syntactic structure of the query text, enabling the system to handle more diverse query texts and improve the flexibility and adaptability of the system.

[0104] The present application embodiment provides an exemplary code to demonstrate how to generate a syntax tree based on components and semantic relationships between components, and further identify the query intent representation description in the natural language query text:

[0105]

[0106]

[0107] In this sample code, the NLTK library and the StanfordNLP interface are used to generate a syntax tree. StanfordNLP is a powerful natural language processing tool that can generate high-quality syntax trees. englishPCFG.ser.gz is the syntax model file of Stanford Parser. The identify_intent_from_syntax_tree function is used to traverse the syntax tree to find key components. The verb object (VOB) is usually the focus of the query, so the subtree containing the VOB tag is found and used as part of the query intent.

[0108] Optionally, generating a syntax tree according to the components and semantic relationships between the components includes:

[0109] generating semantic role annotations according to the components and semantic relationships between the components;

[0110] The syntax tree is generated according to the semantic role labeling.

[0111] In this embodiment, by generating semantic role annotations, the roles played by each component in the sentence and the interactions between them can be more deeply understood, which helps to more accurately construct a syntactic tree and capture the deep structure and semantic information of the sentence. In addition, semantic role annotation can clearly identify the relationship between the predicate (such as verbs, adjectives, etc.) and its related arguments (such as agents, patients, etc.) in the sentence. These relationships are crucial for identifying query intent because they directly reflect the user's concerns and needs. By using semantic role annotations, query intent can be more accurately identified and misunderstandings and ambiguities can be reduced. In addition, different expressions or sentence structures may lead to the same semantics. By generating semantic role annotations, sentences of different forms can be converted into the same semantic representation, thereby improving the model's adaptability to different inputs, which makes the model more robust and able to handle more diverse and complex query texts. At the same time, semantic role annotation is a cross-language semantic representation method. By generating semantic role annotations, syntactic analysis technology can be more easily applied to natural language processing tasks in different languages, which helps to expand the scope of application of the model and support query intent recognition in a multilingual environment. Finally, semantic role labeling provides an intuitive way to explain the relationship between various components in a sentence, making it easier to understand how the model identifies query intent based on the syntactic tree, which is very helpful for debugging models, improving system performance, and interacting with users.

[0112] The present application embodiment provides an exemplary code to illustrate how to generate semantic role annotations based on sentence components and the semantic relationships between them, and generate a syntax tree based on these annotations:

[0113]

[0114] In this example code, the semantic_role_labeler library is used to simulate the generation of semantic role labels, the syntax_tree_generator library is used to simulate the process of generating syntax trees based on semantic role labels, and query_text is the natural language query text used for subsequent semantic role labeling and syntax tree generation. The semantic_role_labeler.generate_semantic_roles function is used to generate semantic role labels. The syntax_tree_generator.generate_syntax_tree function is used to generate syntax trees based on semantic role labels. The example_semantic_roles and example_syntax_tree variables contain example data for simulating the structure of semantic role labeling and syntax trees.

[0115] Optionally, generating semantic role labels according to the components and the semantic relationships between the components includes:

[0116] generating semantic argument data according to the components and semantic relations between the components;

[0117] framing the semantic argument data to generate a semantic framework;

[0118] The semantic framework is matched with a predefined semantic role list to generate semantic role annotations.

[0119] In this embodiment, by generating semantic argument data, the semantic roles played by each component in the sentence can be captured more accurately. These argument data not only include the meaning of the component itself, but also cover the interaction and relationship between them and other components. This deep semantic understanding helps to parse the meaning of the sentence more accurately and provides a solid foundation for subsequent natural language processing tasks. In addition, by framing the semantic argument data, a unified and standardized semantic framework can be formed. Such a framework can clearly express the structural relationship between different components in the sentence, making the semantic information clearer and easier to understand. At the same time, the standardized semantic framework also helps to improve the semantic compatibility across domains and languages, making the semantic role annotation more universal and portable. At the same time, by matching the semantic framework with a predefined semantic role list, a semantic role annotation with consistency and interpretability can be generated. The predefined semantic role list is usually based on linguistic rules and the analysis of a large number of corpora, which can reflect the common semantic role patterns in the language. The annotation results generated using this matching method are more reliable, stable, and easy to understand and interpret. Furthermore, for sentences containing multiple predicates, complex modification relationships, or nested structures, these complex relationships can be better captured by generating semantic role annotations. Semantic role annotations can not only identify the main predicates and arguments in the sentence, but also handle complex modifiers, clauses, and other structures, thereby more comprehensively understanding the meaning of the sentence. Finally, semantic role annotation is an important foundation for many natural language processing tasks, such as question-answering systems, information extraction, and machine translation. By accurately generating semantic role annotations, the performance of these tasks can be improved, allowing the system to better understand and process natural language input.

[0120] The present application embodiment provides an exemplary code for illustrating how to generate semantic argument metadata based on sentence components and the semantic relationships between them, further frame these metadata to form a semantic framework, and finally match them with a predefined semantic role list to generate semantic role annotations:

[0121]

[0122]

[0123] In this sample code, the natural_language_processor library is introduced to process natural language text and generate semantic argument metadata, frame these metadata, and match predefined semantic roles. These functions (generate_semantic_arguments, frame_semantic_arguments, match_semantic_roles) are provided by the natural language processing tool library. predefined_semantic_roles is a list of predefined semantic roles, which defines the semantic roles that different parts of speech may play. This list is built based on linguistic rules and corpus analysis.

[0124] Optionally, generating the syntax tree according to the semantic role labeling includes:

[0125] According to the type of the semantic role annotation, construct a plurality of grammatical units and assign corresponding semantic labels;

[0126] Semantically merge the grammatical units based on the semantic tags to obtain syntactic tree node attributes;

[0127] The syntax tree is generated according to the syntax tree node attributes based on the semantic features and the syntax features of the syntax tree node attributes.

[0128] In this embodiment, by utilizing the information in the semantic role annotation, more accurate grammatical units can be constructed and corresponding semantic labels can be assigned to them. Each node in the syntax tree contains not only syntactic information, but also rich semantic information, so that the syntax tree can more accurately reflect the deep structure and semantic relationship of the sentence, thereby improving the accuracy of syntactic analysis. In addition, traditional syntactic analysis mainly relies on the surface form of the sentence and is easily affected by factors such as lexical ambiguity and complex structure. Syntactic analysis based on semantic role annotation can utilize deeper semantic information to better handle these complex situations. This technology can improve the robustness of syntactic analysis and enable it to maintain high performance in various situations. In addition, the syntax tree is the basis of many natural language processing tasks, such as semantic understanding, machine translation, sentiment analysis, etc. By generating a syntax tree based on semantic role annotation, more accurate and rich syntactic structure information can be provided for these tasks, thereby improving their performance. Furthermore, by generating a syntactic tree based on semantic role annotation, the structure of the syntactic tree is more intuitive and easier to understand. The semantic label of each node clearly indicates the semantic role it represents, so that the structure of the syntactic tree closely corresponds to the semantic relationship of the sentence, which helps to improve the interpretability of the syntactic tree and makes the analysis results easier for users to understand and accept. Finally, there are large differences in the syntactic structures of different languages, which brings challenges to cross-language syntactic analysis. Syntactic analysis based on semantic role annotation can transcend the differences between languages ​​and represent the syntactic structures of different languages ​​through unified semantic roles, which makes cross-language syntactic analysis easier to implement and helps promote information exchange and sharing between different languages.

[0129] This embodiment of the application provides an exemplary code to show how to generate a syntax tree based on semantic role annotation:

[0130]

[0131]

[0132] In this sample code, the semantic role labeling dictionary semantic_role_labels is first defined. Then, the build_syntactic_units function builds grammatical units according to the semantic role labels. Each unit contains a role, a label, and a list of child nodes. The merge_semantic_units function performs semantic merging based on these grammatical units to form the node structure of the syntactic tree. The generate_syntactic_tree_node function converts each grammatical unit into a syntactic tree node, and the generate_syntactic_tree function is responsible for the generation of the entire syntactic tree. The print_syntactic_tree function is used to print the structure of the syntactic tree.

[0133] Optionally, identifying the query intent representation description in the natural language query text according to the syntax tree includes:

[0134] Locating a plurality of query slot features according to the syntax tree;

[0135] A joint semantic fusion analysis is performed on the plurality of query slot features to identify a representation description of the query intent in the natural language query text.

[0136] In this embodiment, the syntax tree can clearly show the relationship and hierarchical structure between the components in the sentence. Through the syntax tree, multiple query slot features in the natural language query text can be accurately located. These slot features are usually closely related to the query intent. Further joint semantic fusion analysis of these slot features can more accurately understand the overall semantics of the query text, thereby accurately identifying the query intent. In addition, natural language query texts often contain complex structures and various expressions. Through the syntax tree, these complex structures, such as parallel relationships, nested relationships, etc., can be processed, so as to accurately capture the intent information in the query text, which is of great significance for processing complex queries and improving user experience. Furthermore, query texts in different fields may have different expressions and slot features. Through the query intent recognition method based on the syntax tree, customized intent recognition can be performed according to the syntactic structure and semantic rules of the specific field, so that the technology can adapt to the query needs of multiple fields and improve the versatility and scalability of the system. Furthermore, the query intent recognition method based on the syntax tree not only provides the recognition results of the query intent, but also displays the syntactic structure and semantic information used in the recognition process, which makes the decision-making process of the system more transparent and explainable, and helps to improve users' understanding and trust in the system's decisions. Finally, as an important intermediate representation in natural language processing, the syntax tree can be coordinated with other NLP tasks. The query intent recognition method based on the syntax tree helps to seamlessly integrate with other NLP tasks and improve overall performance.

[0137] The present application embodiment provides an exemplary code for identifying a query intent representation description in a natural language query text according to a syntax tree:

[0138]

[0139]

[0140] In this sample code, the Stanford CoreNLP toolkit of nltk is used to simulate the generation of a syntax tree, and the extract_query_slots and analyze_slots_semantics functions are defined to extract query slot features and perform joint semantic fusion analysis. Optionally, the multiple query slot features are located according to the syntax tree, including:

[0141] Performing structural analysis on the syntax tree to obtain a structured analysis result;

[0142] Performing context semantic fusion on the structured analysis results to locate multiple candidate query slot features;

[0143] Confidence analysis is performed on the multiple candidate query slot features to obtain confidence scores, so as to select some of the candidate query slot features as the located multiple query slot features according to the confidence scores.

[0144] In this embodiment, by performing structural analysis on the syntax tree, the relationship and hierarchy between the various components in the sentence can be clearly understood. This structured information helps to accurately locate the slot features related to the query intent. Compared with simple text matching or keyword extraction, the method based on the syntax tree can more accurately capture the semantic structure and key information of the sentence. Secondly, when locating the query slot features, it is very important to consider contextual semantic fusion. By performing contextual semantic fusion on the structured analysis results, the meaning and role of the slot features in the sentence can be better understood, which helps to reduce ambiguity and misunderstanding and improve the accuracy of query slot positioning. At the same time, contextual semantic fusion can handle complex query expressions, such as implicit information, metaphors and metaphors. Thirdly, it is an important step to perform confidence analysis on multiple candidate query slot features. By calculating the confidence score, the reliability and importance of each candidate slot feature can be evaluated, which helps to screen out the slot features that best meet the query intent and improve the accuracy and reliability of query intent recognition. Confidence analysis can also handle some fuzzy or uncertain situations and improve the robustness of the system. In addition, different users have different query expressions and habits. Some queries may be very direct and clear, while others may be vague or obscure. By performing structural analysis and contextual semantic fusion on the syntactic tree and combining it with confidence analysis, we can better adapt to this complexity and diversity. Whether it is a simple keyword query or a complex combination query, we can effectively locate the relevant query slot features.

[0145] The embodiment of the present application provides an exemplary code for locating multiple query slot features according to a syntax tree. This example includes structural analysis, context semantic fusion, and confidence analysis:

[0146]

[0147]

[0148] In this sample code, the spaCy library is used to parse sentences and obtain syntactic trees. The structural_analysis function extracts key components based on the dependencies of the syntactic tree. The context_semantic_fusion function returns the structural analysis results as candidate query slot features. The confidence_analysis function assigns a fixed confidence value to each candidate slot. Finally, the select_slots_by_confidence function selects the final query slot feature based on the confidence threshold.

[0149] Optionally, converting the query intent representation description into structured knowledge and generating a knowledge graph based on the structured knowledge includes:

[0150] Perform entity extraction, relationship extraction, and event extraction on the query intent representation description;

[0151] Generate a resource description framework based on the extracted entities, relationships, and events, and use it as structured knowledge;

[0152] The resource description framework is ontology constructed and semi-automatically semantically annotated to generate a knowledge graph.

[0153] In this embodiment, first, by performing entity extraction, relationship extraction and event extraction on the query intent representation description, key information elements can be extracted from the original unstructured text. Entity extraction helps identify specific objects in the text, such as names of people and places; relationship extraction reveals the connection and interaction between these entities; event extraction further captures the important events described in the text and their related attributes. Next, based on the extracted entities, relationships and events, a resource description framework (RDF) is generated and used as structured knowledge. This step allows the originally scattered text information to be structured, which is convenient for subsequent query, reasoning and analysis. Then, these resource description frameworks are ontology constructed and semi-automatic semantic annotation is performed. Ontology construction provides a unified semantic basis for the knowledge graph, defines core concepts, attributes and the relationships between them, and semi-automatic semantic annotation combines automation and artificial intelligence, which not only improves efficiency but also ensures the accuracy of annotation. Finally, through the above steps, the knowledge graph was successfully generated. The knowledge graph not only contains the direct information in the query intent, but also expands the relevant indirect information through relationship extraction and event extraction, thus forming a complete, accurate and in-depth knowledge system.

[0154] This embodiment of the application provides an exemplary code to demonstrate how to convert the query intent representation description into structured knowledge and generate a knowledge graph based on the structured knowledge:

[0155]

[0156]

[0157] This sample code demonstrates how to extract entities, relationships, and events from query intent descriptions and convert these extraction results into structured knowledge. It then simulates the process of ontology construction and semi-automatic semantic annotation, and finally adds the structured knowledge to the knowledge graph library to generate a knowledge graph.

[0158] Optionally, the ontology construction and semi-automatic semantic annotation of the resource description framework to generate a knowledge graph includes:

[0159] The entity parallel relationship similarity and entity hierarchical relationship are extracted from the resource description framework to construct an ontology and the constructed ontology is annotated with semantic roles to perform semi-automatic semantic annotation to generate a knowledge graph.

[0160] In this embodiment, firstly, by extracting the similarity of entity parallel relationship and entity upper and lower relationship from the resource description framework, a clear structure and rigorous logic ontology can be constructed. The extraction of entity parallel relationship similarity helps to identify and merge entities with similar semantics, eliminate redundant information, and thus ensure the accuracy and consistency of the knowledge graph, while the extraction of entity upper and lower relationship can reveal the hierarchical structure and classification relationship between entities, further enriching the semantic content of the knowledge graph. Secondly, semantic role labeling of the constructed ontology is a key link in realizing semi-automatic semantic labeling. Semantic role labeling can deeply analyze the relationship between predicates and arguments in sentences, and provide accurate semantic information for entities and relationships in the knowledge graph. Preliminary labeling through automated tools, combined with manual review and correction, can significantly improve labeling efficiency and reduce labor costs while ensuring labeling quality. Finally, through a series of technical steps, a high-quality and high-accuracy knowledge graph can be generated. This knowledge graph is not only clear in structure and rich in content, but also can support complex query and reasoning operations. It provides strong knowledge support for enterprise decision-making, academic research and other fields, and helps to promote the development and innovation of related fields.

[0161] The present application embodiment provides an exemplary code to show how to extract entity relationships from a resource description framework (RDF), construct an ontology, and perform semi-automatic semantic annotation to generate a knowledge graph:

[0162]

[0163]

[0164] In this sample code, entities and relationships are extracted, the similarity of entity parallel relationships is calculated, and the hierarchical relationship is extracted. The semi-automatic semantic annotation process is simulated, and exemplary semantic labels are added to each entity. Finally, a KnowledgeGraph instance is created, the original RDF triples are added to it, and then the entire knowledge graph is printed out.

[0165] Optionally, the generating of reasoning logic used in information retrieval based on the knowledge graph includes:

[0166] Map the knowledge graph into the set TransE vector space to obtain the association vector between entity and semantics;

[0167] Performing cluster analysis on the association vectors between the entity and the semantics to obtain several intention item sets;

[0168] Calculate the similarity between any intention item set and each other intention item set, and merge the several intention item sets based on the similarity to obtain an intention logic cluster;

[0169] Based on the intention logic cluster, the reasoning logic used in information retrieval is generated.

[0170] In this embodiment, first, by mapping the knowledge graph into the set TransE vector space, the association vector of the entity and the semantics can be obtained. TransE (Translational Embedding) is a translation-based embedding model that can effectively represent entities and relationships in a low-dimensional space and capture the semantic relationship between entities. In this way, the vectorized representation of entities and relationships in the knowledge graph can be realized, which provides a basis for subsequent reasoning and query. Secondly, cluster analysis is performed on the association vector of the entity and the semantics to obtain several intention item sets. Cluster analysis can cluster similar entities and relationships together to form item sets with common intentions, which helps to decompose complex query intentions into several relatively simple sub-intentions, facilitating subsequent reasoning and matching. Next, the similarity between any intention item set and each other intention item set is calculated, and several intention item sets are merged based on the similarity to obtain an intention logic cluster. By calculating the similarity and merging the intention item sets, the query intention can be further integrated and refined, making the reasoning logic more accurate and efficient, which helps to reduce redundant and repeated query operations and improve query efficiency. Finally, the reasoning logic used in information retrieval is generated based on the intention logic cluster. The reasoning logic is generated based on the user's query intention and the knowledge base structure, which can guide the system to perform efficient and accurate queries in the knowledge base. By generating reasoning logic based on the intention logic cluster, it can better meet the user's query needs and improve the accuracy and relevance of the query results.

[0171] This embodiment of the application provides an exemplary code that demonstrates how to map the knowledge graph to the TransE vector space, perform clustering analysis, calculate similarity, and generate reasoning logic:

[0172]

[0173]

[0174] In this sample code, entities and relations in the knowledge graph are embedded in the TransE vector space. These embedding vectors are obtained in some way (such as TransE model training) and are used to capture the semantic associations between entities and relations.

[0175] Optionally, merging the plurality of intention item sets based on the similarity to obtain an intention logic cluster includes:

[0176] Calculate the mean of all the similarities to obtain the median similarity;

[0177] Based on the similarity median, determine the residual difference between the similarity between each intention item set and each other intention item set and the similarity median;

[0178] The residual is matched with a plurality of set residual ranges to group a plurality of intention items whose residuals are within the corresponding residual ranges into an intention logic cluster.

[0179] In this embodiment, by calculating the mean of all similarities to obtain the median similarity, the similarity between the intent item sets can be measured more objectively. Based on the median similarity, the similarity residual between each intent item set and other intent item sets can be further calculated. This residual calculation method can more accurately identify the subtle differences between the intent item sets. By matching the residual with the set multiple residual ranges, the intent item sets with similar residuals can be merged into intent logic clusters. This merging strategy helps to reduce redundant intent item sets and improve the accuracy and consistency of the reasoning logic. Secondly, after the intent item sets are merged into intent logic clusters, when performing information retrieval, queries can be directly performed on these logic clusters instead of querying each individual intent item set, which greatly reduces the number of queries and the amount of calculation, and improves the query efficiency. At the same time, because the intent item sets within the intent logic cluster have similar query intentions, the information required by the user can be more accurately located, which improves the accuracy and relevance of the query results. In addition, by setting multiple residual ranges to match the residuals of the intent item set, these ranges can be adjusted according to actual needs to adapt to different knowledge graphs and query scenarios, which makes the technology more adaptable and flexible when dealing with complex and changeable knowledge graphs. The intent item sets are merged based on the median similarity and residuals, so that the generated intent logical clusters have clear semantic meaning and interpretability. This helps to better understand the user's query intent and explain and illustrate the query results.

[0180] The embodiment of the present application provides an exemplary code to realize the function of merging intent item sets based on similarity to obtain intent logical clusters:

[0181]

[0182]

[0183] In this sample code, the similarity matrix similarity_matrix is ​​first defined, which represents the similarity between each intent item set and other intent item sets. Then, the median similarity_median of all similarities is calculated. Next, the residual range list residual_ranges is defined to merge the intent item sets into different logical clusters based on the residuals. The merge_intent_clusters function accepts the similarity matrix, the median similarity, and the residual range as input, and returns a list of merged intent logical clusters. Inside the function, each intent item set is traversed, its residual with other intent item sets is calculated, and it is added to the corresponding logical cluster according to the residual range. Finally, the merged intent logical cluster is output.

[0184] Optionally, characterizing the object and intention of the user's query based on the reasoning logic to perform information query in the constructed knowledge base includes:

[0185] Based on path reasoning calculus, converting the reasoning logic into a mapping path to the knowledge base;

[0186] Generate a structured query representation according to the mapping path;

[0187] According to the structured query representation, information query is performed in the constructed knowledge base.

[0188] In this embodiment, firstly, by converting the reasoning logic into the mapping path of the knowledge base based on the path reasoning calculation, the system can locate the information required by the user more accurately, avoiding the large number of irrelevant results that may be brought by the traditional full-text search or keyword matching method, thereby improving the query efficiency and accuracy. Secondly, the reasoning logic can flexibly represent various complex query intentions and object objects, and is not limited to fixed query templates or structures. This enables the technology to adapt to the knowledge base query requirements in different fields and scenarios. Thirdly, the generated structured query representation makes the query logic clearer and more intuitive, easy to understand and optimize. This helps to reduce ambiguity and misunderstanding in the query process and improve the satisfaction of the query results. At the same time, the query method based on reasoning logic has good scalability and maintainability. With the continuous updating and expansion of the knowledge base, the reasoning logic can be easily adjusted and optimized to adapt to new query requirements and data structures. Finally, by more accurately understanding the user's query intention and providing accurate query results, the technology can enhance the user's experience when using the knowledge base for querying, and the user can find the required information more quickly and reduce the time cost of screening in a large number of results.

[0189] The present application embodiment provides an exemplary code to demonstrate how to convert the object and intention of the user's query into a mapping path of the knowledge base based on reasoning logic, and then generate a structured query representation and perform information query in the knowledge base:

[0190]

[0191]

[0192] In this sample code, the knowledge base knowledge_base is defined as a nested structure of dictionaries that represents the relationship between entities. reasoning_logic is a string that represents the path from entity A to entity G. The convert_to_mapping_path function accepts the reasoning logic and the knowledge base as input and returns a list of tuples representing the mapping path. The generate_structured_query function converts this mapping path into a simple structured query representation in string form. Finally, the query_knowledge_base function uses this structured query to query the knowledge base and returns the query result.

[0193] Optionally, the converting the reasoning logic into a mapping path to the knowledge base based on the path reasoning calculation includes:

[0194] Obtaining the structure of the knowledge base, including its schema, entity types, attributes, and relationship types;

[0195] Based on the path reasoning calculus, a multi-hop relationship from the reasoning logic to the structure of the knowledge base is calculated to convert the reasoning logic into a mapping path to the knowledge base based on the multi-hop relationship.

[0196] In this embodiment, first, by obtaining the structure of the knowledge base, including its mode, entity type, attribute and relationship type, the system can more deeply understand the organization of the knowledge base and the relationship between data, which helps to ensure that the reasoning logic can be accurately mapped to the relevant parts of the knowledge base, thereby improving the efficiency and accuracy of the query. Secondly, based on the path reasoning calculus, the system can calculate the multi-hop relationship from the reasoning logic to the knowledge base structure. The multi-hop relationship refers to the complex relationship that connects the starting entity and the target entity through multiple intermediate entities or attributes in the knowledge base. By processing the multi-hop relationship, the system can support more complex and flexible query requirements and meet the user's requirements for exploring deep and indirectly related information in the knowledge base. Thirdly, by converting the reasoning logic into the mapping path of the knowledge base, the system can generate accurate query paths for users. These mapping paths are based on the actual structure and relationship of the knowledge base, which can ensure the accuracy and effectiveness of the query, help reduce ambiguity and misunderstanding in the query process, and improve the satisfaction of the query results. At the same time, the generated mapping path provides query interpretability, allowing users to understand how queries are executed in the knowledge base, which helps increase user trust in query results and provides a basis for debugging and optimizing queries. Developers can analyze and improve query logic based on the mapping path to further improve query performance. Finally, the mapping path generation method based on path reasoning calculus has good adaptability and scalability. With the continuous updating and expansion of the knowledge base, the system can automatically adjust and optimize the conversion process from reasoning logic to mapping path to adapt to new data structures and query requirements, which enables the technology to continuously provide users with efficient and accurate knowledge base query services.

[0197] This application example provides an exemplary code:

[0198]

[0199]

[0200] In this sample code, knowledge_base_schema represents the structure of the knowledge base, including a list of entities and the relations between them, reasoning_logic is a string representing the reasoning path from entity A to entity G, and the convert_to_mapping_path function accepts these two parameters and returns a list of tuples representing the mapping path, where each tuple contains the current entity, the relation, and the next entity.

[0201] Optionally, generating a structured query representation according to the mapping path includes:

[0202] Extracting static features and dynamic features in the mapping path, wherein the static features represent fixed entities and attributes in the query intent, and the dynamic features represent dynamically changing entities and attributes in the query intent;

[0203] Based on the query grammar and according to the static features and dynamic features, a structured query representation is generated.

[0204] In this embodiment, by extracting the static features and dynamic features in the mapping path, the query intent can be clearly expressed. The static features usually represent the unchanged subject or attribute in the query, while the dynamic features reflect the part that may change in the query. This distinction makes the generated query representation more accurate and helps to accurately capture the query needs of users. Secondly, compared with the traditional unstructured query method, the structured query representation is more efficient because the structured query representation can be directly mapped to the table structure and field of the database, reducing the parsing and conversion steps in the query process, thereby improving the execution efficiency of the query. Thirdly, since the structured query representation is generated based on the combination of static features and dynamic features, it can easily adapt to different query scenarios and requirements. By adjusting the combination of static features and dynamic features, a variety of query representations can be generated to meet the diverse query needs of users. At the same time, the structured query representation makes the query logic clearer and modular. This makes it easier to maintain and modify the query. When the database structure or query requirements change, only the corresponding static features or dynamic features need to be adjusted without large-scale reconstruction of the entire query logic. Finally, through structured query representation, query failures or incorrect results caused by incorrect query statements or incorrect formats can be reduced. Structured query representation follows certain grammar and rules, which can ensure the correctness and effectiveness of query statements, thereby reducing the query error rate.

[0205] The present application embodiment provides an exemplary code for generating a structured query representation according to a mapping path:

[0206]

[0207] In this sample code, the generate_structured_query function accepts a mapping path as input and traverses this path to extract static and dynamic features. Static features are added to a collection, while dynamic features are stored as key-value pairs, where the key is the relationship name and the value is a list of target entities or attributes. The function then uses these features to build the various parts of the query and ultimately generates a structured query representation that uses placeholders to represent the parameters of the dynamic features, which will be replaced with specific values ​​when the query is executed. Finally, the function returns the structured query string and parameter list for subsequent query execution.

[0208] Optionally, performing information query in a constructed knowledge base according to the structured query representation includes:

[0209] The structured query representation is matched with the edges and nodes of the knowledge base, and information query is performed in the constructed knowledge base. The edges represent entities in the knowledge base, and the edges represent the relationship between entities in the knowledge base, so that when performing the information query, the entities are first matched, and then based on the matched entities, the edges are matched to obtain the query results.

[0210] In this embodiment, through the structured query representation, the system can more accurately understand the user's query intention, so as to quickly locate the relevant entities and relationships in the knowledge base. Compared with the traditional keyword search, the structured query can greatly reduce the search scope of the query and improve the accuracy and efficiency of the query. In addition, in the knowledge base, entities and their relationships are represented by edges. The structured query representation is matched with the edges and nodes of the knowledge base, which can ensure that the query results not only contain relevant entities, but also accurately reflect the relationship between these entities. This precise matching method helps to reduce false positives and false negatives and improve the accuracy of the query. In addition, the structured query representation can express more complex query requirements, such as queries involving multiple entities and relationships. By decomposing the query into matching entities and relationships, the system can process these complex queries and return query results that meet all conditions. Furthermore, since the structured query representation and the knowledge base are both based on graph structures, they can be easily expanded and adapted to new data and query requirements. New entities and relationships can be easily added to the knowledge base, and the structured query representation can also be easily adjusted to adapt to new query scenarios. Finally, through structured query representation, users can express query requirements in a more natural and intuitive way without having to understand the underlying database structure and query syntax. This reduces the user's learning cost and improves the ease of use of queries.

[0211] This application example provides an exemplary code:

[0212]

[0213] In this sample code, we first connect to the Neo4j database, then define the perform_structured_query function, which accepts the structured query representation as input and builds the corresponding Cypher query. This query uses the MATCH clause to match nodes and relationships with the specified entity type and relationship type, and then returns the matching entities, relationships, and related entities. Finally, we traverse the query results and extract the required information, such as the name of the node and the type of the relationship, and then add this information to the result list and close the database connection.

[0214] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.

Claims

1. A method for querying using a large model in a resource-constrained environment, characterized in that: The steps performed based on the large model include: Obtaining a natural language query text input by a user, and preprocessing the natural language query text to remove participles and stop words therein, and obtaining a feature description text in the natural language query text; Performing syntactic analysis and semantic parsing on the feature expression text to identify a representation description of the query intent in the natural language query text; Convert the query intent representation description into structured knowledge, and generate a knowledge graph based on the structured knowledge; Based on the knowledge graph, generate reasoning logic used in information retrieval; Characterizing the object and intention of the user's query based on the reasoning logic to perform information query in the constructed knowledge base; The knowledge graph is mapped into the set TransE vector space to obtain the association vector between entity and semantics; Performing cluster analysis on the association vectors between the entity and the semantics to obtain several intention item sets; Calculate the similarity between any intention item set and each other intention item set, and merge the several intention item sets based on the similarity to obtain an intention logic cluster; According to the intention logic cluster, generate reasoning logic used in information retrieval; Matching is performed to classify multiple intention item sets whose residuals are within the corresponding residual range as intention logical clusters; Wherein, the mean of all the similarities is calculated to obtain the median similarity; Based on the median similarity, the residual between the similarity between each intent item set and each other intent item set and the median similarity is determined.

2. A method for querying using a large model in a resource-constrained environment according to claim 1, characterized in that: The step of obtaining a natural language query text input by a user and preprocessing the natural language query text to remove segmentation words and stop words therein to obtain a feature description text in the natural language query text includes: The large model calls the jieba library embedded therein to segment the natural language query text, and calls the customized word list in the HanLP library embedded therein to preprocess the natural language query text, remove the segmentation words and stop words therein, and obtain the feature description text in the natural language query text.

3. A method for querying using a large model in a resource-constrained environment according to claim 2, characterized in that: The large model calls the jieba library embedded therein to segment the natural language query text, and calls the custom word list in the HanLP library embedded therein to pre-process the natural language query text, remove the segmentation words and stop words therein, and obtain the feature description text in the natural language query text, including: The large model calls the jieba library embedded therein, uses Python's multi-threading to perform parallel segmentation on the natural language query text, assigns multiple segments to multi-process modules for parallel word segmentation, and calls the custom word list embedded in the HanLP library therein to update and iteratively match the results of the jieba word segmentation, so as to pre-process the natural language query text, remove the word segmentations and stop words therein, and obtain the feature description text in the natural language query text.

4. A method for querying using a large model in a resource-constrained environment according to claim 1, characterized in that: The performing syntactic analysis and semantic parsing on the feature expression text to identify the query intent representation description in the natural language query text includes: The large model calls the syntactic analyzer embedded therein to identify part-of-speech tags, dependency relations and syntactic structures, so as to perform syntactic analysis and semantic parsing on the feature description text, so as to determine the components in each sentence of the feature description text, and the semantic relations between the components; According to the components and the semantic relationships between the components, a query intent representation description in the natural language query text is identified.

5. A method for querying using a large model in a resource-constrained environment according to claim 4, characterized in that: The step of identifying the query intent representation description in the natural language query text according to the components and the semantic relationships between the components includes: Generate a syntax tree according to the components and the semantic relations between the components; According to the syntax tree, a query intent representation description in the natural language query text is identified.

6. A method for querying using a large model in a resource-constrained environment according to claim 5, characterized in that: The generating a syntax tree according to the components and the semantic relationships between the components includes: generating semantic role annotations according to the components and semantic relationships between the components; The syntax tree is generated according to the semantic role labeling.

7. A method for querying using a large model in a resource-constrained environment according to claim 6, characterized in that: Generating semantic role labels according to the components and the semantic relationships between the components includes: generating semantic argument data according to the components and semantic relations between the components; framing the semantic argument data to generate a semantic framework; The semantic framework is matched with a predefined semantic role list to generate semantic role annotations.

8. A method for querying using a large model in a resource-constrained environment according to claim 6, characterized in that: The generating the syntax tree according to the semantic role labeling includes: According to the type of the semantic role annotation, construct a plurality of grammatical units and assign corresponding semantic labels; Semantically merge the grammatical units based on the semantic tags to obtain syntactic tree node attributes; The syntax tree is generated according to the syntax tree node attributes based on the semantic features and the syntax features of the syntax tree node attributes.

9. A method for querying using a large model in a resource-constrained environment according to claim 1, characterized in that: The step of converting the query intent representation description into structured knowledge and generating a knowledge graph based on the structured knowledge includes: Perform entity extraction, relationship extraction, and event extraction on the query intent representation description; Generate a resource description framework based on the extracted entities, relationships, and events, and use it as structured knowledge; The resource description framework is ontology constructed and semi-automatically semantically annotated to generate a knowledge graph.

Citation Information

Patent Citations

  • Natural language recognition and Chinese word segmentation query method for efficient data assets based on large model

    CN117874206A