Prompt word optimization method combining expert evaluation rules and large language model
By combining expert evaluation rules and large language model methods, keyword correlation evaluation and semantic analysis are performed on the original prompt words to generate new prompt words, solving the problem of time-consuming and biased generation of prompt words by manually generating prompt words, and achieving efficient, accurate and timely response prompt word generation.
Patent Information
- Application Number
- CN202410905269.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-07-08
AI Technical Summary
In the prior art, manual generation of prompt words is time-consuming and labor-intensive, with objectivity, consistency and accuracy deviations, and it is difficult to respond to domain knowledge updates in a timely manner.
Combining expert evaluation rules and the prompt word optimization method of large language models, by obtaining expert evaluation rules description vectors, keyword correlation evaluation and semantic analysis of the original prompt words are performed to generate new prompt words.
It improves the efficiency and accuracy of prompt word generation, reduces subjectivity, and can respond to field changes and technical upgrades in a timely manner, so the generated prompt words are more semantically richer and more accurate.
Smart Images

Figure CN118886427B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a prompt word optimization method combining expert evaluation rules and a large language model. Background Art
[0002] With the rapid development of artificial intelligence technology, large language models (LLMs) have demonstrated powerful capabilities in the field of natural language processing, especially in text generation, semantic understanding, and question-answering systems. In the current field of natural language processing and artificial intelligence applications, the generation of prompt words (such as search queries, chatbot instructions, document titles, etc.) mainly relies on manual writing or simple rule generation. Although this method can meet basic needs to a certain extent, with the complexity of application scenarios and the diversification of needs, its limitations have become increasingly prominent, leading to a series of problems:
[0003] (1) Manually generating prompt words requires a lot of time and effort, which is particularly inefficient in scenarios where large amounts of data need to be processed or new prompt words need to be generated frequently.
[0004] (2) Since the prompt words are written by humans, they are inevitably affected by the writer’s personal experience, knowledge level, and subjective judgment, resulting in deviations in the objectivity, consistency, and accuracy of the generated prompt words.
[0005] (3) With the continuous updating of domain knowledge and the development of technology, the original prompt words may quickly become outdated or no longer applicable. Manually updating these prompt words requires continuous investment and is difficult to respond in a timely manner.
[0006] (4) Simple rule generation or template-based prompt word generation methods often fail to capture complex semantic relationships and contextual information, resulting in the generated prompt words being semantically monotonous and superficial, making it difficult to meet the needs of professional fields or complex tasks.
[0007] (5) In the absence of an effective evaluation mechanism, artificially generated prompt words may not accurately reflect the user's true intentions or the specific requirements of the task, resulting in a deviation between the generated content and the user's expectations or actual needs. Summary of the invention
[0008] The purpose of this application is to propose a prompt word optimization method combining expert evaluation rules and a large language model to solve or alleviate the technical problems existing in the prior art.
[0009] The technical solutions provided by the embodiments of this application are as follows:
[0010] A prompt word optimization method combining expert evaluation rules and a large language model, comprising:
[0011] Obtain expert evaluation rule description vector;
[0012] Based on the expert evaluation rule description vector, a keyword relevance evaluation is performed on the input original prompt word to obtain a corresponding relevance evaluation value;
[0013] The original prompt word is used as a key in a key-value pair, and the relevance evaluation value is used as a value in the key-value pair, and is input into a large language model to perform semantic analysis on the original prompt word to obtain a semantic analysis vector;
[0014] Based on the semantic analysis vector and the relevance evaluation value, a new prompt word is generated.
[0015] Optionally, before obtaining the expert evaluation rule description vector, the step includes: obtaining an expert evaluation rule description table, and vectorizing the expert evaluation rule description table to obtain the expert evaluation rule description vector.
[0016] Optionally, the step of obtaining an expert evaluation rule description table and vectorizing the expert evaluation rule description table to obtain an expert evaluation rule description vector includes: obtaining an expert evaluation rule description table and performing discrete representation and distributed representation analysis on the expert evaluation rule description table to obtain a bag-of-words mapping representation, and vectorizing the bag-of-words mapping representation to obtain the expert evaluation rule description vector.
[0017] Optionally, performing keyword relevance evaluation on the input original prompt word based on the expert evaluation rule description vector to obtain a corresponding relevance evaluation value includes:
[0018] Based on the expert evaluation rule description vector, the semantic association and fuzzy clustering analysis of the input original prompt word is performed to obtain a modal semantic association and fuzzy clustering analysis framework;
[0019] Calculating the semantically enhanced co-occurrence association measure of the modal semantic association and the fuzzy cluster analysis framework;
[0020] The keyword relevance evaluation is performed on the input original prompt word based on the semantically enhanced co-occurrence association metric, and a cross-cluster semantic relevance score is assigned to the original prompt word as a corresponding relevance evaluation value.
[0021] Optionally, the semantic association and fuzzy clustering analysis of the input original prompt words based on the expert evaluation rule description vector to obtain a modal semantic association and fuzzy clustering analysis framework includes:
[0022] Based on the expert evaluation rule description vector, the semantic association and fuzzy clustering analysis of the input original prompt word are performed to obtain the corresponding modal semantic association and fuzzy clustering membership;
[0023] Based on fuzzy C-means clustering, a fuzzy contribution matrix is generated for the modal semantic association and fuzzy clustering membership;
[0024] Semantic clustering instantiation is performed according to the fuzzy contribution matrix to generate the modal semantic association and fuzzy clustering analysis framework.
[0025] Optionally, calculating the semantic reinforcement co-occurrence association measure of the modal semantic association and the fuzzy cluster analysis framework includes:
[0026] Associating the modal semantics with a semantically weighted co-occurrence matrix of a fuzzy cluster analysis framework;
[0027] Based on the semantic weighted co-occurrence matrix, calculating the cross-modal semantic consistency between different characters of the original prompt word;
[0028] According to the cross-modal semantic consistency, the modal semantic association and the semantic reinforcement co-occurrence association measure of the fuzzy cluster analysis framework are calculated.
[0029] Optionally, the performing keyword relevance evaluation on the input original prompt word based on the semantically enhanced co-occurrence association metric and assigning a cross-cluster semantic relevance score to the original prompt word as a corresponding relevance evaluation value includes:
[0030] Performing multi-scale mapping on the semantically enhanced co-occurrence association metric to obtain a multi-scale semantic association tensor;
[0031] Based on the multi-scale semantic association tensor, keyword relevance evaluation is performed on the input original prompt word, and a cross-cluster semantic relevance score is assigned to the original prompt word as a corresponding relevance evaluation value.
[0032] Optionally, the performing keyword relevance evaluation on the input original prompt word based on the multi-scale semantic association tensor, and assigning a cross-cluster semantic relevance score to the original prompt word as a corresponding relevance evaluation value, includes:
[0033] Performing multi-scale decomposition on the multi-scale semantic association tensor to obtain a plurality of feature subsets;
[0034] Based on the several feature subsets, a cross-cluster semantic analysis is performed on the input original prompt word to obtain a cross-cluster semantic path to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value.
[0035] Optionally, the step of performing cross-cluster semantic analysis on the input original prompt word based on the plurality of feature subsets to obtain a cross-cluster semantic path to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value includes:
[0036] Based on the plurality of feature subsets, cross-cluster semantic analysis is performed on the input original prompt word to obtain a cross-cluster semantic path;
[0037] A path strength evaluation is performed on the cross-cluster semantic path to identify a core semantic path therein to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value.
[0038] Optionally, performing path strength evaluation on the cross-cluster semantic path to identify a core semantic path therein to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value includes:
[0039] Performing path strength evaluation on the cross-cluster semantic paths to identify core semantic paths therein;
[0040] Based on the core semantic path, the semantic profile of the original prompt word is divided to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value.
[0041] Optionally, dividing the semantic profile of the original prompt word based on the core semantic path to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value includes:
[0042] Based on the core semantic path, dividing the semantic profile of the original prompt word;
[0043] Perform keyword relevance evaluation based on the semantic profile of the original prompt word to obtain the contribution of the semantic relevance;
[0044] According to the contribution of the semantic association, a cross-cluster semantic relevance score is calculated as a corresponding relevance evaluation value.
[0045] Optionally, the original prompt word is used as a key in a key-value pair, and the relevance evaluation value is used as a value in the key-value pair, and is input into a large language model to perform semantic analysis on the original prompt word to obtain a semantic analysis vector;
[0046] Using the original prompt word as a key in a key-value pair and using the relevance evaluation value as a value in the key-value pair, so as to encapsulate the key and the value into a key-value pair;
[0047] The key-value pair is converted into an embedding vector to be input into the large language model for multi-layer semantic perception, so as to perform semantic analysis on the original prompt word to obtain a semantic analysis vector.
[0048] Optionally, the converting the key-value pair into an embedding vector to be input into the large language model for multi-layer semantic perception, so as to perform semantic analysis on the original prompt word to obtain a semantic analysis vector, comprises:
[0049] Converting the key-value pairs into embedding vectors to be input into the large language model for multi-layer semantic perception to determine the semantic association distribution characteristics of the characters in the original prompt word;
[0050] Determining the original prompt word context embedding based on the semantic association distribution feature to perform context semantic dependency analysis on the context embedding;
[0051] Multi-head attention analysis is performed on the result of the contextual semantic dependency analysis to generate the semantic analysis vector.
[0052] Optionally, generating a new prompt word based on the semantic analysis vector and the relevance evaluation value includes:
[0053] The relevance evaluation value is discretized to obtain a discrete vector, and the discrete vector is fused with a semantic analysis component to generate a new prompt word.
[0054] Optionally, the discretizing the relevance evaluation value to obtain a discrete vector, and fusing the discrete vector with a semantic analysis component to generate a new prompt word, includes:
[0055] Discretizing the correlation evaluation value to obtain a plurality of discrete labels, encoding each discrete label to obtain a discrete label code, so as to form a discrete label code vector;
[0056] The discrete label encoding vector is fused with the semantic analysis component to generate a new prompt word.
[0057] Optionally, the discretization processing of the correlation evaluation value to obtain a plurality of discrete labels, encoding processing of each discrete label to obtain a discrete label code to form a discrete label code vector includes:
[0058] Calculating the global relevance of each character in the original prompt word with the query target;
[0059] Based on the size of the global correlation corresponding to each character, a corresponding discrete degree weight is assigned to discretize the correlation evaluation value to obtain a plurality of discrete labels;
[0060] Based on a preset embedding table, each discrete label is mapped into a low-dimensional continuous vector control to encode the discrete label to obtain a discrete label code, so as to form a discrete label code vector.
[0061] The prompt word optimization method proposed in this application that combines expert evaluation rules and a large language model has the following technical advantages:
[0062] (1) By embedding expert evaluation rules into the prompt word optimization process and using the efficient computing power of the large language model for semantic analysis, the process of manually evaluating and optimizing prompt words one by one is replaced by automated processing, greatly improving processing efficiency. At the same time, the large language model can process multiple prompt words in parallel, further shortening the overall processing time.
[0063] (2) The expert evaluation rules introduced are based on domain knowledge, experience summary and the requirements of specific tasks, and are objective and professional. These rules reduce the influence of personal subjective judgment when evaluating prompt words, ensuring the objectivity and consistency of the evaluation results. In addition, the large language model has learned rich semantic knowledge and language rules through training on a large amount of text data, and can more accurately understand the semantic connotation of the prompt words, further reducing subjectivity.
[0064] (3) The expert evaluation rules in this method can be dynamically adjusted and optimized as domain knowledge is updated and technology develops. At the same time, the large language model has the ability to continuously learn and can update its internal parameters and knowledge base by continuously receiving new training data to adapt to new prompt word generation requirements. This flexibility enables this method to quickly respond to domain changes and technology upgrades, maintaining the timeliness and accuracy of prompt word generation.
[0065] (4) The large language model can capture complex semantic relationships and contextual information through deep learning technology. In the process of optimizing prompt words, the large language model not only analyzes the surface meaning of the prompt words, but also deeply explores the semantic connotation and logical relationship behind them. At the same time, combined with the professional guidance of expert evaluation rules, the generated new prompt words are more semantically rich, in-depth and accurate.
[0066] (5) The original prompt words are evaluated for keyword relevance through expert evaluation rules to ensure that the generated new prompt words are highly relevant to the original intent or task requirements. At the same time, the large language model will also consider the relevance of the prompt words to the context or specific fields during the semantic analysis process, further enhancing the relevance of the generated content. In addition, by combining the output results of expert evaluation rules and the large language model, new prompt words that meet professional requirements and have high semantic relevance can be generated. 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 The figure is a flowchart of a prompt word optimization method combining expert evaluation rules and a large language model 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] Figure 1 The following is a flow chart of a prompt word optimization method combining expert evaluation rules and a large language model according to an embodiment of the present application. A prompt word optimization method combining expert evaluation rules and a large language model includes:
[0071] Obtain expert evaluation rule description vector;
[0072] Based on the expert evaluation rule description vector, a keyword relevance evaluation is performed on the input original prompt word to obtain a corresponding relevance evaluation value;
[0073] The original prompt word is used as a key in a key-value pair, and the relevance evaluation value is used as a value in the key-value pair, and is input into a large language model to perform semantic analysis on the original prompt word to obtain a semantic analysis vector;
[0074] Based on the semantic analysis vector and the relevance evaluation value, a new prompt word is generated.
[0075] Optionally, before obtaining the expert evaluation rule description vector, the step includes: obtaining an expert evaluation rule description table, and vectorizing the expert evaluation rule description table to obtain the expert evaluation rule description vector.
[0076] The prompt word optimization method proposed in this embodiment that combines expert evaluation rules and a large language model has the following technical advantages:
[0077] (1) By embedding expert evaluation rules into the prompt word optimization process and using the efficient computing power of the large language model for semantic analysis, the process of manually evaluating and optimizing prompt words one by one is replaced by automated processing, greatly improving processing efficiency. At the same time, the large language model can process multiple prompt words in parallel, further shortening the overall processing time.
[0078] (2) The expert evaluation rules introduced are based on domain knowledge, experience summary and the requirements of specific tasks, and are objective and professional. These rules reduce the influence of personal subjective judgment when evaluating prompt words, ensuring the objectivity and consistency of the evaluation results. In addition, the large language model has learned rich semantic knowledge and language rules through training on a large amount of text data, and can more accurately understand the semantic connotation of the prompt words, further reducing subjectivity.
[0079] (3) The expert evaluation rules in this method can be dynamically adjusted and optimized as domain knowledge is updated and technology develops. At the same time, the large language model has the ability to continuously learn and can update its internal parameters and knowledge base by continuously receiving new training data to adapt to new prompt word generation requirements. This flexibility enables this method to quickly respond to domain changes and technology upgrades, maintaining the timeliness and accuracy of prompt word generation.
[0080] (4) The large language model can capture complex semantic relationships and contextual information through deep learning technology. In the process of optimizing prompt words, the large language model not only analyzes the surface meaning of the prompt words, but also deeply explores the semantic connotation and logical relationship behind them. At the same time, combined with the professional guidance of expert evaluation rules, the generated new prompt words are more semantically rich, in-depth and accurate.
[0081] (5) The original prompt words are evaluated for keyword relevance through expert evaluation rules to ensure that the generated new prompt words are highly relevant to the original intent or task requirements. At the same time, the large language model will also consider the relevance of the prompt words to the context or specific fields during the semantic analysis process, further enhancing the relevance of the generated content. In addition, by combining the output results of expert evaluation rules and the large language model, new prompt words that meet professional requirements and have high semantic relevance can be generated.
[0082] Optionally, the step of obtaining an expert evaluation rule description table and vectorizing the expert evaluation rule description table to obtain an expert evaluation rule description vector includes: obtaining an expert evaluation rule description table and performing discrete representation and distributed representation analysis on the expert evaluation rule description table to obtain a bag-of-words mapping representation, and vectorizing the bag-of-words mapping representation to obtain the expert evaluation rule description vector.
[0083] To this end, by obtaining the expert evaluation rule description table and performing discrete representation and distributed representation analysis on it, a bag-of-words mapping representation is obtained, and then the bag-of-words mapping representation is vectorized to obtain the expert evaluation rule description vector, which has the following technical benefits:
[0084] 1. By obtaining the expert evaluation rule description table, this technical solution first ensures the authority and professionalism of the evaluation rules. Discrete representation treats each keyword or phrase in the rule description as an independent unit, which helps to accurately identify the key elements in the rule. Distributed representation analysis further considers the semantic association and contextual information between these units, so that the rule description vector can more comprehensively reflect the expert's knowledge structure and evaluation logic.
[0085] 2. Bag-of-words mapping representation As an intermediate step, the text information in the rule description is converted into a structured numerical form (i.e., bag-of-words model), in which each word or phrase corresponds to one or more specific dimensions. This representation simplifies the processing of text data and facilitates subsequent vectorization operations. The vectorized expert evaluation rule description vector not only retains the key information in the original text, but also enables this information to be efficiently stored and quickly calculated in the computer.
[0086] 3. By vectorizing the description of expert evaluation rules, this technical solution enables these rules to be understood and applied by large language models or other machine learning algorithms in the form of numerical vectors. This representation method enhances the generalization ability of the model, allowing the model to handle more diverse input data and maintain stable performance in different task scenarios. At the same time, vectorization also makes the rule description more flexible, which facilitates further optimization and adjustment.
[0087] 4. In the process of optimizing prompt words, the expert evaluation rule description vector is used to evaluate the keyword relevance of the original prompt words, which can ensure that the generated new prompt words are more logically reasonable and more semantically accurate. At the same time, combined with the semantic analysis capabilities of the large language model, the deep meaning and potential associations in the original prompt words can be further explored, thereby generating new prompt words that are more in line with professional field requirements and highly semantically relevant. This optimization effect not only improves the quality of prompt words, but also enhances their practicality and effectiveness in practical applications.
[0088] In addition, in order to implement how to perform discrete representation and distributed representation analysis on the expert evaluation rule description table, an exemplary code is provided below:
[0089] Step 1: Read the CSV file and process the text data
[0090] Python
[0091] import pandas as pd
[0092] from sklearn.feature_extraction.text import CountVectorizer
[0093] import numpy as np
[0094] # The CSV file is named 'expert_rules.csv', which has a column named 'description' containing the rule description
[0095] df = pd.read_csv('expert_rules.csv')
[0096] descriptions = df['description'].tolist()
[0097] # Use CountVectorizer for bag-of-words representation
[0098] vectorizer = CountVectorizer()
[0099] X = vectorizer.fit_transform(descriptions)
[0100] # X is a sparse matrix, where each row represents a bag-of-words representation of a rule description
[0101] # Convert it to an array
[0102] X_dense = X.toarray()
[0103] # Get vocabulary
[0104] vocabulary = vectorizer.get_feature_names_out()
[0105] Step 2: Vectorize the Bag of Words Mapping Representation
[0106] import pandas as pd
[0107] from sklearn.feature_extraction.text import CountVectorizer
[0108] # Read CSV file
[0109] df = pd.read_csv('expert_rules.csv')
[0110] descriptions = df['description'].tolist()
[0111] # Use CountVectorizer for bag-of-words representation and vectorization
[0112] vectorizer = CountVectorizer()
[0113] X = vectorizer.fit_transform(descriptions)
[0114] # Accessing vectors or vocabularies
[0115] # vocabulary = vectorizer.get_feature_names_out()
[0116] # for idx, desc in enumerate(descriptions):
[0117] #print(f"Rule {idx}: {desc}")
[0118] #print(f"Vectorized Representation: {X[idx,:].toarray()}")
[0119] Optionally, performing keyword relevance evaluation on the input original prompt word based on the expert evaluation rule description vector to obtain a corresponding relevance evaluation value includes:
[0120] Based on the expert evaluation rule description vector, the semantic association and fuzzy clustering analysis of the input original prompt word is performed to obtain a modal semantic association and fuzzy clustering analysis framework;
[0121] Calculating the semantically enhanced co-occurrence association measure of the modal semantic association and the fuzzy cluster analysis framework;
[0122] The keyword relevance evaluation is performed on the input original prompt word based on the semantically enhanced co-occurrence association metric, and a cross-cluster semantic relevance score is assigned to the original prompt word as a corresponding relevance evaluation value.
[0123] To this end, by constructing a modal semantic association and fuzzy clustering analysis framework, and based on this framework, evaluating the keyword relevance of the input original prompt words, the following technical benefits are achieved:
[0124] 1. Through modal semantic association analysis, this technical solution can deeply explore the semantic connection between the original prompt word and the description vector of the expert evaluation rule. This connection is not limited to the surface keyword matching, but also takes into account the context, context and potential semantic meaning. Fuzzy clustering analysis further groups these complex semantic relationships to form clusters with similar semantic features, thereby enhancing the system's ability to understand semantics.
[0125] 2. Traditional keyword relevance evaluation often relies on simple string matching or word frequency statistics, which tends to ignore semantic nuances and complex relationships. This technical solution can more accurately evaluate the relevance between the original prompt words and the expert evaluation rules by calculating the semantic reinforcement co-occurrence correlation metric under the framework of modal semantic association and fuzzy cluster analysis. This evaluation not only considers the direct occurrence of keywords, but also their relative position and association strength in the semantic space, thereby improving the accuracy of the evaluation.
[0126] 3. Assigning cross-cluster semantic relevance scores to original prompt words is a highlight of this technical solution. Through fuzzy cluster analysis, the original prompt words and their related keywords are divided into different semantic clusters. Based on these clusters, the system can calculate the semantic relevance scores between clusters, which not only reflects the correlation within the cluster, but also takes into account the interaction and association between clusters. This cross-cluster semantic relevance score makes the evaluation results more comprehensive and detailed, which helps users or systems better understand and apply the evaluation results.
[0127] 4. This technical solution is not only applicable to specific prompter evaluation tasks, but can also be flexibly applied to various scenarios that require semantic relevance evaluation. Whether it is natural language processing, information retrieval or intelligent recommendation, as long as it involves evaluating the semantic relevance of text or prompters, the ideas and methods of this technical solution can be used as a reference. By adjusting the parameters of the expert evaluation rule description vector and fuzzy clustering analysis, it can be easily adapted to different application scenarios and needs.
[0128] An example code is provided below to implement the above steps:
[0129] import numpy as np
[0130] from sklearn.feature_extraction.text import TfidfVectorizer
[0131] from sklearn.cluster import KMeans
[0132] from scipy.spatial.distance import cosine
[0133] # Expert evaluation rule description vector
[0134] expert_vectors = np.random.rand(10, 100) # There are 10 rules, each rule is represented as a 100-dimensional vector
[0135] # The original prompt word entered
[0136] raw_prompts = ["Sample prompt 1", "Prompts related to expert rules", "Irrelevant prompts"]
[0137] # Use TF-IDF to convert the original prompt word into a vector
[0138] tfidf_vectorizer = TfidfVectorizer()
[0139] prompt_vectors = tfidf_vectorizer.fit_transform(raw_prompts).toarray()
[0140] # Fuzzy cluster analysis
[0141] k = 3 # Assume you want 3 clusters
[0142] kmeans = KMeans(n_clusters=k, random_state=0).fit(prompt_vectors)
[0143] cluster_labels = kmeans.labels_
[0144] # Modal semantic association and fuzzy clustering analysis framework
[0145] # Calculate semantic reinforcement co-occurrence correlation metrics
[0146] def calculate_semantic_strength(prompt_vec, expert_vecs):
[0147] max_similarity = -1
[0148] for expert_vec in expert_vecs:
[0149] similarity = 1 - cosine(prompt_vec, expert_vec) # Use the complement of cosine similarity as the similarity indicator
[0150] if similarity>max_similarity:
[0151] max_similarity = similarity
[0152] return max_similarity
[0153] # Assign a cross-cluster semantic relevance score to each original prompt word
[0154] semantic_scores = []
[0155] for i, prompt_vec in enumerate(prompt_vectors):
[0156] # Take the maximum similarity between the prompt vector and all expert rule vectors as the score
[0157] score = calculate_semantic_strength(prompt_vec, expert_vectors)
[0158] semantic_scores.append((raw_prompts[i], score, cluster_labels[i]))
[0159] # Output results
[0160] for prompt, score, cluster in semantic_scores:
[0161] print(f"Prompt: {prompt}, Semantic Score: {score:.4f}, Cluster:{cluster}")
[0162] Optionally, the semantic association and fuzzy clustering analysis of the input original prompt words based on the expert evaluation rule description vector to obtain a modal semantic association and fuzzy clustering analysis framework includes:
[0163] Based on the expert evaluation rule description vector, the semantic association and fuzzy clustering analysis of the input original prompt word are performed to obtain the corresponding modal semantic association and fuzzy clustering membership;
[0164] Based on fuzzy C-means clustering, a fuzzy contribution matrix is generated for the modal semantic association and fuzzy clustering membership;
[0165] Semantic clustering instantiation is performed according to the fuzzy contribution matrix to generate the modal semantic association and fuzzy clustering analysis framework.
[0166] To this end, a modal semantic association and fuzzy clustering analysis framework was constructed by combining the expert evaluation rule description vector, the semantic association analysis of the original prompt words, and the fuzzy C-Means (FCM) method, which has the following technical benefits:
[0167] 1. By using the expert evaluation rule description vector, the scheme can capture semantic features that are closely related to expert knowledge. These features are not limited to keyword matching, but also involve a wider range of semantic contexts and potential meanings. Therefore, when performing semantic association analysis on the input original prompt words, the semantic information related to the expert rules can be more accurately identified, thereby improving the accuracy of semantic association.
[0168] 2. Traditional hard clustering methods (such as K-Means) explicitly assign each data point to a cluster, while fuzzy C-means clustering allows data points to belong to multiple clusters with different memberships. This fuzziness is particularly important when dealing with semantic data, because semantic boundaries are often fuzzy and a text may be related to multiple topics or concepts at the same time. By calculating modal semantic associations and fuzzy cluster membership, the scheme can more flexibly represent this fuzziness and thus more accurately reflect the actual distribution of the data.
[0169] 3. The generated fuzzy contribution matrix not only contains the membership information of the data points to each cluster, but also implies the semantic relationship between clusters. This relationship can be revealed by analyzing the elements in the fuzzy contribution matrix, thus providing an in-depth semantic interpretation of the clustering results. This interpretability helps users or systems better understand the clustering results and make more accurate decisions or inferences based on them.
[0170] 4. Instantiating semantic clustering based on the fuzzy contribution matrix is a key step in building a modal semantic association and fuzzy clustering analysis framework. This process not only transforms the fuzzy clustering results into specific clustering instances, but also retains the semantic association and fuzziness between clusters. In this way, users or systems can conduct further analysis and applications based on these clustering instances, such as information retrieval, recommendation systems, text classification, etc. Since clustering instances have clear semantic meanings and fuzzy representations, they can better adapt to complex and changing practical application scenarios.
[0171] 5. This technical solution builds a comprehensive evaluation framework by combining expert knowledge, semantic association analysis and fuzzy clustering methods. This framework not only has powerful semantic processing capabilities, but also can handle ambiguity and uncertainty in data. Therefore, when faced with complex and changeable input data, the framework can show higher robustness and adaptability. This feature makes the framework have broad application prospects and practical value in a variety of application scenarios.
[0172] The following is an exemplary code to implement how to process the expert evaluation rule description vector, the semantic association analysis of the original prompt words, the fuzzy C-means clustering (FCM), and generate the fuzzy contribution matrix and perform semantic clustering instantiation, etc.:
[0173] import numpy as np
[0174] from sklearn.feature_extraction.text import TfidfVectorizer
[0175] from skfuzzy import cluster as fuzz
[0176] # Expert evaluation rule description vector
[0177] expert_vectors = np.random.rand(10, 100) # There are 10 rules, each rule is a 100-dimensional vector
[0178] # The original prompt word entered
[0179] raw_prompts = ["Sample prompt 1", "Prompts related to expert rules", "Irrelevant prompts"]
[0180] # Use TF-IDF to convert the original prompt word into a vector
[0181] tfidf_vectorizer = TfidfVectorizer()
[0182] prompt_vectors = tfidf_vectorizer.fit_transform(raw_prompts).toarray()
[0183] # Calculate modal semantic association and fuzzy clustering membership
[0184] # Membership is based on some similarity measure
[0185] def calculate_fuzzy_membership(prompt_vectors, expert_vectors, num_clusters=3):
[0186] # Get the maximum similarity between each prompt and all expert vectors, and normalize it to between 0 and 1
[0187] membership = np.zeros((len(prompt_vectors), num_clusters))
[0188] for i, prompt_vec in enumerate(prompt_vectors):
[0189] similarities = 1 - np.array([np.linalg.norm(prompt_vec - expert_vec)for expert_vec in expert_vectors])
[0190] max_sim_indices = np.argsort(similarities)[-num_clusters:]# Take the most similar num_clusters
[0191] # Assign membership
[0192] membership[i, max_sim_indices] = np.random.rand(num_clusters)
[0193] membership[i] / = np.sum(membership[i]) # Normalization
[0194] return membership
[0195] # Calculate fuzzy clustering membership
[0196] fuzzy_membership = calculate_fuzzy_membership(prompt_vectors, expert_vectors)
[0197] # fuzzy_membership is the result of FCM (i.e. fuzzy contribution matrix)
[0198] # Instantiate semantic clustering based on fuzzy contribution matrix
[0199] for i, prompt in enumerate(raw_prompts):
[0200] print(f"Prompt: {prompt}")
[0201] print(f"Fuzzy Cluster Membership: {fuzzy_membership[i]}")
[0202] Optionally, calculating the semantic reinforcement co-occurrence association measure of the modal semantic association and the fuzzy cluster analysis framework includes:
[0203] Associating the modal semantics with a semantically weighted co-occurrence matrix of a fuzzy cluster analysis framework;
[0204] Based on the semantic weighted co-occurrence matrix, calculating the cross-modal semantic consistency between different characters of the original prompt word;
[0205] According to the cross-modal semantic consistency, the modal semantic association and the semantic reinforcement co-occurrence association measure of the fuzzy cluster analysis framework are calculated.
[0206] To this end, when calculating the semantically enhanced co-occurrence association measure of modal semantic association and fuzzy cluster analysis framework, the concepts of semantic weighted co-occurrence matrix and cross-modal semantic consistency are introduced, which can more deeply reveal the semantic relationship between the original prompt word and different modalities. Specifically, it has the following technical benefits:
[0207] 1. By converting the results of modal semantic association and fuzzy clustering analysis into a semantic weighted co-occurrence matrix, not only the co-occurrence relationship between the elements (such as words and phrases) within the original prompt words is considered, but also the semantic weight is introduced through fuzzy clustering membership and expert evaluation rules. This weighted processing enables the co-occurrence matrix to more accurately reflect the semantic strength and importance between different elements, thereby enhancing the richness and accuracy of semantic representation.
[0208] 2. Based on the semantic weighted co-occurrence matrix, calculating the cross-modal semantic consistency between different characters (or more generally, different semantic units) of the original prompt word is an innovative and effective step. Cross-modal semantic consistency evaluation can reveal the degree of association and consistency between different modalities (such as text, image, speech, etc.) at the semantic level. This is of great significance for applications such as multimodal information processing, cross-media retrieval and recommendation systems, because they usually need to process data from different modalities and evaluate the semantic relationship between them.
[0209] 3. Based on the cross-modal semantic consistency, the semantically enhanced co-occurrence correlation metric of the modal semantic association and the fuzzy clustering analysis framework is further calculated, which is an important supplement and optimization of the traditional co-occurrence correlation metric. The traditional co-occurrence correlation metric often only focuses on the co-occurrence frequency between elements, while ignoring the semantic relationship and importance difference between them. The semantically enhanced co-occurrence correlation metric introduces semantic weighting and cross-modal consistency evaluation, making the measurement results more in line with the needs of actual semantic scenarios and more accurately reflecting the deep semantic associations between elements.
[0210] 4. This technical solution has potential value in multiple application fields. For example, in text mining and information retrieval, by optimizing the semantic reinforcement co-occurrence correlation measurement, the accuracy and relevance of query results can be improved; in recommendation systems, it can provide users with more personalized and accurate recommendation services based on the cross-modal semantic consistency of user behavior and content; in sentiment analysis and public opinion monitoring, it can more accurately identify and analyze the sentiment tendency and public opinion trend in the text. The intelligence and precision of these application fields will benefit from the semantic reinforcement co-occurrence correlation measurement provided by this technical solution.
[0211] 5. By calculating the semantically enhanced co-occurrence correlation metric, the system can more clearly display the semantic relationship and importance difference between different elements, thereby enhancing the interpretability of the system. At the same time, because the metric method takes into account factors such as cross-modal semantic consistency and semantic weighting, the system can show higher robustness and adaptability when facing complex and changing data. This improvement in interpretability and robustness is of great significance to improving user satisfaction and system performance.
[0212] To this end, an exemplary code is provided as follows to calculate the semantically enhanced co-occurrence association measure of modal semantic association and fuzzy cluster analysis framework:
[0213] import numpy as np
[0214] # Semantic weighted co-occurrence matrix
[0215] # The matrix size is (n_characters, n_characters), where n_characters is the number of characters
[0216] semantic_weighted_co_occurrence_matrix = np.random.rand(n_characters,n_characters)
[0217] # Make sure the matrix is symmetric
[0218] semantic_weighted_co_occurrence_matrix = (
[0219] semantic_weighted_co_occurrence_matrix +
[0220] semantic_weighted_co_occurrence_matrix.T
[0221] ) / 2
[0222] # Fuzzy clustering membership matrix
[0223] # There are k clusters, the matrix size is (n_characters, k)
[0224] n_clusters = 3
[0225] fuzzy_membership_matrix = np.random.rand(n_characters, n_clusters)
[0226] # Ensure that the sum of each row of the membership matrix is 1 (normalization)
[0227] fuzzy_membership_matrix = fuzzy_membership_matrix / fuzzy_membership_matrix.sum(axis=1, keepdims=True)
[0228] def calculate_cross_modal_semantic_consistency(fuzzy_membership_matrix):
[0229] consistency_matrix = np.dot(fuzzy_membership_matrix, fuzzy_membership_matrix.T)
[0230] # Diagonal elements represent the similarity between themselves
[0231] np.fill_diagonal(consistency_matrix, 1)
[0232] return consistency_matrix
[0233] cross_modal_semantic_consistency = calculate_cross_modal_semantic_consistency(fuzzy_membership_matrix)
[0234] def calculate_semantic_enhanced_co_occurrence_metric(semantic_weighted_matrix, consistency_matrix):
[0235] # Element-wise multiplication (Hadamard product)
[0236] metric = semantic_weighted_co_occurrence_matrix * consistency_matrix
[0237] # Normalize or further process the results
[0238] return metric
[0239] semantic_enhanced_co_occurrence_metric = calculate_semantic_enhanced_co_occurrence_metric(
[0240] semantic_weighted_co_occurrence_matrix, cross_modal_semantic_consistency )
[0242] # Print results
[0243] print("Semantic Weighted Co-occurrence Matrix:\n", semantic_weighted_co_occurrence_matrix)
[0244] print("Cross-modal Semantic Consistency Matrix:\n", cross_modal_semantic_consistency)
[0245] print("Semantic Enhanced Co-occurrence Metric:\n", semantic_enhanced_co_occurrence_metric)
[0246] Optionally, the performing keyword relevance evaluation on the input original prompt word based on the semantically enhanced co-occurrence association metric and assigning a cross-cluster semantic relevance score to the original prompt word as a corresponding relevance evaluation value includes:
[0247] Performing multi-scale mapping on the semantically enhanced co-occurrence association metric to obtain a multi-scale semantic association tensor;
[0248] Based on the multi-scale semantic association tensor, keyword relevance evaluation is performed on the input original prompt word, and a cross-cluster semantic relevance score is assigned to the original prompt word as a corresponding relevance evaluation value.
[0249] To this end, the semantically enhanced co-occurrence association metric is applied to the multi-scale mapping and further used for keyword relevance assessment of the original cue words, assigning cross-cluster semantic relevance scores to the original cue words, which has the following technical benefits:
[0250] 1. By mapping the semantically enhanced co-occurrence association metric to multiple scales, a multi-scale semantic association tensor is obtained, which can capture the semantic associations between keywords at different granularities or levels. This multi-scale analysis method can more comprehensively reveal the complex relationships between keywords, including direct associations, indirect associations, and potential semantic connections. Therefore, keyword relevance evaluation based on the multi-scale semantic association tensor can more accurately reflect the actual relationship between keywords and improve the depth and accuracy of the evaluation.
[0251] 2. The cross-cluster semantic relevance score is calculated based on the multi-scale semantic association tensor, which takes into account the semantic connection between different clusters. Since clusters are usually divided according to the similarity of data, the elements within a cluster often have similar semantic features. Through cross-cluster analysis, the semantic relevance of keywords between different clusters can be further explored, thereby obtaining a more comprehensive and robust scoring result. This cross-cluster analysis can reduce the impact of the internal deviation of a single cluster on the scoring result and improve the stability and reliability of the scoring.
[0252] 3. Multi-scale mapping and cross-clustering analysis provide more flexible means for semantic analysis and application. By adjusting the parameters of multi-scale mapping or selecting different clustering algorithms, the process of semantic analysis and evaluation can be customized according to specific needs. This flexibility enables the technical solution to be applicable to a variety of different application scenarios, such as text classification, information retrieval, recommendation systems, etc. At the same time, the multi-scale semantic association tensor can also be used as an intermediate representation to support further semantic mining and reasoning tasks.
[0253] To this end, an exemplary code is provided as follows to implement keyword relevance evaluation of the input original prompt words based on semantically enhanced co-occurrence association measurement, and assign cross-cluster semantic relevance scores, etc.:
[0254] import numpy as np
[0255] #Multi-scale mapping function
[0256] def multi_scale_mapping(matrix, scales):
[0257] mapped_tensors = []
[0258] for scale in scales:
[0259] # Scaling matrix
[0260] scaled_matrix = matrix * scale
[0261] kernel = np.ones((3, 3)) / 9# 3x3 mean filter kernel
[0262] mapped_tensors.append(scaled_matrix)
[0263] # Stack matrices of multiple scales into tensors
[0264] # Use higher-dimensional data structures, such as xarray's DataArray or TensorFlow / PyTorch's Tensor
[0265] return np.array(mapped_tensors)
[0266] #Semantic enhancement co-occurrence correlation measurement
[0267] semantic_enhanced_co_occurrence_metric = np.random.rand(10, 10) # Assume it is a 10x10 matrix
[0268] # Define multi-scale parameters
[0269] scales = [0.5, 1.0, 1.5] # Example scaling factors
[0270] # Perform multi-scale mapping
[0271] multi_scale_tensors = multi_scale_mapping(semantic_enhanced_co_occurrence_metric, scales)
[0272] # The original prompt contains a list of keywords
[0273] original_prompt = ["keyword1", "keyword2", "keyword3", "irrelevant_word"]
[0274] # Keyword relevance evaluation function
[0275] def evaluate_keyword_relevance(multi_scale_tensors, keywords):
[0276] scores = []
[0277] for keyword in keywords:
[0278] score = np.random.rand()
[0279] scores.append(score)
[0280] # Average the scores of all keywords
[0281] average_score = np.mean(scores)
[0282] return average_score
[0283] # Perform keyword relevance evaluation
[0284] keywords_in_prompt = [word for word in original_prompt ifword.startswith("keyword")]# Extract keywords
[0285] cross_cluster_semantic_relevance_score = evaluate_keyword_relevance(multi_scale_tensors, keywords_in_prompt)
[0286] # Print results
[0287] print("Cross-cluster Semantic Relevance Score:", cross_cluster_semantic_relevance_score)
[0288] Optionally, the performing keyword relevance evaluation on the input original prompt word based on the multi-scale semantic association tensor, and assigning a cross-cluster semantic relevance score to the original prompt word as a corresponding relevance evaluation value, includes:
[0289] Performing multi-scale decomposition on the multi-scale semantic association tensor to obtain a plurality of feature subsets;
[0290] Based on the several feature subsets, a cross-cluster semantic analysis is performed on the input original prompt word to obtain a cross-cluster semantic path to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value.
[0291] To this end, the keyword relevance of the original prompt words is evaluated based on multi-scale decomposition of the multi-scale semantic association tensor and cross-cluster semantic analysis, and a cross-cluster semantic relevance score is assigned, which has the following technical benefits:
[0292] 1. By performing multi-scale decomposition on the multi-scale semantic association tensor, semantic feature subsets at different granularities or levels can be obtained. These feature subsets not only capture the direct associations between keywords, but also reveal deeper indirect associations and potential semantic structures. This multi-scale feature decomposition helps to understand the semantic information of text data from multiple perspectives and levels, thereby enhancing the depth and breadth of semantic understanding.
[0293] 2. Cross-cluster semantic analysis is a key step in evaluating the relevance of keywords between different clusters. Traditional cluster analysis methods often only focus on the similarities within clusters, while ignoring the semantic connections between clusters. The feature subsets obtained based on multi-scale decomposition can more accurately identify the semantic paths between different clusters. These paths reveal the semantic information transmitted by keywords between different clusters. By calculating the weights or importance of these cross-cluster semantic paths, a more accurate cross-cluster semantic relevance score can be obtained, thereby improving the accuracy of the analysis.
[0294] 3. The combination of multi-scale decomposition and cross-cluster semantic analysis enables the construction of more complex semantic relationship models. These models not only consider the direct associations between keywords, but also their indirect associations and potential influences between different clusters. This complex semantic relationship modeling helps to more fully understand the semantic structure of text data and better capture the deep connections and differences between texts.
[0295] 4. Since multi-scale decomposition and cross-cluster semantic analysis take into account the semantic information between different scales and clusters, they are more robust to noise and outliers. Even if there are some irrelevant or erroneous keywords in the input data, this technical solution can weaken the influence of these noises through multi-scale feature extraction and cross-cluster semantic analysis, thereby obtaining more stable and reliable relevance evaluation results. In addition, this technical solution has strong generalization ability and can be applied to different types of text data and different application scenarios.
[0296] In addition, an exemplary code is provided below to implement multi-scale decomposition and cross-cluster semantic analysis based on multi-scale semantic association tensors to evaluate the keyword relevance of the input original prompt words and assign cross-cluster semantic relevance scores:
[0297] import numpy as np
[0298] # Multi-scale decomposition function
[0299] def multi_scale_decomposition(tensor, num_scales):
[0300] # tensor is a three-dimensional numpy array, where the first two dimensions are feature dimensions and the third dimension is the scale dimension
[0301] from sklearn.decomposition import PCA
[0302] decomposed_tensors = []
[0303] for i in range(1, num_scales + 1): # Decomposition of num_scales scales
[0304] pca = PCA(n_components=i)
[0305] flattened_tensor = tensor.reshape(tensor.shape[0] * tensor.shape[1],tensor.shape[2])
[0306] transformed = pca.fit_transform(flattened_tensor)
[0307] decomposed_tensors.append(transformed[:, :i])# Only take the first i principal components as the features of this scale
[0308] return np.array(decomposed_tensors)# Returns an array containing multiple scale decomposition results
[0309] # Cross-clustering semantic analysis function
[0310] def cross_cluster_semantic_analysis(feature_subsets, original_prompt,clusters):
[0311] # original_prompt is the original prompt word entered, including keywords
[0312] # clusters is the known clustering information
[0313] # Extract the feature vector corresponding to the keyword in the original prompt word
[0314] def extract_features_for_keywords(feature_subsets, keywords):
[0315] #Find feature vectors related to keywords from feature_subsets
[0316] pass
[0317] # Calculate cross-cluster semantic paths and relevance scores
[0318] def calculate_cross_cluster_scores(feature_vectors, clusters):
[0319] return np.random.rand()# Random scoring
[0320] # Extract keyword features
[0321] keyword_features = extract_features_for_keywords(feature_subsets,original_prompt)
[0322] # Calculate cross-cluster semantic relevance scores
[0323] cross_cluster_score = calculate_cross_cluster_scores(keyword_features, clusters)
[0324] return cross_cluster_score
[0325] # Multi-scale semantic association tensor
[0326] multi_scale_tensor = np.random.rand(10, 10, 3) # Features with 3 scales
[0327] # Original prompt words and clustering information
[0328] original_prompt = ["keyword1", "keyword2"]
[0329] clusters = np.array([0, 0, 1, 1, 0, 2, 2, 2, 1, 0])# Cluster labels
[0330] # Perform multi-scale decomposition
[0331] decomposed_tensors = multi_scale_decomposition(multi_scale_tensor,num_scales
[0332] Optionally, the step of performing cross-cluster semantic analysis on the input original prompt word based on the plurality of feature subsets to obtain a cross-cluster semantic path to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value includes:
[0333] Based on the plurality of feature subsets, cross-cluster semantic analysis is performed on the input original prompt word to obtain a cross-cluster semantic path;
[0334] A path strength evaluation is performed on the cross-cluster semantic path to identify a core semantic path therein to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value.
[0335] To this end, we perform cross-cluster semantic analysis on the input original prompt words based on the feature subsets obtained by multi-scale decomposition, and then identify the cross-cluster semantic path and evaluate its path strength to calculate the cross-cluster semantic relevance score, which has the following technical benefits:
[0336] 1. By performing cross-cluster semantic analysis on the input original prompt words, this technology can accurately capture the semantic associations between keywords in different clusters. These associations are not limited to directly adjacent clusters, but may also span multiple clusters to form a complex semantic network. By identifying cross-cluster semantic paths, this technology can reveal the deep semantic structure hidden behind the data, providing strong support for subsequent semantic understanding and analysis.
[0337] 2. After identifying the cross-cluster semantic paths, the technology can further identify the core semantic paths by evaluating the strength of these paths. These core semantic paths play a key role in the semantic network. They connect the core concepts and topics between different clusters and are the key to understanding the entire semantic network structure. By strengthening the identification of core semantic paths, the technology can more accurately evaluate the semantic relevance between the original prompt word and different clusters, thereby providing a more accurate relevance evaluation value.
[0338] 3. Since this technology combines the advantages of multi-scale decomposition and cross-cluster semantic analysis, it can evaluate the semantic relevance of the original prompt words from multiple angles and levels. Multi-scale decomposition provides semantic features at different granularities or levels, making the evaluation process more comprehensive and in-depth; while cross-cluster semantic analysis reveals the semantic connection between keywords in different clusters, making the evaluation results more accurate and reliable. By combining these two methods, this technology can significantly improve the accuracy and reliability of relevance evaluation, providing more powerful support for subsequent decision-making and application.
[0339] 4. This technology not only provides relevance evaluation values by identifying cross-cluster semantic paths and evaluating their strength, but also reveals the semantic structure and logic behind the evaluation process. This transparency and explainability enables users to better understand how the evaluation results are generated, thereby enhancing their trust and acceptance of the evaluation results. At the same time, this also provides more clues and inspiration for subsequent semantic analysis and optimization.
[0340] 5. The proposal and implementation of this technology not only solves practical problems in specific application scenarios, but also promotes innovation in natural language processing and semantic analysis technologies. By introducing new technical means such as cross-cluster semantic analysis and path strength evaluation, this technology provides new ideas and methods for semantic understanding and analysis. This technological breakthrough and innovation will further promote research and application progress in related fields and contribute new strength to the development of artificial intelligence and big data technologies.
[0341] The following is an exemplary implementation code to implement the above-described process of cross-cluster semantic analysis and calculating cross-cluster semantic relevance scores:
[0342] import random
[0343] from collections import defaultdict
[0344] # Clustering results and feature subsets
[0345] clusters = {
[0346] 'cluster1': ['doc1', 'doc2', 'doc3'],
[0347] 'cluster2': ['doc4', 'doc5', 'doc6'],
[0348] 'cluster3': ['doc7', 'doc8', 'doc9']
[0349] }
[0350] # Feature set for each document (data point)
[0351] features = {
[0352] 'doc1': ['feature1', 'feature2'],
[0353] 'doc2': ['feature2', 'feature3'],
[0354] 'doc3': ['feature1', 'feature4'],
[0355] 'doc4': ['feature3', 'feature4'],
[0356] 'doc5': ['feature5', 'feature6'],
[0357] 'doc6': ['feature5', 'feature7'],
[0358] 'doc7': ['feature2', 'feature8'],
[0359] 'doc8': ['feature8', 'feature9'],
[0360] 'doc9': ['feature9', 'feature10']
[0361] }
[0362] # Original prompt word
[0363] query = "feature2 and feature3"
[0364] # Cross-cluster semantic analysis
[0365] def find_cross_cluster_paths(query, features, clusters):
[0366] required_features = set(query.split(' and '))
[0367] cluster_paths = defaultdict(list)
[0368] for cluster_name, docs in clusters.items():
[0369] cluster_features = set().union(*[features[doc] for doc in docs if doc in features])
[0370] if required_features.issubset(cluster_features):
[0371] cluster_paths[cluster_name].append(cluster_features)
[0372] cross_cluster_paths = []
[0373] for c1, f1 in cluster_paths.items():
[0374] for c2, f2 in cluster_paths.items():
[0375] if c1 != c2 and any(ff & f2 for ff in f1):
[0376] cross_cluster_paths.append((c1, c2))
[0377] return cross_cluster_paths
[0378] # Path strength evaluation
[0379] def evaluate_path_strength(paths, features):
[0380] strengths = {path: sum(len(set(features[doc]) & set(features[next_doc])) for doc, next_doc in zip(docs1, docs2))
[0381] for path, (docs1, docs2) in paths.items()}
[0382] return strengths
[0383] # Cross-cluster paths
[0384] cross_cluster_paths = find_cross_cluster_paths(query, features,clusters)
[0385] # cross_cluster_paths have been converted to document pairs or more specific path forms
[0386] # Evaluate path strength
[0387] strengths = evaluate_path_strength(cross_cluster_paths, features)
[0388] # Calculate cross-cluster semantic relevance scores
[0389] if strengths:
[0390] avg_strength = sum(strengths.values()) / len(strengths)
[0391] print(f"Cross-cluster semantic relevance score is: {avg_strength}")
[0392] else:
[0393] print("No valid cross-cluster path was found.")
[0394] Optionally, performing path strength evaluation on the cross-cluster semantic path to identify a core semantic path therein to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value includes:
[0395] Performing path strength evaluation on the cross-cluster semantic paths to identify core semantic paths therein;
[0396] Based on the core semantic path, the semantic profile of the original prompt word is divided to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value.
[0397] To this end, we evaluate the path strength of cross-cluster semantic paths to identify core semantic paths, and divide the semantic profiles of the original prompt words based on these core semantic paths, and then calculate the cross-cluster semantic relevance score, which has the following technical benefits:
[0398] By evaluating the strength of cross-cluster semantic paths, we can screen out the most critical and core paths in terms of information transmission, knowledge sharing or concept association. These core semantic paths usually represent the most intimate and meaningful connections between different clusters, which helps to understand the semantic relationship between different clusters more accurately. Semantic analysis based on core semantic paths can reduce the impact of noise and redundant information, make the analysis results more focused and accurate, and thus improve the accuracy of the overall semantic analysis. Semantic profile refers to the performance or mapping of the original prompt words in different clusters or knowledge domains. By dividing the semantic profile based on the core semantic path, the distribution and association of the original prompt words between different clusters can be more clearly outlined. This division method not only helps to reveal the intrinsic structure and characteristics of the original prompt words, but also provides more clear and useful guidance for subsequent tasks such as semantic reasoning, information retrieval or knowledge mining. The cross-cluster semantic relevance score is an important indicator to measure the degree of semantic association between different clusters. The score calculated based on the core semantic path is more reliable and convincing because it takes into account the path strength and the clarity of the semantic profile. This scoring method can more accurately reflect the actual correlation between the original prompt words in different clusters, and provide more accurate and comprehensive reference information for decision makers or researchers. In large-scale data sets or complex knowledge networks, traditional semantic analysis methods often face problems such as large amount of calculation and slow processing speed. By focusing on the core semantic path for semantic analysis, the amount of calculation can be significantly reduced and the efficiency of information processing can be improved. This optimization effect not only helps to improve the response speed of a single query or task, but also provides a strong guarantee for large-scale data processing and real-time analysis. The following is an example code that implements the process of cross-cluster semantic paths, defines a method to evaluate the strength of these paths, and then identifies the core semantic paths based on these evaluation results, and finally calculates the cross-cluster semantic relevance score based on the core semantic paths:
[0399] import random
[0400] from collections import defaultdict
[0401] # Cross-cluster semantic path (represented by tuples, each tuple contains two cluster labels)
[0402] cross_cluster_paths = [
[0403] ('cluster1', 'cluster2'),
[0404] ('cluster1', 'cluster3'),
[0405] ('cluster2', 'cluster3'),
[0406] ('cluster1', 'cluster4'), # cluster4 is another existing cluster ]
[0408] # Path strength evaluation function
[0409] def evaluate_path_strength(path):
[0410] return random.random()
[0411] # Evaluate the strength of all paths
[0412] path_strengths = {path: evaluate_path_strength(path) for path incross_cluster_paths}
[0413] # Identify the core semantic path
[0414] threshold = 0.5 # Set an intensity threshold
[0415] core_paths = [path for path, strength in path_strengths.items() ifstrength>threshold]
[0416] # Original prompt string
[0417] original_query = "query about some topic"
[0418] # Divide semantic profiles based on core semantic paths
[0419] print("Core Paths:")
[0420] for path in core_paths:
[0421] print(f"Path between {path[0]} and {path[1]}")
[0422] # Calculate cross-cluster semantic relevance scores
[0423] def calculate_cross_cluster_semantic_relevance(core_paths):
[0424] # Returns the linear score of the number of core semantic paths
[0425] return len(core_paths) / len(cross_cluster_paths) if cross_cluster_paths else 0
[0426] relevance_score = calculate_cross_cluster_semantic_relevance(core_paths)
[0427] print(f"Cross-Cluster Semantic Relevance Score: {relevance_score}")
[0428] Optionally, dividing the semantic profile of the original prompt word based on the core semantic path to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value includes:
[0429] Based on the core semantic path, dividing the semantic profile of the original prompt word;
[0430] Perform keyword relevance evaluation based on the semantic profile of the original prompt word to obtain the contribution of the semantic relevance;
[0431] According to the contribution of the semantic association, a cross-cluster semantic relevance score is calculated as a corresponding relevance evaluation value.
[0432] To this end, we evaluate the path strength of cross-cluster semantic paths to identify core semantic paths, and divide the semantic profiles of the original prompt words based on the core semantic paths to calculate the cross-cluster semantic relevance score, which has the following technical benefits:
[0433] By evaluating the strength of cross-cluster semantic paths, the technology can accurately identify those paths that connect different clusters and are the most semantically close and have the most effective information transmission, namely the core semantic paths. These paths not only represent the key flow direction of keywords or concepts between different clusters, but also reflect the core structure and logical relationship in the overall semantic network. Therefore, the identification of core semantic paths provides an important basis for in-depth understanding of the cross-cluster semantic relationship of the original prompt word. Based on the identified core semantic paths, the technology can further divide the semantic profile of the original prompt word. The semantic profile refers to the distribution of the original prompt word in the cross-cluster semantic space, which reflects the distribution characteristics and mutual correlation of the prompt content under different clusters or topics. By dividing the semantic profile, the technology can clearly show how the original prompt word spans multiple clusters to form a complex semantic network, and provide a more comprehensive and detailed perspective for the subsequent relevance scoring. Because the technology combines the two steps of path strength evaluation and semantic profile division, it can more accurately calculate the cross-cluster semantic relevance score. On the one hand, path strength evaluation ensures the accuracy and representativeness of the core semantic path; on the other hand, semantic profile division provides richer and more detailed semantic background information. The combination of the two makes the calculation process of the relevance score more scientific and reasonable, and the results are more accurate and reliable. This technology makes the entire semantic analysis process more transparent and explainable by clearly identifying the core semantic path and dividing the semantic profile. Users can not only obtain the quantitative result of the relevance score, but also understand the semantic structure and logical relationship behind the score. This transparency and explainability helps to improve users' trust and acceptance of the analysis results, and also provides clearer guidance for subsequent decision-making and optimization. An example code is provided below to implement path strength evaluation of cross-cluster semantic paths, identify core semantic paths, and divide the semantic profile of the original prompt words based on the core semantic path to calculate the cross-cluster semantic relevance score:
[0434] import numpy as np
[0435] # List of cross-cluster semantic paths, each path is a list of cluster IDs
[0436] cross_cluster_paths = [
[0437] [0, 1, 2],# Path 1: From cluster 0 to cluster 1 and then to cluster 2
[0438] [0, 3, 2],# Path 2: From cluster 0 to cluster 3 and then to cluster 2
[0439] [1, 3, 4]# Path 3: From cluster 1 to cluster 3 and then to cluster 4 ]
[0441] # Path strength evaluation function
[0442] def evaluate_path_strength(paths):
[0443] # Calculate the length of each path and take the reciprocal as the strength
[0444] path_strengths = [1 / len(path) for path in paths]
[0445] return path_strengths
[0446] # Evaluate path strength
[0447] path_strengths = evaluate_path_strength(cross_cluster_paths)
[0448] # Identify the core semantic path
[0449] core_path_index = np.argmax(path_strengths)
[0450] core_path = cross_cluster_paths[core_path_index]
[0451] # Function to divide semantic contours based on core semantic paths
[0452] # The semantic profile is a dictionary, the key is the cluster ID, and the value is the importance index of the cluster in the core semantic path
[0453] def outline_semantic_contour(core_path):
[0454] contour = {}
[0455] for i, cluster_id in enumerate(reversed(core_path)):
[0456] contour[cluster_id] = i + 1 # Reverse numbering so that clusters closer to the end point have larger numbers
[0457] return contour
[0458] # Divide semantic contours
[0459] semantic_contour = outline_semantic_contour(core_path)
[0460] # Function to calculate cross-cluster semantic relevance score
[0461] # Calculate the score using the number of cluster IDs in the semantic profile and the strength of the core semantic path
[0462] def calculate_cross_cluster_semantic_score(semantic_contour, path_strengths):
[0463] # The score is the product of the number of cluster IDs in the semantic profile and the core semantic path strength
[0464] score = len(semantic_contour) * path_strengths[core_path_index]
[0465] return score
[0466] # Calculate cross-cluster semantic relevance scores
[0467] cross_cluster_semantic_score = calculate_cross_cluster_semantic_score(semantic_contour, path_strengths)
[0468] # Print results
[0469] print(f"Core Semantic Path: {core_path}")
[0470] print(f"Semantic Contour: {semantic_contour}")
[0471] print(f"Cross-Cluster Semantic Score: {cross_cluster_semantic_score}")
[0472] Optionally, the step of using the original prompt word as a key in a key-value pair and the relevance evaluation value as a value in the key-value pair, inputting the original prompt word into a large language model to perform semantic analysis on the original prompt word to obtain a semantic analysis vector, includes:
[0473] Using the original prompt word as a key in a key-value pair and using the relevance evaluation value as a value in the key-value pair, so as to encapsulate the key and the value into a key-value pair;
[0474] The key-value pair is converted into an embedding vector to be input into the large language model for multi-layer semantic perception, so as to perform semantic analysis on the original prompt word to obtain a semantic analysis vector.
[0475] To this end, the original prompt word and the relevance evaluation value are encapsulated as key-value pairs, and these key-value pairs are converted into embedding vectors and input into the large language model for multi-layer semantic perception to obtain the semantic analysis vector of the original prompt word, which has the following technical benefits:
[0476] By encapsulating the original cue words and the relevance evaluation values into key-value pairs, additional contextual information is provided for the semantic analysis process. This contextual information (i.e., relevance evaluation values) reflects the importance or degree of association of the original cue words under different clusters or topics. When the large language model receives these key-value pairs, it can use this information to more accurately understand the semantics of the original cue words, thereby reducing ambiguity and improving accuracy during the semantic analysis process. Since the relevance evaluation value is based on the strength evaluation of the cross-cluster semantic path, it contains information about the position and relationship of the original cue words in the global semantic space. This global information helps the large language model to use the learned knowledge and patterns for reasoning and generalization when dealing with unseen or novel cue words, thereby enhancing the generalization ability of the model. Converting the key-value pairs into embedding vectors and inputting them into the large language model can make full use of the model's multi-layer neural network structure for multi-layer semantic perception. Large language models usually contain multiple processing layers, each of which can capture different levels of semantic information. Through multi-layer semantic perception, the model can more deeply understand the intrinsic meaning and contextual relationship of the original cue words, thereby generating richer and more accurate semantic analysis vectors. Although the introduction of key-value pairs increases the complexity of data processing, it also optimizes the computational process of semantic analysis by providing more targeted information. Since the relevance evaluation value has already screened and sorted the original prompt words to a certain extent, the large language model can focus more on important semantic information when processing these key-value pairs, reducing unnecessary calculations and resource consumption. This technical solution is not only applicable to basic semantic analysis tasks, such as word sense disambiguation, sentiment analysis, etc., but also supports more complex semantic analysis tasks, such as text generation, dialogue systems, etc. In these tasks, the semantic accuracy and contextual understanding ability of the original prompt words are crucial. By combining the relevance evaluation value with the original prompt word, the large language model can generate a response or output that is more in line with the context and semantic logic. In addition, the following provides an exemplary code to realize the encapsulation of the original prompt word and the relevance evaluation value as a key-value pair, and convert these key-value pairs into embedding vectors and input them into the large language model for semantic analysis, etc.:
[0477] from transformers import AutoTokenizer, AutoModel
[0478] import torch
[0479] # Original prompt words and relevance evaluation values
[0480] original_prompt = "A cat under the tree"
[0481] relevance_score = 0.8 # Assume this is a relevance score calculated in some way
[0482] # Convert the relevance evaluation value to a specific token or embedding vector
[0483] input_text = f"{original_prompt}||{relevance_score:.2f}"
[0484] # Load the Tokenizer and Model of the large language model
[0485] # Using AutoTokenizer and AutoModel in the Transformers library, they can automatically load the corresponding Tokenizer and Model according to the model name
[0486] tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased') # Example: Using the base version of BERT
[0487] model = AutoModel.from_pretrained('bert-base-uncased')# Example: Also use the basic version of BERT
[0488] # Convert the input text into tokens that the model can understand
[0489] inputs = tokenizer(input_text, return_tensors="pt", padding=True,truncation=True, max_length=512)
[0490] #Call the model for forward propagation to obtain the semantic analysis vector
[0491] with torch.no_grad():
[0492] outputs = model(**inputs)
[0493] last_hidden_states = outputs.last_hidden_state
[0494] # Since we are only interested in the original prompt word, we can try to extract the corresponding semantic analysis vector from it
[0495] seq_length = torch.sum(inputs['attention_mask'], dim=1)# Calculate the effective sequence length
[0496] pooled_output = last_hidden_states[:, 0, :].unsqueeze(1)# Usually BERT uses the [CLS] tag representation as the representation of the entire sequence, but it is simplified here
[0497] # Or, take the average of all valid tokens
[0498] # pooled_output = torch.sum(last_hidden_states * inputs['attention_mask'].unsqueeze(-1), dim=1) / seq_length.unsqueeze(-1)
[0499] # pooled_output now contains the semantic analysis vector of the original prompt word (and its relevance score)
[0500] print(pooled_output)
[0501] Optionally, the converting the key-value pair into an embedding vector to be input into the large language model for multi-layer semantic perception, so as to perform semantic analysis on the original prompt word to obtain a semantic analysis vector, comprises:
[0502] Converting the key-value pairs into embedding vectors to be input into the large language model for multi-layer semantic perception to determine the semantic association distribution characteristics of the characters in the original prompt word;
[0503] Determining the original prompt word context embedding based on the semantic association distribution feature to perform context semantic dependency analysis on the context embedding;
[0504] Multi-head attention analysis is performed on the result of the contextual semantic dependency analysis to generate the semantic analysis vector.
[0505] To this end, the key-value pairs are converted into embedding vectors and input into a large language model for multi-layer semantic perception to determine the semantic association distribution characteristics of the characters in the original prompt words, and further generate semantic analysis vectors through context embedding and context semantic dependency analysis, as well as multi-head attention analysis, which has the following technical benefits:
[0506] By converting the key-value pairs (original prompt words and relevance evaluation values) into embedding vectors, rich contextual information (including the semantic importance contained in the relevance evaluation values) can be effectively passed to the large language model. In the process of multi-layer semantic perception, the model can deeply explore the semantic association distribution characteristics between characters in the original prompt words. These characteristics not only cover the direct relationship between words, but also involve a wider semantic network and contextual dependency. This enhancement in depth and breadth makes the model's understanding of the original prompt words more comprehensive and accurate. The context embedding of the original prompt word determined based on the semantic association distribution characteristics provides a solid foundation for contextual semantic dependency analysis. Context embedding can capture the changes of the original prompt word in different contexts, thereby more accurately reflecting its semantic connotation. By performing semantic dependency analysis on the context embedding, the model can identify the complex relationship between the original prompt word and the surrounding text, such as causal relationship, parallel relationship, transition relationship, etc. This improvement in accuracy helps the model to be closer to the actual semantics when generating semantic analysis vectors. Multi-head attention analysis is an important technology in the field of natural language processing in recent years. It can simultaneously focus on multiple positions in the input sequence to capture richer semantic information. In this solution, by performing multi-head attention analysis on the results of contextual semantic dependency analysis, the model can further refine and integrate the semantic features of the original prompt words and generate more accurate and rich semantic analysis vectors. This optimization not only improves the efficiency of the multi-head attention mechanism, but also significantly enhances its effect, making the model more capable of handling complex semantic relationships. Since the technical solution has improved the depth, breadth and accuracy of semantic understanding, it can support more advanced semantic analysis tasks. For example, in scenarios such as text generation, question-answering systems, and sentiment analysis, the technical solution can generate more accurate and contextual semantic analysis vectors, thereby providing strong support for subsequent task processing. In addition, the technical solution also has strong scalability and adaptability, and can be flexibly adjusted and optimized according to the needs of different tasks. By introducing relevance evaluation values and multi-layer semantic perception mechanisms, the technical solution enables large language models to use learned knowledge and patterns for reasoning and generalization when processing unseen or novel original prompt words. At the same time, because the model fully considers the influence of contextual semantic dependencies and multi-head attention mechanism when generating semantic analysis vectors, its output results are more stable and reliable, which improves the robustness of the model. In addition, an exemplary code is provided as follows to convert key-value pairs (original prompt words and relevance evaluation values) into embedding vectors and input them into the large language model for multi-layer semantic perception to generate semantic analysis vectors:
[0507] import torch
[0508] import torch.nn as nn
[0509] import torch.nn.functional as F
[0510] # Large Language Model
[0511] class LargeLanguageModel(nn.Module):
[0512] def __init__(self, embedding_dim, hidden_dim, num_layers, num_heads):
[0513] super(LargeLanguageModel, self).__init__()
[0514] self.embedding = nn.Embedding(num_embeddings=10000, embedding_dim=embedding_dim) # Vocabulary size is 10000
[0515] self.lstm = nn.LSTM(embedding_dim, hidden_dim, num_layers=num_layers,batch_first=True)
[0516] self.self_attention = nn.MultiheadAttention(embedding_dim, num_heads)
[0517] self.fc = nn.Linear(hidden_dim, embedding_dim)
[0518] def forward(self, x):
[0519] # x is already an embedded vector sequence, and position encoding has been added
[0520] lstm_out, _ = self.lstm(x)
[0521] # Only take the last hidden state of LSTM as the input of multi-head attention
[0522] attention_out, _ = self.self_attention(lstm_out[:, -1:, :].unsqueeze(1), lstm_out[:, -1:, :].unsqueeze(1), lstm_out[:, -1:, :].unsqueeze(1))
[0523] # Directly take the output of multi-head attention as the semantic analysis vector
[0524] semantic_vector = self.fc(attention_out.squeeze(1))
[0525] return semantic_vector
[0526] # Original prompt words and relevance evaluation values
[0527] original_prompt = "A cat under the tree"
[0528] # Convert the relevance evaluation value to an embedding vector
[0529] relevance_embedding = torch.randn(1, 1, 100) # The dimension of the embedding vector is 100
[0530] # Function to convert text into embedded vector (here using Embedding layer)
[0531] tokenizer = lambda x: torch.tensor([1, 2, 3, 4, 5])
[0532] prompt_embedding = tokenizer(original_prompt).unsqueeze(0) # Embedding vector, dimension is [batch_size, seq_len, embedding_dim]
[0533] combined_embedding = torch.cat([prompt_embedding, relevance_embedding], dim=2)
[0534] model_input = prompt_embedding# Use the embedding vector of the original prompt word as the model input
[0535] # Create a model instance
[0536] model = LargeLanguageModel(embedding_dim=100, hidden_dim=256, num_layers=2, num_heads=8)
[0537] Optionally, generating a new prompt word based on the semantic analysis vector and the relevance evaluation value includes:
[0538] The relevance evaluation value is discretized to obtain a discrete vector, and the discrete vector is fused with a semantic analysis component to generate a new prompt word.
[0539] To this end, the relevance evaluation value is discretized to obtain a discrete vector, and then fused with the semantic analysis vector to generate a new prompt word, etc., which has the following technical benefits:
[0540] By discretizing the relevance evaluation value, the original, possibly broad or vague relevance evaluation can be converted into a specific, easy-to-operate discrete vector. This discrete vector can more accurately reflect the importance or relevance of different prompt word elements or features. Subsequently, these discrete vectors are fused with the semantic analysis vector to ensure that when generating new prompt words, the semantic importance and relevance of each element in the original prompt word are fully considered. The new prompt words generated in this way will be more targeted and accurate, and can better meet user needs or adapt to specific scenarios. The semantic analysis vector is obtained by performing multi-layer semantic perception and contextual semantic dependency analysis on the original prompt word, and it contains rich semantic information and contextual relationships. Fusion of the discretized relevance evaluation value with the semantic analysis vector can ensure that the newly generated prompt word maintains semantic coherence and consistency. This coherence and consistency is not only reflected in the relationship between the various elements within the prompt word, but also in the association between the prompt word and the external text or context. This helps to improve the user experience and the overall performance of the system. Since the relevance evaluation value can be adjusted dynamically, the generation result of the new prompt word can be flexibly adjusted by changing these values. This dynamic adjustment capability enables the technical solution to adapt to the changing needs of different users or different scenarios. At the same time, combined with the user's historical behavior, preferences and other information, the personalized customization of new prompt words can also be achieved. This personalized customization can not only improve user satisfaction and loyalty, but also create more commercial value for enterprises or organizations. The technical solution of combining relevance evaluation values with semantic analysis vectors to generate new prompt words is an important manifestation of the intelligent development in the field of natural language processing. It makes full use of the advantages of advanced technologies such as machine learning and deep learning to achieve in-depth understanding and precise analysis of the original prompt words. By continuously optimizing the algorithm and model structure, the intelligence level of the system can be further improved, so that it can show stronger capabilities and advantages in processing complex semantic relationships and generating high-quality prompt words. In addition, an exemplary code is provided as follows to implement the process of generating new prompt words based on semantic analysis vectors and discretized relevance evaluation values:
[0541] import torch
[0542] # Semantic analysis vector
[0543] semantic_vector = torch.randn(1, 100)#The dimension of semantic analysis vector is 100
[0544] # Correlation evaluation value
[0545] relevance_score = 0.8# relevance evaluation value
[0546] # Discretization
[0547] discrete_relevance = torch.tensor([[1 if relevance_score>0.5 else0]])# Discrete into a two-dimensional tensor
[0548] # Fusion semantic analysis vector and discretized correlation evaluation value
[0549] # Copy or expand discrete_relevance to the same dimension as semantic_vector
[0550] expanded_discrete_relevance = discrete_relevance.expand_as(semantic_vector).float() * relevance_score
[0551] fused_vector = semantic_vector + expanded_discrete_relevance
[0552] # Generate new prompt words based on the fused vector
[0553] def generate_new_prompt(fused_vector):
[0554] return "Optimized new prompt word"
[0555] # Generate new prompt words
[0556] new_prompt = generate_new_prompt(fused_vector)
[0557] print(new_prompt)
[0558] Optionally, the discretizing the relevance evaluation value to obtain a discrete vector, and fusing the discrete vector with a semantic analysis component to generate a new prompt word, includes:
[0559] Discretizing the correlation evaluation value to obtain a plurality of discrete labels, encoding each discrete label to obtain a discrete label code, so as to form a discrete label code vector;
[0560] The discrete label encoding vector is fused with the semantic analysis component to generate a new prompt word.
[0561] To this end, the relevance evaluation value is discretized to obtain discrete labels, and each discrete label is encoded to form a discrete label encoding vector, which is then fused with the semantic analysis component to generate a new prompt word, which has the following technical benefits:
[0562] 1. By discretizing the correlation evaluation value into several discrete labels, the correlation between different elements or features can be expressed in a more intuitive and easier to understand way. This discretization not only simplifies the subsequent processing flow, but also enables the system to more flexibly respond to changes in correlation in different scenarios. At the same time, encoding each discrete label can further convert the discretized information into a numerical form that can be understood by the machine, which facilitates the subsequent fusion and generation process.
[0563] The fusion of discrete label encoding vectors and semantic analysis components ensures that the newly generated prompt words can fully consider the correlation between elements while retaining the original semantic information. This fusion method can capture the intrinsic connection and interaction between different elements, thereby generating more accurate prompt words that better meet user needs. For example, in the text summarization task, by fusing discrete label encoding vectors and semantic analysis components, a summary that summarizes the main content of the original text and highlights the key information can be generated. Since the discrete label encoding vector provides rich correlation information, and this information can be fused with the semantic analysis component in different ways, this technical solution supports the generation of diversified prompt words. By adjusting the fusion strategy and parameter settings, prompt words of different styles and lengths can be generated to meet the needs of different users or different scenarios. This diversified generation capability not only improves the user experience, but also broadens the application scope of the system. The discretization process makes the correlation evaluation value intuitive and understandable, and the introduction of discrete label encoding vectors further enhances the interpretability of the system. By looking at the fusion process of discrete label encoding vectors and semantic analysis components, we can better understand how the system generates new prompt words based on the input information. In addition, since the discrete labels are configurable, the system also has a certain degree of controllability. By adjusting the set and encoding method of the discrete labels, the process of the system generating prompt words can be intervened and controlled to a certain extent. In addition, the following also provides an exemplary code to realize the process of discretizing and encoding the relevance evaluation value, and fusing the generated discrete label encoding vector with the semantic analysis component:
[0564] import numpy as np
[0565] # List of relevance evaluation values
[0566] relevance_scores = [0.1, 0.9, 0.4, 0.7]# Relevance evaluation value
[0567] # Discretization
[0568] def discretize(scores, threshold=0.5):
[0569] return [1 if score>threshold else 0 for score in scores]
[0570] # Discrete labels
[0571] discrete_labels = discretize(relevance_scores)
[0572] # Encoding process: Convert discrete labels to one-hot encoding to form discrete label encoding vectors
[0573] def one_hot_encode(labels, num_classes=2):
[0574] one_hot = np.zeros((len(labels), num_classes))
[0575] one_hot[np.arange(len(labels)), labels] = 1
[0576] return one_hot
[0577] discrete_label_encodings = one_hot_encode(discrete_labels, num_classes=2)
[0578] # Semantic analysis component
[0579] semantic_components = np.random.randn(1, 4)
[0580] # Fusion of discrete label encoding vector and semantic analysis component
[0581] fused_vector = np.concatenate([np.tile(semantic_components,(discrete_label_encodings.shape[0], 1)), discrete_label_encodings], axis=1)
[0582] # Generate new prompt words based on the fused vector
[0583] def generate_new_prompt(fused_vector):
[0584] return "An example of a prompt word generated based on the fused vector"
[0585] # Generate new prompt words
[0586] new_prompt = generate_new_prompt(fused_vector)
[0587] print(new_prompt)
[0588] Optionally, the discretization processing of the correlation evaluation value to obtain a plurality of discrete labels, encoding processing of each discrete label to obtain a discrete label code to form a discrete label code vector includes:
[0589] Calculating the global relevance of each character in the original prompt word with the query target;
[0590] Based on the size of the global correlation corresponding to each character, a corresponding discrete degree weight is assigned to discretize the correlation evaluation value to obtain a plurality of discrete labels;
[0591] Based on a preset embedding table, each discrete label is mapped into a low-dimensional continuous vector control to encode the discrete label to obtain a discrete label code, so as to form a discrete label code vector.
[0592] To this end, the global correlation between each character in the original prompt word and the query target is calculated, and discretization and encoding are performed based on these correlations to finally generate a discrete label encoding vector, which has the following technical benefits:
[0593] By calculating the global correlation between each character in the original prompt word and the query target, the scheme can more comprehensively capture the overall connection between the prompt word and the query target. This global correlation perception ability helps to more accurately evaluate the importance of different parts of the prompt word to the query target, thereby providing a richer and more accurate information basis for subsequent processing. Based on the size of the global correlation corresponding to each character, the corresponding discrete degree weight is assigned and discretization is performed, which can make the discretization process more refined and personalized. Different characters are assigned different discrete labels according to the size of their correlation with the query target. This differentiated processing helps to better reflect the differences and importance between characters and provide more valuable input for subsequent encoding and fusion processes. Discrete labels are mapped to low-dimensional continuous vector space through a preset embedding table, realizing efficient encoding processing of discrete labels. This low-dimensional representation not only reduces data redundancy and computational complexity, but also makes discrete label encoding vectors easier to be processed and understood by subsequent neural network models. In addition, the preset embedding table can also be tuned and updated according to specific tasks to adapt to different application scenarios and data distributions. By fusing the discrete label encoding vector with the semantic analysis component, we can make full use of the character-level relevance information contained in the discrete label encoding vector and the contextual semantic information contained in the semantic analysis component. This fusion method can generate more accurate prompt words that are more in line with the user's query intention. At the same time, since the discrete label encoding vector contains character-level relevance information, the generated prompt words can better highlight key information and key points while maintaining overall semantic coherence. 5. The discretization process makes the original relevance evaluation value intuitive and understandable, and the encoding process based on the preset embedding table further enhances the interpretability of the system. By looking at the discrete labels and the corresponding encoding vectors, we can better understand how the system generates new prompt words based on the input information. In addition, since both the discrete labels and the embedding table are configurable, the system also has a certain degree of controllability. By adjusting the discretization strategy and the embedding table parameters, the process of generating prompt words by the system can be intervened and controlled to a certain extent.
[0594] The following is an exemplary code to implement the above steps of calculating global correlation, performing discretization, and encoding based on a preset embedding table to generate a discrete label encoding vector:
[0595] import numpy as np
[0596] # Original prompt words and query targets
[0597] original_prompt = "this is an example prompt"
[0598] query_target = "example"
[0599] # Simulate global correlation calculation
[0600] def calculate_global_relevance(prompt, target):
[0601] # If the character appears in the query target, the relevance is 1, otherwise it is 0
[0602] relevance_scores = [int(char in target) for char in prompt]
[0603] return relevance_scores
[0604] # Global relevance of each character in the original prompt word to the query target
[0605] global_relevance = calculate_global_relevance(original_prompt, query_target)
[0606] # Discretization: Assign discreteness weights based on the size of global correlation
[0607] def discretize_with_weights(relevance_scores, threshold=0.5):
[0608] return [1 if score>threshold else 0 for score in relevance_scores]
[0609] # Discrete labels
[0610] discrete_labels = discretize_with_weights(global_relevance)
[0611] # Pre-built embedding table
[0612] # There are two discrete labels (0 and 1), each label is mapped to a two-dimensional vector
[0613] embedding_table = np.random.randn(2, 2) # 2 labels, each label 2 dimensions
[0614] # Map discrete labels into low-dimensional continuous vectors
[0615] def encode_discrete_labels(discrete_labels, embedding_table):
[0616] # Get the corresponding vector from the embedding table based on the discrete label index
[0617] return embedding_table[discrete_labels]
[0618] # Discrete label encoding vector
[0619] discrete_label_encodings = encode_discrete_labels(np.array(discrete_labels), embedding_table)
[0620] # The shape of the discrete label encoding vector should be (prompt word length, embedding vector dimension)
[0621] print("Shape of discrete label encoding vector:", discrete_label_encodings.shape)
[0622] semantic_component = np.random.randn(1, 4)
[0623] The present application embodiment provides a prompt word optimization device combining expert evaluation rules and a large language model, which includes:
[0624] A first processing unit, used for obtaining an expert evaluation rule description vector;
[0625] A second processing unit is used to perform keyword relevance evaluation on the input original prompt word based on the expert evaluation rule description vector to obtain a corresponding relevance evaluation value;
[0626] A third processing unit is used to use the original prompt word as a key in a key-value pair and the relevance evaluation value as a value in the key-value pair, and input them into a large language model to perform semantic analysis on the original prompt word to obtain a semantic analysis vector;
[0627] The fourth processing unit is used to generate a new prompt word based on the semantic analysis vector and the relevance evaluation value.
[0628] For an exemplary description of each unit in the above device, please refer to the above Figure 1Records of.
[0629] An embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory stores a computer executable program, and the processor is used to run the computer executable program to implement the method described in any embodiment of the present application.
[0630] 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 prompt word optimization method combining expert evaluation rules and a large language model, characterized in that: include: Obtain expert evaluation rule description vector; Based on the expert evaluation rule description vector, a keyword relevance evaluation is performed on the input original prompt word to obtain a corresponding relevance evaluation value; The original prompt word is used as a key in a key-value pair, and the relevance evaluation value is used as a value in the key-value pair, and is input into a large language model to perform semantic analysis on the original prompt word to obtain a semantic analysis vector; Generate a new prompt word based on the semantic analysis vector and the relevance evaluation value; Wherein, the obtaining of the expert evaluation rule description vector, before, includes: obtaining an expert evaluation rule description table, and vectorizing the expert evaluation rule description table to obtain the expert evaluation rule description vector; The step of obtaining an expert evaluation rule description table and vectorizing the expert evaluation rule description table to obtain an expert evaluation rule description vector includes: obtaining an expert evaluation rule description table and performing discrete representation and distributed representation analysis on the expert evaluation rule description table to obtain a bag-of-words mapping representation, and vectorizing the bag-of-words mapping representation to obtain the expert evaluation rule description vector.
2. The method for optimizing prompt words by combining expert evaluation rules and a large language model according to claim 1, characterized in that: Based on the expert evaluation rule description vector, the keyword relevance evaluation is performed on the input original prompt word to obtain the corresponding relevance evaluation value, including: Based on the expert evaluation rule description vector, the semantic association and fuzzy clustering analysis of the input original prompt word is performed to obtain a modal semantic association and fuzzy clustering analysis framework; Calculating the semantically enhanced co-occurrence association measure of the modal semantic association and the fuzzy cluster analysis framework; Performing keyword relevance evaluation on the input original prompt word based on the semantically enhanced co-occurrence association metric, and assigning a cross-cluster semantic relevance score to the original prompt word as a corresponding relevance evaluation value; The semantic association and fuzzy clustering analysis of the input original prompt words based on the expert evaluation rule description vector to obtain a modal semantic association and fuzzy clustering analysis framework includes: Based on the expert evaluation rule description vector, the semantic association and fuzzy clustering analysis of the input original prompt word are performed to obtain the corresponding modal semantic association and fuzzy clustering membership; Based on fuzzy C-means clustering, a fuzzy contribution matrix is generated for the modal semantic association and fuzzy clustering membership; Semantic clustering instantiation is performed according to the fuzzy contribution matrix to generate the modal semantic association and fuzzy clustering analysis framework.
3. The method for optimizing prompt words by combining expert evaluation rules and a large language model according to claim 2, characterized in that: Calculating the semantically enhanced co-occurrence association measure of the modal semantic association and the fuzzy cluster analysis framework includes: Associating the modal semantics with a semantically weighted co-occurrence matrix of a fuzzy cluster analysis framework; Based on the semantic weighted co-occurrence matrix, calculating the cross-modal semantic consistency between different characters of the original prompt word; According to the cross-modal semantic consistency, the modal semantic association and the semantic reinforcement co-occurrence association measure of the fuzzy cluster analysis framework are calculated.
4. The method for optimizing prompt words by combining expert evaluation rules and a large language model according to claim 2, characterized in that: The step of performing keyword relevance evaluation on the input original prompt word based on the semantically enhanced co-occurrence association metric and assigning a cross-cluster semantic relevance score to the original prompt word as a corresponding relevance evaluation value includes: Performing multi-scale mapping on the semantically enhanced co-occurrence association metric to obtain a multi-scale semantic association tensor; Based on the multi-scale semantic association tensor, keyword relevance evaluation is performed on the input original prompt word, and a cross-cluster semantic relevance score is assigned to the original prompt word as a corresponding relevance evaluation value.
5. The method for optimizing prompt words by combining expert evaluation rules and a large language model according to claim 4, characterized in that: The step of performing keyword relevance evaluation on the input original prompt word based on the multi-scale semantic association tensor and assigning a cross-cluster semantic relevance score to the original prompt word as a corresponding relevance evaluation value includes: Performing multi-scale decomposition on the multi-scale semantic association tensor to obtain a plurality of feature subsets; Based on the several feature subsets, a cross-cluster semantic analysis is performed on the input original prompt word to obtain a cross-cluster semantic path to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value.
6. The method for optimizing prompt words by combining expert evaluation rules and a large language model according to claim 5, characterized in that: The step of performing cross-cluster semantic analysis on the input original prompt words based on the plurality of feature subsets to obtain a cross-cluster semantic path to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value includes: Based on the plurality of feature subsets, cross-cluster semantic analysis is performed on the input original prompt word to obtain a cross-cluster semantic path; A path strength evaluation is performed on the cross-cluster semantic path to identify a core semantic path therein to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value.
7. The method for optimizing prompt words by combining expert evaluation rules and a large language model according to claim 6, characterized in that: The performing path strength evaluation on the cross-cluster semantic path to identify the core semantic path therein to calculate the cross-cluster semantic relevance score as the corresponding relevance evaluation value includes: Performing path strength evaluation on the cross-cluster semantic paths to identify core semantic paths therein; Based on the core semantic path, the semantic profile of the original prompt word is divided to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value.
8. The method for optimizing prompt words by combining expert evaluation rules and a large language model according to claim 7, characterized in that: The step of dividing the semantic profile of the original prompt word based on the core semantic path to calculate a cross-cluster semantic relevance score as a corresponding relevance evaluation value includes: Based on the core semantic path, dividing the semantic profile of the original prompt word; Perform keyword relevance evaluation based on the semantic profile of the original prompt word to obtain the contribution of the semantic relevance; According to the contribution of the semantic association, a cross-cluster semantic relevance score is calculated as a corresponding relevance evaluation value.
9. The method for optimizing prompt words by combining expert evaluation rules and a large language model according to claim 1, characterized in that: The step of using the original prompt word as the key in a key-value pair and the relevance evaluation value as the value in the key-value pair, and inputting the original prompt word into a large language model to perform semantic analysis on the original prompt word to obtain a semantic analysis vector comprises: Using the original prompt word as a key in a key-value pair and using the relevance evaluation value as a value in the key-value pair, so as to encapsulate the key and the value into a key-value pair; The key-value pair is converted into an embedding vector to be input into the large language model for multi-layer semantic perception, so as to perform semantic analysis on the original prompt word to obtain a semantic analysis vector.
10. The method for optimizing prompt words by combining expert evaluation rules and a large language model according to claim 1, characterized in that: The generating a new prompt word based on the semantic analysis vector and the relevance evaluation value comprises: Discretizing the relevance evaluation value to obtain a discrete vector, and fusing the discrete vector with a semantic analysis component to generate a new prompt word; The step of discretizing the correlation evaluation value to obtain a discrete vector, and fusing the discrete vector with a semantic analysis component to generate a new prompt word includes: Discretizing the correlation evaluation value to obtain a plurality of discrete labels, encoding each discrete label to obtain a discrete label code, so as to form a discrete label code vector; fusing the discrete label encoding vector with the semantic analysis component to generate a new prompt word; The discretization process of the correlation evaluation value to obtain a plurality of discrete labels, and the encoding process of each discrete label to obtain a discrete label code to form a discrete label code vector includes: Calculating the global relevance of each character in the original prompt word with the query target; Based on the size of the global correlation corresponding to each character, a corresponding discrete degree weight is assigned to discretize the correlation evaluation value to obtain a plurality of discrete labels; Based on a preset embedding table, each discrete label is mapped into a low-dimensional continuous vector control to encode the discrete label to obtain a discrete label code, so as to form a discrete label code vector.
Citation Information
Patent Citations
Prompt information generation method and device, electronic equipment and storage medium
CN116484879A
Prompt word full life cycle management method and system, electronic equipment and storage medium
CN117494814A