Text processing method and device, electronic equipment and storage medium
By selecting matching reference texts from a preset text library and utilizing a sentence transformation model, the problem of non-native speakers writing high-quality texts is solved, enabling automatic adjustment of text content and style, and improving text processing efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-29
- Publication Date
- 2026-04-07
Smart Images

Figure CN115688685B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure belongs to the technical field of computers, and particularly relates to a text processing method and device, electronic equipment and a storage medium. BACKGROUND
[0002] With the rapid development of computer technologies such as machine learning in recent years, people often use machine learning models to solve various problems. Among them, with the increasing requirements for text processing, the development of natural language processing (NLP) technology is also becoming faster and faster. For example, in work or study, it is often required that the text written by the user is a high-quality text, that is, a text with more advanced words and expression methods. Especially for personnel whose writing language is not their mother tongue, it is more difficult to write and takes more time.
[0003] In related technologies, natural language processing methods mainly focus on the field of grammar correction. Therefore, there is an urgent need for a text processing method that can adjust the expression content and expression method of a text. SUMMARY
[0004] To overcome the problems in related technologies, the present disclosure provides a text processing method, device, electronic equipment and storage medium.
[0005] According to a first aspect of the present disclosure, a text processing method is provided, which comprises:
[0006] obtaining an input text to be processed;
[0007] selecting, in a preset text library, a reference text that matches the text to be processed and meets a preset requirement;
[0008] determining, in the reference text, a target reference sentence similar to a sentence to be modified in the text to be processed;
[0009] According to a target sentence conversion model, converting the sentence to be modified according to the target reference sentence to obtain a target recommended sentence corresponding to the sentence to be modified. Optionally, the preset text library stores a plurality of sample texts;
[0010] The selecting, in a preset text library, a reference text that matches the text to be processed and meets a preset requirement comprises:
[0011] determining a target field to which the text to be processed belongs, and determining a value label of each sample text;
[0012] performing classification processing on the value label, and taking a sample text whose processing result meets the preset requirement as a first type of text;
[0013] Select sample texts belonging to the target domain as the second type of text;
[0014] Sample texts that belong to both the first type of text and the second type of text are used as reference texts.
[0015] Optionally, determining the target domain to which the text to be processed belongs includes:
[0016] Obtain the keywords from the text to be processed;
[0017] The domain that the keyword matches is taken as the target domain to which the text to be processed belongs.
[0018] Optionally, the method further includes:
[0019] The sample text is split to obtain text fragments corresponding to different content attributes;
[0020] According to each of the aforementioned content attributes, the text fragments corresponding to each content attribute are stored in the preset text library.
[0021] Optionally, determining a target reference sentence in the reference text that is similar to the sentence to be modified in the text to be processed includes:
[0022] Identify the sentences to be modified in the text to be processed;
[0023] Based on the sentence to be modified and a preset text filtering algorithm, the reference text is filtered to determine target reference sentences similar to the sentence to be modified.
[0024] Optionally, the step of filtering the reference text based on the sentence to be modified and a preset text filtering algorithm to determine target reference sentences similar to the sentence to be modified includes:
[0025] The first filtering algorithm is used to filter the statements contained in the reference text to determine the first reference sentence that is similar to the sentence to be modified;
[0026] The first reference sentence is filtered using a second filtering algorithm, and the first reference sentence whose similarity meets a preset threshold is used as the target reference sentence.
[0027] Optionally, the method further includes:
[0028] Obtain multiple sample statements;
[0029] The sample statement is translated using a preset translation method to obtain the translated sample statement;
[0030] The sample statement and the sample translated statement are used as a training sample pair;
[0031] The initial sentence conversion model is trained using the training samples to obtain the target sentence conversion model.
[0032] Optionally, the method further includes:
[0033] The position embedding parameters in the initial statement conversion model are set to trainable values so that the position embedding parameters can be trained using samples.
[0034] Optionally, the initial statement transformation model is a Transformer model.
[0035] According to a second aspect of this disclosure, a text processing apparatus is provided, the apparatus comprising:
[0036] The first acquisition module is used to acquire the input text to be processed;
[0037] The selection module selects a reference text from a preset text library that matches the text to be processed and meets preset requirements.
[0038] The first determining module is used to determine, in the reference text, a target reference sentence that is similar to the sentence to be modified in the text to be processed;
[0039] The conversion module is used to convert the sentence to be modified according to the target reference sentence based on the target sentence conversion model, so as to obtain the target recommended sentence corresponding to the sentence to be modified.
[0040] Optionally, the preset text library stores multiple sample texts;
[0041] The selection module is also used for:
[0042] Determine the target domain to which the text to be processed belongs, and determine the value tag for each of the sample texts;
[0043] The value tags are categorized, and sample texts whose processing results meet the preset requirements are taken as the first type of text.
[0044] Select sample texts belonging to the target domain as the second type of text;
[0045] Sample texts that belong to both the first type of text and the second type of text are used as reference texts.
[0046] Optionally, the selection module is further configured to:
[0047] Obtain the keywords from the text to be processed;
[0048] The domain that the keyword matches is taken as the target domain to which the text to be processed belongs.
[0049] Optionally, the device further includes:
[0050] The splitting module is used to split the sample text to obtain text fragments corresponding to different content attributes;
[0051] The storage module is used to store the text fragments corresponding to each of the content attributes in the preset text library according to each of the content attributes.
[0052] Optionally, the first determining module is further configured to:
[0053] Identify the sentences to be modified in the text to be processed;
[0054] Based on the sentence to be modified and a preset text filtering algorithm, the reference text is filtered to determine target reference sentences similar to the sentence to be modified.
[0055] Optionally, the first determining module is further configured to:
[0056] The first filtering algorithm is used to filter the statements contained in the reference text to determine the first reference sentence that is similar to the sentence to be modified;
[0057] The first reference sentence is filtered using a second filtering algorithm, and the first reference sentence whose similarity meets a preset threshold is used as the target reference sentence.
[0058] Optionally, the device further includes:
[0059] The second acquisition module is used to acquire multiple sample statements;
[0060] The translation module is used to translate the sample statement according to a preset translation method to obtain the translated sample statement;
[0061] The second determining module is used to treat the sample statement and the sample translated statement as a training sample pair;
[0062] The training module is used to train the initial sentence conversion model using the training samples to obtain the target sentence conversion model.
[0063] Optionally, the device further includes:
[0064] The setting module is used to set the position embedding parameters in the initial statement conversion model to trainable values so that the position embedding parameters can be trained using samples.
[0065] Optionally, the initial statement transformation model is a Transformer model.
[0066] According to a third aspect of this disclosure, an electronic device is provided, comprising:
[0067] processor;
[0068] Memory used to store processor-executable instructions;
[0069] The processor is configured to execute the instructions to implement the text processing method as described in any one of the first aspects.
[0070] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided, which, when instructions in the storage medium are executed by a processor of a mobile terminal, enables the mobile terminal to perform the text processing method as described in any one of the first aspects.
[0071] According to a fifth aspect of this disclosure, a computer program product is provided, the computer program product including readable program instructions that, when executed by a processor of a mobile terminal, enable the mobile terminal to perform the steps in the text processing method as described in any of the above embodiments.
[0072] Compared with related technologies, this disclosure has the following advantages and positive effects:
[0073] The text processing method provided in this disclosure can acquire input text to be processed, select reference texts that match the text to be processed and meet preset requirements from a preset text library, determine target reference sentences similar to the sentence to be modified in the text to be processed from the reference texts, and finally, according to a target sentence conversion model, convert the sentence to be modified according to the target reference sentences to obtain the target recommended sentences corresponding to the sentence to be modified. In this way, by converting the sentence to be modified according to the target reference sentences through the sentence conversion model, a target recommended sentence with more accurate wording and expression style that is more in line with the habits of reviewers can be obtained. This allows for the adjustment of the text's content and expression style, enabling high-quality written text to be obtained without the user manually modifying the text, thus improving the efficiency of text processing.
[0074] The above description is merely an overview of the technical solution disclosed herein. In order to better understand the technical means of this disclosure and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this disclosure more apparent and understandable, specific embodiments of this disclosure are described below. Attached Figure Description
[0075] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this disclosure. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:
[0076] Figure 1 This is a flowchart of the steps of a text processing method provided in an embodiment of this disclosure;
[0077] Figure 2 This is a schematic diagram of text processing provided in an embodiment of the present disclosure;
[0078] Figure 3 This is a block diagram of a text processing apparatus provided in an embodiment of this disclosure;
[0079] Figure 4 This is a block diagram illustrating an apparatus for text processing according to an exemplary embodiment;
[0080] Figure 5 This is a block diagram illustrating another apparatus for text processing according to an exemplary embodiment. Detailed Implementation
[0081] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0082] Figure 1 This is a flowchart of the steps of a text processing method provided in an embodiment of this disclosure, as follows: Figure 1 As shown, the method may include:
[0083] Step 101: Obtain the input text to be processed.
[0084] In this embodiment of the disclosure, the text to be processed can be text whose expression needs to be adjusted. Obtaining the input text to be processed can be done by selecting the text to be adjusted by the user as the text to be processed. For example, if a "Upload Paper" button is displayed on the interface, clicking this button can select the text to be adjusted as the uploaded text, and correspondingly, this text can be identified as the text to be processed.
[0085] Step 102: Select a reference text from the preset text library that matches the text to be processed and meets the preset requirements.
[0086] In this embodiment, selecting text that matches the text to be processed can be selecting text that shares a certain attribute with the text to be processed. For example, this attribute could be the technical field to which the text belongs, keywords contained in the text, or the publication journal in which the text was published, etc. The preset requirement could be sorting the text according to a certain dimension, with the top N texts being the texts that meet the preset requirement, where N is a positive integer. For example, the preset requirement could be sorting by the number of citations, in which case the N texts with the most citations would meet the preset requirement; or it could be sorting by the size of the tags corresponding to the publication journal, in which case the N texts with the largest tags corresponding to the publication journal would meet the preset requirement. This disclosure does not limit this approach.
[0087] In this embodiment of the disclosure, selecting reference text that matches the text to be processed and meets preset requirements can be done in several ways. First, text that matches the text to be processed is selected, and then text that meets the preset requirements is selected from the matched text as reference text. Alternatively, text that meets the preset requirements is selected first, and then text that matches the preset requirements is selected from the text that meets the preset requirements as reference text. Another method is to simultaneously select text that matches the text to be processed and text that meets the preset requirements, and then use the text that matches and meets the preset requirements as reference text.
[0088] It should be noted that the preset text library can be pre-stored text, which can be articles published in a designated journal, literature belonging to a certain technical field, or papers written by a certain author, etc. This disclosure does not impose any restrictions. Compared with the text to be processed, the text stored in the preset text library has often been reviewed and approved by professionals. Therefore, the text in the preset text library has the advantage of more accurate wording and expression style that is more in line with the reviewers' habits.
[0089] Step 103: In the reference text, identify a target reference sentence that is similar to the sentence to be modified in the text to be processed.
[0090] In this embodiment of the disclosure, the similarity between each sentence in the reference text and the sentence to be modified can be calculated separately, and sentences with a similarity greater than a preset threshold can be used as target reference sentences similar to the sentence to be modified. The similarity can be determined based on the similarity of the content or the similarity of the expression method; this disclosure does not impose any limitations on this.
[0091] Step 104: Based on the target sentence transformation model, the sentence to be modified is transformed according to the target reference sentence to obtain the target recommended sentence corresponding to the sentence to be modified.
[0092] In this embodiment, the target sentence conversion model can be obtained by iteratively training an initial sentence conversion model using sample sentences and sample translated sentences as training sample pairs. Through continuous iterative training, the sentence conversion model can learn the ability to convert sentences according to the target expression method while keeping the content unchanged. Therefore, in this embodiment, the trained sentence conversion model can be used to convert the sentence to be modified according to the target reference sentence to obtain the target recommended sentence corresponding to the sentence to be modified.
[0093] In summary, the text processing method provided in this disclosure can acquire the input text to be processed, select a reference text from a preset text library that matches the text to be processed and meets preset requirements, then determine a target reference sentence similar to the sentence to be modified in the text to be processed from the reference text, and finally, according to the target sentence conversion model, convert the sentence to be modified according to the target reference sentence to obtain the target recommended sentence corresponding to the sentence to be modified. In this way, by converting the sentence to be modified according to the target reference sentence through the sentence conversion model, a target recommended sentence with more accurate wording and a more suitable expression style for reviewers can be obtained. This allows for adjustments to the content and expression style of the text, enabling high-quality written text to be obtained without manual modification by the user, thus improving the efficiency of text processing.
[0094] Optionally, in this embodiment of the present disclosure, a preset text library stores multiple sample texts. These sample texts can be articles published in designated journals, such as all articles published in academic journals or articles published in foreign journals. The operation of selecting a reference text from the preset text library that matches the text to be processed and meets the preset requirements can specifically include:
[0095] Step 1021: Determine the target domain to which the text to be processed belongs, and determine the value tag of each of the sample texts.
[0096] In this embodiment of the disclosure, determining the target domain to which the text to be processed belongs can be done by determining the target domain to which the text to be processed belongs through the content of the text to be processed, or by marking the domain to which the text to be processed belongs and using that domain as the target domain, or by obtaining a specified domain input by the user and using that specified domain as the domain to which the text to be processed belongs.
[0097] In this embodiment of the disclosure, the value tag of the sample text can be determined based on the journal level in which the sample text is published. Specifically, the journal in which the sample text is sent is first determined, for example, the sample is published in journal X. Then, the value tag of the sample text is determined based on the evaluation parameters corresponding to the journal. For example, if the evaluation parameter of journal X is 7, then the value tag of the sample text is 7.
[0098] Step 1022: Classify the value tags and take the sample texts whose processing results meet the preset requirements as the first type of text.
[0099] In this embodiment, a preset classification algorithm can be used to classify value tags. This preset classification algorithm can be a knowledge graph-based recommendation algorithm (KGCN model) in Graph Convolutional Network (GCN). Specifically, it can be done by randomly selecting articles from multiple academic journals and constructing a corresponding knowledge graph for each article. That is, the knowledge graph is obtained by decomposing the articles according to various content attributes. Then, value tags are set according to the evaluation parameters corresponding to each zone of the academic journals. For example, the value tag for academic journal zone 1 is 10, the value tag for academic journal zone 2 is 7, the value tag for academic journal zone 3 is 4, and the value tag for academic journal zone 4 is 2. The articles from multiple academic journals and the value tags corresponding to each article are input into the graph convolutional KGCN model for training. The KGCN model extracts the parts that have a greater impact on the final value tag value by propagating the articles on the knowledge graph. The principle can be to use a certain range of neighboring nodes to continuously aggregate and iterate, and use the aggregated vector to replace the vector representation of the current node. The aggregation formula can be as follows:
[0100]
[0101] Among them, agg sum It can be an aggregation formula used to calculate the numerical impact of each text segment on the final value label, where σ can be a non-linear function, u can represent the embedding vector representation of the article's domain, and v can represent the embedding vector representation of the articles in the training set. This can be represented as an embedded vector representation of the neighborhood of the article to be trained, S (v) This can be used to control the number of adjacent nodes in the article to be trained; for example, S can be... (v) Defined as a hyperparameter K, such as K=3, where W can be the weights of the fully connected layer and b can be the bias.
[0102] Furthermore, a probability f(u,v) can be obtained by calculating the inner product between the embedding vector u of the article domain and the embedding vector v of the article. The formula for calculating this probability is as follows:
[0103] y uv =f(u,v)
[0104] By training this loss function for probability and value labels, the probability f(u,v) can be maximized. In this embodiment, to improve the accuracy of text processing, the loss function in the KGCN model can be replaced with variance.
[0105] In this embodiment, the preset classification algorithm can also be a random forest model in traditional machine learning. Specifically, it can involve selecting articles from multiple academic journals, constructing a corresponding knowledge graph for each article, determining the value tags for each article, and then selecting feature information based on the article's attributes. This feature information can be any one or more of the following: the number of citations, the journal's impact factor, and the article's keywords. Each article, along with its corresponding value tags and feature information, is then input into the random forest model, and the final fitted result is the value ranking order of the articles.
[0106] In this embodiment of the disclosure, the sample text whose processing results meet the preset requirements is taken as the first type of text. This can be done by classifying the value tags to obtain the value ranking order of multiple sample texts, and then taking the top ten sample texts with the highest value as the first type of text according to the ranking order.
[0107] Step 1023: Filter sample texts belonging to the target domain as the second type of text.
[0108] In this embodiment of the disclosure, the domain to which each sample text belongs may be determined first, and then the sample texts belonging to the target domain may be used as the second type of text. Determining the domain to which each sample text belongs may involve extracting keywords from the sample text, determining the corresponding domain based on the keywords, and using that domain as the domain to which the sample text belongs.
[0109] Step 1024: The sample text that belongs to both the first type of text and the second type of text is used as the reference text.
[0110] In this embodiment of the present disclosure, a first type of text may be determined first, and then a second type of text may be determined from the first type of text. This will result in a sample text that belongs to both the first type of text and the second type of text, and this sample text will be used as a reference text. Alternatively, a second type of text may be determined first, and then a first type of text may be determined from the second type of text. This will result in a sample text that belongs to both the first type of text and the second type of text, and this sample text will be used as a reference text. This disclosure does not limit the scope of the embodiments.
[0111] In this embodiment, the target domain to which the text to be processed belongs and the value tags of each sample text can be determined first. Then, the value tags are classified. Sample texts whose processing results meet the preset requirements are taken as first-type texts, and sample texts belonging to the target domain are selected as second-type texts. Finally, sample texts belonging to both the first-type and second-type texts are taken as reference texts. In this way, sample texts belonging to the same domain as the text to be processed and with higher text value can be selected so that they can be used as training samples to improve the accuracy of model training.
[0112] Optionally, the operation of determining the target domain to which the text to be processed belongs in the embodiments of this disclosure may specifically include:
[0113] Sub-step (1): Obtain keywords from the text to be processed.
[0114] In this embodiment of the disclosure, when the text to be processed contains keywords, those keywords can be directly used as keywords in the text to be processed; when the text to be processed does not contain keywords, a preset recognition algorithm can be used to recognize the text to be processed, and the recognized keywords can be used as keywords in the text to be processed. The preset recognition algorithm can be Named Entity Recognition (NER) technology, which uses basic tools such as information extraction, syntactic analysis, and machine translation to recognize the text to be processed and extract keywords.
[0115] Sub-step (2): The domain matched by the keyword is taken as the target domain to which the text to be processed belongs.
[0116] In this embodiment, different domains can be pre-defined for matching different keywords. Based on the keywords in the text to be processed, the domain to which the keyword matches is determined, and this domain is used as the target domain of the text to be processed. It should be noted that when there are many keywords in the text to be processed, for example, 11 keywords, the first three keywords can be selected to determine the matching domain. This is because the order of keywords is often based on their importance within the text. Selecting the first three keywords to determine the matching domain can improve the accuracy of determining the domain to which the text to be processed belongs to a certain extent. Furthermore, the matching domain can be any domain that simultaneously contains all three keywords.
[0117] Optionally, in one implementation, the following steps may also be performed in this embodiment of the disclosure:
[0118] Sub-step S11: Segment the sample text to obtain text fragments corresponding to different content attributes.
[0119] In this embodiment of the disclosure, the content attributes can be information such as the author, title, abstract, keywords, field, publication location, and journal of the sample text. Decomposing the sample text to obtain text fragments corresponding to different content attributes can be achieved by breaking down the sample text according to each content attribute, obtaining text fragments corresponding to each content attribute separately.
[0120] Sub-step S12: According to each of the content attributes, store the text fragments corresponding to each content attribute in the preset text library respectively.
[0121] In this embodiment of the disclosure, after decomposing multiple sample texts stored in a preset text library, they are classified according to their respective content attributes to obtain text fragments belonging to the same content attribute in each sample text, and these text fragments are stored in the preset text library according to their content attributes.
[0122] Optionally, in this embodiment of the present disclosure, the operation of determining a target reference sentence in the reference text that is similar to the sentence to be modified in the text to be processed may specifically include:
[0123] Step 1031: Determine the sentence to be modified in the text to be processed.
[0124] In this embodiment of the disclosure, the sentence to be modified can be a sentence whose expression needs to be adjusted or whose content needs to be replaced. Determining the sentence to be modified in the text to be processed can be done by arbitrarily extracting a sentence from the text according to its period, or by having the user specify a sentence in the text to be modified.
[0125] Step 1032: Based on the sentence to be modified and a preset text filtering algorithm, filter the reference text to determine target reference sentences similar to the sentence to be modified.
[0126] In this embodiment of the disclosure, the preset text filtering algorithm can be a text filtering algorithm in Natural Language Processing (NLP), such as the TextRank algorithm or the BERT algorithm; this disclosure does not limit this. For example, the BERT algorithm can be used to calculate the similarity between each sentence in the reference text and the sentence to be modified, and the sentence with the highest similarity can be used as the target reference sentence similar to the sentence to be modified.
[0127] Optionally, in this embodiment of the present disclosure, the operation of filtering the reference text based on the sentence to be modified and a preset text filtering algorithm to determine target reference sentences similar to the sentence to be modified may specifically include:
[0128] Sub-step (3): Use the first filtering algorithm to filter the statements contained in the reference text and determine the first reference sentence that is similar to the sentence to be modified.
[0129] In this embodiment of the disclosure, the first filtering algorithm can be the TextRank algorithm, which filters each sentence in the reference text, selects sentences similar to the sentence to be modified, and uses these sentences as the first reference sentences similar to the sentence to be modified. For example, the similarity between each sentence in the reference text and the sentence to be modified can be determined, and sentences with a similarity greater than 50% can be used as the first reference sentences.
[0130] Sub-step (4): Use the second filtering algorithm to filter the first reference sentence, and use the first reference sentence whose similarity meets the preset threshold as the target reference sentence.
[0131] In this embodiment of the disclosure, the second filtering algorithm may be the BERT algorithm, which calculates the similarity between the first reference sentence and the sentence to be modified, and uses the first reference sentence whose similarity meets a preset threshold as the target reference sentence. For example, the first reference sentence with a similarity greater than 80% may be used as the target reference sentence.
[0132] In this embodiment of the disclosure, by determining the sentence to be modified in the text to be processed, and by filtering the reference text according to the preset text filtering algorithm and the sentence to be modified, a target reference sentence similar to the sentence to be modified is determined. In this way, by using the text filtering algorithm to filter similar sentences, the accuracy of text processing can be improved and the processing time can be shortened.
[0133] Optionally, in one implementation, the following steps may also be performed in this embodiment of the disclosure:
[0134] Sub-step S21: Obtain multiple sample statements.
[0135] In this embodiment of the disclosure, the sample statement can be a statement extracted from a preset sample library, a statement downloaded from the Internet, or a statement specified by the user; this disclosure does not impose any restrictions on this. For example, a sentence can be randomly selected from an academic journal as a sample statement.
[0136] Sub-step S22: Translate the sample statement according to a preset translation method to obtain the sample translated statement.
[0137] In this embodiment of the disclosure, the preset translation method can be to perform forward and reverse translation of the sample statement into different languages. For example, if the sample statement is French, it can be translated from French to English to obtain an English sample statement, and then the English sample statement can be translated from English to French to obtain a French sample statement. The French sample statement is then used as the sample translation statement.
[0138] Example, Figure 2 This is a text processing illustration provided by an embodiment of the present disclosure, such as... Figure 2As shown, sentence 1 is a sample sentence. Translating sentence 1 from English to Chinese yields sentence 2 in Chinese. Then, translating sentence 2 from Chinese to English yields sentence 3 in English. Sentence 3 can then be used as a sample translation sentence.
[0139] Sub-step S23: Combine the sample statement and the sample translated statement as a training sample pair.
[0140] For example, a sample sentence and a sample translated sentence can be used as a training sample pair. This could be a Japanese sentence and a Japanese sentence obtained through Japanese-to-English and English-to-Japanese translation, or a German sentence and a German sentence obtained through German-to-French and French-to-German translation.
[0141] Sub-step S24: Train the initial sentence conversion model using the training samples to obtain the target sentence conversion model.
[0142] In this embodiment, the initial sentence transformation model can be a Transformer model for text processing. In one specific implementation, the specific processing steps of the Transformer model can be as follows: First step: Obtain the representation vector X of each word in the input sentence. X can be obtained by adding the word's embedding vector and the vector of the word's position. Second step: The obtained word representation vector matrix can be passed into the encoder. After passing through N (e.g., 6) encoder blocks, the encoded information matrix C of all words in the sentence can be obtained. The word vector matrix can be represented by X(n×d), where n can be the number of words in the sentence and d can be the dimension of the vector representation. For example, d = 512. The dimension of the matrix output by each encoder block can be completely consistent with the input. Third step: The encoded information matrix C output by the encoder can be passed into the decoder. The decoder can sequentially translate the next word i+1 based on the currently translated words 1 to i. During the process, when translating word i+1, the words after i+1 can be masked through a masking operation, and the predicted word is output.
[0143] It's important to note that the Transformer model comprises an encoder and a decoder, each containing six blocks. The encoder block can include one multi-head attention mechanism, while the decoder block can include two. One of these multi-head attention mechanisms can utilize a masking operation. Before the multi-head attention mechanisms in the decoder block, an Add & Norm layer can be included. Add represents a residual connection to prevent network degradation, and Norm represents layer normalization to normalize the activation values of each layer. By using input corpus 1 as sample sentences and corpus 2 as sample translated sentences, the Transformer model can be iteratively trained to learn the conversion method between corpus 1 and corpus 2, enabling it to convert sentences according to the target expression while preserving the original content.
[0144] Furthermore, a multi-head attention mechanism can be composed of multiple self-attention mechanisms. The decoder, unlike the encoder, has a self-attention layer that focuses only on preceding information while masking subsequent information. In the decoder, subsequent word inferences can be based on preceding words. At time t, the decoder may not know the words at time t+1. Therefore, to ensure consistency between training and inference, attention allocation is needed to prevent inconsistencies between a given word and its subsequent words. Finally, the decoder stack can be externally connected to a linear layer and a softmax layer, mapping the vector to style-transformed output words. The linear layer can be a fully connected layer, followed by a softmax layer, which yields the probability of each input word (style 1) being converted to each word in another text style (style 2).
[0145] It should be noted that the Transformer model in this embodiment may further include a multi-head attention mechanism. In the second multi-head attention mechanism, the preceding encoder can provide key (K) and value (V) matrices, and the output can provide a query (Q) matrix. The multi-head attention mechanism module differs from the single-head attention mechanism in that it can generate multiple Q, K, and V matrices. Different Q, K, and V matrices expand the model's representational capabilities. Specifically, the Transformer model in this embodiment may contain eight attention mechanisms.
[0146] In this embodiment, after training the initial sentence conversion model using training samples, a target sentence conversion model can be obtained; that is, the target sentence conversion model can be a pre-trained sentence conversion model. The target sentence conversion model can also be a sentence conversion model that is continuously updated based on the user's usage of the model, building upon the pre-trained model. Specifically, in the process of using the pre-trained sentence conversion model to convert the sentence to be modified according to the target reference sentence to obtain the target recommended sentence corresponding to the sentence to be modified, the pre-trained sentence conversion model can be trained and learned based on the user's input corpus, thereby continuously updating the sentence conversion model. In this way, by learning from the input corpus in actual use, the training samples of the model can be expanded, making the model's output results more in line with the user's needs, thereby reducing the error rate of the output results.
[0147] Optionally, in one implementation, the following steps may also be performed in this embodiment of the disclosure:
[0148] Sub-step S25: Set the position embedding parameters in the initial statement conversion model to trainable values so that the position embedding parameters can be trained using samples.
[0149] In this embodiment, since the present disclosure transforms the sentence to be modified according to the target reference sentence to obtain the target recommended sentence corresponding to the sentence to be modified, when the sentence to be modified is transformed, it may not only replace words with synonyms, but also adjust the word order of the expression. In the initial sentence transformation model, the position embedding parameter is often set to a fixed value and does not participate in training. Therefore, by setting the position embedding parameter to a trainable value, the adjustment of word order can be taken into account when transforming the sentence to be modified, so as to make the target recommended sentence and the target reference sentence more similar in expression, making the word choice of the target recommended sentence more accurate and the expression more in line with the habits of reviewers.
[0150] Figure 3 This is a block diagram of a text processing apparatus provided in an embodiment of this disclosure, such as... Figure 3As shown, the device 30 may include:
[0151] The first acquisition module 301 is used to acquire the input text to be processed;
[0152] The selection module 302 selects a reference text from a preset text library that matches the text to be processed and meets the preset requirements;
[0153] The first determining module 303 is used to determine, in the reference text, a target reference sentence that is similar to the sentence to be modified in the text to be processed;
[0154] The conversion module 304 is used to convert the sentence to be modified according to the target reference sentence based on the target sentence conversion model, so as to obtain the target recommended sentence corresponding to the sentence to be modified.
[0155] In summary, the text processing apparatus provided in this embodiment can acquire input text to be processed, select reference text from a preset text library that matches the text to be processed and meets preset requirements, then determine a target reference sentence similar to the sentence to be modified in the text to be processed from the reference text, and finally, according to the target sentence conversion model, convert the sentence to be modified according to the target reference sentence to obtain the target recommended sentence corresponding to the sentence to be modified. In this way, by converting the sentence to be modified according to the target reference sentence through the sentence conversion model, a target recommended sentence with more accurate wording and a more suitable expression style for reviewers can be obtained. This allows for adjustments to the content and expression style of the text, enabling high-quality written text to be obtained without manual modification by the user, thus improving the efficiency of text processing.
[0156] Optionally, the preset text library stores multiple sample texts;
[0157] The selection module 302 is further configured to:
[0158] Determine the target domain to which the text to be processed belongs, and determine the value tag for each of the sample texts;
[0159] The value tags are categorized, and sample texts whose processing results meet the preset requirements are taken as the first type of text.
[0160] Select sample texts belonging to the target domain as the second type of text;
[0161] Sample texts that belong to both the first type of text and the second type of text are used as reference texts.
[0162] Optionally, the selection module 302 is further configured to:
[0163] Obtain the keywords from the text to be processed;
[0164] The domain that the keyword matches is taken as the target domain to which the text to be processed belongs.
[0165] Optionally, the device 30 further includes:
[0166] The splitting module is used to split the sample text to obtain text fragments corresponding to different content attributes;
[0167] The storage module is used to store the text fragments corresponding to each of the content attributes in the preset text library according to each of the content attributes.
[0168] Optionally, the first determining module 303 is further configured to:
[0169] Identify the sentences to be modified in the text to be processed;
[0170] Based on the sentence to be modified and a preset text filtering algorithm, the reference text is filtered to determine target reference sentences similar to the sentence to be modified.
[0171] Optionally, the first determining module 303 is further configured to:
[0172] The first filtering algorithm is used to filter the statements contained in the reference text to determine the first reference sentence that is similar to the sentence to be modified;
[0173] The first reference sentence is filtered using a second filtering algorithm, and the first reference sentence whose similarity meets a preset threshold is used as the target reference sentence.
[0174] Optionally, the device 30 further includes:
[0175] The second acquisition module is used to acquire multiple sample statements;
[0176] The translation module is used to translate the sample statement according to a preset translation method to obtain the translated sample statement;
[0177] The second determining module is used to treat the sample statement and the sample translated statement as a training sample pair;
[0178] The training module is used to train the initial sentence conversion model using the training samples to obtain the target sentence conversion model.
[0179] Optionally, the device 30 further includes:
[0180] The setting module is used to set the position embedding parameters in the initial statement conversion model to trainable values so that the position embedding parameters can be trained using samples.
[0181] Optionally, the initial statement transformation model is a Transformer model.
[0182] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0183] According to one embodiment of the present disclosure, an electronic device is provided, including: a processor and a memory for storing processor-executable instructions, wherein the processor is configured to perform, when executing, steps in the text processing method as described in any of the above embodiments.
[0184] According to one embodiment of this disclosure, a non-transitory computer-readable storage medium is also provided, which, when the instructions in the storage medium are executed by the processor of a mobile terminal, enables the mobile terminal to perform the steps in the text processing method as described in any of the above embodiments.
[0185] According to one embodiment of this disclosure, a computer program product is also provided, which includes readable program code that, when executed by a processor of a mobile terminal, enables the mobile terminal to perform steps in the text processing method as described in any of the above embodiments.
[0186] Figure 4 This is a block diagram illustrating an apparatus for text processing according to an exemplary embodiment. For example, apparatus 400 may be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.
[0187] Reference Figure 4 The device 400 may include one or more of the following components: a processing component 402, a memory 404, a power supply component 406, a multimedia component 408, an audio component 410, an input / output (I / O) interface 412, a sensor component 414, and a communication component 416.
[0188] Processing component 402 typically controls the overall operation of device 400, such as operations associated with display, telephone calls, data communication, camera operation, and recording. Processing component 402 may include one or more processors 420 to execute instructions to complete all or part of the steps of the text processing method described above. Furthermore, processing component 402 may include one or more modules to facilitate interaction between processing component 402 and other components. For example, processing component 402 may include a multimedia module to facilitate interaction between multimedia component 408 and processing component 402.
[0189] Memory 404 is configured to store various types of data to support the operation of device 400. Examples of this data include instructions for any application or method operating on device 400, contact data, phonebook data, messages, pictures, videos, etc. Memory 404 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 storage, flash memory, magnetic disk, or optical disk.
[0190] Power supply component 406 provides power to various components of device 400. Power supply component 406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to device 400.
[0191] Multimedia component 408 includes a screen that provides an output interface between the device 400 and the user. 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 touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 408 includes a front-facing camera and / or a rear-facing camera. When the device 400 is in an operating mode, such as a shooting mode or a video mode, the front-facing camera and / or the rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0192] Audio component 410 is configured to output and / or input audio signals. For example, audio component 410 includes a microphone (MIC) configured to receive external audio signals when device 400 is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals may be further stored in memory 404 or transmitted via communication component 416. In some embodiments, audio component 410 also includes a speaker for outputting audio signals.
[0193] I / O interface 412 provides an interface between processing component 402 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0194] Sensor assembly 414 includes one or more sensors for providing status assessments of various aspects of device 400. For example, sensor assembly 414 may detect the on / off state of device 400, the relative positioning of components such as the display and keypad of device 400, changes in the position of device 400 or a component of device 400, the presence or absence of user contact with device 400, the orientation or acceleration / deceleration of device 400, and temperature changes of device 400. Sensor assembly 414 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 414 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 414 may also include an accelerometer, a gyroscope, a magnetometer, a pressure sensor, or a temperature sensor.
[0195] Communication component 416 is configured to facilitate wired or wireless communication between device 400 and other devices. Device 400 can access wireless networks based on communication standards, such as WiFi, carrier networks (such as 2G, 3G, 4G, or 5G), or combinations thereof. In one exemplary embodiment, communication component 416 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 416 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0196] In an exemplary embodiment, the apparatus 400 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 perform the text processing method described above.
[0197] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, which can be executed by a processor 420 of the device 400 to complete the text processing method described above. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0198] Figure 5This is a block diagram illustrating another apparatus for text processing according to an exemplary embodiment. For example, apparatus 500 may be provided as a server. (Refer to...) Figure 5 The apparatus 500 includes a processing component 522, which further includes one or more processors, and memory resources represented by memory 532 for storing instructions, such as application programs, that can be executed by the processing component 522. The application programs stored in memory 532 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 522 is configured to execute instructions to perform the aforementioned text processing method.
[0199] Device 500 may also include a power supply component 526 configured to perform power management of device 500, a wired or wireless network interface 550 configured to connect device 500 to a network, and an input / output (I / O) interface 558. Device 500 may operate on an operating system stored in memory 532, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or similar.
[0200] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0201] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A text processing method, characterized in that, The method includes: Get the input text to be processed; Select reference texts from a preset text library that match the text to be processed and meet preset requirements; In the reference text, a target reference sentence similar to the sentence to be modified in the text to be processed is identified; Based on the target sentence transformation model, the sentence to be modified is transformed according to the target reference sentence to obtain the target recommended sentence corresponding to the sentence to be modified; The step of selecting reference texts from a preset text library that match the text to be processed and meet preset requirements includes: The target domain to which the text to be processed belongs is determined, and the value tags of each sample text stored in the preset text library are determined according to the journal level in which the sample text is published. The value tags are categorized, and sample texts whose processing results meet the preset requirements are taken as the first type of text. Select sample texts belonging to the target domain as the second type of text; Sample texts that belong to both the first type of text and the second type of text are used as reference texts.
2. The method according to claim 1, characterized in that, Determining the target domain to which the text to be processed belongs includes: Obtain the keywords from the text to be processed; The domain that the keyword matches is taken as the target domain to which the text to be processed belongs.
3. The method according to claim 1, characterized in that, The method further includes: The sample text is split to obtain text fragments corresponding to different content attributes; According to each of the aforementioned content attributes, the text fragments corresponding to each content attribute are stored in the preset text library.
4. The method according to claim 1, characterized in that, The step of identifying a target reference sentence in the reference text that is similar to the sentence to be modified in the text to be processed includes: Identify the sentences to be modified in the text to be processed; Based on the sentence to be modified and a preset text filtering algorithm, the reference text is filtered to determine target reference sentences similar to the sentence to be modified.
5. The method according to claim 4, characterized in that, The step of filtering the reference text based on the sentence to be modified and a preset text filtering algorithm to determine target reference sentences similar to the sentence to be modified includes: The first filtering algorithm is used to filter the statements contained in the reference text to determine the first reference sentence that is similar to the sentence to be modified; The first reference sentence is filtered using a second filtering algorithm, and the first reference sentence whose similarity meets a preset threshold is used as the target reference sentence.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: Obtain multiple sample statements; The sample statement is translated using a preset translation method to obtain the translated sample statement; The sample statement and the sample translated statement are used as a training sample pair; The initial sentence conversion model is trained using the training samples to obtain the target sentence conversion model.
7. The method according to claim 6, characterized in that, The method further includes: The position embedding parameters in the initial statement conversion model are set to trainable values so that the position embedding parameters can be trained using samples.
8. The method according to claim 6, characterized in that, The initial statement transformation model is the Transformer model.
9. A text processing device, characterized in that, The device includes: The first acquisition module is used to acquire the input text to be processed; The selection module selects a reference text from a preset text library that matches the text to be processed and meets preset requirements. The first determining module is used to determine, in the reference text, a target reference sentence that is similar to the sentence to be modified in the text to be processed; The conversion module is used to convert the sentence to be modified according to the target reference sentence based on the target sentence conversion model, so as to obtain the target recommended sentence corresponding to the sentence to be modified; The selection module is further configured to: The target domain to which the text to be processed belongs is determined, and the value tags of each sample text stored in the preset text library are determined. The value tags of the sample texts are determined according to the journal level in which the sample texts are published. The value tags are categorized, and sample texts whose processing results meet the preset requirements are taken as the first type of text. Select sample texts belonging to the target domain as the second type of text; Sample texts that belong to both the first type of text and the second type of text are used as reference texts.
10. The apparatus according to claim 9, characterized in that, The selection module is also used for: Extract keywords from the text to be processed; The domain that the keyword matches is taken as the target domain to which the text to be processed belongs.
11. The apparatus according to claim 9, characterized in that, The device further includes: The splitting module is used to split the sample text to obtain text fragments corresponding to different content attributes; The storage module is used to store the text fragments corresponding to each of the content attributes in the preset text library according to each of the content attributes.
12. The apparatus according to claim 9, characterized in that, The first determining module is further configured to: Identify the sentences to be modified in the text to be processed; Based on the sentence to be modified and a preset text filtering algorithm, the reference text is filtered to determine target reference sentences similar to the sentence to be modified.
13. The apparatus according to claim 12, characterized in that, The first determining module is further configured to: The first filtering algorithm is used to filter the statements contained in the reference text to determine the first reference sentence that is similar to the sentence to be modified; The first reference sentence is filtered using a second filtering algorithm, and the first reference sentence whose similarity meets a preset threshold is used as the target reference sentence.
14. The apparatus according to any one of claims 9 to 13, characterized in that, The device further includes: The second acquisition module is used to acquire multiple sample statements; The translation module is used to translate the sample statement according to a preset translation method to obtain the translated sample statement; The second determining module is used to treat the sample statement and the sample translated statement as a training sample pair; The training module is used to train the initial sentence conversion model using the training samples to obtain the target sentence conversion model.
15. The apparatus according to claim 14, characterized in that, The device further includes: The setting module is used to set the position embedding parameters in the initial statement conversion model to trainable values so that the position embedding parameters can be trained using samples.
16. The apparatus according to claim 14, characterized in that, The initial statement transformation model is the Transformer model.
17. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to execute the instructions to implement the text processing method as described in any one of claims 1 to 8.
18. A non-transitory computer-readable storage medium, wherein when instructions in the storage medium are executed by a processor of a mobile terminal, the mobile terminal is enabled to perform the text processing method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Auxiliary writing method and apparatus based on artificial intelligence
CN106650943A