Methods, devices, and electronic equipment for recognizing prompt words and phrases.
By calculating the distance between prompt words and intent boundary thresholds using a semantic recognition model, the problem of low maintenance efficiency of the intent dictionary is solved, achieving accurate recognition and efficient updates while avoiding redundant storage.
Patent Information
- Application Number
- CN202310640441.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-31
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2043-05-31
AI Technical Summary
In existing technologies, the inability to accurately identify prompt words leads to low maintenance efficiency of the intent dictionary, and prompt words with repetitive meanings cause redundancy problems.
By acquiring the prompt words to be identified and inputting them into the semantic recognition model, the distance between the target semantic feature vector and the preset cluster center vector is calculated. The recognition result is determined based on the intent boundary threshold, and the intent dictionary is updated to avoid storing redundant prompt words.
It enables efficient maintenance of the intent dictionary, avoids the storage of redundant prompts, and improves recognition accuracy and maintenance efficiency.
Smart Images

Figure CN116756312B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and more specifically, to a method, apparatus, and electronic device for recognizing prompt words. Background Technology
[0002] With the rapid development of large-scale pre-trained models and the massive increase in computational instances, AIGC (AI GenerateContent) technology is experiencing exponential growth, reshaping the "digital transformation" of various industries and even globally. Generated text images (GTIs) are a technology within AIGC for image content generation. Users input a series of prompts for their desired content, and the AI model generates image content that matches the theme. This effectively empowers various departments within an enterprise, assisting in generating new ideas and design solutions, developing personalized and customized products, improving design speed and agility, and reducing costs while increasing efficiency. However, users without artistic expertise or a certain level of literary cultivation often struggle to obtain the desired images when using AI models due to a lack of prompts. To address this issue, existing technologies utilize (theme-prompt) intent dictionaries constructed by professionals to lower the entry barrier for top-down GTI creation within enterprises, thereby improving the user experience.
[0003] However, with the surge in creative fields, the repetitive meanings of (topic-cue words) lead to redundant intent understanding. When updating and maintaining the intent dictionary, the inability to accurately identify cue word statements results in duplicate correspondences in the intent dictionary, leading to low maintenance efficiency.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] This application provides a method, apparatus, and electronic device for recognizing prompt words and phrases, so as to at least solve the technical problem of low maintenance efficiency of intent dictionaries caused by the inability to accurately recognize prompt words and phrases in related technologies.
[0006] According to one aspect of this application, a method for recognizing prompt words is provided, comprising: acquiring a prompt word to be recognized, wherein the prompt word to be recognized is used to characterize textual description information corresponding to a target image, and the target image is an image expected to be generated by a target object; inputting the prompt word to be recognized into a semantic recognition model to obtain a target semantic feature vector corresponding to the prompt word to be recognized and a target intent category corresponding to the prompt word to be recognized output by the semantic recognition model; acquiring a preset clustering center vector corresponding to the target intent category and an intent boundary threshold corresponding to the target intent category; calculating the distance between the target semantic feature vector and the preset clustering center vector to obtain a target distance; determining the recognition result of the prompt word to be recognized based on the target distance and the intent boundary threshold, and updating an intent dictionary based on the recognition result, wherein the intent dictionary is used to store M prompt words, each prompt word representing textual description information corresponding to an image, each image being an image expected to be generated by the target object, and M being a positive integer.
[0007] Further, determining the recognition result of the prompt word statement to be recognized based on the target distance and the intent boundary threshold includes: determining whether the target distance is greater than or equal to the intent boundary threshold; if the target distance is greater than or equal to the intent boundary threshold, determining a first recognition result as the recognition result, wherein the first recognition result is used to characterize the prompt word statement to be recognized as a prompt word statement that does not exist in the intent dictionary; if the target distance is less than the intent boundary threshold, determining a second recognition result as the recognition result, wherein the second recognition result is used to characterize the prompt word statement to be recognized as a prompt word statement that already exists in the intent dictionary.
[0008] Furthermore, updating the intent dictionary based on the recognition result includes: if the recognition result is determined to be a first recognition result, adding the prompt word to be recognized to the intent dictionary; if the recognition result is determined to be a second recognition result, prohibiting the addition of the prompt word to be recognized to the intent dictionary.
[0009] Further, the semantic recognition model is obtained as follows: A target training set is acquired, wherein the target training set includes at least N first prompt words, each first prompt word representing the textual description information corresponding to a first image, each first image being the image expected to be generated by the target object, and N being a positive integer; each first prompt word is encoded to obtain N first feature vectors; the N first feature vectors are input into an initial neural network model, and the initial neural network model is iteratively trained according to the cross-entropy loss function and the normalization exponential function to obtain the semantic recognition model.
[0010] Further, the N first feature vectors are input into an initial neural network model, and the initial neural network model is iteratively trained according to the cross-entropy loss function and the normalization exponential function to obtain the semantic recognition model. This includes: inputting the N first feature vectors into a pooling layer in the initial neural network model to obtain N second feature vectors output by the pooling layer, wherein the pooling layer is used to perform feature filtering on the first feature vectors; inputting the N second feature vectors into a dense layer in the initial neural network model to obtain N first semantic feature vectors output by the dense layer, wherein the dense layer is used to convert the second feature vectors into dense vectors in a low-dimensional space; and inputting the N first semantic feature vectors into a fully connected layer in the initial neural network model, and iteratively training the initial neural network model according to the cross-entropy loss function and the normalization exponential function to obtain the semantic recognition model.
[0011] Further, before obtaining the preset cluster center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category, the method further includes: obtaining M prompt words from the intent dictionary; encoding each prompt word to obtain M third feature vectors; inputting the M third feature vectors into the semantic recognition model to obtain M second semantic feature vectors and K intent categories output by the semantic recognition model, where K is a positive integer and K is less than or equal to M; dividing the M second semantic feature vectors into K vector sets according to the K intent categories, where the second semantic feature vectors in each vector set correspond to the same intent category; and determining the preset cluster center vector corresponding to each intent category based on the preset clustering algorithm, each intent category, and the vector set corresponding to that intent category.
[0012] Furthermore, after determining the preset clustering center vector corresponding to each intent category based on the preset clustering algorithm, each intent category, and the vector set corresponding to the intent category, the method further includes: calculating the distance between the L second semantic feature vectors in each vector set and the preset clustering center vector corresponding to the vector set to obtain the L first distances corresponding to each intent category, where L is a positive integer; and using the maximum distance among the L first distances corresponding to each intent category as the intent boundary threshold corresponding to that intent category.
[0013] According to another aspect of this application, a device for recognizing prompt words and phrases is also provided, comprising: a first acquisition module, configured to acquire prompt words and phrases to be recognized, wherein the prompt words and phrases to be recognized are used to characterize textual description information corresponding to a target image, and the target image is an image expected to be generated by a target object; a semantic recognition module, configured to input the prompt words and phrases to be recognized into a semantic recognition model to obtain a target semantic feature vector corresponding to the prompt words and phrases to be recognized and a target intent category corresponding to the prompt words and phrases to be recognized, output by the semantic recognition model; a second acquisition module, configured to acquire a preset clustering center vector corresponding to the target intent category and an intent boundary threshold corresponding to the target intent category; a calculation module, configured to calculate the distance between the target semantic feature vector and the preset clustering center vector to obtain a target distance; and a determination module, configured to determine the recognition result of the prompt words and phrases to be recognized based on the target distance and the intent boundary threshold, and update the intent dictionary based on the recognition result, wherein the intent dictionary stores M prompt words and phrases, each prompt word and phrase characterizing textual description information corresponding to an image, each image being an image expected to be generated by the target object, and M being a positive integer.
[0014] According to another aspect of this application, a computer-readable storage medium is also provided, in which a computer program is stored, wherein the computer program is configured to execute the above-described method for recognizing prompt words at runtime.
[0015] According to another aspect of this application, an electronic device is also provided, the electronic device including one or more processors; a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement a method for running the programs, wherein the programs are configured to execute the above-described method for recognizing prompt statements during runtime.
[0016] In this application, firstly, a prompt phrase to be identified is obtained, wherein the prompt phrase is used to represent the text description information corresponding to the target image, and the target image is the image expected to be generated by the target object; then, the prompt phrase to be identified is input into a semantic recognition model to obtain the target semantic feature vector corresponding to the prompt phrase to be identified and the target intent category corresponding to the prompt phrase to be identified output by the semantic recognition model; secondly, a preset cluster center vector corresponding to the target intent category and an intent boundary threshold corresponding to the target intent category are obtained; then, the distance between the target semantic feature vector and the preset cluster center vector is calculated to obtain the target distance; finally, the recognition result of the prompt phrase to be identified is determined based on the target distance and the intent boundary threshold, and the intent dictionary is updated based on the recognition result, wherein the intent dictionary is used to store M prompt phrases, each prompt phrase is used to represent the text description information corresponding to an image, each image is the image expected to be generated by the target object, and M is a positive integer.
[0017] In the above process, the trained semantic recognition model processes the prompt words to be recognized, obtaining accurate target semantic feature vectors and target intent categories corresponding to the prompt words. Then, based on the target distance between the target semantic feature vector and the preset cluster center vector corresponding to the target intent category, and the intent boundary threshold corresponding to the target intent category, the recognition result of the prompt words is determined, which can accurately identify the prompt words and obtain accurate recognition results. Furthermore, the intent dictionary is updated based on the recognition results, which can avoid the problem of storing too many redundant prompt words in the intent dictionary, thereby improving the technical effect of maintaining the intent dictionary and solving the technical problem of low maintenance efficiency of the intent dictionary due to the inability to accurately recognize prompt words in related technologies. Attached Figure Description
[0018] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0019] Figure 1 This is a flowchart of an optional method for recognizing prompt words according to an embodiment of this application;
[0020] Figure 2 This is a flowchart of an optional prompt word statement recognition process according to an embodiment of this application;
[0021] Figure 3 This is a schematic diagram of an optional intent dictionary according to an embodiment of this application;
[0022] Figure 4 This is a schematic diagram of an optional prompt word / phrase recognition device according to an embodiment of this application;
[0023] Figure 5 This is a schematic diagram of an optional electronic device according to an embodiment of this application. Detailed Implementation
[0024] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0025] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0026] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0027] Example 1
[0028] According to an embodiment of this application, a method embodiment for recognizing prompt words is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0029] Figure 1This is a flowchart of an optional method for recognizing prompt words according to an embodiment of this application, such as... Figure 1 As shown, the method includes the following steps:
[0030] Step S101: Obtain the prompt word statement to be recognized.
[0031] In an optional embodiment, a prompt word / statement recognition system can serve as the execution entity for the prompt word / statement recognition method in this application embodiment. For ease of description, the prompt word / statement recognition system will be referred to simply as the system below.
[0032] In step S101, the prompt words to be identified are used to characterize the textual description information corresponding to the target image, where the target image is the image that the target object expects to generate. That is, the prompt words to be identified can be textual information used in text-to-image technology (i.e., technology that generates corresponding images from text) to describe the image that the target object expects to generate. For example, if the target object expects to generate an image of a Valentine's Day pop-up ad, then the corresponding textual description information for that image would be outdoor, everyday, anime / manga scene, boy and girl's back view, lovers, under cherry blossom trees, blue sky and white clouds, healing style, soft light, etc.
[0033] Optionally, the prompt phrase to be identified can consist of a theme and prompt words. The theme is the target audience's intent. For example, if the target audience expects an image of a Valentine's Day pop-up ad, then the theme is "Valentine's Day pop-up ad." The prompt words are textual information describing the target audience's intent. For example, when the theme is "Valentine's Day pop-up ad," the prompt words might be: outdoor, everyday, anime scene, boy and girl's back view, lovers, under cherry blossom trees, blue sky and white clouds, healing style, soft light, etc.
[0034] Step S102: Input the prompt word statement to be identified into the semantic recognition model to obtain the target semantic feature vector corresponding to the prompt word statement to be identified and the target intent category corresponding to the prompt word statement to be identified, which are output by the semantic recognition model.
[0035] In step S102, the semantic recognition model is a neural network model pre-trained through supervised classification. The system can input the prompt word / phrase to be recognized into this neural network model to obtain the target semantic feature vector corresponding to the prompt word / phrase and the target intent category corresponding to the prompt word / phrase. For example, as... Figure 2 As shown, the system inputs the prompt words to be identified into the semantic recognition model, and processes the prompt words through the pooling layer and the dense layer in the semantic recognition model to obtain the target semantic feature vector and the target intent category.
[0036] Optionally, the prompt word statement to be identified is input into the semantic recognition model to obtain the target semantic feature vector corresponding to the prompt word statement to be identified and the target intent category corresponding to the prompt word statement to be identified, as output by the semantic recognition model. This includes: encoding the prompt word statement to be identified to obtain the target feature vector; and inputting the encoding process into the semantic recognition model to obtain the target semantic feature vector corresponding to the prompt word statement to be identified and the target intent category corresponding to the prompt word statement to be identified, as output by the semantic recognition model.
[0037] In this embodiment, to improve the data processing efficiency of the semantic recognition model, before inputting the prompt words to be recognized into the neural network model, the system can process the prompt words to be recognized into... Figure 2 The system shows individual characters for CLS (classification) and Tok1 to TokN. After obtaining these individual characters, the system can also input them. Figure 2 The target feature vector is obtained by encoding in the Transformer encoder shown.
[0038] Step S103: Obtain the preset clustering center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category.
[0039] In step S103, the preset cluster center vector is determined by the K-means clustering algorithm and multiple second semantic feature vectors. Each second semantic feature vector is determined by a prompt word statement in the intent database that corresponds to the target intent category. The intent boundary threshold is the maximum distance among the distances between the preset cluster center vector and each second semantic feature vector.
[0040] Step S104: Calculate the distance between the target semantic feature vector and the preset cluster center vector to obtain the target distance.
[0041] Step S105: Determine the recognition result of the prompt word statement to be recognized based on the target distance and the intent boundary threshold, and update the intent dictionary based on the recognition result.
[0042] In steps S104-S105, the intent dictionary is used to store M prompt words, each prompt word is used to represent the text description information corresponding to an image, each image is the image expected to be generated for the target object, and M is a positive integer.
[0043] Optionally, the target distance may include, but is not limited to, Euclidean distance.
[0044] To improve the accuracy of prompt word recognition and address the problem of low maintenance efficiency of the intent dictionary due to the inability of related technologies to accurately recognize prompt words, this embodiment calculates the distance between the target semantic feature vector of the prompt word to be recognized and the preset cluster center vector to obtain the target distance. Then, based on the target distance and the intent boundary threshold, the recognition result of the prompt word to be recognized is determined, and the intent dictionary is updated based on the recognition result. For example, as... Figure 2 As shown, the system can determine the recognition result of the prompt word statement by judging whether the target distance is greater than or equal to the intent boundary threshold. Specifically, when the target distance is greater than or equal to the intent boundary threshold (i.e., ... Figure 2 If the target distance is less than the intention boundary threshold, the recognition result is determined as the first recognition result, which indicates that the prompt word to be recognized is not in the intention dictionary, and the prompt word to be recognized is added to the intention dictionary; if the target distance is less than the intention boundary threshold, the recognition result is determined as the second recognition result, which indicates that the prompt word to be recognized is in the intention dictionary, and the addition of the prompt word to be recognized to the intention dictionary is prohibited.
[0045] Optionally, in addition to storing M cue words, the intent dictionary also stores the intent category corresponding to each cue word and the image corresponding to each cue word. Each cue word consists of a topic and a cue word. For example, such as... Figure 3 As shown, when the prompt phrase is: Valentine's Day Credit Card Marketing Poster + prompt phrases: peach blossoms, a pair of lively magpies, enchanting fragrance, natural light, Valentine's Day, solid color background, warm color tone, ultra-detail, ink splatter art, HD (High Definition), 8K (resolution), the corresponding intent category is Valentine's Day, and the corresponding image is as follows. Figure 3 Image 1 in the image; the prompt phrase is: Valentine's Day pop-up ad + prompt words: outdoor, daily life, anime scene, boy and girl's back view, lovers, under cherry blossom tree, blue sky and white clouds, healing style, soft light, its corresponding intent category is Valentine's Day, and its corresponding image is as follows. Figure 3 Image 2 in the image; with the prompt phrase "Women's Day greeting card" + prompt phrases "female programmer, working on a computer," the image is exquisite, with perfect facial features, beautiful and dreamy, high-definition, and surrealistic, and its corresponding intention category is Women's Day, and its corresponding image is as follows. Figure 3 Image 3; the prompt phrase is: Spring Equinox Promotional Poster + prompt words: Awakening of Insects, Spring Rain, Willow Branches, Misty Jiangnan Water Town, Swallows, Bright Illustration, Oil Painting, its corresponding intent category is Spring, and its corresponding image is as follows. Figure 3Image 4; the prompt phrase is: "Awakening of Insects Promotional Poster" + prompt phrases: textured film, ultimate detail, normal facial features, spring thunder begins, diligent farming continues, all things revive, concept illustration, beautiful Jiangnan, traditional Chinese spring, solar term illustration, high definition, its corresponding intent category is spring, and its corresponding image is as follows. Figure 3 Image 5 in the image.
[0046] Based on the scheme defined in steps S101 to S105 above, it can be understood that in this embodiment, firstly, the prompt words to be identified are obtained, wherein the prompt words to be identified are used to characterize the text description information corresponding to the target image, and the target image is the image that the target object expects to generate; then, the prompt words to be identified are input into the semantic recognition model to obtain the target semantic feature vector corresponding to the prompt words to be identified and the target intent category corresponding to the prompt words to be identified output by the semantic recognition model; secondly, the preset cluster center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category are obtained; then, the distance between the target semantic feature vector and the preset cluster center vector is calculated to obtain the target distance; finally, the recognition result of the prompt words to be identified is determined based on the target distance and the intent boundary threshold, and the intent dictionary is updated based on the recognition result, wherein the intent dictionary is used to store M prompt words, each prompt word is used to characterize the text description information corresponding to an image, each image is the image that the target object expects to generate, and M is a positive integer.
[0047] It should be noted that in the above process, by processing the prompt words to be identified through the trained semantic recognition model, the accurate target semantic feature vector and target intent category corresponding to the prompt words can be obtained. Then, based on the target distance between the target semantic feature vector and the preset cluster center vector corresponding to the target intent category, and the intent boundary threshold corresponding to the target intent category, the recognition result of the prompt words to be identified is determined, which can accurately identify the prompt words and obtain accurate recognition results. Furthermore, based on the recognition results, the intent dictionary is updated, which can avoid the problem of storing too many redundant prompt words in the intent dictionary, thereby achieving the technical effect of improving the maintenance efficiency of the intent dictionary. This solves the technical problem of low maintenance efficiency of the intent dictionary due to the inability to accurately identify prompt words in related technologies.
[0048] Optionally, in the method for recognizing prompt words provided in this application embodiment, the system determines the recognition result of the prompt word to be recognized based on the target distance and the intent boundary threshold, including: determining whether the target distance is greater than or equal to the intent boundary threshold; if the target distance is greater than or equal to the intent boundary threshold, the system can determine a first recognition result as the recognition result, wherein the first recognition result is used to characterize the prompt word to be recognized as a prompt word not existing in the intent dictionary; if the target distance is less than the intent boundary threshold, the system can determine a second recognition result as the recognition result, wherein the second recognition result is used to characterize the prompt word to be recognized as a prompt word already existing in the intent dictionary.
[0049] To improve the accuracy of prompt word recognition, in this embodiment, the system can determine the recognition result of the prompt word by judging whether the target distance is greater than or equal to the intent boundary threshold. For example, if the target distance is greater than or equal to the intent boundary threshold, the system can determine the recognition result as a first recognition result, indicating that the prompt word does not exist in the intent dictionary; if the target distance is less than the intent boundary threshold, the system can determine the recognition result as a second recognition result, indicating that the prompt word exists in the intent dictionary.
[0050] Optionally, in the method for recognizing prompt words and phrases provided in the embodiments of this application, the system updates the intent dictionary based on the recognition result, including: if the recognition result is determined to be a first recognition result, the system can add the prompt word or phrase to be recognized to the intent dictionary; if the recognition result is determined to be a second recognition result, the system can prevent the prompt word or phrase to be recognized from being added to the intent dictionary.
[0051] To improve the maintenance efficiency of the intent dictionary and avoid storing too many redundant prompt words in the intent dictionary, in this embodiment, if the recognition result is determined to be the first recognition result, the system can add the prompt words to be recognized to the intent dictionary; if the recognition result is determined to be the second recognition result, the system can prevent the prompt words to be recognized from being added to the intent dictionary.
[0052] Optionally, in the method for recognizing prompt words provided in the embodiments of this application, the semantic recognition model is obtained in the following manner:
[0053] Step 201: Obtain the target training set.
[0054] In step 201, the target training set includes at least N first prompt words, each first prompt word is used to characterize the text description information corresponding to a first image, and each first image is the image expected to be generated for the target object, where N is a positive integer.
[0055] Step 202: Encode each first prompt word statement to obtain N first feature vectors.
[0056] In step 201, the system can encode each first prompt word statement using a Transformer encoder to obtain N first feature vectors.
[0057] Step 203: Input the N first feature vectors into the initial neural network model, and iteratively train the initial neural network model according to the cross-entropy loss function and the normalized exponential function to obtain the semantic recognition model.
[0058] To improve the recognition accuracy of the semantic recognition model, in this embodiment, the system can input N first feature vectors into the initial neural network model, and then iteratively train the initial neural network model based on the cross-entropy loss function and the normalized exponential function to obtain the semantic recognition model.
[0059] Optionally, in the method for recognizing prompt words provided in this application embodiment, N first feature vectors are input into an initial neural network model, and the initial neural network model is iteratively trained according to the cross-entropy loss function and the normalization exponential function to obtain a semantic recognition model. This includes: the system inputs N first feature vectors into a pooling layer in the initial neural network model to obtain N second feature vectors output by the pooling layer, wherein the pooling layer is used to perform feature filtering on the first feature vectors; then, the N second feature vectors are input into a dense layer in the initial neural network model to obtain N first semantic feature vectors output by the dense layer, wherein the dense layer is used to convert the second feature vectors into dense vectors in a low-dimensional space; finally, the N first semantic feature vectors are input into a fully connected layer in the initial neural network model, and the initial neural network model is iteratively trained according to the cross-entropy loss function and the normalization exponential function to obtain a semantic recognition model.
[0060] To further improve the recognition accuracy of the semantic recognition model, in this embodiment, the system inputs N first feature vectors into the pooling layer of the initial neural network model, and performs feature filtering on the first feature vectors according to the average pooling algorithm to obtain N second feature vectors. Then, the system sets a dense layer in the initial neural network model, inputs the N second feature vectors into the dense layer of the initial neural network model, and transforms each second feature vector into a dense vector in a low-dimensional space to obtain N first semantic feature vectors. Finally, the system inputs the N first semantic feature vectors into the fully connected layer of the initial neural network model, and iteratively trains the initial neural network model according to the cross-entropy loss function and the normalized exponential function to obtain the semantic recognition model.
[0061] Optionally, after obtaining N first semantic feature vectors, the system can set a target label for each first semantic feature vector to obtain N target labels, where the target labels are used to characterize the intent category of each first prompt word statement. Then, the N first semantic feature vectors and N target labels are input into the fully connected layer in the initial neural network model, and the initial neural network model is iteratively trained according to the cross-entropy loss function and the normalized exponential function to obtain the semantic recognition model.
[0062] Optionally, in the method for recognizing prompt words provided in this application embodiment, before obtaining the preset clustering center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category, the system can obtain M prompt words from the intent dictionary; then encode each prompt word to obtain M third feature vectors; then input the M third feature vectors into the semantic recognition model to obtain M second semantic feature vectors and K intent categories output by the semantic recognition model, where K is a positive integer and K is less than or equal to M; then divide the M second semantic feature vectors into K vector sets according to the K intent categories, where the second semantic feature vectors in each vector set correspond to the same intent category; finally, based on the preset clustering algorithm, each intent category, and the vector set corresponding to the intent category, determine the preset clustering center vector corresponding to each intent category.
[0063] For example, such as Figure 2 As shown, the system can obtain 6 prompt words from the intent dictionary and encode the 6 prompt words to obtain 6 third feature vectors. The system then uses a semantic recognition model to perform semantic recognition on the six third feature vectors, resulting in six second semantic feature vectors: a, b, c, d, e, and f, and three intent categories: A, B, and C. Specifically, a, b, and c belong to intent category A; d and e belong to intent category B; and f belongs to intent category C. Based on these three intent categories, the six second semantic feature vectors are then divided into three vector sets: {a, b, c}, {d, e}, and {f}. The system then uses the K-means clustering algorithm to aggregate the second semantic feature vectors in intent category A and the vector set {a, b, c}, obtaining the preset cluster center vectors corresponding to intent category A. Similarly, the system uses the K-means clustering algorithm to aggregate the second semantic feature vectors in intent category B and the vector set {d, e}, obtaining the preset cluster center vectors corresponding to intent category B. Finally, the system uses the K-means clustering algorithm to aggregate the second semantic feature vectors in intent category C and the vector set {f}, obtaining the preset cluster center vectors corresponding to intent category C.
[0064] It should be noted that by determining the preset cluster center vector for each intent category based on the preset clustering algorithm, each intent category, and the vector set corresponding to that intent category, an accurate preset cluster center vector can be obtained, which provides data preparation for subsequently determining accurate intent boundary thresholds and recognizing prompt words.
[0065] Optionally, in the method for recognizing prompt words provided in the embodiments of this application, after determining the preset clustering center vector corresponding to each intent category based on the preset clustering algorithm, each intent category, and the vector set corresponding to the intent category, the system can obtain L first distances corresponding to each intent category by calculating the distances between L second semantic feature vectors in each vector set and the preset clustering center vector corresponding to the vector set, where L is a positive integer; then, the maximum distance among the L first distances corresponding to each intent category is used as the intent boundary threshold corresponding to the intent category.
[0066] For example, the system can calculate the distances between vectors a, b, and c in the vector set {a, b, c} and the preset cluster center vector corresponding to intent category A, and obtain the first distances as 10, 20, and 30 respectively. Then the system can determine 30 as the intent boundary threshold corresponding to intent category A.
[0067] Optionally, the first distance may include, but is not limited to, Euclidean distance.
[0068] It should be noted that, as Figure 2 As shown, by using the maximum distance between the L second semantic feature vectors in each vector set and the preset cluster center vector corresponding to that vector set as the intent boundary threshold, the accuracy of the intent boundary threshold is improved, thereby improving the accuracy of prompt word statement recognition.
[0069] Therefore, the technical solution of this application, by incorporating prompt words into the topic and conducting supervised classification training, obtains a semantic recognition model that integrates prior knowledge. This model processes the prompt words to be recognized, yielding accurate target semantic feature vectors and target intent categories. Then, based on the target distance between the target semantic feature vector and the preset clustering center vector corresponding to the target intent category, as well as the intent boundary threshold corresponding to the target intent category, the recognition result of the prompt words is determined, ensuring accurate identification. Furthermore, updating the intent dictionary based on the recognition result avoids storing excessive redundant prompt words, thus improving the maintenance efficiency of the intent dictionary and solving the problem of low maintenance efficiency in related technologies due to the inability to accurately recognize prompt words.
[0070] Example 2
[0071] According to an embodiment of this application, an embodiment of a device for recognizing prompt words is provided, wherein, Figure 4 A schematic diagram of an optional prompt word / phrase recognition device according to an embodiment of this application is shown below. Figure 4 As shown, the device includes:
[0072] The first acquisition module 401 is used to acquire the prompt words to be recognized, wherein the prompt words to be recognized are used to characterize the text description information corresponding to the target image, and the target image is the image expected to be generated for the target object;
[0073] The semantic recognition module 402 is used to input the prompt word statement to be recognized into the semantic recognition model to obtain the target semantic feature vector corresponding to the prompt word statement to be recognized and the target intent category corresponding to the prompt word statement to be recognized output by the semantic recognition model.
[0074] The second acquisition module 403 is used to acquire the preset clustering center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category;
[0075] Calculation module 404 is used to calculate the distance between the target semantic feature vector and the preset cluster center vector to obtain the target distance;
[0076] The determination module 405 is used to determine the recognition result of the prompt words and statements to be recognized based on the target distance and the intent boundary threshold, and to update the intent dictionary based on the recognition result. The intent dictionary is used to store M prompt words and statements, each prompt word and statement is used to represent the text description information corresponding to an image, each image is the image expected to be generated by the target object, and M is a positive integer.
[0077] It should be noted that the first acquisition module 401, semantic recognition module 402, second acquisition module 403, calculation module 404 and determination module 405 mentioned above correspond to steps S101 to S105 in the above embodiment 1. The five modules and the corresponding steps implement the same examples and application scenarios, but are not limited to the content disclosed in the above embodiment 1.
[0078] Optionally, the determining module includes: a judging unit, used to judge whether the target distance is greater than or equal to the intent boundary threshold; a first determining unit, used to determine a first recognition result as the recognition result when the target distance is greater than or equal to the intent boundary threshold, wherein the first recognition result is used to characterize the prompt word statement to be recognized as a prompt word statement that does not exist in the intent dictionary; and a second determining unit, used to determine a second recognition result as the recognition result when the target distance is less than the intent boundary threshold, wherein the second recognition result is used to characterize the prompt word statement to be recognized as a prompt word statement that already exists in the intent dictionary.
[0079] Optionally, the determination module further includes: an adding unit, used to add the prompt word / statement to be recognized to the intent dictionary when the recognition result is determined to be the first recognition result; and a prohibition module, used to prohibit the addition of the prompt word / statement to be recognized to the intent dictionary when the recognition result is determined to be the second recognition result.
[0080] Optionally, the device for recognizing prompt words and phrases further includes: a third acquisition module, used to acquire a target training set, wherein the target training set includes at least N first prompt words and phrases, each first prompt word and phrase being used to characterize the textual description information corresponding to a first image, each first image being an image expected to be generated by the target object, and N being a positive integer; a first processing module, used to encode each first prompt word and phrase to obtain N first feature vectors; and a first training module, used to input the N first feature vectors into an initial neural network model, and iteratively train the initial neural network model according to the cross-entropy loss function and the normalized exponential function to obtain a semantic recognition model.
[0081] Optionally, the first training module includes: a first processing unit, used to input N first feature vectors into a pooling layer in the initial neural network model to obtain N second feature vectors output by the pooling layer, wherein the pooling layer is used to perform feature filtering on the first feature vectors; a second processing unit, used to input N second feature vectors into a dense layer in the initial neural network model to obtain N first semantic feature vectors output by the dense layer, wherein the dense layer is used to convert the second feature vectors into dense vectors in a low-dimensional space; and a third processing unit, used to input N first semantic feature vectors into a fully connected layer in the initial neural network model, and iteratively train the initial neural network model according to the cross-entropy loss function and the normalized exponential function to obtain a semantic recognition model.
[0082] Optionally, the device for recognizing prompt words and phrases further includes: a fourth acquisition module, used to acquire M prompt words and phrases from an intent dictionary before acquiring the preset clustering center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category; a second processing module, used to encode each prompt word and phrase to obtain M third feature vectors; a first semantic recognition module, used to input the M third feature vectors into a semantic recognition model to obtain M second semantic feature vectors and K intent categories output by the semantic recognition model, where K is a positive integer and K is less than or equal to M; a partitioning module, used to partition the M second semantic feature vectors into K vector sets according to the K intent categories, where the second semantic feature vectors in each vector set correspond to the same intent category; and a first determination module, used to determine the preset clustering center vector corresponding to each intent category based on a preset clustering algorithm, each intent category, and the vector set corresponding to the intent category.
[0083] Optionally, the device for recognizing prompt words further includes: a first calculation module, used to determine the preset clustering center vector corresponding to each intent category based on a preset clustering algorithm, each intent category, and the vector set corresponding to the intent category, and then calculate the distance between L second semantic feature vectors in each vector set and the preset clustering center vector corresponding to the vector set, to obtain L first distances corresponding to each intent category, where L is a positive integer; and a second determination module, used to take the maximum distance among the L first distances corresponding to each intent category as the intent boundary threshold corresponding to the intent category.
[0084] Example 3
[0085] According to another aspect of the embodiments of this application, a computer-readable storage medium is also provided, in which a computer program is stored, wherein the computer program is configured to execute the above-described method for recognizing prompt words when it is run.
[0086] Example 4
[0087] According to another aspect of the embodiments of this application, an electronic device is also provided, wherein, Figure 5 This is a schematic diagram of an optional electronic device according to an embodiment of this application, such as... Figure 5 As shown, the electronic device includes one or more processors; and a memory for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement a method for running the programs, wherein the programs are configured to execute the aforementioned method for recognizing prompt statements during runtime.
[0088] like Figure 5As shown, this application embodiment provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps:
[0089] The process involves: acquiring the prompt phrases to be recognized, where each prompt phrase represents the textual description information corresponding to a target image, and the target image is the image expected to be generated by the target object; inputting the prompt phrases to be recognized into a semantic recognition model to obtain the target semantic feature vector and the target intent category corresponding to the prompt phrases output by the semantic recognition model; acquiring the preset cluster center vector and the intent boundary threshold corresponding to the target intent category; calculating the distance between the target semantic feature vector and the preset cluster center vector to obtain the target distance; determining the recognition result of the prompt phrases based on the target distance and the intent boundary threshold; and updating the intent dictionary based on the recognition result, where the intent dictionary stores M prompt phrases, each prompt phrase represents the textual description information corresponding to an image, and each image is the image expected to be generated by the target object, where M is a positive integer.
[0090] Optionally, when the processor executes the program, it further implements the following steps: determining whether the target distance is greater than or equal to the intent boundary threshold; if the target distance is greater than or equal to the intent boundary threshold, determining a first recognition result as the recognition result, wherein the first recognition result is used to characterize the prompt word statement to be recognized as a prompt word statement that does not exist in the intent dictionary; if the target distance is less than the intent boundary threshold, determining a second recognition result as the recognition result, wherein the second recognition result is used to characterize the prompt word statement to be recognized as a prompt word statement that already exists in the intent dictionary.
[0091] Optionally, when the processor executes the program, it also implements the following steps: if the recognition result is determined to be the first recognition result, the prompt word to be recognized is added to the intent dictionary; if the recognition result is determined to be the second recognition result, the addition of the prompt word to be recognized to the intent dictionary is prohibited.
[0092] Optionally, the processor, when executing the program, further implements the following steps: obtaining a target training set, wherein the target training set includes at least N first prompt words, each first prompt word being used to characterize the textual description information corresponding to a first image, each first image being the image expected to be generated for the target object, and N being a positive integer; encoding each first prompt word to obtain N first feature vectors; inputting the N first feature vectors into an initial neural network model, and iteratively training the initial neural network model based on the cross-entropy loss function and the normalization exponential function to obtain a semantic recognition model.
[0093] Optionally, the processor further implements the following steps when executing the program: inputting N first feature vectors into the pooling layer in the initial neural network model to obtain N second feature vectors output by the pooling layer, wherein the pooling layer is used to perform feature filtering on the first feature vectors; inputting N second feature vectors into the dense layer in the initial neural network model to obtain N first semantic feature vectors output by the dense layer, wherein the dense layer is used to convert the second feature vectors into dense vectors in a low-dimensional space; inputting N first semantic feature vectors into the fully connected layer in the initial neural network model, and iteratively training the initial neural network model according to the cross-entropy loss function and the normalized exponential function to obtain a semantic recognition model.
[0094] Optionally, the processor further implements the following steps when executing the program: before obtaining the preset clustering center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category, obtain M prompt words from the intent dictionary; encode each prompt word to obtain M third feature vectors; input the M third feature vectors into the semantic recognition model to obtain M second semantic feature vectors and K intent categories output by the semantic recognition model, where K is a positive integer and K is less than or equal to M; divide the M second semantic feature vectors into K vector sets according to the K intent categories, where the second semantic feature vectors in each vector set correspond to the same intent category; determine the preset clustering center vector corresponding to each intent category based on the preset clustering algorithm, each intent category, and the vector set corresponding to that intent category.
[0095] Optionally, when the processor executes the program, it also implements the following steps: after determining the preset clustering center vector corresponding to each intent category based on the preset clustering algorithm, each intent category, and the vector set corresponding to the intent category, it calculates the distance between the L second semantic feature vectors in each vector set and the preset clustering center vector corresponding to the vector set, and obtains the L first distances corresponding to each intent category, where L is a positive integer; and takes the maximum distance among the L first distances corresponding to each intent category as the intent boundary threshold corresponding to the intent category.
[0096] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0097] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0098] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between units or modules may be electrical or other forms.
[0099] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0100] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0101] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0102] The above are merely preferred embodiments of this application. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for recognizing prompt words in sentences, characterized in that, include: Obtain the prompt words to be identified, wherein the prompt words to be identified are used to characterize the text description information corresponding to the target image, and the target image is the image expected to be generated for the target object; The prompt word to be identified is input into the semantic recognition model to obtain the target semantic feature vector corresponding to the prompt word to be identified and the target intent category corresponding to the prompt word to be identified, which are output by the semantic recognition model. Obtain the preset cluster center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category, wherein the intent boundary threshold is the maximum distance among the distances between the preset cluster center vector and each second semantic feature vector, and each second semantic feature vector is determined based on the prompt word statement corresponding to the target intent category; Calculate the distance between the target semantic feature vector and the preset cluster center vector to obtain the target distance; The recognition result of the prompt word statement to be recognized is determined based on the target distance and the intent boundary threshold, and the intent dictionary is updated based on the recognition result. The intent dictionary is used to store M prompt words, each prompt word is used to represent the text description information corresponding to an image, each image is the image expected to be generated by the target object, and M is a positive integer. Determining the recognition result of the prompt word statement to be recognized based on the target distance and the intent boundary threshold includes: determining whether the target distance is greater than or equal to the intent boundary threshold; if the target distance is greater than or equal to the intent boundary threshold, determining a first recognition result as the recognition result, wherein the first recognition result is used to characterize the prompt word statement to be recognized as a prompt word statement that does not exist in the intent dictionary; if the recognition result is determined to be the first recognition result, adding the prompt word statement to be recognized to the intent dictionary.
2. The method according to claim 1, characterized in that, The recognition result of the prompt word statement to be recognized is determined based on the target distance and the intent boundary threshold, including: If the target distance is less than the intent boundary threshold, the second recognition result is determined as the recognition result, wherein the second recognition result is used to characterize the prompt word statement to be recognized as a prompt word statement that already exists in the intent dictionary.
3. The method according to claim 2, characterized in that, The intent dictionary is updated based on the recognition results, including: If the recognition result is determined to be the second recognition result, it is prohibited to add the prompt word to be recognized to the intent dictionary.
4. The method according to claim 1, characterized in that, The semantic recognition model is obtained in the following way: Obtain a target training set, wherein the target training set includes at least N first prompt words, each first prompt word is used to characterize the text description information corresponding to a first image, each first image is the image expected to be generated by the target object, and N is a positive integer; Each of the first prompt words is encoded to obtain N first feature vectors; The N first feature vectors are input into the initial neural network model, and the initial neural network model is iteratively trained according to the cross-entropy loss function and the normalization exponential function to obtain the semantic recognition model.
5. The method according to claim 4, characterized in that, The N first feature vectors are input into an initial neural network model, and the initial neural network model is iteratively trained according to the cross-entropy loss function and the normalization exponential function to obtain the semantic recognition model, including: The N first feature vectors are input into the pooling layer in the initial neural network model to obtain N second feature vectors output by the pooling layer, wherein the pooling layer is used to perform feature filtering on the first feature vectors; The N second feature vectors are input into the dense layer of the initial neural network model to obtain N first semantic feature vectors output by the dense layer, wherein the dense layer is used to convert the second feature vectors into dense vectors in a low-dimensional space; The N first semantic feature vectors are input into the fully connected layer of the initial neural network model, and the initial neural network model is iteratively trained according to the cross-entropy loss function and the normalized exponential function to obtain the semantic recognition model.
6. The method according to claim 1, characterized in that, Before obtaining the preset clustering center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category, the method further includes: Obtain M prompt words from the intent dictionary; Each prompt word statement is encoded to obtain M third feature vectors; The M third feature vectors are input into the semantic recognition model to obtain the M second semantic feature vectors and K intent categories output by the semantic recognition model, where K is a positive integer and K is less than or equal to M; Based on the K intent categories, the M second semantic feature vectors are divided into K vector sets, wherein the second semantic feature vectors in each vector set correspond to the same intent category; Based on a preset clustering algorithm, each intent category, and the vector set corresponding to that intent category, a preset clustering center vector is determined for each intent category.
7. The method according to claim 6, characterized in that, After determining the preset cluster center vector corresponding to each intent category based on a preset clustering algorithm, each intent category, and the vector set corresponding to that intent category, the method further includes: Calculate the distance between the L second semantic feature vectors in each vector set and the preset cluster center vector corresponding to the vector set to obtain the L first distances corresponding to each intent category, where L is a positive integer; The maximum distance among the L first distances corresponding to each intent category is used as the intent boundary threshold corresponding to that intent category.
8. A device for recognizing prompt words and phrases, used to implement the method for recognizing prompt words and phrases according to any one of claims 1 to 7, characterized in that, include: The first acquisition module is used to acquire the prompt words to be identified, wherein the prompt words to be identified are used to characterize the text description information corresponding to the target image, and the target image is the image expected to be generated for the target object; The semantic recognition module is used to input the prompt word statement to be recognized into the semantic recognition model to obtain the target semantic feature vector corresponding to the prompt word statement to be recognized and the target intent category corresponding to the prompt word statement to be recognized output by the semantic recognition model. The second acquisition module is used to acquire the preset clustering center vector corresponding to the target intent category and the intent boundary threshold corresponding to the target intent category; The calculation module is used to calculate the distance between the target semantic feature vector and the preset cluster center vector to obtain the target distance; The determination module is used to determine the recognition result of the prompt word statement to be recognized based on the target distance and the intent boundary threshold, and to update the intent dictionary based on the recognition result. The intent dictionary is used to store M prompt word statements, each prompt word statement is used to represent the text description information corresponding to an image, each image is the image expected to be generated by the target object, and M is a positive integer.
9. A computer-readable storage medium, characterized in that, A computer-readable storage medium stores a computer program, wherein the computer program is configured to execute, at runtime, the method for recognizing prompt words as described in any one of claims 1 to 7.
10. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the prompt word statement recognition method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Intention recognition model optimization method and device, equipment and storage medium
CN115146064A
Transaction transaction-oriented intention recognition method in online dialogue
CN115982337A