Text generation method and device, electronic equipment and storage medium
By calculating and clustering the corpus data of the target user, a personalized text generation instruction is constructed, and a text generation model is input to generate the target text, the problem of cumbersome text generation process in the existing technology is solved. The text generation process is complicated and cannot be personalized in the existing technology. , realizes efficient and personalized text content generation.
Patent Information
- Application Number
- CN202411309865.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2025-02-18
AI Technical Summary
The generation process of text content in the prior art is cumbersome, requiring a lot of resources, and personalized text content display cannot be realized.
By obtaining the corpus data of the target user, calculating the semantic similarity between candidate words, clustering to determine label information, constructing text generation instructions, and inputting them into the text generation model for semantic analysis to generate personalized target text.
It realizes personalized generation of text content, improves targetedness for different target users, reduces manual operations, and saves resources.
Smart Images

Figure CN119476250A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a text generation method, device, electronic device and storage medium. Background Art
[0002] On the Internet platform, it is often necessary to display a large amount of text content. For example, on the activity page, it is necessary to use text to introduce the mechanism of the current activity. On some front-end pages, it is necessary to use text to introduce the operation process of the current page, and so on.
[0003] However, the generation of text content requires staff to review the content many times, which is a cumbersome process that consumes a lot of resources. Moreover, in the face of a large number of visiting users, it is impossible to achieve personalized text content display. Summary of the invention
[0004] In order to solve the above technical problems, the present application shows a text generation method, device, electronic device and storage medium, so as to at least solve the problem that the text content generation process in the related art is relatively cumbersome, requires a large amount of resources, and cannot realize personalized text content display. The technical solution of the present disclosure is as follows:
[0005] In a first aspect, the present application provides a text generation method, the method comprising:
[0006] Obtain corpus data of target users;
[0007] Calculating semantic similarities between candidate words included in the corpus data, clustering the candidate words based on the semantic similarities, and determining label information of the target user according to the clustering results;
[0008] Based on the tag information, construct a text generation instruction;
[0009] The text generation instruction is input into a target text generation model, and semantic analysis is performed on the text generation instruction to generate a target text corresponding to the target user.
[0010] Optionally, obtaining the corpus data of the target user includes:
[0011] Acquire initial data related to the target user; the initial data includes feature data and behavior data of the target user;
[0012] The initial data is cleaned to obtain the corpus data of the target user.
[0013] Optionally, calculating the semantic similarity between the candidate words included in the corpus data, clustering the candidate words based on the semantic similarity, and determining the label information of the target user according to the clustering result includes:
[0014] Performing word segmentation processing on the corpus data to obtain multiple candidate words;
[0015] Calculating the semantic similarity between every two candidate words;
[0016] Based on the semantic similarity between every two candidate words, clustering the plurality of candidate words to determine a plurality of groups;
[0017] According to the descending order of the number of the candidate words included in each group, a preset number of target groups are determined from the multiple groups, and the label information of the target user is determined based on the target groups.
[0018] Optionally, constructing a text generation instruction based on the tag information includes:
[0019] Obtaining a scene label and an identity label of the current scene; the identity label is used to indicate the identity of the role that the target text generation model needs to play;
[0020] Determine the prompt word corresponding to the scene label, use the identity label as role information of the prompt word, use the label information as a keyword in the prompt word, and construct a text generation instruction.
[0021] Optionally, before inputting the text generation instruction into a target text generation model, performing semantic analysis on the text generation instruction, and generating a target text corresponding to the target user, the method further includes:
[0022] Obtain the reference text generation model and the training corpus for the current scenario;
[0023] Clustering the training words according to the semantic similarity between the training words included in the training corpus, and determining the training data based on the clustering result;
[0024] Based on the training data, construct text training instructions;
[0025] Inputting the text training instruction into the reference text generation model for semantic analysis and processing to generate training text;
[0026] In the case that the training text does not meet the evaluation condition, the model parameters of the reference text generation model are debugged until the training text meets the evaluation condition, and the reference text generation model is used as the target text generation model.
[0027] Optionally, after using the reference text generation model as the target text generation model, the method further includes:
[0028] Encapsulating the target text generation model as a target interface;
[0029] The step of inputting the text generation instruction into a target text generation model, performing semantic analysis on the text generation instruction, and generating a target text corresponding to the target user includes:
[0030] The text generation instruction is input into the target interface, and the target text generation model is called to perform semantic analysis on the text generation instruction to generate a target text corresponding to the target user.
[0031] Optionally, the step of inputting the text generation instruction into a target text generation model, performing semantic analysis on the text generation instruction, and generating a target text corresponding to the target user includes:
[0032] Inputting the text generation instruction into a target text generation model, performing semantic analysis on the text generation instruction, and generating a reference text;
[0033] Performing data verification on the reference text to obtain a verification result;
[0034] In the case where the verification result satisfies the text output condition, using the reference text as the target text corresponding to the target user;
[0035] When the verification result does not satisfy the text output condition, text adjustment is performed on the reference text to obtain the target text corresponding to the target user.
[0036] Optionally, when the verification result does not meet the text output condition, the method further includes:
[0037] Model parameters of the target text generation model are debugged based on the target text.
[0038] In a second aspect, an embodiment of the present invention provides a text generation device, including:
[0039] The acquisition module is used to obtain the corpus data of the target user;
[0040] A clustering module, used to calculate the semantic similarity between the candidate words included in the corpus data, cluster the candidate words based on the semantic similarity, and determine the label information of the target user according to the clustering result;
[0041] A construction module, used to construct a text generation instruction based on the tag information;
[0042] The generation module is used to input the text generation instruction into the target text generation model, perform semantic analysis on the text generation instruction, and generate the target text corresponding to the target user.
[0043] In a third aspect, an embodiment of the present invention provides an electronic device, including:
[0044] processor;
[0045] a memory for storing instructions executable by the processor;
[0046] The processor is configured to execute the instructions to implement any of the above-mentioned text generation methods.
[0047] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium. When instructions in the computer-readable storage medium are executed by a processor of a text generating electronic device, the text generating electronic device can execute any of the text generating methods described above.
[0048] In a fifth aspect, an embodiment of the present invention provides a computer program product, including a computer program, which implements any of the above-mentioned text generation methods when executed by a processor.
[0049] Compared with the prior art, this application has the following advantages:
[0050] Acquire the corpus data of the target user; calculate the semantic similarity between the candidate words included in the corpus data, cluster the candidate words based on the semantic similarity, and determine the label information of the target user according to the clustering result; construct a text generation instruction based on the label information; input the text generation instruction into the target text generation model, perform semantic analysis on the text generation instruction, and generate a target text corresponding to the target user.
[0051] In this way, based on the semantic similarity between candidate words included in the corpus data of the target user, the candidate words can be clustered and analyzed to determine the label information of the target user, thereby constructing personalized text generation instructions related to the target user. Then, the text generation instructions are input into the target text generation model to automatically generate the target text corresponding to the target user. On the one hand, the pertinence of the target text for different target users can be improved and the target text can be personalized. On the other hand, no manual operation is required in the generation process of the target text, which can save a lot of resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 It is a flowchart of the steps of a text generation method of the present application;
[0053] Figure 2It is a logical diagram of text clustering in this application;
[0054] Figure 3 It is a logical schematic diagram of a text generation method of the present application;
[0055] Figure 4 It is a structural block diagram of a text generation device of the present application;
[0056] Figure 5 is a schematic diagram of an electronic device of the present application;
[0057] Figure 6 It is a block diagram of a device for text generation in the present application. DETAILED DESCRIPTION
[0058] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0059] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0060] In the Internet platform, some scenarios need to display a large amount of text content. For example, on the activity page, you need to use text to introduce the mechanism of the current activity. On some front-end pages, you need to use text to introduce the operation process of the current page, and so on.
[0061] Usually, the generation of text content is done manually, and the staff needs to conduct multiple content deliberations before determining the text content to be displayed. Therefore, it will consume a lot of resources, and the time and manpower costs are high. Moreover, in the case of a large number of visiting users, it is impossible to achieve targeted text content display for different users. Based on this, the present application provides a text generation method to solve the above problems.
[0062] Specifically, the present application can be applied to a server or a terminal. The server may be a local server, other servers in the network, and so on. By obtaining the corpus data of the target user and based on the semantic similarity between the candidate words included in the corpus data, the candidate words can be clustered and analyzed to determine the label information of the target user, and personalized text generation instructions related to the target user can be constructed. The text generation instructions are then input into the target text generation model, and semantic analysis is performed on the text generation instructions to generate the target text corresponding to the target user, so as to obtain the personalized target text for the target user without manual intervention.
[0063] The above-mentioned terminal can be a terminal device in various forms such as a mobile phone, a tablet computer, a desktop computer, a portable laptop computer, etc., and the embodiments of the present application are not limited to this.
[0064] The above-mentioned server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), as well as big data and artificial intelligence platforms.
[0065] Among them, cloud technology refers to a hosting technology that unifies hardware, software, network and other resources in a wide area network or local area network to realize data computing, storage, processing and sharing. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, which is used on demand and flexible and convenient. Cloud computing technology will become an important support. The background services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the high development and application of the Internet industry, in the future, each item may have its own identification mark, and all need to be transmitted to the background system for logical processing. Data of different levels will be processed separately. All kinds of industry data require strong system backing support, which can only be achieved through cloud computing.
[0066] In some embodiments, the above-mentioned server can also be implemented as a node in a blockchain system. Blockchain is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product service layer, and the application service layer.
[0067] Reference Figure 1 , shows a flowchart of the steps of a text generation method of the present application, which may specifically include the following steps:
[0068] In step S11, the corpus data of the target user is obtained.
[0069] In this step, first, it is necessary to obtain the corpus data of the target user, wherein the corpus data can be extracted and constructed from massive data such as platform data, forum data, and off-site data. The corpus data of the target user refers to the corpus data that has a high correlation with the target user, that is, for different users, the corresponding corpus data is different.
[0070] For example, the corpus data of the target user can come from the characteristic data of the target user, such as the target user's gender, age, region, and membership level, etc., and can also come from the target user's behavioral data, such as the comments, barrage or subject content posted by the target user, etc., and can also come from other users' comments on the target user, and can also come from the target user's user information and historical browsing records, etc. This application does not make any specific limitations on this.
[0071] In one implementation, obtaining corpus data of a target user includes:
[0072] Acquire initial data related to the target user; the initial data includes feature data and behavior data of the target user; perform data cleaning on the initial data to obtain corpus data of the target user.
[0073] That is to say, first you need to obtain the initial data related to the target user, for example, feature data includes the target user's membership level, gender and birthday, behavioral data includes the comments, barrage or subject content posted by the target user, etc. Then, clean the initial data to obtain the corpus data of the target user. By cleaning the initial data, screening and normalizing the initial data, it can be ensured that the obtained corpus data can be used for generating the target text in subsequent steps, and the efficiency of generating the target text can be further improved.
[0074] Among them, data cleaning may include steps such as removing special characters, removing HTML (Hyper Text Markup Language) tags, removing stop words, converting uppercase and lowercase letters, and removing spelling errors, etc., and this application does not specifically limit this.
[0075] In step S12, the semantic similarity between the candidate words included in the corpus data is calculated, and the candidate words are clustered based on the semantic similarity, and the label information of the target user is determined according to the clustering result.
[0076] In this step, it is first necessary to determine the semantic similarity between the candidate words, that is, the semantic similarity between the candidate words. Then, the candidate words can be clustered according to the semantic similarity between the candidate words.
[0077] For example, each candidate word and other candidate words with the highest semantic similarity to the candidate word can be grouped in the same group; alternatively, multiple candidate words can be subjected to K-means clustering based on semantic similarity, K candidate words are randomly selected as the initial cluster centers of each cluster, and then each candidate word is assigned to the cluster center closest to it according to the semantic similarity between the remaining candidate words and each cluster center, wherein each time a candidate word is assigned, each cluster will recalculate its cluster center according to the included candidate words until there are no unassigned candidate words; in addition, K-nearest neighbor clustering algorithm, spectral clustering algorithm or density-based clustering algorithm can also be used. The present application does not limit the specific clustering method used, and it is only necessary to divide the candidate words with higher semantic similarity into a group to obtain the clustering result.
[0078] In this way, the semantic similarity between candidate words in the same group is high, which can concentrate on reflecting the characteristics of the target user in a certain aspect. Furthermore, based on the clustering results, the label information of the target user can be determined, and the label information can be more effectively associated with the characteristics of the target user, thereby improving the relevance of the text generation instructions constructed based on the label information and the target user in the subsequent steps.
[0079] The tag information may correspond to the target user's account category, gender, birthday, hobbies, and other information, without specific limitation.
[0080] In one implementation, the semantic similarity between the candidate words included in the corpus data is calculated, and the candidate words are clustered based on the semantic similarity, and the label information of the target user is determined according to the clustering result, including:
[0081] The corpus data is segmented to obtain multiple candidate words; the semantic similarity between every two candidate words is calculated; based on the semantic similarity between every two candidate words, the multiple candidate words are clustered to determine multiple groups; according to the order of the number of candidate words included in each group from large to small, a preset number of target groups are determined from the multiple groups, and the label information of the target user is determined based on the target groups.
[0082] That is to say, for the corpus data of the target user, NLP (Neuro-Linguistic Programming) can be combined for text segmentation and clustering. By performing word segmentation on the corpus data, the corpus data is converted into a series of discrete word units to obtain multiple candidate words. Then, the semantic similarity between each candidate word is calculated, and these candidate words are clustered according to the semantic similarity. The multiple candidate words are divided into multiple groups, and then, a preset number of groups with a larger number of candidate words are determined as target groups, and the label information of the target user is determined based on the target groups.
[0083] Among them, in order to improve the processing speed and reduce noise, after the word segmentation of the corpus data, the stop words can also be removed to make the important information in the corpus data more prominent. After the stop words are removed, each candidate word can be vectorized by using methods such as one-hot encoding, bag-of-words model, word embedding or word frequency statistics, and then the semantic similarity between each candidate word is calculated. For example, the semantic similarity can be measured by using methods such as cosine similarity or vector space model, and there is no specific limitation.
[0084] In this embodiment, the label information of the target user is determined based on the target grouping. This can be by further feature analysis of the candidate words included in the target grouping to obtain a feature label for each target group, and using the feature label of the target group as the label information of the target user. Alternatively, word frequency statistics or correlation analysis can be performed on the candidate words included in the target grouping, and the candidate words with the highest frequency of occurrence or the highest correlation can be used as the label information of the target user, and the present application does not impose any limitation on this.
[0085] For example, the preset number of the determined target groups can be set according to different business scenarios, such as 5, that is, the 5 groups including the largest number of candidate words are used as target groups.
[0086] In Chinese business scenarios, HanLP (Han Linguistic Programming) can be used to perform text segmentation and clustering on the target user's corpus data. HanLP is an NLP toolkit consisting of a series of models and algorithms, which has the characteristics of complete functions, efficient performance, clear architecture, up-to-date corpus, and customizability; alternatively, other natural language processing models can also be used, which is not limited in this application.
[0087] like Figure 2 As shown, a logical diagram of text clustering in an embodiment of the present application, wherein each letter corresponds to a candidate word, and after word segmentation processing of the corpus data, multiple candidate words are obtained and mixed together. Through text clustering, the semantic similarity between each candidate word is first calculated, and then the candidate words with higher semantic similarity can be aggregated into the same category, and four groups A, B, C, and D are obtained, and each group includes several candidate words with higher semantic similarity.
[0088] In step S13, a text generation instruction is constructed based on the tag information.
[0089] In this step, a text generation instruction may be constructed according to the tag information of the target user, wherein the text generation instruction may include a text description about the target user to reflect the relevant characteristics of the target user.
[0090] For example, in an event marketing scenario, the text generation instruction may be: "Please write three marketing copies, each with less than 30 Chinese characters, based on the following keywords, as a marketer of a video website. Keywords: A, B, C", where "A", "B", and "C" are words related to the characteristics of the target users.
[0091] For example, the label information can be directly used as "A", "B", "C" in the text generation instruction, or the label information can be further processed and converted to obtain more standardized user labels as "A", "B", "C" in the text generation instruction. This application does not make any specific limitations on this.
[0092] In one implementation, constructing a text generation instruction based on tag information includes:
[0093] Get the scene label and identity label of the current scene. The identity label is used to indicate the identity of the role that the target text generation model needs to play. Determine the prompt word corresponding to the scene label, use the identity label as the role information of the prompt word, and use the label information as the keyword in the prompt word to construct the text generation instruction.
[0094] In this embodiment, the prompt words corresponding to different scenes can be configured in advance based on the prompt word project. Then, after obtaining the scene label, the prompt word corresponding to the current scene can be queried based on the scene label, and then the text generation instruction can be constructed. It can be understood that the text generation instruction usually needs to indicate the role information to be played by the target text generation model, the current scene, and the keywords of the target text to be generated. Different roles, scenes, and keywords will result in different generated target texts.
[0095] For example, in the above example, the current scene is an event marketing scene, and the corresponding prompt is "Please write three marketing copies with less than 30 Chinese characters each according to the following keywords as a [...], keywords: [...]", the role information is a marketing staff of a video website, and the keywords are A, B, and C. After determining the prompt, role information, and keywords, fill the role information and keywords into the corresponding positions in the prompt, and you will get the text generation instruction.
[0096] In addition, if the current scene is an operation instruction scene, the corresponding prompt word is "Please guide the users corresponding to the following keywords to perform preset operations in sequence as a [...], keywords: [...]", and the identity tag is the guide of the website, then, continuing the previous example, the text generation instruction can be: "Please guide the users corresponding to the following keywords to perform preset operations in sequence as a guide of the website, keywords: A, B, C".
[0097] Among them, the scene label of the current scene can be determined according to the user's input instruction, or according to the current time, location or page information, etc., without specific limitation.
[0098] In this way, various text generation instructions can be generated more flexibly to suit different business scenarios.
[0099] In step S14, the text generation instruction is input into the target text generation model, and semantic analysis is performed on the text generation instruction to generate a target text corresponding to the target user.
[0100] In this step, after obtaining the text generation instruction, the target text generation model can be used to perform semantic analysis on the text generation instruction to automatically generate the target text corresponding to the target user without manual writing, thereby reducing the generation cost of the target text.
[0101] Among them, the target text generation model can select the GPT-3 (Generative Pre-Trained Transformer-3) model or the GPT-3.5 (Generative Pre-Trained Transformer-3.5) model, and this application does not limit this.
[0102] In one implementation, before inputting the text generation instruction into the target text generation model and performing semantic analysis on the text generation instruction to generate the target text corresponding to the target user, the method further includes:
[0103] Obtain a reference text generation model and training corpus for the current scenario; the training corpus includes input instructions corresponding to the current scenario and expected text corresponding to the input instructions; input the input instructions into the reference text generation model for semantic analysis and processing to generate training text; when the loss value between the training text and the expected text is greater than a preset loss value, debug the model parameters of the reference text generation model until the loss value is no greater than the preset loss value, and use the reference text generation model as the target text generation model.
[0104] That is to say, before the text generation instruction is input into the target text generation model for semantic analysis, the reference text generation model can be trained, and the model parameters of the reference text generation model can be debugged using the training corpus of the current scene to obtain the target text generation model, wherein the training corpus of the current scene can include the input instruction corresponding to the current scene and the expected text corresponding to the input instruction. The input instruction is input into the reference text generation model for semantic analysis to generate the training text. Then, the loss value between the training text and the expected text can be calculated. If the loss value is greater than the preset loss value, the model parameters of the reference text generation model can be debugged until the loss value is no greater than the preset loss value, and the reference text generation model can be used as the target text generation model.
[0105] By training the reference text generation model based on the training corpus, the target text generation model can filter and match the preset vocabulary. For example, some special words cannot be included in the target text, or the current scenario requires the recognition of some special words, etc. In this way, the target text generation model can be more adapted to the current scenario. After semantic analysis of the text generation instructions, a target text that better meets the requirements can be obtained, thereby realizing the customization of the target text generation model.
[0106] The input instructions in the training corpus can be obtained based on cluster analysis of pre-acquired training words. For example, the training words can be clustered according to the semantic similarity between the training words, and the training data can be determined based on the clustering results; based on the training data, the input instructions are constructed.
[0107] For example, if the text generation instruction includes three consecutive characters "XYZ", under normal circumstances, the probability of the word segmentation result being "XY / Z" is greater than the probability of the word segmentation result being "X / YZ". However, in some professional fields or custom scenarios, "YZ" needs to be a complete special word. Obviously, the word segmentation result of "XY / Z" under normal circumstances is inappropriate, and the final target text will also be affected.
[0108] Then, the reference text generation model can be trained through the training corpus. The input instructions of the training corpus include "XYZ", and the expected text is the text generated based on the word segmentation result "X / YZ", so as to achieve the matching filtering of "YZ" by the target text generation model. The target text generation model can recognize and obtain the word segmentation result "X / YZ". In this way, the target text generation model can accurately recognize the semantics included in the text generation instructions, and the generated target text will be more fluent.
[0109] In addition, training the reference text generation model may also include supplementary definitions of certain special words so that the target text generation model can further perform semantic analysis on the text generation instructions based on the definitions of these special words, etc. This application does not limit this.
[0110] In one implementation, after training a reference text generation model based on training corpus and debugging model parameters of the reference text generation model to obtain a target text generation model, the method further includes:
[0111] Encapsulate the target text generation model as a target interface;
[0112] The text generation instruction is input into the target text generation model, and the text generation instruction is semantically analyzed and processed to generate the target text corresponding to the target user, including:
[0113] The text generation instruction is input into the target interface, and the target text generation model is called to perform semantic analysis on the text generation instruction to generate the target text corresponding to the target user.
[0114] That is to say, after training the reference text generation model and obtaining the target text generation model, the target text generation model can be encapsulated into an API (Application Programming Interface) interface, so that the trained target text generation model can be used to generate the target text through the interface call.
[0115] Specifically, the function code of the target text generation model can be loaded into the target interface first, and then the interface information of the target interface can be defined, including the request method, the format and type of input data, and the format and type of output data, etc. In this way, an encapsulated target interface is obtained, wherein the target interface can be an OpenAI (Open Artificial Intelligence) interface.
[0116] In one implementation, a text generation instruction is input into a target text generation model, a semantic analysis is performed on the text generation instruction, and a target text corresponding to a target user is generated, including:
[0117] Inputting the text generation instruction into the target text generation model, performing semantic analysis on the text generation instruction, and generating a reference text; performing data verification on the reference text, and obtaining a verification result;
[0118] When the inspection result satisfies the text output condition, the reference text is used as the target text corresponding to the target user;
[0119] When the verification result does not meet the text output condition, the reference text is adjusted to obtain the target text corresponding to the target user.
[0120] It is understandable that since the output of the target text generation model may be uncertain or not smooth enough, the reference text output by the target text generation model may be further post-processed and optimized to obtain the target text.
[0121] For example, some sensitive vocabulary libraries may be created to filter or replace sensitive words, or the fluency of the reference text may be tested and optimized. In addition, the reference text may be manually reviewed and tested, etc. This application does not limit this.
[0122] The fluency of the reference text may be tested by using LM (Language Model) or other text fluency detection algorithms, which are not limited in this application.
[0123] In one implementation, when the verification result does not meet the text output condition, the model parameters of the target text generation model may be further debugged based on the target text.
[0124] That is to say, when the test results do not meet the text output conditions, the reference text can be optimized and adjusted to obtain the target text. Then, based on the adjusted target text, the target text generation model can be feedback optimized. In this way, through continuous adjustment, the output of the target text generation model becomes more and more stable and smooth, and the subsequently generated reference text can better meet the needs, thereby continuously reducing the adjustment of the reference text, making the generation of the target text more efficient.
[0125] like Figure 3 Shown is a logical schematic diagram of a text generation method of the present application.
[0126] First, data collection is performed on platform data, forum data, off-site data, etc. to obtain the initial data of the target user; the initial data is cleaned to obtain the corpus data of the target user; the corpus data is converted into a series of discrete word units by performing word segmentation processing to obtain multiple candidate words, and these candidate words are aggregated and classified to determine the target group, and the label information of the target user is determined based on the target group.
[0127] Then, the target text generation model is selected, and based on the label information of the target user, a text generation instruction is generated as the input instruction of the target text generation model. By calling the OpenAI interface of the target text generation model, the target text generation model performs semantic analysis on the text generation instruction to generate a reference text corresponding to the target user.
[0128] Then, data verification is performed on the reference text to obtain a verification result; when the verification result meets the text output condition, the reference text is used as the target text corresponding to the target user; when the verification result does not meet the text output condition, text adjustment is performed on the reference text to obtain the target text corresponding to the target user.
[0129] From the above, it can be seen that the technical solution provided by the embodiments of the present disclosure can perform cluster analysis on the candidate words based on the semantic similarity between the candidate words included in the corpus data of the target user, determine the label information of the target user, and then construct personalized text generation instructions related to the target user. Then, the text generation instructions are input into the target text generation model, so as to automatically generate the target text corresponding to the target user. On the one hand, it can improve the targeting of the target text for different target users and realize the personalization of the target text. On the other hand, no manual operation is required in the generation process of the target text, which can save a lot of resources.
[0130] Reference Figure 4 , shows a schematic diagram of the structure of a text generation device of the present application, which may specifically include:
[0131] An acquisition module 201 is used to acquire corpus data of a target user;
[0132] A clustering module 202, configured to calculate the semantic similarity between the candidate words included in the corpus data, cluster the candidate words based on the semantic similarity, and determine the tag information of the target user according to the clustering result;
[0133] A construction module 203, used to construct a text generation instruction based on the tag information;
[0134] The generation module 204 is used to input the text generation instruction into the target text generation model, perform semantic analysis on the text generation instruction, and generate a target text corresponding to the target user.
[0135] From the above, it can be seen that the technical solution provided by the embodiments of the present disclosure can perform cluster analysis on the candidate words based on the semantic similarity between the candidate words included in the corpus data of the target user, determine the label information of the target user, and then construct personalized text generation instructions related to the target user. Then, the text generation instructions are input into the target text generation model, so as to automatically generate the target text corresponding to the target user. On the one hand, it can improve the targeting of the target text for different target users and realize the personalization of the target text. On the other hand, no manual operation is required in the generation process of the target text, which can save a lot of resources.
[0136] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0137] Figure 5 It is a block diagram of an electronic device for text generation according to an exemplary embodiment, including a processor and a memory, wherein the memory is used to store computer programs; and the processor is used to execute the programs stored in the memory.
[0138] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0139] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0140] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory including instructions, and the above instructions can be executed by a processor of an electronic device to perform the above method. Optionally, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0141] In an exemplary embodiment, a computer program product is also provided. When the computer program product is executed on a computer, the computer implements the above-mentioned method for generating a comment text.
[0142] From the above, it can be seen that the technical solution provided by the embodiment of the embodiment of the present invention can perform cluster analysis on the candidate words based on the semantic similarity between the candidate words included in the corpus data of the target user, determine the label information of the target user, and then construct personalized text generation instructions related to the target user. Then, the text generation instructions are input into the target text generation model, so as to realize automatic generation of the target text corresponding to the target user. On the one hand, it can improve the targeting of the target text for different target users and realize the personalization of the target text. On the other hand, no manual operation is required in the generation process of the target text, which can save a lot of resources.
[0143] Figure 6 It is a block diagram of a device 800 for text generation according to an exemplary embodiment.
[0144] For example, apparatus 800 may be a mobile phone, a computer, a digital broadcast electronic device, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0145] Reference Figure 6, the device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .
[0146] The processing component 802 generally controls the overall operation of the device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.
[0147] The memory 804 is configured to store various types of data to support operations on the device 800. Examples of such data include instructions for any application or method operating on the device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0148] The power supply component 807 provides power to the various components of the device 800. The power supply component 807 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 800.
[0149] The multimedia component 808 includes a screen that provides an output interface between the device 800 and the account. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the account. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data to be processed. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0150] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the device 800 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.
[0151] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: home button, volume button, start button, and lock button.
[0152] The sensor assembly 814 includes one or more sensors for providing various aspects of the status assessment of the device 800. For example, the sensor assembly 814 can detect the open / closed state of the device 800, the relative positioning of components, such as the display and keypad of the device 800, and the sensor assembly 814 can also detect the position change of the device 800 or a component of the device 800, the presence or absence of contact with the device 800, the orientation or acceleration / deceleration of the device 800, and the temperature change of the device 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0153] The communication component 816 is configured to facilitate wired or wireless communication between the device 800 and other devices. The device 800 can access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0154] In an exemplary embodiment, the apparatus 800 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to execute the methods described in the first and second aspects.
[0155] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, and the instructions can be executed by the processor 820 of the device 800 to complete the above method. Optionally, for example, the storage medium can be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0156] In an exemplary embodiment, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the text generation method described in any one of the above embodiments.
[0157] From the above, it can be seen that the technical solution provided by the embodiment of the embodiment of the present invention can perform cluster analysis on the candidate words based on the semantic similarity between the candidate words included in the corpus data of the target user, determine the label information of the target user, and then construct personalized text generation instructions related to the target user. Then, the text generation instructions are input into the target text generation model, so as to realize automatic generation of the target text corresponding to the target user. On the one hand, it can improve the targeting of the target text for different target users and realize the personalization of the target text. On the other hand, no manual operation is required in the generation process of the target text, which can save a lot of resources.
[0158] Those skilled in the art will readily appreciate other implementations of the embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The embodiments of the present invention are intended to cover any variations, uses, or adaptations of the embodiments of the present invention that follow the general principles of the embodiments of the present invention and include common knowledge or customary technical means in the art that are not disclosed in the embodiments of the present invention. The specification and examples are to be regarded as exemplary only, and the true scope and spirit of the embodiments of the present invention are indicated by the following claims.
[0159] It should be understood that the embodiments of the present invention are not limited to the precise structures described above and shown in the drawings, and various modifications and changes may be made without departing from the scope thereof. The scope of the embodiments of the present invention is limited only by the appended claims.
Claims
1. A text generation method, characterized in that: include: Obtain corpus data of target users; Calculating semantic similarities between candidate words included in the corpus data, clustering the candidate words based on the semantic similarities, and determining label information of the target user according to the clustering result; Based on the tag information, construct a text generation instruction; The text generation instruction is input into a target text generation model for semantic analysis and processing to generate a target text corresponding to the target user.
2. The method according to claim 1, characterized in that The step of obtaining the corpus data of the target user includes: Acquire initial data related to the target user; the initial data includes feature data and behavior data of the target user; The initial data is cleaned to obtain the corpus data of the target user.
3. The method according to claim 1, characterized in that The calculating the semantic similarity between the candidate words included in the corpus data, clustering the candidate words based on the semantic similarity, and determining the label information of the target user according to the clustering result includes: Performing word segmentation processing on the corpus data to obtain multiple candidate words; Calculating the semantic similarity between every two candidate words; Based on the semantic similarity between every two candidate words, clustering the plurality of candidate words to determine a plurality of groups; According to the descending order of the number of the candidate words included in each group, a preset number of target groups are determined from the multiple groups, and the label information of the target user is determined based on the target groups.
4. The method according to claim 1, characterized in that: The step of constructing a text generation instruction based on the tag information includes: Obtaining a scene label and an identity label of the current scene; the identity label is used to indicate the identity of the role that the target text generation model needs to play; Determine a prompt word corresponding to the scene label; The identity tag is used as the role information of the prompt word, and the tag information is used as the keyword in the prompt word to construct a text generation instruction.
5. The method according to claim 1, characterized in that Before inputting the text generation instruction into the target text generation model, performing semantic analysis on the text generation instruction, and generating the target text corresponding to the target user, the method further includes: Acquire a reference text generation model and training corpus of the current scene; the training corpus includes an input instruction corresponding to the current scene and an expected text corresponding to the input instruction; Inputting the input instruction into the reference text generation model for semantic analysis and processing to generate training text; When the loss value between the training text and the expected text is greater than a preset loss value, the model parameters of the reference text generation model are adjusted until the loss value is no greater than the preset loss value, and the reference text generation model is used as the target text generation model.
6. The method according to claim 5, characterized in that After the reference text generation model is used as the target text generation model, the method further includes: Encapsulating the target text generation model as a target interface; The step of inputting the text generation instruction into a target text generation model, performing semantic analysis on the text generation instruction, and generating a target text corresponding to the target user includes: The text generation instruction is input into the target interface, and the target text generation model is called to perform semantic analysis on the text generation instruction to generate a target text corresponding to the target user.
7. The method according to claim 1, characterized in that The step of inputting the text generation instruction into a target text generation model, performing semantic analysis on the text generation instruction, and generating a target text corresponding to the target user includes: Inputting the text generation instruction into a target text generation model, performing semantic analysis on the text generation instruction, and generating a reference text; Performing data verification on the reference text to obtain a verification result; In the case where the verification result satisfies the text output condition, using the reference text as the target text corresponding to the target user; When the verification result does not satisfy the text output condition, text adjustment is performed on the reference text to obtain the target text corresponding to the target user.
8. The method according to claim 7, characterized in that When the verification result does not meet the text output condition, the method further includes: Model parameters of the target text generation model are debugged based on the target text.
9. A text generation device, characterized in that: include: The acquisition module is used to obtain the corpus data of the target user; A clustering module, used to calculate the semantic similarity between the candidate words included in the corpus data, cluster the candidate words based on the semantic similarity, and determine the label information of the target user according to the clustering result; A construction module, used to construct a text generation instruction based on the tag information; The generation module is used to input the text generation instruction into the target text generation model, perform semantic analysis on the text generation instruction, and generate the target text corresponding to the target user.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the text generation method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the text generation method according to any one of claims 1 to 8 are implemented.
12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the text generation method according to any one of claims 1 to 8 is implemented.