Comment Paragraph Generation Method, Device, Electronic Device, and Storage Medium

By classifying and sorting comment items and combining with the pre-trained segment generation model, the problem of inefficiency of existing comment generation methods is solved, and automatic generation of logically smooth comment segments is realized, which improves generation efficiency and reduces complexity.

CN115080731BActive Publication Date: 2025-06-20GUANGZHOU SHIYUAN ELECTRONICS CO LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110280828.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-16
Publication Date
2025-06-20
Estimated Expiration
2041-03-16

AI Technical Summary

Technical Problem

The existing comment generation method has the problem of low generation efficiency, especially when dealing with disordered comment items, transition words need to be added manually to ensure semantic coherence, but this requires a lot of labor costs.

Method used

By obtaining comment items, classifying text information to obtain comment categories, sorting the comment item sequences according to the categories, and using the pre-trained segment generation model to predict the sorted comment item sequences to generate comment paragraphs.

Benefits of technology

This method can automatically generate logically smooth comment segments, reduce manual intervention, improve the efficiency of comment generation, and reduce the complexity of the generation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115080731B_ABST
    Figure CN115080731B_ABST
Patent Text Reader

Abstract

The present application relates to a method, apparatus, electronic device, and storage medium for generating a comment paragraph. The method includes: obtaining a comment item; the comment item includes text information; classifying the text information to obtain a comment category corresponding to the comment item; sorting the comment items according to the comment category to obtain a comment item sequence; predicting the comment item sequence through a pre-trained paragraph generation model to generate a comment paragraph corresponding to the comment item. By using this method, a number of unordered comment items can be sorted according to the comment category, and directly through the paragraph generation model, a logically coherent comment paragraph can be automatically generated without manually adding transitional words between sentences, improving the generation efficiency of the comment paragraph.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and particularly to a method, apparatus, electronic device, and storage medium for generating comment paragraphs. Background Art

[0002] A comment is an evaluation written by a reviewer based on the performance of the object being reviewed over a period of time. With the development of computer technology, automatically generating comments based on review items can reduce the workload of reviewers in editing comments. For example, when a teacher comments on a student's learning situation, by simply inputting the review item "homework is completed carefully", a logically coherent comment sentence "Each homework can be completed carefully" can be automatically generated.

[0003] The input of review items is usually unordered. The current comment generation method is to first classify a number of unordered review items, then input the review items of each category into a comment generation model respectively to generate corresponding comment sentences, and then combine the comment sentences into a comment paragraph. The comment paragraphs generated by the above method usually have the problem of semantic incoherence between sentences. For this problem, the existing solution is to add transition words between sentences manually.

[0004] However, adding transition words between comment sentences manually requires a lot of labor costs, and the generation efficiency of comment paragraphs is low.

[0005] Therefore, the current comment paragraph generation method has the problem of low generation efficiency. Summary of the Invention

[0006] Based on this, it is necessary to provide a method, apparatus, electronic device, and storage medium for generating comment paragraphs to solve the above technical problems.

[0007] In a first aspect, a method for generating comment paragraphs is provided. The method includes:

[0008] Obtain review items; the review items contain text information;

[0009] By classifying the text information, obtain the review categories corresponding to the review items;

[0010] Sort the review items according to the review categories to obtain a review item sequence;

[0011] Use a pre-trained paragraph generation model to predict the review item sequence and generate a comment paragraph corresponding to the review items.

[0012] In another embodiment, the step of obtaining the review categories corresponding to the review items by classifying the text information includes:

[0013] Input the comment item into a text classifier to obtain a probability vector of the comment item; the probability vector is used to represent the probabilities of the comment item belonging to each of the comment categories;

[0014] Convert the probability vector into a one-hot vector; the one-hot vector is used to represent the comment category corresponding to the comment item.

[0015] In another embodiment, the converting the probability vector into a one-hot vector includes:

[0016] Sample the probability vector according to the probability vector dimension to obtain a sampling vector; each element in the sampling vector follows a uniform distribution;

[0017] Determine the probability vector noise through the sampling vector according to a preset mapping relationship;

[0018] Add the probability vector and the probability vector noise to obtain a probability noise vector;

[0019] Normalize the probability noise vector to obtain a normalized probability noise vector;

[0020] Obtain the one-hot vector by suppressing the backpropagation of the vector difference and superimposing the normalized probability noise vector; the vector difference is the difference between the sampling value of the normalized probability noise vector and the normalized probability noise vector.

[0021] In another embodiment, the sorting the comment items according to the comment categories to obtain a comment item sequence includes:

[0022] Obtain a comment item vector and the one-hot vector corresponding to the comment item; the comment item vector is the vector representation of the comment item;

[0023] Generate a comment item matrix according to the comment item vector, and generate a one-hot matrix according to the one-hot vector;

[0024] Perform matrix operations on the comment item matrix and the one-hot matrix to obtain a comment item three-dimensional tensor;

[0025] Perform dimension swapping on the comment item three-dimensional tensor to obtain a swapped three-dimensional tensor;

[0026] Perform splicing on two dimensions in the swapped three-dimensional tensor to obtain a spliced two-dimensional matrix;

[0027] Obtain the comment item sequence by removing the zero vectors in the spliced two-dimensional matrix.

[0028] In another embodiment, the method further includes:

[0029] Obtain a sequence sample of comment items and the corresponding comment text segments for the sequence sample of comment items;

[0030] Mask the comment text segments corresponding to the sequence sample of comment items to obtain masked comment text segments;

[0031] Train the text segment generation model to be trained according to the sequence sample of comment items and the masked comment text segments;

[0032] When the trained text segment generation model meets the preset training conditions, obtain the pre-trained text segment generation model.

[0033] In another embodiment, the step of when the trained text segment generation model meets the preset training conditions, obtaining the pre-trained text segment generation model includes:

[0034] Obtain the loss of the text classifier and the loss of the text segment generation model;

[0035] Obtain the loss of comment text segment generation by performing weighted summation on the loss of the text classifier and the loss of the text segment generation model;

[0036] When the loss of comment text segment generation meets the preset loss conditions, use the trained text segment generation model as the pre-trained text segment generation model.

[0037] In another embodiment, the step of obtaining the loss of the text classifier includes:

[0038] Obtain a sample of comment items and the corresponding comment categories for the sample of comment items;

[0039] Input the sample of comment items into the text classifier to obtain the probabilities that the sample of comment items belong to each comment category;

[0040] Obtain the loss of the text classifier according to the probabilities that the sample of comment items belong to each comment category and the comment categories.

[0041] In a second aspect, a comment text segment generation device is provided. The device includes:

[0042] An acquisition module, configured to acquire comment items; the comment items include text information;

[0043] A classification module, configured to classify the text information to obtain the corresponding comment categories for the comment items;

[0044] A sorting module, configured to sort the comment items according to the comment categories to obtain a sequence of comment items;

[0045] A comment paragraph generation module, configured to predict the sequence of comment items through a pre-trained paragraph generation model, and generate a comment paragraph corresponding to the comment item.

[0046] In a third aspect, there is provided an electronic device, including: a memory, and one or more processors;

[0047] The memory is configured to store one or more programs;

[0048] When the one or more programs are executed by the one or more processors, the one or more processors perform the following operations:

[0049] Obtain a comment item; the comment item includes text information;

[0050] By classifying the text information, obtain a comment category corresponding to the comment item;

[0051] Sort the comment items according to the comment category to obtain a sequence of comment items;

[0052] Predict the sequence of comment items through a pre-trained paragraph generation model, and generate a comment paragraph corresponding to the comment item.

[0053] In a fourth aspect, there is provided a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0054] Obtain a comment item; the comment item includes text information;

[0055] By classifying the text information, obtain a comment category corresponding to the comment item;

[0056] Sort the comment items according to the comment category to obtain a sequence of comment items;

[0057] Predict the sequence of comment items through a pre-trained paragraph generation model, and generate a comment paragraph corresponding to the comment item.

[0058] For the above comment paragraph generation method, device, electronic device and storage medium, by obtaining comment items, classifying the text information to obtain a comment category corresponding to the comment item, sorting the comment items according to the comment category to obtain a sequence of comment items, and predicting the sequence of comment items through a pre-trained paragraph generation model to generate a comment paragraph corresponding to the comment item, several unordered comment items can be sorted according to the comment category and directly input into the paragraph generation model to automatically generate a logically coherent comment paragraph without manually adding transitional words between sentences, improving the efficiency of comment paragraph generation.

[0059] Moreover, the paragraph generation model of the present application directly predicts the comment item sequence, without separately inputting the comment items of each category into the comment generation model to generate corresponding comment sentences, nor merging the comment sentences, which reduces the complexity of comment paragraph generation. BRIEF DESCRIPTION OF THE DRAWINGS

[0060] Figure 1 is a flowchart of a comment paragraph generation method provided in Embodiment 1 of the present application;

[0061] Figure 2 is a schematic diagram of classifying comment items;

[0062] Figure 3 is a schematic diagram of sorting comment items;

[0063] Figure 4 is a flowchart of a comment paragraph generation method provided in Embodiment 2 of the present application;

[0064] Figure 5 is a schematic diagram of an end-to-end comment generation network;

[0065] Figure 6 is a schematic diagram of the structure of a comment paragraph generation device provided in Embodiment 3 of the present application;

[0066] Figure 7 is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0067] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application.

[0068] The comment paragraph generation method provided by the present application can be applied to a terminal or a server. Among them, the terminal can be, but is not limited to, various personal computers, laptop computers, smart phones, tablet computers, and portable wearable devices, and the server can be implemented by an independent server or a server cluster composed of multiple servers.

[0069] Embodiment 1

[0070] Figure 1 is a flowchart of a comment paragraph generation method provided in Embodiment 1 of the present application. Specifically, referring to Figure 1 , the comment paragraph generation method of Embodiment 1 of the present application specifically includes:

[0071] Step S110, obtain comment items; the comment items include text information.

[0072] Among them, the comment item can be the keyword of the comment entered by the commenter. The text information can be the literal content of the keyword of the comment.

[0073] In a specific implementation, the commenter can manually input at least one keyword of the comment as a comment item according to the performance of the commented object within a period of time, or can select at least one keyword of the comment from a preset set of keywords of the comment as a comment item, or can also adopt a combination of manual input and selection from the set. For example, after the commenter selects at least one keyword of the comment from the set of keywords of the comment, if it is considered that the existing keywords in the set cannot fully comment on the commented object, several keywords of the comment can be manually input again.

[0074] It should be noted that an end-to-end comment generation network can be designed. The comment generation network can automatically implement the acquisition, classification, sorting, and comment paragraph generation of the comment items in sequence. The user only needs to input all the comment items of the student, and the comment generation network can automatically generate a logically smooth comment paragraph, with a relatively high efficiency of comment paragraph generation. Moreover, the acquisition, classification, sorting, and comment paragraph generation of the comment items can interact with each other to promote the generation of better comment paragraphs.

[0075] Step S120, by classifying the text information, obtain the comment category corresponding to the comment item.

[0076] Among them, the comment category can be the category to which the comment item belongs after classification.

[0077] In a specific implementation, at least one comment item can be input into a text classifier, and the text classifier can classify the comment item according to the text information to determine the comment category to which the comment item belongs.

[0078] Among them, the text classifier can be obtained by training a textcnn (Text-Convolutional Neural Networks, a text classification model based on a convolutional neural network), textrnn (Text-Recurrent Neural Networks, a text classification model based on a recurrent neural network), or BERT (Bidirectional Encoder Representations from Transformers, bidirectional encoder representations) model.

[0079] Preferably, a textcnn model can be adopted to enable the text classifier to have a relatively high classification efficiency.

[0080] It should be noted that any neural network-related classification model can be used to replace the textcnn model.

[0081] In practical applications, several comment categories can be preset in advance. After inputting the comment item into the text classifier, a probability vector corresponding to the comment item can be obtained. Each element in the probability vector represents the probability that the comment item belongs to each comment category. By converting the probability vector into a one-hot vector (a unique hot vector), the comment category to which the comment item belongs can be determined according to the one-hot vector.

[0082] For example, 3 comment categories, namely "Academic Level", "Moral Character", and "Comprehensive Quality", can be preset in advance, corresponding to the one-hot vectors [1, 0, 0] T , [0, 1, 0] T , [0, 0, 1] T . After obtaining the comment item "Concentrated Attention", inputting it into the text classifier, the probability vector corresponding to "Concentrated Attention" can be obtained as [0.7, 0.1, 0.2] T , indicating that the probability that this comment item belongs to "Academic Level" is 0.7, the probability that it belongs to "Moral Character" is 0.1, and the probability that it belongs to "Comprehensive Quality" is 0.2. By selecting the maximum value among the 3 probability values and setting the vector element corresponding to the maximum value to 1 and the other vector elements to 0, the probability vector can be converted into a one-hot vector [1, 0, 0] T , that is, "Concentrated Attention" belongs to "Academic Level".

[0083] It should be noted that during the process of converting the probability vector into a one-hot vector, a sampling operation needs to be performed on the probability vector. The sampling process is not differentiable, resulting in difficulty in determining a specific formula to generate a one-hot vector, and thus it is impossible to generate an end-to-end comment generation network to automatically generate comment paragraphs. To solve this problem, the present application adopts the Gumbel Softmax method to separate the sampling process from the computational graph, making the classification process of the comment generation network differentiable.

[0084] The Gumbel Softmax method can specifically include:

[0085] 1. Assume that an m-dimensional probability vector V is obtained through the text classifier, and sample V using a uniform distribution with a mean of 0 and a variance of 1 to obtain α = [α1,..., α m ;

[0086] 2. Calculate G through G = -log(-logα);

[0087] 3. Add the probability vector V and the vector G after sampling processing to obtain a new vector where

[0088] 4. Obtain the sampling probability value through the softmax function The formula can be

[0089]

[0090] where \(i = 1,\ldots,m\), \(\tau\) is a regulation factor. The larger \(\tau\) is, the smoother the generated distribution is; the smaller \(\tau\) is, the closer the generated distribution is to the discrete one-hot distribution.

[0091] To make the finally obtained one-hot vector represent the category, we can obtain the sampling value by sampling according to the maximum probability Use the sampling value and take the difference to get the vector difference. Use the \(z()\) function to suppress the backpropagation of the vector difference, and superimpose the backpropagable to obtain the one-hot vector \(y\). The formula can be

[0092]

[0093] where is the one-hot vector obtained by sampling according to the maximum probability, that is, the sampling value. The \(z()\) function means not to update the gradient of the network parameters of this part. Specifically, the \(z()\) function can use the \(detach()\) function in PyTorch. By suppressing the backpropagation, the parameters in the comment generation network can remain unchanged, and only the parameters are adjusted, so as to ensure that the result used in the next step is a one-hot vector while still taking the derivative of during backpropagation.

[0094] Figure 2 This is a schematic diagram for classifying comment items. As shown in the figure, there are 3 comment categories: "Academic level", "Moral character", and "Comprehensive quality". Input the comment items "Concentrated attention", "Careful eye exercises", "Little calligrapher", "Study hard", and "Abide by discipline" into the text classifier. The text classifier can classify according to the text information of the comment items and obtain the comment categories of each comment item as "Academic level", "Moral character", "Comprehensive quality", "Academic level", and "Moral character" respectively.

[0095] Step S130, sort the comment items according to the comment category to obtain a comment item sequence.

[0096] ​In a specific implementation, a matrix operation can be performed on the one-hot vector representing the comment category and the comment items. According to the result of the matrix operation, the ranking of the comment items can be obtained, and a comment item sequence can be obtained according to the ranking of the comment items.

[0097] Figure 3 It is a schematic diagram for ranking comment items. As shown in the figure, the original order of the comment items is "Concentrated attention", "Serious eye exercises", "Little calligrapher", "Serious study", "Abide by discipline". After inputting into the text classifier, the corresponding comment categories obtained are "Academic level", "Moral character", "Comprehensive quality", "Academic level", "Moral character". The vector representations of each comment item and the one-hot vectors of each comment category are obtained. By performing a matrix operation on the comment item vector and the one-hot vector, the comment items can be ranked according to the result of the matrix operation, and a comment item sequence "Concentrated attention", "Serious study", "Serious eye exercises", "Abide by discipline", "Little calligrapher" is obtained. Among them, "Concentrated attention" and "Serious study" belong to "Academic level", which is the first category and are ranked 1st and 2nd; "Serious eye exercises" and "Abide by discipline" belong to "Moral character", which is the second category and are ranked 3rd and 4th; "Little calligrapher" belongs to "Comprehensive quality", which is the third category and is ranked 5th.

[0098] In practical applications, it can be set that m represents the number of comment items, n represents the number of comment categories, and d represents the vector dimension of the comment items. Take m = 4, n = 3, d = 6. The matrix composed of the vector representations of the comment items can be

[0099]

[0100] For classifying the comment items, the matrix composed of the obtained one-hot vectors can be

[0101]

[0102] Perform matrix multiplication on x and y to obtain a three-dimensional tensor D ∈ R m×n×d , specifically

[0103]

[0104] Among them, taking as an example, the calculation process is

[0105]

[0106] For the three-dimensional tensor D sample , perform dimension swapping on the first and second dimensions to obtain

[0107]

[0108] For D' sample Concatenate the first dimension and the second dimension of it to obtain a two-dimensional matrix, and then remove the zero vectors in the two-dimensional matrix, and a sorted sequence of comment items can be obtained

[0109]

[0110] For example, when a teacher comments on a certain student, input "abide by school discipline", "listen carefully in class", "very good at singing and dancing", "actively answer questions", and the corresponding comment vectors are x1, x2, x3, x4 respectively, and the comment categories are "ideological and moral character", "academic level", "comprehensive quality", "academic level" respectively. After sorting, the comment sequence x2, x4, x1, x3 is obtained, corresponding to "listen carefully in class", "actively answer questions", "abide by school discipline", "very good at singing and dancing". Among them, "listen carefully in class" and "actively answer questions" belong to "academic level", which is the first category; "abide by school discipline" belongs to "ideological and moral character", which is the second category; "very good at singing and dancing" belongs to "comprehensive quality", which is the third category.

[0111] Step S140, use the pre-trained text generation model to predict the comment item sequence and generate the comment text corresponding to the comment item.

[0112] In specific implementation, a text generation model can be pre-trained, and the comment item sequence is input into the text generation model to output a comment text.

[0113] In practical applications, the text generation model can be unilm( Pre-trained Language Model, unified pre-trained language model). Use the comment item sequence samples and their corresponding comment texts to train the unilm model. During the training process, part of the comment text is masked, the comment item sequence and the masked comment text are concatenated, and a delimiter is used to distinguish between the comment item sequence and the masked comment text. By setting the training objective to predict the masked part of the content, when the unilm model converges, the text generation model can be obtained.

[0114] It should be noted that any generation model based on the seq2seq framework can be used to replace the unilm model.

[0115] When using the trained text generation model to predict the comment item sequence, beam search can be used to decode to obtain the comment text. Beam search can optimize the search space on the basis of breadth-first search, reduce memory consumption, and accelerate the search process.

[0116] The technical solution provided by the embodiments of the present application obtains evaluation items, classifies text information to obtain evaluation categories corresponding to the evaluation items, sorts the evaluation items according to the evaluation categories to obtain an evaluation item sequence, and predicts the evaluation item sequence through a pre-trained paragraph generation model to generate a comment paragraph corresponding to the evaluation item. It is possible to sort a number of unordered evaluation items by evaluation category, directly input them into the paragraph generation model, and automatically generate a logically coherent comment paragraph without manually adding transitional words between sentences, improving the efficiency of generating the comment paragraph.

[0117] Moreover, the paragraph generation model of the embodiments of the present application directly predicts the evaluation item sequence, without separately inputting the evaluation items of each category into the comment generation model to generate corresponding comment sentences, nor merging the comment sentences, reducing the complexity of generating the comment paragraph.

[0118] Embodiment 2

[0119] Figure 4 is a flowchart of a method for generating a comment paragraph provided by Embodiment 2 of the present application. Specifically, referring to Figure 4 , the method for generating a comment paragraph in Embodiment 2 of the present application specifically includes:

[0120] Step S210, obtaining an evaluation item sequence sample and the comment paragraph corresponding to the evaluation item sequence sample; masking the comment paragraph corresponding to the evaluation item sequence sample to obtain a masked comment paragraph; training a paragraph generation model to be trained according to the evaluation item sequence sample and the masked comment paragraph; when the trained paragraph generation model meets a preset training condition, obtaining the pre-trained paragraph generation model.

[0121] Among them, the evaluation item sequence sample can be a sample set composed of at least one evaluation item sequence.

[0122] Among them, the comment paragraph corresponding to the evaluation item sequence sample can be a set composed of at least one comment paragraph, and each comment paragraph can be a logically coherent comment generated according to the evaluation item sequence sample.

[0123] In specific implementation, an evaluation item sequence sample and its corresponding comment paragraph can be generated manually. During the training process of the paragraph generation model, at least one evaluation item sequence and its corresponding comment paragraph can be obtained as training samples, and partial masking is performed on each comment paragraph to obtain a masked comment paragraph. The evaluation item sequence and the masked comment paragraph are spliced, and a separator is added between the evaluation item sequence and the masked comment paragraph for distinction to obtain spliced content, and the spliced content is used to train the paragraph generation model. The training objective can be to predict the masked part in the comment paragraph. When the paragraph generation model converges, the pre-trained paragraph generation model can be obtained.

[0124] According to the technical solution of the embodiment of the present application, by obtaining a sample sequence of comment items and the comment text segments corresponding to the sample sequence of comment items, masking the comment text segments corresponding to the sample sequence of comment items to obtain the masked comment text segments, partial content in the comment text segments can be blocked, enabling the trained text segment generation model to have learning ability. Training the text segment generation model to be trained according to the sample sequence of comment items and the masked comment text segments, when the trained text segment generation model meets the preset training conditions, a pre-trained text segment generation model is obtained, which can enable the trained text segment generation model to implicitly learn the transition between sentences and ensure the semantic coherence between sentences, so as to generate a logically smooth comment text segment from a number of ordered comment items.

[0125] Optionally, the step of obtaining the pre-trained text segment generation model when the trained text segment generation model meets the preset training conditions includes:

[0126] Obtaining the loss of the text classifier, and obtaining the loss of the text segment generation model; by performing weighted summation on the loss of the text classifier and the loss of the text segment generation model, obtaining the loss of comment text segment generation; when the loss of comment text segment generation meets the preset loss conditions, using the trained text segment generation model as the pre-trained text segment generation model.

[0127] Among them, the loss of the text classifier can be the loss value obtained by classifying comment items through the text classifier.

[0128] Among them, the loss of the text segment generation model can be the loss value obtained by generating a comment text segment from a sequence of comment items through the text segment generation model.

[0129] In specific implementation, the calculation formula of the loss of the text classifier can be

[0130]

[0131] where N represents the number of comment item samples for training the text classifier, M represents the number of categories that the text classifier can determine, y ic represents whether sample i belongs to category c. If so, then y ic = 1; otherwise, if not, then y ic = 0, and p ic represents the probability that the predicted sample i is category c.

[0132] The calculation formula of the loss of the text segment generation model can be

[0133]

[0134] where N represents the number of comment item sequence samples for training the text segment generation model, C represents the comment item sequence, and x itDenote the content of the comment segment at the t-th moment of the i-th sample as x i,<t Denote all the comment segment contents before the t-th moment of the i-th sample as x it ∈Mask means that only the predicted content of the masked comment segment is predicted.

[0135] By weighted summation of the text classifier loss and the segment generation model loss for joint learning, the loss value of the comment generation network can be obtained as

[0136] L = λL1+(1 - λ)L2.

[0137] Among them, λ can be a hyperparameter. Since in the comment segment generation scenario, the text classification task is relatively simple compared to the segment generation task, λ = 0.25 can be set.

[0138] According to the comment segment generation loss L, each parameter of the text classifier and the segment generation model in the comment generation network is adjusted, and a comment generation network that meets the requirements can be obtained. For example, each parameter in the text classifier and the segment generation model can be adjusted by an iterative method, that is, L is calculated after one comment segment generation, and each parameter of the text classifier and the segment generation model is adjusted according to L to generate a new comment generation network. The new comment generation network is used to generate comment segments again to obtain a new L. In the above process, the comment segment generation loss L can be continuously reduced. Repeat the above process. When L no longer decreases (the difference between L in two adjacent iterations is less than a certain threshold), a text classifier and a segment generation model that meet the requirements can be obtained.

[0139] According to the technical solution of the embodiment of the present application, by obtaining the text classifier loss and the segment generation model loss, and performing weighted summation on the text classifier loss and the segment generation model loss to obtain the comment segment generation loss, the influence of the text classifier and the segment generation model on the comment generation network can be obtained. When the comment segment generation loss meets the preset loss condition, the trained segment generation model is used as the pre-trained segment generation model, and a segment generation model that meets the requirements can be designed according to the comment segment generation loss, improving the accuracy of the segment generation model for predicting comment segments.

[0140] Moreover, by feeding back the text classifier loss and the segment generation model loss to the comment generation network including the text classifier and the segment generation model, each part of the comment generation network can be made to be interrelated, playing a role of mutual promotion, and improving the accuracy of the comment generation network for predicting comment segments.

[0141] Optionally, the obtaining of the text classifier loss includes:

[0142] Obtain a sample of review items and the corresponding review categories of the review item sample; by inputting the review item sample into the text classifier, obtain the probabilities that the review item sample belongs to each review category; according to the probabilities that the review item sample belongs to each review category and the review category, obtain the loss of the text classifier.

[0143] In a specific implementation, review item samples and their corresponding review categories can be generated manually. During the process of calculating the loss of the text classifier, several review categories can be preset in advance. Input the review item sample into the text classifier, and through the text classifier, determine the probabilities that the review item sample belongs to each review category. According to the preset mapping relationship, the loss of the text classifier can be calculated through the probabilities that the review item sample belongs to each review category and the review category of the review item sample.

[0144] In practical applications, the calculation formula for the loss of the text classifier can be

[0145]

[0146] where N represents the number of review item samples for training the text classifier, M represents the number of categories that the text classifier can determine, y ic represents whether sample i belongs to category c (the review category corresponding to the review item sample). If so, then y ic = 1; otherwise, if not, then y ic = 0, and p ic represents the probability that the predicted sample i is category c (the probability that the review item sample belongs to the review category).

[0147] According to the technical solution of the embodiment of the present application, by obtaining a review item sample and the corresponding review category of the review item sample, inputting the review item sample into the text classifier to obtain the probabilities that the review item sample belongs to each review category, and obtaining the loss of the text classifier according to the probabilities that the review item sample belongs to each review category and the review category, the influence of the text classifier on the comment generation network can be obtained, and then the comment generation network can be adjusted according to the loss of the text classifier to improve the accuracy of comment paragraph prediction.

[0148] Step S220: Obtain a review item; the review item includes text information.

[0149] In a specific implementation, the reviewer can manually input at least one comment keyword as a review item according to the performance of the review object within a period of time, or select at least one comment keyword from a preset set of comment keywords as a review item, or also adopt a combination of manual input and selection from the set. For example, after the reviewer selects at least one comment keyword from the set of comment keywords, if the reviewer believes that the existing keywords in the set cannot fully review the review object, the reviewer can manually input several more comment keywords.

[0150] Step S230: By classifying the text information, obtain the comment category corresponding to the comment item.

[0151] Optionally, step S230 includes:

[0152] Input the comment item into a text classifier to obtain a probability vector of the comment item; the probability vector is used to represent the probability that the comment item belongs to each comment category; convert the probability vector into a one-hot vector; the one-hot vector is used to represent the comment category corresponding to the comment item.

[0153] Among them, the probability vector can be a vector representing the probability that the comment item belongs to each comment category. The dimension of the probability vector can be the number of comment categories, and each element in the probability vector can be the probability that the comment item belongs to each comment category.

[0154] Among them, the one-hot vector can be a vector composed of 0 and 1. Among them, 0 indicates that the comment item does not belong to the corresponding comment category, and 1 indicates that the comment item belongs to the corresponding comment category.

[0155] In a specific implementation, several comment categories can be preset in advance. Input the comment item into a text classifier to obtain a probability vector corresponding to the comment item. Each element in the probability vector represents the probability that the comment item belongs to each comment category. Convert the probability vector into a one-hot vector, and the comment category of the comment item can be determined according to the one-hot vector.

[0156] According to the technical solution of the embodiment of the present application, by inputting the comment item into a text classifier to obtain a probability vector of the comment item and converting the probability vector into a one-hot vector, the comment category to which the comment item belongs can be automatically determined, the efficiency of comment item classification can be improved, and thus the efficiency of generating a comment paragraph can be improved.

[0157] Optionally, the converting the probability vector into a one-hot vector includes:

[0158] Sample the probability vector according to the dimension of the probability vector to obtain a sampling vector; each element in the sampling vector follows a uniform distribution; determine the probability vector noise through the sampling vector according to a preset mapping relationship; add the probability vector and the probability vector noise to obtain a probability noise vector; normalize the probability noise vector to obtain a normalized probability noise vector; obtain the one-hot vector by performing backpropagation inhibition on the vector difference and superimposing the normalized probability noise vector; the vector difference is the difference between the sampling value of the normalized probability noise vector and the normalized probability noise vector.

[0159] In a specific implementation, during the process of converting a probability vector into a one-hot vector, it is necessary to perform a sampling operation on the probability vector. The sampling process is non-differentiable, making it difficult to determine a specific formula to generate the one-hot vector. Consequently, it is impossible to generate an end-to-end comment generation network to automatically generate comment paragraphs. To address this issue, the following process can be used to convert the probability vector into a one-hot vector:

[0160] 1. Let the m-dimensional probability vector V be obtained through a text classifier. Sample V using a uniform distribution with a mean of 0 and a variance of 1 to obtain the sampling vector α = [α1, …, α m ;

[0161] 2. Calculate the probability vector noise G through the mapping relationship G = -log(-logα);

[0162] 3. Add the probability vector V and the probability vector noise G to obtain the probability noise vector where,

[0163] 4. Normalize the probability noise vector through the softmax function to obtain the normalized probability noise vector The formula can be

[0164]

[0165] where i = 1, …, m, τ is a regulation factor. The larger τ is, the smoother the generated distribution is; the smaller τ is, the closer the generated distribution is to the discrete one-hot distribution.

[0166] To enable the finally obtained one-hot vector to represent the category, sample according to the maximum probability to obtain the sampling value Use the sampling value to make a difference with to obtain the vector difference. Use the z() function to suppress the backpropagation of the vector difference, and superimpose the backpropagation-enabled to obtain the one-hot vector y. The formula can be

[0167]

[0168] where, is the one-hot vector obtained by sampling according to the maximum probability, that is, the sampling value. The z() function indicates that no gradient update is performed on the network parameters of this part. Specifically, the z() function can use the detach() function in pytorch. Through backpropagation suppression, the parameters in the comment generation network can remain unchanged, and only the parameters Make adjustments to ensure that the result used in the next step is a one-hot vector During backpropagation, still perform Derivative calculation on.

[0169] According to the technical solution of the embodiment of the present application, by sampling the probability vector according to the dimension of the probability vector to obtain a sampling vector, determining the probability vector noise through the sampling vector according to a preset mapping relationship, adding the probability vector and the probability vector noise to obtain a probability noise vector, normalizing the probability noise vector to obtain a normalized probability noise vector, suppressing the backpropagation of the vector difference, and superimposing the normalized probability noise vector to obtain a one-hot vector, the sampling process can be separated from the computational graph, ensuring that the gradient of the comment generation network can be backpropagated, effectively solving the discrete problem caused by sampling the output of the text classifier, and ensuring that an end-to-end comment generation network can be constructed to automatically generate comment segments, improving the efficiency of comment segment generation.

[0170] Step S240: Sort the comment items according to the comment category to obtain a comment item sequence.

[0171] Optionally, step S240 includes:

[0172] Obtain a comment item vector and the one-hot vector corresponding to the comment item; the comment item vector is the vector representation of the comment item; generate a comment item matrix according to the comment item vector, and generate a one-hot matrix according to the one-hot vector; perform matrix operations on the comment item matrix and the one-hot matrix to obtain a comment item three-dimensional tensor; perform dimension exchange on the comment item three-dimensional tensor to obtain an exchanged three-dimensional tensor; splice two dimensions in the exchanged three-dimensional tensor to obtain a spliced two-dimensional matrix; remove the zero vectors in the spliced two-dimensional matrix to obtain the comment item sequence.

[0173] In specific implementation, it can be set that m represents the number of comment items, n represents the number of comment categories, d represents the vector dimension of the comment item, take m = 4, n = 3, d = 6, the comment item vectors can be x1, x2, x3, x4, and the comment item matrix composed of the comment item vectors can be

[0174]

[0175] Classify the comment items to obtain corresponding one-hot vectors y1, y2, y3, y4, and the one-hot matrix composed of the one-hot vectors can be

[0176]

[0177] Perform matrix multiplication on x and y to obtain a comment item three-dimensional tensor D ∈ Rm×n×d , specifically

[0178]

[0179] Among them, taking as an example, the calculation process is

[0180]

[0181] For the review item three-dimensional tensor D sample , perform dimension swapping on the first and second dimensions to obtain the swapped three-dimensional tensor

[0182]

[0183] For D′ sample , perform splicing on the first and second dimensions to obtain the spliced two-dimensional matrix, and then remove the zero vectors in the spliced two-dimensional matrix to obtain the sorted review item sequence

[0184]

[0185] According to the technical solution of the embodiment of the present application, by obtaining the review item vector and the one-hot vector corresponding to the review item, generating a review item matrix according to the review item vector, generating a one-hot matrix according to the one-hot vector, performing matrix operations on the review item matrix and the one-hot matrix to obtain a review item three-dimensional tensor, and performing dimension swapping, splicing, and removing zero vectors to obtain a review item sequence, the disordered review items can be sorted through matrix operations, and an ordered review item sequence can be generated according to the review category, ensuring that the gradient of the comment generation network can be backpropagated, and ensuring that an end-to-end comment generation network can be constructed to automatically generate comment paragraphs, improving the efficiency of comment paragraph generation.

[0186] Moreover, by inputting the ordered review item sequence into the paragraph generation model, the learning difficulty of paragraph generation can be reduced, and the efficiency of training the paragraph generation model can be improved.

[0187] Step S250, predict the review item sequence through a pre-trained paragraph generation model to generate the comment paragraph corresponding to the review item.

[0188] In specific implementation, a paragraph generation model can be pre-trained, and the review item sequence is input into the paragraph generation model to output a comment paragraph.

[0189] In practical applications, the paragraph generation model can be unilm( Pre-trained Language Model (Unified Pre-trained Language Model), uses the sample sequence of review items and their corresponding comment paragraphs to train the Unilm model. During the training process, part of the comment paragraphs are masked, the review item sequence and the masked comment paragraphs are concatenated, and a separator is used to distinguish between the review item sequence and the masked comment paragraphs. By setting the training objective to predict the masked content, when the Unilm model converges, a paragraph generation model can be obtained.

[0190] It should be noted that any generation model based on the seq2seq framework can be used to replace the Unilm model.

[0191] When using the trained paragraph generation model to predict the review item sequence, beam search can be used to decode the comment paragraph. Beam search can optimize the search space based on breadth-first search, reduce memory consumption, and accelerate the search process.

[0192] To facilitate those skilled in the art to deeply understand the embodiments of the present application, a specific example will be described below.

[0193] Figure 5It is a schematic diagram of an end-to-end comment generation network. Taking the teacher's comment on students as an example, based on the performance of students over a period of time, the teacher gives a set of unordered comment items, such as "concentrating attention", "doing eye exercises seriously", "little calligrapher", "studying seriously", "observing discipline". If the unordered comment items are directly input into the generator, there is a high probability of getting a comment with poor fluency and logic. Therefore, they are first input into the classifier, and the corresponding categories of the comment items are obtained as "academic level", "ideological and moral character", "comprehensive quality", "academic level", "ideological and moral character". The Gumbel Softmax method can be used during the classification process to solve the problem of non-differentiability in the sampling process of the classification results. Then, matrix operations are performed based on the vector representation of the comment items and the one-hot vectors of the corresponding categories to sort the categories. The order is "concentrating attention", "studying seriously", "doing eye exercises seriously", "observing discipline", "little calligrapher". Among them, "concentrating attention" and "studying seriously" belong to "academic level", which is the first category; "doing eye exercises seriously" and "observing discipline" belong to "ideological and moral character", which is the second category; "little calligrapher" belongs to "comprehensive quality", which is the third category. By inputting the sorted comment items into the generator, a complete comment result can be generated. For example, it can generate "You are a smart and lively child, concentrating attention in class and having a serious learning attitude. At the same time, you can observe the class-break discipline, do eye exercises seriously, and also actively participate in extracurricular activities, winning the title of little calligrapher." The above comment generation network is in an end-to-end form, which can implicitly sort the unordered comment items by category, reduce the learning difficulty of the generator, and generate a comment with smooth logic and coherent semantics. At the same time, the gradient of the generator can be transmitted to the classifier to promote better classification results, and better classification results can in turn promote the generator to generate more compliant comments.

[0194] It should be understood that although Figure 1 and Figure 4 the steps in the flowcharts of Figure 1 and Figure 4 are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise clearly stated in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover,

[0195] Example 3

[0196] Figure 6It is a schematic structural diagram of a comment paragraph generation device provided in Embodiment 3 of the present application. Refer to Figure 6 Specifically, the comment paragraph generation device provided in this embodiment includes: an acquisition module 310, a classification module 320, a sorting module 330, and a comment paragraph generation module 340, where:

[0197] The acquisition module 310 is used to acquire evaluation items; the evaluation items contain text information;

[0198] The classification module 320 is used to classify the text information to obtain the evaluation category corresponding to the evaluation item;

[0199] The sorting module 330 is used to sort the evaluation items according to the evaluation category to obtain an evaluation item sequence;

[0200] The comment paragraph generation module 340 is used to predict the evaluation item sequence through a pre-trained paragraph generation model to generate the comment paragraph corresponding to the evaluation item.

[0201] The technical solution provided in the embodiment of the present application acquires evaluation items, classifies the text information to obtain the evaluation category corresponding to the evaluation item, sorts the evaluation items according to the evaluation category to obtain an evaluation item sequence, and predicts the evaluation item sequence through a pre-trained paragraph generation model to generate the comment paragraph corresponding to the evaluation item. It can sort several unordered evaluation items according to the evaluation category, directly input them into the paragraph generation model, and automatically generate a logically smooth comment paragraph without manually adding transitional words between sentences, improving the efficiency of comment paragraph generation.

[0202] Moreover, the paragraph generation model in the embodiment of the present application directly predicts the evaluation item sequence, without separately inputting the evaluation items of each category into the comment generation model to generate corresponding comment sentences, nor merging the comment sentences, reducing the complexity of comment paragraph generation.

[0203] In another embodiment, the classification module 320 includes:

[0204] The classification module is used to input the evaluation item into a text classifier to obtain the probability vector of the evaluation item; the probability vector is used to represent the probability that the evaluation item belongs to each evaluation category;

[0205] The vector conversion module is used to convert the probability vector into a one-hot vector; the one-hot vector is used to represent the evaluation category corresponding to the evaluation item.

[0206] In another embodiment, the vector conversion module is specifically used for:

[0207] Sample the probability vector according to the dimension of the probability vector to obtain a sampled vector; each element in the sampled vector follows a uniform distribution;

[0208] Determine the probability vector noise through the sampled vector according to a preset mapping relationship;

[0209] Add the probability vector and the probability vector noise to obtain a probability noise vector;

[0210] Normalize the probability noise vector to obtain a normalized probability noise vector;

[0211] Obtain the one-hot vector by suppressing the backpropagation of the vector difference and superimposing the normalized probability noise vector; the vector difference is the difference between the sampled value of the normalized probability noise vector and the normalized probability noise vector.

[0212] In another embodiment, the sorting module 330 is specifically configured to:

[0213] Obtain a comment item vector and the one-hot vector corresponding to the comment item; the comment item vector is the vector representation of the comment item;

[0214] Generate a comment item matrix according to the comment item vector, and generate a one-hot matrix according to the one-hot vector;

[0215] Obtain a comment item three-dimensional tensor through matrix operations on the comment item matrix and the one-hot matrix;

[0216] Obtain a swapped three-dimensional tensor by swapping the dimensions of the comment item three-dimensional tensor;

[0217] Obtain a concatenated two-dimensional matrix by concatenating two dimensions in the swapped three-dimensional tensor;

[0218] Obtain the comment item sequence by removing the zero vectors in the concatenated two-dimensional matrix.

[0219] In another embodiment, the comment text generation device further includes:

[0220] A sample acquisition module, configured to acquire a comment item sequence sample and the comment text corresponding to the comment item sequence sample;

[0221] A masking module, configured to mask the comment text corresponding to the comment item sequence sample to obtain a masked comment text;

[0222] A training module, configured to train a text generation model to be trained according to the comment item sequence sample and the masked comment text;

[0223] A model generation module, configured to obtain the pre-trained paragraph generation model when the trained paragraph generation model meets a preset training condition.

[0224] In another embodiment, the model generation module includes:

[0225] A loss acquisition module, configured to acquire a text classifier loss and a paragraph generation model loss;

[0226] A comment paragraph generation loss calculation module, configured to obtain a comment paragraph generation loss by performing weighted summation on the text classifier loss and the paragraph generation model loss;

[0227] A model generation sub-module, configured to use the trained paragraph generation model as the pre-trained paragraph generation model when the comment paragraph generation loss meets a preset loss condition.

[0228] In another embodiment, the loss acquisition module is specifically configured to:

[0229] Obtain a comment item sample and a comment category corresponding to the comment item sample;

[0230] By inputting the comment item sample into the text classifier, obtain probabilities that the comment item sample belongs to each comment category;

[0231] According to the probabilities that the comment item sample belongs to each comment category and the comment category, obtain the text classifier loss.

[0232] The above-provided comment paragraph generation device can be used to execute the comment paragraph generation method provided in any of the above embodiments, and has corresponding functions and beneficial effects.

[0233] For specific limitations on the comment paragraph generation device, reference can be made to the limitations on the comment paragraph generation method in the above text, which will not be elaborated here. Each module in the above comment paragraph generation device can be implemented in whole or in part through software, hardware, and their combination. The above modules can be embedded in the processor in the electronic device in hardware form or be independent of it, or can be stored in the memory in the electronic device in software form, so that the processor can call and execute the operations corresponding to the above modules.

[0234] Embodiment 4

[0235] Figure 7It is a schematic structural diagram of an electronic device provided in Embodiment 4 of the present application. As shown in the figure, the electronic device includes: a processor 40, a memory 41, a display screen 42 with a touch function, an input device 43, an output device 44, and a communication device 45. The number of processors 40 in the electronic device can be one or more. In the figure, one processor 40 is taken as an example. The number of memories 41 in the electronic device can be one or more. In the figure, one memory 41 is taken as an example. The processor 40, memory 41, display screen 42, input device 43, output device 44, and communication device 45 of the electronic device can be connected through a bus or other means. In the figure, connection through a bus is taken as an example. In the embodiment, the electronic device can be a computer, a mobile phone, a tablet, a projector, or an interactive intelligent tablet, etc. In the embodiment, the electronic device is taken as an interactive intelligent tablet for description.

[0236] As a computer-readable storage medium, the memory 41 can be used to store software programs, computer-executable programs, and modules, such as program instructions / modules corresponding to the comment paragraph generation method described in any embodiment of the present application. The memory 41 mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created according to the use of the device, etc. In addition, the memory 41 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some instances, the memory 41 can further include a memory remotely set relative to the processor 40, and these remote memories can be connected to the device through a network. Examples of the above network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.

[0237] The display screen 42 is a display screen 42 with a touch function, which can be a capacitive screen, an electromagnetic screen, or an infrared screen. Generally speaking, the display screen 42 is used to display data according to the instructions of the processor 40, and is also used to receive touch operations acting on the display screen 42 and send corresponding signals to the processor 40 or other devices. Optionally, when the display screen 42 is an infrared screen, it further includes an infrared touch frame, which is arranged around the display screen 42 and can also be used to receive infrared signals and send the infrared signals to the processor 40 or other devices.

[0238] The communication device 45 is used to establish a communication connection with other devices, and it can be a wired communication device and / or a wireless communication device.

[0239] The input device 43 can be used to receive input digital or character information, generate key signal inputs related to the user settings and function controls of the electronic device, and can also be a camera for acquiring images and a sound pickup device for acquiring audio data. The output device 44 can include audio devices such as speakers. It should be noted that the specific compositions of the input device 43 and the output device 44 can be set according to actual situations.

[0240] The processor 40 executes various functional applications and data processing of the device by running software programs, instructions, and modules stored in the memory 41, that is, implements the above-mentioned comment paragraph generation method.

[0241] Specifically, in the embodiment, when the processor 40 executes one or more programs stored in the memory 41, the following operations are specifically implemented:

[0242] Obtain comment items; the comment items contain text information;

[0243] By classifying the text information, obtain the comment category corresponding to the comment item;

[0244] Sort the comment items according to the comment category to obtain a comment item sequence;

[0245] Predict the comment item sequence through a pre-trained paragraph generation model to generate a comment paragraph corresponding to the comment item.

[0246] Based on the above embodiment, one or more processors 40 also implement the following operations:

[0247] Input the comment item into a text classifier to obtain a probability vector of the comment item; the probability vector is used to represent the probability that the comment item belongs to each comment category;

[0248] Convert the probability vector into a one-hot vector; the one-hot vector is used to represent the comment category corresponding to the comment item.

[0249] Based on the above embodiment, one or more processors 40 also implement the following operations:

[0250] Sample the probability vector according to the probability vector dimension to obtain a sampling vector; each element in the sampling vector follows a uniform distribution;

[0251] Determine a probability vector noise through the sampling vector according to a preset mapping relationship;

[0252] Add the probability vector and the probability vector noise to obtain a probability noise vector;

[0253] Normalize the probability noise vector to obtain a normalized probability noise vector;

[0254] Suppress the backpropagation of the vector difference and superimpose the normalized probability noise vector to obtain the one-hot vector; the vector difference is the difference between the sampled value of the normalized probability noise vector and the normalized probability noise vector.

[0255] Based on the above embodiments, one or more processors 40 also perform the following operations:

[0256] Obtain a review item vector and the one-hot vector corresponding to the review item; the review item vector is the vector representation of the review item;

[0257] Generate a review item matrix according to the review item vector, and generate a one-hot matrix according to the one-hot vector;

[0258] Perform matrix operations on the review item matrix and the one-hot matrix to obtain a review item three-dimensional tensor;

[0259] Perform dimension swapping on the review item three-dimensional tensor to obtain a swapped three-dimensional tensor;

[0260] Perform splicing on two dimensions in the swapped three-dimensional tensor to obtain a spliced two-dimensional matrix;

[0261] Obtain the review item sequence by removing the zero vectors in the spliced two-dimensional matrix.

[0262] Based on the above embodiments, one or more processors 40 also perform the following operations:

[0263] Obtain a review item sequence sample and the corresponding comment paragraph of the review item sequence sample;

[0264] Mask the comment paragraph corresponding to the review item sequence sample to obtain a masked comment paragraph;

[0265] Train the to-be-trained paragraph generation model according to the review item sequence sample and the masked comment paragraph;

[0266] When the trained paragraph generation model meets the preset training conditions, obtain the pre-trained paragraph generation model.

[0267] Based on the above embodiments, one or more processors 40 also perform the following operations:

[0268] Obtain the text classifier loss, and obtain the paragraph generation model loss;

[0269] By performing a weighted sum of the text classifier loss and the paragraph generation model loss, a comment paragraph generation loss is obtained;

[0270] When the comment paragraph generation loss meets a preset loss condition, the trained paragraph generation model is used as the pre-trained paragraph generation model.

[0271] Based on the above embodiments, one or more processors 40 also perform the following operations:

[0272] Obtain a comment item sample and the comment category corresponding to the comment item sample;

[0273] By inputting the comment item sample into the text classifier, the probabilities that the comment item sample belongs to each comment category are obtained;

[0274] Based on the probabilities that the comment item sample belongs to each comment category and the comment category, the text classifier loss is obtained.

[0275] Embodiment Five

[0276] Embodiment Five of the present application further provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute a comment paragraph generation method when executed by a computer processor, including:

[0277] Obtain a comment item; the comment item includes text information;

[0278] By classifying the text information, the comment category corresponding to the comment item is obtained;

[0279] Sort the comment items according to the comment category to obtain a comment item sequence;

[0280] Use a pre-trained paragraph generation model to predict the comment item sequence and generate a comment paragraph corresponding to the comment item.

[0281] Certainly, the computer-executable instructions of the storage medium provided by the embodiments of the present application are not limited to the operations of the comment paragraph generation method as described above, and can also execute the relevant operations in the comment paragraph generation method provided by any embodiment of the present application, and have corresponding functions and beneficial effects.

[0282] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above various methods. Among them, any reference to a memory, storage, database, or other medium used in the various embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.

[0283] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.

[0284] The above-described embodiments merely represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the appended claims.

Claims

1. A method for generating a comment paragraph, characterized in that, The method includes: Obtaining a review item; the review item contains text information; By classifying the text information, obtaining a review category corresponding to the review item; Obtaining a review item vector and a one-hot vector corresponding to the review item; the review item vector is a vector representation of the review item; Generating a review item matrix according to the review item vector, and generating a one-hot matrix according to the one-hot vector; By performing matrix operations on the review item matrix and the one-hot matrix, obtaining a review item three-dimensional tensor; By performing dimension swapping on the review item three-dimensional tensor, obtaining a swapped three-dimensional tensor; By splicing two dimensions in the swapped three-dimensional tensor, obtaining a spliced two-dimensional matrix; By removing zero vectors in the spliced two-dimensional matrix, obtaining a review item sequence; By using a pre-trained text segment generation model to predict the review item sequence, generating a review text segment corresponding to the review item.

2. The method according to claim 1, characterized in that, The obtaining a review category corresponding to the review item by classifying the text information includes: Inputting the review item into a text classifier to obtain a probability vector of the review item; the probability vector is used to represent the probability that the review item belongs to each review category; Converting the probability vector into a one-hot vector; the one-hot vector is used to represent the review category corresponding to the review item.

3. The method according to claim 2, characterized in that, The converting the probability vector into a one-hot vector includes: Sampling the probability vector according to the dimension of the probability vector to obtain a sampling vector; each element in the sampling vector follows a uniform distribution; Determining a probability vector noise according to a preset mapping relationship through the sampling vector; Adding the probability vector and the probability vector noise to obtain a probability noise vector; Normalizing the probability noise vector to obtain a normalized probability noise vector; By performing backpropagation suppression on the vector difference and superimposing the normalized probability noise vector, obtaining the one-hot vector; the vector difference is the difference between the sampling value of the normalized probability noise vector and the normalized probability noise vector.

4. The method according to claim 2, characterized in that, The method further includes: Obtaining a review item sequence sample and a review text segment corresponding to the review item sequence sample; Masking the review text segment corresponding to the review item sequence sample to obtain a masked review text segment; Training a text segment generation model to be trained according to the review item sequence sample and the masked review text segment; When the trained text segment generation model meets a preset training condition, obtaining the pre-trained text segment generation model.

5. The method according to claim 4, characterized in that, The obtaining the pre-trained text segment generation model when the trained text segment generation model meets a preset training condition includes: Obtaining a text classifier loss, and obtaining a text segment generation model loss; By performing weighted summation on the text classifier loss and the text segment generation model loss, obtaining a review text segment generation loss; When the review text segment generation loss meets a preset loss condition, using the trained text segment generation model as the pre-trained text segment generation model.

6. The method according to claim 5, characterized in that, The obtaining the text classifier loss includes: Obtaining a review item sample and a review category corresponding to the review item sample; By inputting the comment item sample into the text classifier, the probabilities of the comment item sample belonging to each comment category are obtained; Based on the probabilities of the comment item sample belonging to each comment category and the comment category, the loss of the text classifier is obtained.

7. A device for generating a comment paragraph, characterized in that, The device includes: An acquisition module, configured to acquire a comment item; the comment item includes text information; A classification module, configured to obtain the comment category corresponding to the comment item by classifying the text information; A sorting module, configured to acquire a comment item vector and the one-hot vector corresponding to the comment item, where the comment item vector is a vector representation of the comment item, generate a comment item matrix according to the comment item vector, and generate a one-hot matrix according to the one-hot vector. By performing matrix operations on the comment item matrix and the one-hot matrix, a comment item three-dimensional tensor is obtained. By performing dimension exchange on the comment item three-dimensional tensor, an exchanged three-dimensional tensor is obtained. By splicing two dimensions in the exchanged three-dimensional tensor, a spliced two-dimensional matrix is obtained. By removing the zero vectors in the spliced two-dimensional matrix, a comment item sequence is obtained; A comment paragraph generation module, configured to predict the comment item sequence through a pre-trained paragraph generation model to generate a comment paragraph corresponding to the comment item.

8. The device according to claim 7, wherein, The classification module is further configured to input the comment item into a text classifier to obtain a probability vector of the comment item, where the probability vector is used to represent the probabilities of the comment item belonging to each of the comment categories, and convert the probability vector into a one-hot vector, where the one-hot vector is used to represent the comment category corresponding to the comment item.

9. An electronic device, wherein, It includes: A memory and one or more processors; The memory is configured to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors execute the comment paragraph generation method according to any one of claims 1-6.

10. A storage medium containing computer-executable instructions, wherein, The computer-executable instructions are used to execute the comment paragraph generation method according to any one of claims 1-6 when executed by a computer processor.

Citation Information

Patent Citations

  • Intelligent explanation generating and playing method and device, equipment and storage medium

    CN110971964A

  • Coding and decoding-based comment generation method and device, equipment and storage medium

    CN111897955A

  • Hybrid model for short text classification with imbalanced data

    US20200327445A1