Self-adaptive context learning method based on syntactic similarity

By constructing an adaptive contextual learning method for syntactic similarity and using the syntactic dependency tree and edit distance algorithm to match the most syntactically similar examples, we solved the problem of insufficient accuracy of large language models in generating search expressions in semantic search scenarios, and achieved efficient and low-cost model optimization and response.

CN120745818APending Publication Date: 2025-10-03WANDE INFORMATION SOFTWARE (SHANGHAI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510852664.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-24
Publication Date
2025-10-03

AI Technical Summary

Technical Problem

In semantic search scenarios, existing large language models are insufficiently accurate in generating search expressions, and traditional methods cannot effectively utilize syntactically similar examples to enhance the model's contextual learning capabilities.

Method used

By constructing an adaptive context learning method for syntactic similarity, using the syntactic dependency tree and edit distance algorithm to match the most syntactically similar examples, the model input context is dynamically adjusted to generate accurate search expressions.

Benefits of technology

It improves the accuracy of large language models in generating search expressions, reduces the resource consumption and implementation difficulty of complex model optimization tasks, and enhances the adaptability and response speed of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120745818A_ABST
    Figure CN120745818A_ABST
Patent Text Reader

Abstract

The invention relates to a syntactic similarity-based adaptive context learning method. The method comprises the following steps of: constructing an example library; collecting query statements of a user; performing dependency relationship analysis on the queries, constructing syntactic dependency trees one by one, and performing search expression labeling on the queries; performing dependency relationship analysis on the query statement, then constructing a syntactic dependency tree, and performing editing distance calculation on the syntactic dependency tree corresponding to the query statement input by the user and all the constructed syntactic dependency trees in the sample library through an editing distance algorithm; the editing distance is converted into syntactic similarity, and then QA pairs with similar syntactic are taken; taking the QA pair as a feed-shot sample, filling the feed-shot sample into prompt, and then inputting the feed-shot sample into a large model; and finally, after large model analysis, outputting a search expression corresponding to a user query statement. The problem that the accuracy of the large language model in generating the search expression is difficult to improve in a semantic search scene is solved, and special training or fine tuning for a specific task is not needed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a large language model technology, and in particular to an adaptive context learning method based on syntactic similarity matching. Background Art

[0002] In-Context Learning (ICL) of large language models is a method to improve model performance by providing relevant context (such as prompts or samples) to the model without explicitly fine-tuning the model weights. It is currently a hot research direction in the field of large language models (LLMs).

[0003] The rise of in-context learning is closely related to the development of large language models (LLMs). As the model size increases, LLMs show the ability to learn from a small number of examples in context, which is called in-context learning.

[0004] 1. The shift in the natural language processing (NLP) paradigm

[0005] Traditional NLP tasks typically rely on supervised learning, requiring large amounts of labeled data. Learning new tasks is then accomplished through model training, backpropagation, gradient updates, and ultimately updating model parameters. ICL offers a new paradigm that eliminates the need for model parameter updates and instead enables task learning by providing examples in context, similar to how humans understand and solve problems through analogies. This approach offers low learning costs and improved generalization.

[0006] 2. The Importance of Contextual Examples

[0007] ICL requires carefully crafted representative prompt examples, but its performance is highly sensitive to specific settings, such as the prompt template and the selection and order of context examples. Furthermore, these examples are fixed and cannot be adaptively adjusted based on the input content. This means that it performs significantly better for inputs similar to the context prompt, but struggles with inputs that differ significantly.

[0008] 3. Impact of text length on ICL effect

[0009] To improve ICL's performance across various tasks, we need to add more examples. However, when the number of examples increases to a certain level, the length of text the model must process also increases significantly, which can cause the model to forget information and even affect output quality. Therefore, the number of ICL examples cannot be increased indefinitely; a balance must be struck between quantity and effectiveness.

[0010] 4. Advantages and disadvantages of ICL for automatic matching of semantically similar examples

[0011] To improve ICL's performance across various tasks without increasing the number of examples, vector matching technology can be used to automatically select contextual examples that are most similar to the input requirements and incorporate these highly matched examples into the model input, thereby optimizing the model's performance while keeping the input concise. However, relying solely on semantic similarity to automatically match examples also has certain limitations. Below, we will delve into the highlights and challenges of AICL (Adaptive Contextual Learning).

[0012] The advantage of AICL lies in its ability to automatically select k examples that best match the semantics of the input content as contextual input. This mechanism not only allows for flexible adjustment of the number and content of examples, but also significantly enhances the expressiveness of large language models within specific domains. This dynamic selection approach allows the model to better adapt to various task requirements, demonstrating exceptional flexibility and adaptability.

[0013] However, AICL also faces challenges. In particular, when generating search expressions, the method often performs poorly. This is because the construction of search expressions relies more on the structural logic of the input text than on the content itself. Therefore, simply matching examples based on semantic similarity may not accurately capture the logical essence of the input content, thus affecting the final processing results.

[0014] 5. The effect of AICL in semantic search scenarios

[0015] Take semantic search as an example. This task requires a large language model to intelligently translate user natural language questions into precise search expressions. This translation process not only requires the model to have strong language understanding capabilities but also to be able to adaptively learn context to generate high-quality search expressions. To achieve this, the model needs to be able to match syntactically similar examples. From these examples, it can learn how to generate the most appropriate search expressions in different contexts, thereby improving the model's contextual learning capabilities.

[0016] However, despite the increasing prevalence of semantic search in everyday applications such as intelligent assistants and search engines, research in this area remains relatively limited. In particular, research on how to improve a model's contextual learning capabilities by matching syntactically similar examples is even rarer. This is primarily because achieving this goal requires not only a large amount of high-quality example data but also advanced algorithms to accurately identify and match these examples.

[0017] For example, suppose a user enters a question about "How to make pasta at home?" The model needs to be able to understand the intent of this question and convert it into an expression that can search for relevant recipes. If the model has previously learned similar questions, such as "How to make pizza," it can learn how to better handle this type of "how to make" question by comparing the syntactic structure of the two questions, thereby improving search accuracy and efficiency.

[0018] To advance research in this area, some research institutions and companies have begun constructing specialized datasets containing large numbers of annotated questions and corresponding search expressions, aiming to provide more learning material for models. Furthermore, researchers are exploring new algorithms to improve the performance of models in handling complex semantic tasks. These efforts are expected to not only improve the quality of semantic search but also open up new possibilities for the application of large language models in a wider range of fields.

[0019] In semantic search scenarios, using ICL to improve the task of generating search expressions using large language models faces two main difficulties and challenges:

[0020] 1. If fixed context examples are used, as the diversity of tasks increases, the context required becomes longer and longer. This not only slows down the processing of large models but also causes the model to forget information, reducing its ability to handle tasks and causing the accuracy of generated expressions to deteriorate.

[0021] 2. If we use semantic similarity to automatically match related examples and then adaptively add them to the model input context, the problem here is that the examples matched by semantic similarity cannot effectively guide the generation of search expressions. This is because in this task, the generated expressions are more related to the results of the grammar and less related to the surface semantic relationship. Moreover, this matching is only related to the input question, rather than being compared with the entire example. Summary of the Invention

[0022] To address the problem of difficulty in improving the accuracy of large language models in generating search expressions in semantic search scenarios, an adaptive context learning method based on syntactic similarity is proposed.

[0023] In order to enable the LLM to accurately generate precise search expressions based on user questions, the core idea of ​​this solution is to match the examples most similar to the user questions through syntactic similarity (assuming there is already a library of high-quality, manually annotated examples). Then, the most syntactically similar examples are placed in the context of the entire input and given to the large model. The large model can imitate the paradigm of the examples and generate precise expressions.

[0024] Moreover, this method can solve bad cases (situations that do not meet expectations) encountered on the product line without fine-tuning the model. Every time a new bad case is encountered, you only need to add a similar example to the example library, and then you can solve this type of case during reasoning.

[0025] The technical solution of the present invention is:

[0026] An adaptive context learning method based on syntactic similarity includes the following steps:

[0027] Step 1: Build a sample library: Collect user query statements, clean them, and remove duplicates. Then, obtain the user query statements with large sentence structure differences and low similarity after deduplication.

[0028] Step 2: Dependency analysis is performed on these queries, and syntactic dependency trees are constructed one by one. At the same time, these queries are annotated with search expressions. Finally, the constructed syntactic dependency tree, user query statements, and annotated search expressions are used as the basic units in the sample library.

[0029] Step 3: When the user enters a new query, the query is first parsed for dependency relationships, and then a syntactic dependency tree is constructed. The edit distance algorithm is then used to calculate the edit distance between the syntactic dependency tree corresponding to the user's query and all the constructed syntactic dependency trees in the sample library.

[0030] Step 4: Convert the edit distance into syntactic similarity, and then select the top n syntactically similar QA pairs with the highest syntactic similarity;

[0031] Step 5: Use the top n syntactically similar QA pairs obtained as few-shot examples, fill them into the prompt, and then input them into the main model;

[0032] Step 6: The final large model analyzes and refers to examples of similar sentences in few-shot to output the search expression corresponding to the user query statement.

[0033] Furthermore, the specific steps of step 1 are as follows:

[0034] Step 1.1) Collect original questions: Collect original data from real online users' questions;

[0035] Step 1.2) Dependency parsing of the original questions: Use the dependency parser of the Spacy library to parse the collected questions. This process requires dependency parsing of all user questions in the sample library collected in the previous step for subsequent construction of a syntactic dependency tree. This step is the input for the subsequent construction of the syntactic dependency tree.

[0036] Step 1.3) Constructing a syntactic dependency tree: Using the dependency relationships parsed in the previous step, construct a tree in the form of zss.Node. The basic construction process starts from the root node and continuously builds new nodes based on the syntactic dependency relationships, ultimately forming a syntactic dependency tree structure. The parsed dependency relationships of each user question in the sample library will be constructed into a syntactic dependency tree. This step is the basis for the subsequent calculation of the edit distance.

[0037] Step 1.4) Calculate the edit distance of the syntactic dependency tree: Use the edit distance algorithm to calculate the edit distance between each pair of the syntactic dependency trees obtained in the previous step, and calculate the edit distance of the syntactic dependency trees between all collected user questions;

[0038] Step 1.5) Deduplication: Based on the syntactic similarity results, i.e., the edit distance between syntactic dependency trees, duplicate user query statements with similarity greater than a certain threshold are deduplicated;

[0039] Step 1.6) Build a query library: Use the deduplicated user questions as queries in the sample library;

[0040] Step 1.7) Task-labeled query: Use manual or model-labeling methods to label the deduplicated query and generate the corresponding search expression.

[0041] Step 1.8) Build an index table: Build an index table for query and search expression pairs to complete the construction of the sample library. This step is to build an index table from query to search expression for subsequent search expression searches.

[0042] Step 1.9) Final example library construction: Each minimum unit in the complete example library contains three parts: the collected user query statement query, the corresponding syntactic dependency tree, and the annotated search expression search expression. The entire example library can be regarded as consisting of several triplets such as (query, syntactic dependency tree, search expression).

[0043] Furthermore, the specific steps of step 2 are as follows:

[0044] Step 2.1) After building the sample library, we need to perform dependency analysis and construct a syntactic dependency tree for the actual user input query. The basic process is: input sentence -> word segmentation -> feature extraction -> neural network prediction -> transfer action -> syntactic dependency tree construction. This step mainly uses the parser module in the spacy library and the syntactic dependency analyzer to analyze the grammatical structure of the sentence, identify the dependency relationship between words, and then construct a syntactic dependency tree based on the dependency relationship for subsequent edit distance calculation.

[0045] Step 2.2) Use the Transformer model architecture to perform the syntactic dependency analysis task; the goal of dependency analysis is to predict the dominant word head of each word and the type of dependency between them from the input sentence; the process of using the transformer model to build dependencies includes text input, word embedding vector representation, feature extraction, dominant word prediction, and dependency label prediction. The specific process is as follows: after the original sentence is input, it enters the embedding layer, that is, the word embedding vector layer, to be converted into a vector representation of a fixed dimension; then, the multi-head attention mechanism MHA and the feedforward neural network FFN are used to further extract features; finally, a linear layer is used to map the output of the transformers containing the three modules of embedding, MHA, and FFN to the dominant word index of each word, and another linear layer maps the output of the transformer to the dependency label. Finally, according to the dominant word index and dependency label, the corresponding dominant word and dependency are obtained. At this point, the entire dependency analysis is completed;

[0046] The dependency parsing process is as follows: each word token is iteratively obtained, its dominant word, dependency type, and child nodes are extracted, and then the final syntactic dependency tree is constructed and dependency traversal is performed. The syntactic dependency tree constructed by spcay will be saved in the feature library; this feature information will become the input for subsequent syntactic similarity calculations and will be used for syntactic similarity matching with the real questions entered by the user, thereby improving the accuracy of question understanding and response.

[0047] Furthermore, the specific steps of step 3 are as follows:

[0048] Step 3.1) Using the edit distance algorithm, calculate the edit distance between the syntactic dependency tree of the user query statement and the syntactic dependency trees corresponding to all sentences in the sample library in parallel one by one;

[0049] Step 3.2) Calculate the syntactic similarity. Using the edit distance K obtained in the previous step, the syntactic similarity is simi = 1 / (K+1). This syntactic similarity is a number between (0, 1].

[0050] Furthermore, the specific steps of step 4 are as follows:

[0051] In step 3, the edit distance matching technology of the syntactic dependency tree is used to match the query with the highest syntactic similarity to the user input question. The matched query can then be indexed in the example library to find the answer search expression corresponding to the query. The query and search expression pairs in the example library are then used as dynamic examples for context learning in the large model, which are also the example pairs with the most similar syntax.

[0052] Furthermore, the specific steps of step 5 are as follows:

[0053] Based on the most syntactically similar example pair obtained in step 4, this example pair is used as the context example in the few-shot, inserted into the prompt of the entire task, and used as a dynamic example.

[0054] Furthermore, the specific steps of step 6 are as follows: Based on the complete prompt input, the model will better learn the requirements of the task and output the search expression more accurately based on the adaptively matched context examples.

[0055] The beneficial effects of the present invention are:

[0056] This solution utilizes advanced adaptive contextual learning technology for large language models. The core advantage of this technology is that it requires no specialized training or fine-tuning for specific tasks, such as processing search expressions. This means we can quickly adapt and optimize for various application scenarios with lower technical barriers and resource consumption, significantly reducing task complexity and cost.

[0057] 1) No targeted fine-tuning training is required

[0058] This solution cleverly leverages adaptive contextual learning techniques from large language models, eliminating the need for additional training or fine-tuning for specific tasks, such as search expressions. This significantly simplifies the task process and reduces resource consumption. This innovative approach not only reduces implementation complexity but also ensures efficiency and convenience, making complex tasks a breeze.

[0059] 2) Greatly improved the accuracy of search expressions generated by large models

[0060] This solution significantly improves the model's accuracy in handling similar tasks by automatically matching examples with similar syntax. This allows large models to efficiently complete complex tasks with simple imitation, making the application of technology even more user-friendly.

[0061] 3) Simplified the process of subsequent badcase optimization

[0062] The key advantage of this solution is that, leveraging the power of the example library, we can cost-effectively optimize bad cases encountered after launch. Whenever we encounter a bad case, we analyze its syntactic characteristics and add similar cases to the example library. This allows the model to learn the characteristics of the bad case in similar contexts, enabling rapid and effective optimization. This strategy not only improves the model's adaptability but also ensures the efficiency of continuous improvement. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] Figure 1 Schematic diagram of the process of constructing an example library in the adaptive context learning method of the present invention;

[0064] Figure 2 Flowchart of the adaptive context learning method of the present invention. DETAILED DESCRIPTION

[0065] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments. This embodiment is implemented based on the technical solution of the present invention, and provides a detailed implementation method and specific operation process, but the protection scope of the present invention is not limited to the following embodiments.

[0066] An adaptive context learning method based on syntactic similarity,

[0067] like Figure 2 As shown, Figure 2 This shows the basic process of how to adaptively learn context using a large model based on syntactic similarity:

[0068] First build the example library: Figure 1 As shown, Figure 1 The figure shows the entire sample library construction process. The basic process is to collect user query statements, clean them, and remove duplicates. The deduplication method here is not limited to similarity deduplication. Then, deduplicated queries with large sentence structure differences and low similarity are obtained. The second step is to perform dependency analysis on these queries and build syntactic dependency trees one by one. At the same time, these queries are annotated with search expressions. Finally, the constructed syntactic dependency tree, user query statements, and annotated search expressions are used as the basic units in the sample library.

[0069] When a user enters a new query statement, the query statement is first parsed for dependencies, and then a syntactic dependency tree is constructed. Then, using the edit distance algorithm, the edit distance between the syntactic dependency tree corresponding to the user-entered query statement and all the constructed syntactic dependency trees in the sample library is calculated and converted into syntactic similarity. Then, the top n syntactically similar qa pairs (also known as QA pairs) are selected.

[0070] The top n syntactically similar QA pairs are used as few-shot examples, entered into the prompt, and then fed into the large model. The large model finally analyzes and references examples of similar sentences in the few-shot and outputs the search expression corresponding to the user's query.

[0071] The detailed process is as follows:

[0072] Step 1: Build a high-quality sample library (QA pairs)

[0073] The example library is a large index table, where the key is the search input text query (the query text entered by the user), and the value is the search expression corresponding to the input text. The expression should be a structured language representation. The main function of the example library is to provide as many examples as possible for matching, so that each input search question can find an example with very similar syntax. There are three goals in the process of building the example library:

[0074] First, the query syntax in the sample library should be as diverse as possible, with every sentence type included.

[0075] Second: The syntactic similarity between examples in the example library should be minimized. Do not put all the same examples in the library.

[0076] Third: The values ​​in the example library are generated and voted using multiple models, and manually verified to ensure the high quality of the generated example answers.

[0077] The process of building the sample library is divided into the following steps:

[0078] Step 1.1) Collect original questions: Collect original data from real online users. These questions form the basis for building a sample library, ensuring the authenticity and diversity of the data.

[0079] Step 1.2) Dependency parsing of the original questions: Use the dependency parser in Spacy (a Python natural language processing package) to parse the collected questions. This process requires dependency parsing of all user questions in the sample library collected in the previous step to construct a syntactic dependency tree. This step serves as input for the subsequent syntactic dependency tree construction.

[0080] Step 1.3) Constructing a syntactic dependency tree: Using the dependencies parsed in the previous step, construct a tree in the form of zss.Node (zss is a Python package primarily used for calculating tree edit distances and other tree-structure related operations). The basic construction process starts from the root node and continuously builds new nodes based on the syntactic dependencies, ultimately forming a syntactic dependency tree. The parsed dependencies of each user question in the sample library are constructed into a syntactic dependency tree. This step forms the basis for the subsequent edit distance calculation.

[0081] Step 1.4) Calculate the edit distance of the syntactic dependency tree: Use the edit distance algorithm to calculate the edit distance between each pair of the syntactic dependency trees obtained in the previous step, and calculate the edit distance of the syntactic dependency trees between all collected user questions (assuming the number of user questions is N, then the number of edit distances between each pair that should be calculated is (N x N) / 2). This step helps identify syntactically similar questions.

[0082] Step 1.5) Deduplication: Based on the syntactic similarity results (i.e., the edit distance between syntactic dependency trees), duplicate user queries with a similarity greater than a certain threshold (determined based on actual conditions) are removed. This step ensures the efficiency and diversity of the sample library.

[0083] Step 1.6) Build a query library: Use the deduplicated user questions as queries in the sample library.

[0084] Step 1.7) Label the query and the corresponding search expression: Use manual or model annotation to label the deduplicated query and generate the corresponding search expression. This step ensures the accuracy and practicality of the sample library.

[0085] Step 1.8) Build an index table: Build an index table for query and search expression pairs to complete the construction of the sample library. This step is to build an index table from query to search expression for subsequent search expression searches.

[0086] Step 1.9) Final example library construction: Each minimum unit in the complete example library contains three parts: the collected user query statement query, the corresponding syntactic dependency tree, and the annotated search expression search expression. The entire example library can be regarded as consisting of several triplets such as (query, syntactic dependency tree, search expression).

[0087] Step 2: Construction of dependency and syntactic dependency tree of user input query

[0088] After building the sample library in step 2.1, we next need to perform dependency analysis and construct a syntactic dependency tree for actual user input queries. The basic process is sentence input -> word segmentation -> feature extraction -> neural network prediction -> transfer action -> syntactic dependency tree construction. This step primarily uses the parser module in the spacy library, using the syntactic dependency analyzer to analyze the grammatical structure of the sentence, identify the dependencies between words, and then construct a syntactic dependency tree based on these dependencies for subsequent edit distance calculations.

[0089] Step 2.2: To ensure accurate and comprehensive analysis, we will use the Transformer (a deep learning model) architecture to perform syntactic dependency analysis. The goal of dependency analysis is to predict the dominant word (head) of each word in the input sentence and the type of dependency relationship between them (e.g., subject-verb, verb-object). The process of constructing dependencies using the Transformer model involves text input, word embedding vector representation, feature extraction, dominant word prediction, and dependency label prediction. The specific process is as follows: after the original sentence is input, it enters the embedding layer (word embedding vector layer) to be converted into a fixed-dimensional vector representation; then it passes through the multi-head attention mechanism (MHA, this model layer can capture the global dependency between words) and the feed-forward neural network (FFN) to further extract features; finally, a linear layer is used to map the output of transformers (including the previous three modules of embedding, MHA, and FFN) to the dominant word index of each word, and another linear layer maps the output of the transformer to the dependency label. Finally, the corresponding dominant word and dependency are obtained according to the dominant word index and dependency label. At this point, the entire dependency analysis is completed.

[0090] The dependency parsing process is as follows: it iterates through each token, extracts its governing words, dependency types, and children, and then constructs the final syntactic dependency tree. This traversal and extraction process is often referred to as dependency parsing traversal. The following is a code example of a dependency traversal:

[0091]

[0092] doc is the syntactic dependency tree constructed by spcay and stored in the feature library. This feature information becomes the input for subsequent syntactic similarity calculations, used to match syntactic similarity with real user-entered questions, thereby improving the accuracy of question understanding and response.

[0093] For example, when a user asks a question about financial market trends, the system leverages the syntactic information in the feature library to quickly find examples with similar structures to the user's question, providing a more accurate and relevant answer. This process not only improves the system's response speed but also enhances the user experience, providing users with a more intelligent and personalized service.

[0094] Step 3: Edit distance matching based on syntactic dependency tree

[0095] Edit distance matching technology based on syntactic dependency trees is a method used in natural language processing to measure the similarity between two sentences. By constructing a syntactic dependency tree, we can more accurately capture the structural information of the sentences. When comparing two sentences, we consider not only the similarity at the lexical level but also the similarity of the grammatical structure.

[0096] Syntactic dependency tree: Each sentence can be parsed into a tree structure, where each node represents a word and the edges represent the dependency relationships between words. This structure can clearly show the grammatical structure of the sentence.

[0097] Edit distance: Traditionally, edit distance refers to the minimum number of operations (inserting, deleting, or replacing a character) required to transform one string into another. In edit distance matching based on syntactic dependency trees, this concept is extended to tree structures, that is, calculating the minimum number of operations required to transform one tree into another.

[0098] In this solution, the syntactic similarity between the user query and the sentences in the sample library is calculated. The specific implementation is:

[0099] Step 3.1). Use the edit distance algorithm to calculate the edit distance between the syntactic dependency tree of the user query statement and the syntactic dependency trees corresponding to all sentences in the sample library in parallel. This edit distance should be an integer greater than zero.

[0100] Step 3.2). Calculate the syntactic similarity. Using the edit distance K obtained in the previous step, the syntactic similarity is simi = 1 / (K+1). This syntactic similarity is a number between (0, 1].

[0101] Step 4: Get the most syntactically similar examples

[0102] In the previous step, the edit distance matching technology of the syntactic dependency tree is used to match the query with the highest syntactic similarity to the user input question. The matched query is then indexed in the example library to find the corresponding search expression. The query and search expression pairs in the example library are then used as dynamic examples for context learning in the large model, which are also the example pairs with the highest syntactic similarity.

[0103] Step 5: Insert into prompt as context example

[0104] Based on the most syntactically similar example pair obtained in step 4, this example pair is used as a context example in few-shot learning, inserted into the prompt of the entire task, and used as a dynamic example.

[0105] Few-shot techniques allow models to learn on new tasks with very few examples. For example, in text generation tasks, this means that after seeing just a few examples of search expressions, the model can identify search expressions in new user queries. This capability is extremely valuable in scenarios where data annotation is expensive or scarce.

[0106] Step 6: The model outputs the accurate search expression

[0107] Based on the complete prompt input, the model will better learn the requirements of the task and output the search expression more accurately based on the adaptively matched context examples.

[0108] The above-described embodiment merely represents one embodiment of the present invention. While the description is relatively specific and detailed, it should not be construed as limiting the scope of the patent. It should be noted that a person skilled in the art would be able to make various modifications and improvements without departing from the spirit of the present invention, and these modifications and improvements fall within the scope of protection of the present invention. Therefore, the scope of protection of the patent for this invention shall be determined by the appended claims.

Claims

1. An adaptive context learning method based on syntactic similarity, characterized in that The following steps are involved: Step 1: Build a sample library: Collect user query statements, clean them, and remove duplicates. Then, obtain the user query statements with large sentence structure differences and low similarity after deduplication. Step 2: parse the dependencies of these queries and build syntactic dependency trees one by one. At the same time, mark these queries with search expressions. Finally, the constructed syntactic dependency tree, user query statements and annotated search expressions are used as the basic units in the sample library; Step 3: When the user enters a new query, the query is first parsed for dependency relationships, and then a syntactic dependency tree is constructed. The edit distance algorithm is then used to calculate the edit distance between the syntactic dependency tree corresponding to the user's query and all the constructed syntactic dependency trees in the sample library. Step 4: Convert the edit distance into syntactic similarity, and then select the top n syntactically similar QA pairs with the highest syntactic similarity; Step 5: Use the top n syntactically similar QA pairs obtained as few-shot examples, fill them into the prompt, and then input them into the main model; Step 6: The final large model analyzes and refers to examples of similar sentences in few-shot to output the search expression corresponding to the user query statement.

2. The adaptive context learning method based on syntactic similarity according to claim 1, characterized in that The specific steps of step 1 are as follows: Step 1.1) Collect original questions: Collect original data from real online users' questions; Step 1.2) Dependency parsing of the original questions: Use the dependency parser of the Spacy library to parse the collected questions. This process requires dependency parsing of all user questions in the sample library collected in the previous step for subsequent construction of a syntactic dependency tree. This step is the input for the subsequent construction of the syntactic dependency tree; Step 1.3) Constructing a syntactic dependency tree: Using the dependency relationships parsed in the previous step, construct a tree in the form of zss.Node. The basic construction process starts from the root node and continuously builds new nodes based on the syntactic dependency relationships, ultimately forming a syntactic dependency tree structure. The parsed dependency relationships of each user question in the sample library will be constructed into a syntactic dependency tree. This step is the basis for the subsequent calculation of the edit distance. Step 1.4) Calculate the edit distance of the syntactic dependency tree: Use the edit distance algorithm to calculate the edit distance between each pair of the syntactic dependency trees obtained in the previous step, and calculate the edit distance of the syntactic dependency trees between all collected user questions; Step 1.5) Deduplication: Based on the syntactic similarity results, i.e., the edit distance between syntactic dependency trees, duplicate user query statements with similarity greater than a certain threshold are deduplicated; Step 1.6) Build a query library: Use the deduplicated user questions as queries in the sample library; Step 1.7) Task-labeled query: Use manual or model-labeling methods to label the deduplicated query and generate the corresponding search expression. Step 1.8) Build an index table: Build an index table for query and search expression pairs to complete the construction of the sample library. This step is to build an index table from query to search expression for subsequent search expression searches. Step 1.9) Final example library construction: Each minimum unit in the complete example library contains three parts: the collected user query statement query, the corresponding syntactic dependency tree, and the annotated search expression search expression. The entire example library can be regarded as consisting of several triplets such as (query, syntactic dependency tree, search expression).

3. The adaptive context learning method based on syntactic similarity according to claim 1, characterized in that The specific steps of step 2 are as follows: Step 2.1) After building the sample library, we need to perform dependency analysis and construct a syntactic dependency tree for the actual user input query. The basic process is: input sentence -> word segmentation -> feature extraction -> neural network prediction -> transfer action -> build a syntactic dependency tree; This step mainly uses the parser module in the spacy library and the syntactic dependency analyzer to analyze the grammatical structure of the sentence, identify the dependency relationship between words, and then build a syntactic dependency tree based on the dependency relationship for subsequent edit distance calculation; Step 2.2) Use the Transformer model architecture to perform syntactic dependency analysis tasks; The goal of dependency analysis is to predict the dominant word head of each word and the type of dependency relationship between them from the input sentence; The process of building dependency relationships using the transformer model includes text input, word embedding vector representation, feature extraction, dominant word prediction, and dependency label prediction. The specific process is as follows: After the original sentence is input, it enters the embedding layer, which is the word embedding vector layer, to convert it into a fixed-dimensional vector representation. Then, it passes through the multi-head attention mechanism (MHA) and the feedforward neural network (FFN) to further extract features. Finally, a linear layer is used to map the output of the transformer, which includes the embedding, MHA, and FFN modules, to the dominant word index of each word. Another linear layer maps the transformer output to the dependency label. Finally, based on the dominant word index and dependency label, the corresponding dominant word and dependency relationship are obtained, and the entire dependency analysis is completed. The dependency parsing process is as follows: each word token is obtained through iteration, its dominant words, dependency type, and child nodes are extracted, and then the final syntactic dependency tree is constructed and dependency traversal is performed. The syntactic dependency tree constructed by spcay will be saved in the feature library; These feature information will become the input for subsequent syntactic similarity calculation and be used to perform syntactic similarity matching with the real questions input by the user, thereby improving the accuracy of question understanding and response.

4. The adaptive context learning method based on syntactic similarity according to claim 1, characterized in that The specific steps of step 3 are as follows: Step 3.1) Using the edit distance algorithm, calculate the edit distance between the syntactic dependency tree of the user query statement and the syntactic dependency trees corresponding to all sentences in the sample library in parallel one by one; Step 3.2) Calculate the syntactic similarity. Using the edit distance K obtained in the previous step, the syntactic similarity is simi = 1 / (K+1). This syntactic similarity is a number between (0, 1].

5. The adaptive context learning method based on syntactic similarity according to claim 1, characterized in that: The specific steps of step 4 are as follows: In step 3, the edit distance matching technology of the syntactic dependency tree is used to match the query with the highest syntactic similarity to the user input question. The matched query can then be indexed in the example library to find the answer search expression corresponding to the query. The query and search expression pairs in the example library are then used as dynamic examples for context learning in the large model, which are also the example pairs with the most similar syntax.

6. The adaptive context learning method based on syntactic similarity according to claim 1, characterized in that The specific steps of step 5 are as follows: Based on the most syntactically similar example pair obtained in step 4, this example pair is used as the context example in the few-shot, inserted into the prompt of the entire task, and used as a dynamic example.

7. The adaptive context learning method based on syntactic similarity according to claim 1, characterized in that: The specific steps of step 6 are as follows: Based on the complete prompt input, the model will better learn the requirements of the task and output the search expression more accurately based on the context examples matched adaptively.