Text prompt generation method and system and computer program product
Through deep semantic analysis and feature optimization generation, the problem of insufficient flexibility and adaptability of the Prompt generation method in the prior art is solved, and efficient excitation of large models and adaptation to complex scenarios is achieved.
Patent Information
- Application Number
- CN202510512948.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-08-01
AI Technical Summary
The Prompt generation method in the prior art lacks flexibility and adaptability, it is difficult to fully tap potential information in text training data, and it is unable to effectively stimulate the emergence of large models' capabilities.
Through deep semantic analysis of text training data, a semantic relationship network is constructed, key features such as semantic dynamics, context adaptability and emotional tendency are extracted, and the initial Prompt is optimized based on these features to generate the target Prompt.
The generated Prompt is highly adaptable and flexible, able to meet the needs of complex language scenarios and diverse tasks, and stimulate the emergence of large models.
Smart Images

Figure CN120409493A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of large models, and in particular, to a method, system, and computer program product for generating text prompts. Background Art
[0002] In related technologies, large models are increasingly widely used in fields such as natural language processing. However, there are many deficiencies in the existing methods for generating prompts (Prompts). The publicly disclosed conventional methods are usually relatively simple, making it difficult to fully explore the potential information in text training data and unable to effectively stimulate the emergence of the capabilities of large models. For example, some methods only rely on fixed templates or rules, lacking flexibility and adaptability; while other methods, although considering some text features, are not comprehensive and in-depth enough, resulting in limited effects of the generated Prompts. Summary of the Invention
[0003] Embodiments of this application provide a method, system, and computer program product for generating text prompts to solve the problem of the limitations of existing methods for generating Prompts.
[0004] In a first aspect, embodiments of this application provide a method for generating text prompts, including: Obtaining text training data; Performing in-depth semantic analysis on the text training data to determine the semantic relationships of the text training data, where the semantic relationships include the semantic relationship network between words in the text training data and the theme corresponding to the text training data; For any text data, based on the semantic relationships, extracting key features in the text data, where the key features include semantic dynamics, context adaptability, and sentiment tendency; Based on the semantic dynamics, the context adaptability, and the sentiment tendency, optimizing an initial prompt to generate a target prompt, where the initial prompt is determined based on task requirements.
[0005] In a second aspect, embodiments of this application provide a system for generating text prompts, including: An obtaining module, configured to obtain text training data; An analysis module, configured to perform in-depth semantic analysis on the text training data to determine the semantic relationships of the text training data, where the semantic relationships include the semantic relationship network between words in the text training data and the theme corresponding to the text training data; An extraction module, configured to, for any text data, based on the semantic relationships, extract key features in the text data, where the key features include semantic dynamics, context adaptability, and sentiment tendency; A generation module, configured to optimize an initial prompt based on the semantic dynamics, the context adaptability, and the sentiment tendency degree to generate a target prompt, where the initial prompt is determined based on task requirements.
[0006] In a third aspect, an embodiment of the present application provides an electronic device, including a processor, a memory, and a program or instruction stored on the memory and executable on the processor. When the program or instruction is executed by the processor, the steps of the method described in the first aspect are implemented.
[0007] In a fourth aspect, an embodiment of the present application provides a computer program product. The computer program product includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the steps of the method described in the first aspect are implemented.
[0008] In the embodiment of the present application, first, text training data is obtained. Secondly, in-depth semantic analysis is performed on the text training data to determine the semantic relationships of the text training data. The semantic relationships include the semantic relationship network between words in the text training data and the theme corresponding to the text training data. Then, for any text data, based on the semantic relationships, key features in the text data are extracted. The key features include semantic dynamics, context adaptability, and sentiment tendency degree. Finally, based on the semantic dynamics, context adaptability, and sentiment tendency degree, the initial prompt is optimized to generate a target prompt, where the initial prompt is determined based on task requirements. The present application deeply mines the potential information of the text data, provides rich semantic understanding for subsequent feature extraction and prompt generation, extracts key features according to different task requirements, provides a feature basis for generating accurate and highly adaptable prompts, and through continuous optimization, makes the finally generated prompt meet complex language scenarios and diverse task requirements, and has high adaptability and flexibility. Description of the Drawings
[0009] The drawings described herein are used to provide a further understanding of the present application, and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application, and do not constitute an improper limitation to the present application. In the drawings: Figure 1 is a flowchart of the text prompt generation method provided by the embodiment of the present application; Figure 2 is a detailed flowchart of the text prompt generation method provided by the embodiment of the present application; Figure 3 is a flowchart of the evaluation method provided by the embodiment of the present application; Figure 4It is a schematic diagram of the text prompt generation system provided by an embodiment of the present application; Figure 5 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0010] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, rather than all, of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0011] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein. In addition, "and / or" in the specification and claims means at least one of the connected objects, and the character " / " generally indicates an "or" relationship between the associated objects before and after.
[0012] Next, in conjunction with the attached Figures 1 to 5 drawings, a text prompt generation method, system, and computer program product provided by an embodiment of the present application will be described in detail through specific embodiments and their application scenarios. The embodiments of the present application can deeply mine text training data, generate Prompts with powerful emergent excitation capabilities, form a sharp contrast with existing methods, overcome the limitations of existing methods, and meet the requirements of complex language scenarios and diverse tasks.
[0013] As Figure 1 shown, it is a flowchart of a text prompt generation method provided by an embodiment of the present application. As Figure 1 shown, the text prompt generation method may include the content shown in S101 to S104.
[0014] In S101, text training data is obtained.
[0015] In this embodiment, a large amount of raw text data can be collected from various data sources and operations such as screening and duplicate removal can be performed to ensure the quality, uniqueness, and relevance of the data, improve the pertinence of the data, and provide good basic data for the entire system.
[0016] Among them, the text training data may include academic papers, news reports, literary works, technical documents, etc., and may also include other types of data, subject to actual applications, and this embodiment does not make limitations.
[0017] Furthermore, intelligent screening algorithms can be used to remove low-quality, duplicate, or irrelevant data, ensuring the high quality and diversity of the data, as Figure 2 shown. The purpose is to provide a rich and reliable data source for subsequent processing.
[0018] In S102, in-depth semantic analysis is performed on the text training data to determine the semantic relationships of the text training data. The semantic relationships include the semantic relationship network between words in the text training data and the topics corresponding to the text training data.
[0019] In this embodiment, the text data screened in the data collection stage is received, and through various technical means, the semantic information of the text data is deeply mined, a semantic vector space is constructed, potential topics are mined, and the semantic relationship network is analyzed to provide richer semantic understanding for subsequent feature extraction and prompt generation.
[0020] In S103, for any text data, based on the semantic relationship, the key features in the text data are extracted. The key features include semantic dynamics, context adaptability, and sentiment tendency.
[0021] In this embodiment, based on the results of in-depth semantic analysis, key features are dynamically extracted, including semantic dynamics, context adaptability, and sentiment tendency, providing a feature basis for generating more accurate and adaptable prompts.
[0022] In S104, based on semantic dynamics, context adaptability, and sentiment tendency, the initial prompt is optimized to generate the target prompt. The initial prompt is determined based on the task requirements.
[0023] In this embodiment, it is selected according to the task requirements and application scenarios, an initial prompt seed is defined, and then the extracted features and innovative iterative algorithms are used to continuously generate and optimize the prompt to meet different task requirements and stimulate the emergence of the capabilities of the large model.
[0024] In the embodiments of the present application, first, text training data is obtained. Secondly, deep semantic analysis is performed on the text training data to determine the semantic relationships of the text training data. The semantic relationships include the semantic relationship network between the words in the text training data and the theme corresponding to the text training data. Then, for any text data, based on the semantic relationships, key features in the text data are extracted. The key features include semantic dynamics, context adaptability, and sentiment tendency. Finally, based on the semantic dynamics, context adaptability, and sentiment tendency, the initial prompt is optimized to generate the target prompt. The initial prompt is determined based on the task requirements. By deeply mining the potential information of the text data, the present application provides rich semantic understanding for subsequent feature extraction and prompt generation, extracts key features according to different task requirements, provides a feature basis for generating accurate and highly adaptable prompts, and through continuous optimization, makes the finally generated prompt meet complex language scenarios and diverse task requirements, with high adaptability and flexibility.
[0025] In a possible implementation manner of the present application, performing deep semantic analysis on the text training data to determine the semantic relationships of the text training data may include: performing deep semantic analysis on the text training data, mapping the words in the text training data to a semantic vector space, and constructing the semantic vector space; by analyzing the text training data, mining the themes in the text training data, and determining the theme to which each text data belongs; based on the similarity between the words in the text training data, constructing a semantic relationship network between the words. The semantic relationship network represents the association strength and semantic hierarchical structure between the words in the text training data.
[0026] This embodiment uses deep learning algorithms and semantic analysis techniques to deeply analyze the text training data, construct a semantic vector space, mine potential themes, and analyze the semantic relationship network, providing richer semantic understanding for subsequent feature extraction and prompt generation.
[0027] In a possible implementation manner of the present application, performing deep semantic analysis on the text training data, mapping the words in the text training data to a semantic vector space, and constructing the semantic vector space may include: for each word in the text training data, representing it with a multi-dimensional vector to obtain a matrix corresponding to the text training data. The matrix is a matrix composed of the number of words and the multi-dimensional vectors; mapping each word to the vector space through a deep learning model to obtain the corresponding vector representation; performing dimensionality reduction processing on the matrix to obtain the semantic vector space.
[0028] In this embodiment, it is assumed that the text consists of N words, each word can be represented by a D-dimensional vector, and the entire text can be represented as an N×D matrix X. Each word is mapped into the vector space through the deep learning model Word2Vec to obtain the corresponding vector representation. Then, dimensionality reduction processing is performed on the matrix X. Using the principal components analysis (PCA) algorithm, it is reduced to a semantic vector space with a lower dimension. Let the dimensionality-reduced semantic vector space be V with a dimension of M. Then, for each word in the text , its representation in the semantic vector space is .
[0029] In a possible implementation manner of this application, by analyzing the text training data, mining the topics in the text training data, and determining the topic to which each text data belongs, it may include: mining the topics in the text training data based on the LDA document topic generation model, where each topic represents a word distribution; through training the text training data, obtaining the distribution of each text data on each topic and the word distribution under each topic.
[0030] In this embodiment, through the topic model algorithm Latent Dirichlet Allocation (LDA), the latent topics in the text data are discovered. It is assumed that there are T topics in the text set, and each topic can be represented as a word distribution. The LDA model assumes that the words in the text are generated by mixing multiple latent topics, and each topic is again a word distribution. By training the text set, the distribution of each text on each topic and the word distribution under each topic can be obtained. Let the distribution of text d on topic t be , and the distribution of word w under topic t be .
[0031] In an example, analyzing the semantic relationship network may specifically be: constructing a semantic relationship network between words, analyzing the association strength and semantic hierarchical structure between words, and using Neo4j, taking the words in the text as nodes and the semantic relationships between words as edges to construct a semantic relationship network. Let the semantic relationship strength between words and be , which can be determined by calculating the similarity between word vectors, using the cosine similarity .
[0032] In a possible implementation manner of the present application, for any text data, based on semantic relationships, extracting key features from the text data may include: for any text data, based on the change trend of the semantic similarity between adjacent segments in the text data, determining the semantic dynamics of the text data, where the semantic dynamics is used to characterize the change trend and dynamic features of the semantics in the text data; for each word in the text data, based on the frequency of the word appearing in the topic and the association strength of the word with other words in the semantic relationship network, determining the context adaptability of each word; performing sentiment analysis on the text data to determine the sentiment tendency degree of the text data, where the sentiment tendency degree includes positive sentiment, negative sentiment, and neutral sentiment.
[0033] In this embodiment, key features are dynamically extracted according to different task requirements and text characteristics.
[0034] Among them, semantic dynamics: measures the change trend and dynamic features of the semantics in the text. First, the text is segmented into multiple segments according to chronological or logical order. Then, for each segment, its semantic vector representation is calculated. Next, the cosine similarity metric method is used to calculate the semantic vector similarity between adjacent segments. Finally, by analyzing the change trend of the similarity, the semantic dynamics index is determined. Suppose the text segments and have semantic vectors and respectively, and the similarity between them is . The semantic dynamics index can be defined as the standard deviation of the similarity between adjacent segments, that is , where n is the number of segments, is the average similarity.
[0035] Context adaptability: evaluates the adaptability and importance of a word in different contexts. For each word, its distribution in different topics and semantic relationship networks is statistically analyzed. Suppose the frequency of word w appearing in topic t is , and the average association strength with other words in the semantic relationship network is , where is the number of words having a semantic relationship with word w. The context adaptability index can be defined as , where and are weight coefficients.
[0036] Sentiment tendency degree: analyzes the sentiment tendency in the text to determine the degree of positive, negative, or neutral sentiment. The sentiment analysis tool TextBlob can be used to perform sentiment analysis on the text. Suppose the sentiment tendency degree is E, and it is quantified according to the output result of the sentiment analysis tool. A positive sentiment is assigned a value of E = 1, a negative sentiment is assigned a value of E = -1, and a neutral sentiment is assigned a value of E = 0.
[0037] In a possible implementation of the present application, based on semantic dynamics, context adaptability, and sentiment inclination, the initial prompt is optimized to generate a target prompt, which may include: setting an initial prompt based on task requirements, where the initial prompt is a question, instruction, or keyword; performing iterative operations on the initial prompt based on semantic dynamics, context adaptability, and sentiment inclination until the determined prompt meets the preset conditions, and taking the determined prompt as the target prompt, where the preset conditions include conforming to at least one of the theme, semantic dynamics, and context adaptability.
[0038] In this embodiment, the extracted features and innovative generation algorithms are used to generate a prompt with strong ability emergence excitation ability.
[0039] In a possible implementation of the present application, the following iterative algorithm is used for iterative operations:
[0040]
[0041]
[0042]
[0043] Among them, is the prompt for each iteration; , , , , are all weight coefficients, which are respectively used to adjust the influence degrees of word frequency, part of speech, semantic dynamics, context adaptability, and sentiment inclination features; , , , , respectively represent the feature indicators of word frequency, part of speech, semantic dynamics, context adaptability, and sentiment inclination; , , , , are functions related to word frequency, part of speech, semantic dynamics, context adaptability, and sentiment inclination features respectively, is assigned according to the grammatical function and semantic contribution of the part of speech, is assigned according to the positive, negative, or neutral degree of the sentiment inclination; is a weight factor dynamically adjusted according to the importance of words in different themes; is an adjustment parameter; is a weight factor for dynamically adjusting the importance of prompt generation according to semantic dynamics; is a weight factor for dynamically adjusting the importance in different tasks according to context adaptability.
[0044] Among them, for the word frequency related function , , where is a weight factor dynamically adjusted according to the importance of words in different topics. The specific calculation method is as follows: 1. Calculate the frequency of occurrence of words in each topic; 2. Weight and sum the frequencies of occurrence according to the importance of the topic to obtain the importance index of words in different topics; 3. Determine the weight factor according to the importance index . If a word has a high frequency of occurrence in important topics, then will also be relatively large.
[0045] For the part of speech related function , it can be assigned values according to the grammatical functions and semantic contributions of parts of speech. At the same time, considering the changes of parts of speech in different contexts, the function values are dynamically adjusted. The specific calculation method is as follows: 1. Determine an initial part of speech assignment according to the basic grammatical functions and semantic contributions of parts of speech. 2. For each text segment, analyze the specific roles and contexts of the parts of speech of words in this segment. If a part of speech has important grammatical functions or semantic contributions in a specific context, adjust its assignment. 3. Obtain the part of speech function values of each word in different contexts . Among them, higher values can be assigned to nouns and verbs, and lower values to auxiliary words and interjections, etc.
[0046] For the semantic dynamics related function , , where k is an adjustment parameter, is the semantic dynamics index, is a weight factor for dynamically adjusting the importance of Prompt generation according to semantic dynamics. The specific calculation method is as follows: 1. Determine the degree of semantic dynamics according to the previously calculated semantic dynamics index ; 2. Control the shape of the function through the adjustment parameter so that when the semantic dynamics is high, the function value is also relatively large; 3. Determine the weight factor according to the importance of semantic dynamics to Prompt generation . If the semantic dynamics is very important in the current task, then will be large; otherwise, it will be small.
[0047] For the context adaptability related function , , where is a context adaptability index, is a weight factor dynamically adjusted according to the importance of context adaptability in different tasks. The specific calculation method is as follows: 1. Determine the adaptability degree of words in different contexts according to the context adaptability index obtained previously . 2. Determine the importance of context adaptability in the current task according to the characteristics and requirements of the task. If context adaptability is very important for the current task, then will have a larger value; otherwise, it will be smaller; 3. Obtain the context adaptability function value .
[0048] For the function related to the sentiment tendency degree , assign values according to the positive, negative or neutral degree of the sentiment tendency. A relatively high value can be assigned to positive sentiment, a relatively low value to negative sentiment, and a moderate value to neutral sentiment. At the same time, consider the changes of the sentiment tendency in different themes and contexts, and dynamically adjust the function value. The specific calculation method is as follows: 1. Use a sentiment analysis tool to determine the sentiment tendency of the text; 2. Assign different initial values to positive, negative and neutral sentiments according to the degree of the sentiment tendency; 3. Analyze the changes of the sentiment tendency in different themes and contexts; if a sentiment tendency has special significance or influence in a specific theme or context, then adjust its assigned value; 4. Obtain the sentiment tendency degree function value .
[0049] In a possible implementation manner of the present application, the above steps can also be comprehensively evaluated and optimized, as Figure 3 shown.
[0050] When the system is initially running or at a preset time interval (for example, every 24 hours), first start the automatic evaluation link, and accurately calculate the accuracy rate, recall rate and F1 value of the generated results.
[0051] After completing the automatic evaluation and obtaining the corresponding results, enter the manual discrimination process. Experienced professionals conduct a comprehensive and in-depth analysis and judgment on the results obtained from the automatic evaluation according to the preset criteria and comprehensive consideration factors.
[0052] If the manual discrimination result shows that the requirements are not met, it is necessary to optimize and update the data set in a targeted manner, such as adding more diverse sample data or removing abnormal data. At the same time, adjust the weight coefficient to change the influence proportion of each factor, such as increasing the weight of some key features. In addition, make detailed modifications and improvements to the relevant functions, such as adjusting the parameters of the function or changing the form of the function. Once the manual discrimination result meets the requirements, the entire optimization and evaluation process is successfully completed.
[0053] The evaluation indicators are as follows: Accuracy evaluation: By inputting the generated prompt into the large model, count the matching degree between the output result of the large model and the actual correct result, and calculate the accuracy.
[0054] Recall evaluation: Measure the proportion of relevant results that the large model can correctly recall when using the generated prompt.
[0055] F1-score evaluation: A balanced metric that comprehensively considers accuracy and recall.
[0056] Response time evaluation: Record the time required for the large model to output the result after receiving the generated prompt.
[0057] Semantic coherence evaluation: Use natural language processing techniques to analyze the semantic coherence between the generated prompt and the output result of the large model. Let the semantic vector of the prompt be , and the semantic vector of the output result of the large model be , then the semantic coherence is . Set the threshold of semantic coherence, for example, the semantic coherence is above 0.7.
[0058] Sentiment consistency evaluation: Analyze whether the sentiment tendencies between the generated prompt and the output result of the large model are consistent. Let the sentiment tendency degree of the prompt be , and the sentiment tendency degree of the output result of the large model be , if and have the same sign, it is considered that the sentiment is consistent. Count the proportion of sentiment consistency, for example, the sentiment consistency reaches more than 70%.
[0059] In a specific embodiment of the present application, the text prompt generation method provided by the present application includes the following steps.
[0060] Step 1: Data collection and screening. 800 academic papers on the cutting-edge technologies of artificial intelligence were collected from multiple well-known academic databases; 1500 news reports related to technological innovation were crawled from mainstream news websites; 400 novel fragments involving future technology themes were obtained from large literary platforms. After screening, 200 duplicate news reports and 80 novel fragments with obvious grammar errors were removed. Finally, 600 academic papers, 1300 news reports, and 320 novel fragments were obtained. These data all revolve around the technology theme and provide rich materials for subsequent analysis.
[0061] Step 2: Deep semantic analysis. Receive the text data filtered in the data collection phase. For the text "Innovative Applications of Deep Learning Algorithms in the Field of Image Recognition" in an academic paper, after being processed by Word2Vec, words such as "deep learning", "algorithm", "image recognition", and "innovative application" are mapped into the semantic vector space. By analyzing the entire dataset using the LDA algorithm, it is found that one of the main themes is "Innovative Development of Artificial Intelligence", and it is judged that the text of this paper may belong to this theme. In the semantic relationship network, words such as "deep learning" are strongly associated with "neural network" and "artificial intelligence" because these words often appear together in many academic papers and news reports. For example, in a news report, it is mentioned that "The rapid development of artificial intelligence is inseparable from the support of deep learning and neural network technologies", which further strengthens the semantic relationship between them.
[0062] Step 3: Dynamic feature extraction. Based on the results of deep semantic analysis, a science fiction novel is segmented into multiple fragments according to chapters. After calculating the semantic vectors of each fragment, it is found that as the story develops, the semantic similarity between adjacent chapters changes to a certain extent. For example, when introducing the background of the future world at the beginning of the novel, words related to the theme of "Innovative Development of Artificial Intelligence" determined in the deep semantic analysis module appear with a high frequency, and the semantic similarity is also high. However, as the plot progresses, new conflicts and challenges emerge, and the semantic content related to this theme changes, resulting in a decrease in semantic similarity, which reflects a high degree of semantic dynamics. In different chapters, the word "innovation" appears with a high frequency in the context related to the theme of "Innovative Development of Artificial Intelligence", and it is strongly associated with words such as "technological progress" and "future development" in the semantic relationship network, indicating its good adaptability in this context. By analyzing the novel using an emotion analysis tool, it is found that the overall emotion of the novel shows a positive tendency, which echoes the expectation and positive attitude towards the future usually brought by the science and technology theme in the deep semantic analysis module, further verifying the effectiveness of dynamic feature extraction.
[0063] Step 4: Intelligent prompt generation. Combining the verification requirements of this time, define the initial prompt seed as "What will the future of artificial intelligence in science fiction novels be like?", and after several iterations, combine features such as semantic dynamics and context adaptability to generate a new prompt: "In this science fiction novel full of a sense of technology, as the plot develops, what innovative features does artificial intelligence show in different scenarios? What role do they play in the development of the future world?" This prompt not only considers the themes of the novel (science fiction and artificial intelligence), but also combines semantic dynamics (as the plot develops) and context adaptability (the meaning of innovative features in the context of the science and technology theme), and can better stimulate the large model to deeply understand and analyze the novel.
[0064] Step 5: Evaluation and Optimization. After inputting the previously generated prompt "In this science fiction novel full of a sense of technology, as the plot develops, what innovative features does artificial intelligence exhibit in different scenarios? What role does it play in the development of the future world?" into the large model, the large model outputs some analyses of the characteristics and roles of artificial intelligence in the novel. By comparing with the correct results manually annotated, the calculated accuracy is 90%. The recall rate evaluation finds that the large model can correctly recall most of the relevant characteristics and roles of artificial intelligence, and the recall rate is 85%. The F1 value is 87.5%, indicating a good balance between accuracy and recall rate. The response time is 0.7 seconds, meeting the requirement of fast response. The semantic coherence evaluation shows that the semantic coherence between the generated prompt and the output result of the large model is 0.8, indicating a high semantic consistency between the two. The emotion consistency evaluation finds that both the prompt and the output result of the large model show a positive emotional tendency, and the emotion consistency is 90%. The overall evaluation result is relatively good.
[0065] In the embodiments of this application, in terms of the depth of semantic analysis, this patent not only constructs a semantic vector space, but also mines potential themes and analyzes the semantic relationship network. The words are mapped to the vector space and dimensionally reduced through a deep learning model, the LDA algorithm is used to mine themes, and a knowledge graph construction tool is used to analyze the semantic relationship network to deeply understand the text semantics in multiple dimensions. In terms of innovative feature extraction, this patent introduces innovative feature indicators such as semantic dynamics, context adaptability, and emotional tendency, and adopts a dynamic extraction method. The semantic dynamics is determined by calculating the semantic vector similarity of text segments, the context adaptability is determined by statistically analyzing the distribution of words in different themes and semantic relationship networks, and the emotional tendency is determined by using an emotion analysis tool. In terms of the prompt generation algorithm, this patent adopts an innovative iterative algorithm, combines multi-dimensional features such as word frequency, part of speech, semantic dynamics, context adaptability, and emotional tendency and weight coefficients to generate a prompt with strong ability emergence and excitation ability.
[0066] As Figure 4 shown, it is a schematic diagram of a text prompt generation system provided by the embodiments of this application. As Figure 4 shown, the text prompt generation system may include: an acquisition module 401, an analysis module 402, an extraction module 403, and a generation module 404.
[0067] Among them, the acquisition module 401 is used to acquire text training data; the analysis module 402 is used to perform in-depth semantic analysis on the text training data to determine the semantic relationships of the text training data. The semantic relationships include the semantic relationship network between words in the text training data and the theme corresponding to the text training data; the extraction module 403 is used to extract key features in the text data based on the semantic relationships for any text data. The key features include semantic dynamics, context adaptability, and sentiment orientation; the generation module 404 is used to optimize the initial prompt based on semantic dynamics, context adaptability, and sentiment orientation to generate the target prompt. The initial prompt is determined based on the task requirements.
[0068] In the embodiment of the present application, first, the acquisition module 401 acquires text training data. Secondly, the analysis module 402 performs in-depth semantic analysis on the text training data to determine the semantic relationships of the text training data. The semantic relationships include the semantic relationship network between words in the text training data and the theme corresponding to the text training data. Then, the extraction module 403 extracts key features in the text data based on the semantic relationships for any text data. The key features include semantic dynamics, context adaptability, and sentiment orientation. Finally, the generation module 404 optimizes the initial prompt based on semantic dynamics, context adaptability, and sentiment orientation to generate the target prompt. The initial prompt is determined based on the task requirements. By deeply mining the potential information of the text data, the present application provides rich semantic understanding for subsequent feature extraction and prompt generation, extracts key features according to different task requirements, provides a feature basis for generating accurate and highly adaptable prompts, and through continuous optimization, makes the finally generated prompt meet complex language scenarios and diverse task requirements, with high adaptability and flexibility.
[0069] In a possible implementation manner of the present application, the analysis module 402 is used to: perform in-depth semantic analysis on the text training data, map the words in the text training data to the semantic vector space, and construct the semantic vector space; by analyzing the text training data, mine the theme in the text training data and determine the theme to which each text data belongs; based on the similarity between words in the text training data, construct the semantic relationship network between words. The semantic relationship network represents the association strength and semantic hierarchical structure between each word in the text training data.
[0070] In a possible implementation manner of the present application, the analysis module 402 is used to: represent each word in the text training data with a multi-dimensional vector to obtain the matrix corresponding to the text training data. The matrix is a matrix composed of the number of words and the multi-dimensional vectors; map each word to the vector space through a deep learning model to obtain the corresponding vector representation; perform dimensionality reduction processing on the matrix to obtain the semantic vector space.
[0071] In a possible implementation of the present application, the analysis module 402 is configured to: mine the topics in the text training data based on the LDA document topic generation model, where each topic represents a word distribution; and obtain the distribution of each text data on each topic and the word distribution under each topic by training the text training data.
[0072] In a possible implementation of the present application, the extraction module 403 is configured to: for any text data, determine the semantic dynamics in the text data based on the change trend of the semantic similarity between adjacent segments in the text data, where the semantic dynamics is used to characterize the change trend and dynamic features of the semantics in the text data; for each word in the text data, determine the context adaptability of each word based on the frequency of the word in the topic and the association strength of the word with other words in the semantic relationship network; and perform sentiment analysis on the text data to determine the sentiment tendency degree of the text data, where the sentiment tendency degree includes positive sentiment, negative sentiment, and neutral sentiment.
[0073] In a possible implementation of the present application, the generation module 404 is configured to: set an initial prompt based on the task requirements, where the initial prompt is a question, an instruction, or a keyword; and perform iterative operations on the initial prompt based on the semantic dynamics, context adaptability, and sentiment tendency degree until the determined prompt meets the preset conditions, and use the determined prompt as the target prompt, where the preset conditions include conforming to at least one of the topic, semantic dynamics, and context adaptability.
[0074] In a possible implementation of the present application, the generation module 404 is configured to: perform iterative operations using the iterative algorithm shown in the following formula:
[0075]
[0076]
[0077]
[0078] where is the prompt for each iteration; and and and and are all weight coefficients, which are respectively used to adjust the influence degrees of the word frequency, part of speech, semantic dynamics, context adaptability, and sentiment tendency degree features; and and and , respectively represent the feature indicators of word frequency, part of speech, semantic dynamics, context adaptability, and sentiment tendency; , , , , are functions related to word frequency, part of speech, semantic dynamics, context adaptability, and sentiment tendency respectively, are assigned values according to the grammatical functions and semantic contributions of parts of speech, are assigned values according to the positive, negative, or neutral degree of sentiment tendency; is a weight factor dynamically adjusted according to the importance of words in different topics; is an adjustment parameter; is a weight factor dynamically adjusted according to the importance of prompt generation based on semantic dynamics; is a weight factor dynamically adjusted according to the importance of context adaptability in different tasks.
[0079] The functions of the text prompt generation system of this application have been described in detail in the Figures 1 to 3 method embodiments shown. Therefore, for the details not described in this embodiment, reference can be made to the relevant descriptions in the foregoing embodiments, and details will not be repeated here.
[0080] As Figure 5 shown, this embodiment of the application also provides an electronic device 500, including a processor 501, a memory 502, a program or instruction stored on the memory 502 and executable on the processor 501, and when the program or instruction is executed by the processor 501, it realizes each process of the above-mentioned text prompt generation processing method embodiment, and can achieve the same technical effect. To avoid repetition, details will not be repeated here.
[0081] Optionally, this embodiment of the application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it realizes each process of the above-mentioned text prompt generation method embodiment, and can achieve the same technical effect. To avoid repetition, details will not be repeated here. Among them, the computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc.
[0082] Optionally, the embodiments of the present application further provide a computer program product. The computer program product includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, they implement each process of the text prompt generation method embodiment as described above, and can achieve the same technical effects. To avoid repetition, details are not described herein again.
[0083] It should be noted that in this article, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or system. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of another identical element in the process, method, article or system including that element.
[0084] Through the description of the above embodiments, those skilled in the art can clearly understand that the method of the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions for causing a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present application.
[0085] The embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Under the inspiration of the present application, those of ordinary skill in the art can also make many forms without departing from the purpose of the present application and the scope protected by the claims, and all of them belong to the protection scope of the present application.
Claims
1. A method for generating text prompts, characterized in that, Including: Obtain text training data; Perform in-depth semantic analysis on the text training data to determine the semantic relationships of the text training data, where the semantic relationships include the semantic relationship network between words in the text training data and the theme corresponding to the text training data; For any text data, based on the semantic relationships, extract the key features in the text data, where the key features include semantic dynamics, context adaptability, and sentiment tendency; Based on the semantic dynamics, the context adaptability, and the sentiment tendency, optimize the initial prompt to generate a target prompt, where the initial prompt is determined based on task requirements.
2. The method according to claim 1, characterized in that The performing in-depth semantic analysis on the text training data to determine the semantic relationships of the text training data includes: Perform in-depth semantic analysis on the text training data, map the words in the text training data to a semantic vector space, and construct a semantic vector space; By analyzing the text training data, mine the themes in the text training data and determine the theme to which each text data belongs; Based on the similarity between words in the text training data, construct the semantic relationship network between the words, where the semantic relationship network represents the association strength and semantic hierarchical structure between each word in the text training data.
3. The method according to claim 2, wherein The performing in-depth semantic analysis on the text training data, mapping the words in the text training data to a semantic vector space, and constructing a semantic vector space includes: For each word in the text training data, represent it with a multi-dimensional vector to obtain the matrix corresponding to the text training data, where the matrix is a matrix composed of the number of words and multi-dimensional vectors; Map each word to the vector space through a deep learning model to obtain the corresponding vector representation; Perform dimensionality reduction processing on the matrix to obtain a semantic vector space.
4. The method according to claim 2, wherein The by analyzing the text training data, mining the themes in the text training data, and determining the theme to which each text data belongs includes: Based on the LDA document topic generation model, mine the themes in the text training data, where each theme represents a word distribution; Through training on the text training data, obtain the distribution of each text data on each theme and the word distribution under each theme.
5. The method according to claim 1, wherein The for any text data, based on the semantic relationships, extracting the key features in the text data includes: For any text data, based on the change trend of the semantic similarity between each adjacent segment in the text data, determine the semantic dynamics in the text data, where the semantic dynamics is used to represent the change trend and dynamic features of the semantics in the text data; For each word in the text data, based on the frequency of the word appearing in the theme and the association strength of the word with other words in the semantic relationship network, determine the context adaptability of each word; Perform sentiment analysis on the text data to determine the sentiment tendency of the text data, where the sentiment tendency includes positive sentiment, negative sentiment, and neutral sentiment.
6. The method according to claim 1, characterized in that, Optimizing the initial prompt based on the semantic dynamics, the context adaptability, and the sentiment tendency to generate a target prompt, including: Setting an initial prompt based on task requirements, where the initial prompt is a question, an instruction, or a keyword; Performing iterative operations on the initial prompt based on the semantic dynamics, the context adaptability, and the sentiment tendency until the determined prompt meets the preset conditions, and taking the determined prompt as the target prompt, where the preset conditions include meeting at least one of the theme, semantic dynamics, and context adaptability.
7. The method according to claim 6, characterized in that, Performing iterative operations using the iterative algorithm shown in the following formula: Among them, is the prompt for each iteration; , , , , are all weight coefficients, which are respectively used to adjust the influence degrees of word frequency, part of speech, semantic dynamicity, context adaptability, and sentiment tendency features; , , , , respectively represent the feature indexes of word frequency, part of speech, semantic dynamicity, context adaptability, and sentiment tendency; , , , , are respectively functions related to the features of word frequency, part of speech, semantic dynamicity, context adaptability, and sentiment tendency, is assigned according to the grammatical function and semantic contribution of the part of speech, is assigned according to the positive, negative, or neutral degree of the sentiment tendency; is a weight factor dynamically adjusted according to the importance of words in different topics; is an adjustment parameter; is a weight factor dynamically adjusted according to the importance of the prompt generation based on semantic dynamicity; is a weight factor dynamically adjusted according to the importance of context adaptability in different tasks.
8. A text prompt generation system, characterized in that, Including: An acquisition module for acquiring text training data; An analysis module for performing in-depth semantic analysis on the text training data to determine the semantic relationships of the text training data, where the semantic relationships include the semantic relationship network between words in the text training data and the theme corresponding to the text training data; An extraction module for extracting key features in any text data based on the semantic relationships, where the key features include semantic dynamics, context adaptability, and sentiment tendency; A generation module for optimizing the initial prompt based on the semantic dynamics, the context adaptability, and the sentiment tendency to generate a target prompt, where the initial prompt is determined based on task requirements.
9. An electronic device, characterized in that, Including a processor, a memory, a program or instruction stored on the memory and executable on the processor, and when the program or instruction is executed by the processor, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer program product, characterized in that, The computer program product includes a computer program stored on a non-transitory computer-readable storage medium, where the computer program includes program instructions, and when the program instructions are executed by a computer, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Model training method and device, electronic equipment and storage medium
CN120975180A
Model training method and device, electronic equipment and storage medium
CN120975180B