Character extraction method, text reading method, conversational text generation method, device, equipment and storage medium

Through pre-trained language model and attention mechanism, combined with context attention and mask processing, the problem of the inability to accurately extract the speaker in the prior art is solved, and accurate character recognition of discourse in text is achieved, especially effective extraction in unmanned sentences.

CN114492382BActive Publication Date: 2025-08-12BEIJING CAICHE QUMING TECH +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111467067.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-03
Publication Date
2025-08-12
Estimated Expiration
2041-12-03

AI Technical Summary

Technical Problem

Existing text content character recognition methods cannot accurately extract the attributed characters of sentences with speech content, especially those sentences that do not contain names.

Method used

The pre-trained language model is adopted, combining attention mechanisms and mask matrix, and the speaking characters are inferred through the context of the sentence, and the character extraction is performed using models such as the Transformer architecture, including cleaning and formatting text, setting marks, using context attention and mask to process the attention score matrix, and generating the speaking characters word by word or word.

Benefits of technology

It can accurately identify the speaker corresponding to the discourse in the text, and can accurately extract the speaker in even the unmanned sentences, improving the logic and prediction effect of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114492382B_ABST
    Figure CN114492382B_ABST
Patent Text Reader

Abstract

The present invention relates to a method for extracting characters, a method for reading aloud text, a method for generating conversational text, an apparatus, a device, and a storage medium. The method comprises: receiving a target text, the target text containing one or more sentences; inputting the target text into a pre-trained language model, and using the language model to determine the speakers corresponding to the utterances in the target text; wherein using the language model to determine the speakers corresponding to the utterances in the target text comprises: using the context of sentences in the text input into the language model to infer the speakers corresponding to the utterances in the target text; wherein training the language model comprises: using the context of sentences in the training text input into the language model to infer the speakers corresponding to the utterances in the training text. The method of extracting characters according to the present invention can accurately extract and identify the speakers corresponding to the utterances in the text.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a character extraction method, a text reading method, a conversational text generation method, a device, a device and a storage medium. Background Art

[0002] The statements herein merely provide background information related to the present disclosure and do not necessarily constitute prior art.

[0003] Existing methods for identifying and extracting characters from text can only identify the characters that appear in the text, but cannot confirm who spoke the words. Accurately extracting the person who speaks a sentence from a text is impossible with traditional methods. Summary of the Invention

[0004] The purpose of the present invention is to provide a new character extraction method, device, equipment and storage medium, so as to accurately extract and identify the speaker corresponding to the speech in the text.

[0005] The purpose of the present invention is achieved by the following technical solutions. A character extraction method proposed in the present invention includes the following steps: receiving a target text, wherein the target text contains one or more sentences; inputting the target text into a pre-trained language model, and using the language model to determine the speaker corresponding to the utterance in the target text; wherein using the language model to determine the speaker corresponding to the utterance in the target text includes: using the context of the sentences in the text input into the language model to infer the speaker corresponding to the utterance in the target text; wherein the process of training the language model includes: using the context of the sentences in the training text input into the language model to infer the speaker corresponding to the utterance in the training text.

[0006] The purpose of the present invention can be further achieved by adopting the following technical measures.

[0007] The aforementioned character extraction method, wherein the process of using the language model to determine the speaking character corresponding to the utterance in the target text, and the process of training the language model, specifically includes: using the target text or the training text as the leading text to determine the vocabulary probability of the subsequent text, and determining the corresponding text as the speaking character text corresponding to the utterance in the target text or the training text based on the vocabulary probability.

[0008] The aforementioned character extraction method, wherein the use of the context of sentences in the text input into the language model to infer the speaker corresponding to the utterance in the target text, and the use of the context of sentences in the training text input into the language model to infer the speaker corresponding to the utterance in the training text include: using an attention mechanism to perform contextual attention.

[0009] The aforementioned character extraction method, wherein the use of the attention mechanism for contextual attention specifically includes: setting each word in the input target text or training text to focus on each other, and setting each word in the generated speaking character text to focus on the word before the current word.

[0010] The aforementioned character extraction method, wherein the context of the sentences in the text input to the language model is used to infer the speaker corresponding to the speech in the target text, and the context of the sentences in the training text input to the language model is used to infer the speaker corresponding to the speech in the training text, specifically includes: inputting the text T into the language model to obtain the attention score matrix α of the text T, wherein the elements in the attention score matrix α are attention scores, which are used to represent the degree of attention between the words in the text T; using the mask matrix M to mask the attention score matrix α to obtain the masked attention score matrix α new ; Wherein, the masking process is used to change the values of some elements in the attention score matrix α to change the degree of attention between words; the attention score matrix α after the masking process is used new To infer the speaker of the text.

[0011] The aforementioned character extraction method, wherein the mask matrix M is a single- and double-way combined mask matrix, used to indicate that each word in the input text pays attention to each other, and each word in the generated text pays attention to the word before the current word; wherein the single- and double-way combined mask matrix includes 4 sub-matrices; wherein the first sub-matrix corresponds to the degree of attention between the characters in the input text, and at least some elements in the first sub-matrix are not 0; the second sub-matrix corresponds to the degree of attention between the characters in the generated speaking character text, and the second sub-matrix is a triangular matrix; the third sub-matrix corresponds to the degree of attention of the characters in the input text to the characters in the speaking character text, and the elements in the third sub-matrix are all 0; the fourth sub-matrix corresponds to the degree of attention of the characters in the speaking character text to the characters in the input text, and at least some elements in the fourth sub-matrix are not 0.

[0012] The aforementioned character extraction method, wherein the attention score matrix α after the mask processing is used newTo infer the speaker corresponding to the utterance in the text, including: combining the word vector corresponding to the text T, or the intermediate vector converted from the word vector, with the masked attention score matrix α new Multiply and use the result of multiplication to infer the speaker corresponding to the words in the text.

[0013] The aforementioned character extraction method, wherein the inputting of the target text into a pre-trained language model comprises: cleaning and formatting the target text, and then inputting it into the pre-trained language model; the training process of the language model comprises: cleaning and formatting the training data, and then inputting it into the language model to be trained for training; wherein the formatting comprises: determining whether each sentence in the target text or training text contains speech; setting a mark for the sentence containing speech, and adding the mark to the target text or training text, so that the mark and text are input together into the language model to infer the speaking character.

[0014] The aforementioned character extraction method, wherein the process of using the language model to determine the speaking character corresponding to the discourse in the target text and the process of training the language model include: after using the language model to generate a part of the word units of the speaking character corresponding to the discourse, the currently generated word units and the text currently input into the language model are input into the language model again to generate another part of the word units of the speaking character again until the language model generates an end symbol; and the word units generated before the end symbol are used as the text of the speaking character.

[0015] The aforementioned character extraction method, wherein the training process of the language model includes: a first stage, pre-training the language model; and a second stage, fine-tuning the pre-trained language model; wherein the language model of the pre-training process is a Transformer architecture, a GPT architecture, a Bert architecture, a CNN architecture, an RNN architecture, or an LSTM architecture.

[0016] The objectives of the present invention are also achieved by the following technical solution. A text reading method proposed in this disclosure includes the following steps: obtaining a target text; extracting speakers corresponding to one or more sentences in the target text using the aforementioned character extraction method; and playing the speech corresponding to the target text, wherein playing the speech corresponding to the target text includes assigning a voice corresponding to the extracted speaker to each sentence in the text for reading.

[0017] The objectives of the present invention are also achieved using the following technical solution. A method for generating conversational text, as proposed in this disclosure, comprises the following steps: obtaining a target text; extracting speaking characters corresponding to one or more sentences in the target text using the aforementioned character extraction method; and converting the target text into conversational text based on the extracted speaking characters.

[0018] The purpose of the present invention is also achieved by the following technical solutions. According to the present disclosure, a person extraction device is proposed, comprising: an acquisition module for receiving a target text, wherein the target text contains one or more sentences; a speaker identification module for inputting the target text into a pre-trained language model and using the language model to determine the speaker corresponding to the utterance in the target text; wherein using the language model to determine the speaker corresponding to the utterance in the target text comprises: using the context of sentences in the text input into the language model to infer the speaker corresponding to the utterance in the target text; wherein the process of training the language model comprises: using the context of sentences in the training text input into the language model to infer the speaker corresponding to the utterance in the training text.

[0019] The objectives of the present invention are also achieved by the following technical solutions. A text reading device proposed in accordance with the present disclosure includes: an acquisition module for acquiring a target text; a character extraction module for extracting a speaker corresponding to one or more sentences in the target text according to any of the aforementioned character extraction methods; and a playback module for playing the speech corresponding to the target text, wherein the playback module is specifically configured to assign a voice corresponding to the extracted speaker to each sentence in the target text for reading aloud.

[0020] The objectives of the present invention are also achieved using the following technical solutions. A conversational text generation device, according to the present disclosure, comprises: an acquisition module for acquiring a target text; a character extraction module for extracting, according to any of the aforementioned character extraction methods, characters corresponding to one or more sentences in the target text; and a conversion module for converting the target text into conversational text based on the extracted characters.

[0021] The object of the present invention is also achieved by the following technical solution: A person extraction device proposed in accordance with the present disclosure includes: a memory for storing non-transitory computer-readable instructions; and a processor for running the computer-readable instructions, so that when the processor executes the instructions, any of the aforementioned person extraction methods is implemented.

[0022] The object of the present invention is also achieved by the following technical solution: A computer-readable storage medium proposed in the present disclosure is used to store non-transitory computer-readable instructions, which, when executed by a computer, causes the computer to execute any of the aforementioned character extraction methods.

[0023] The present invention has significant advantages and beneficial effects compared to the prior art. By virtue of the above technical solution, the character extraction method, text reading method, conversational text generation method, device, equipment, and storage medium proposed in the present invention have at least the following advantages and beneficial effects:

[0024] 1. The present invention can accurately extract and identify the speaker corresponding to the speech in the text.

[0025] 2. The present invention uses the context of the current sentence to enable the model to predict the speaker of a sentence without a name.

[0026] 3. The present invention processes text sentences by numbering, so that the model can better generate the speaker at the corresponding mark.

[0027] 4. This invention modifies the attention mechanism to make the model more logical and improve the prediction effect of the model.

[0028] 5. The present invention can directly generate the speakers of all sentences with speaking content in the current text at one time by performing special encoding on the text.

[0029] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the following preferred embodiments are specifically cited and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 1 is a flow chart of a method for extracting characters according to an embodiment of the present invention;

[0031] Figure 2 is a schematic diagram of a method for extracting a person according to another embodiment of the present invention;

[0032] Figure 3 is a flowchart of an improved attention mechanism provided by one embodiment of the present invention;

[0033] Figure 4 is a schematic diagram of a unidirectional attention matrix provided by one embodiment of the present invention;

[0034] Figure 5 is a schematic diagram of a one-way + two-way attention matrix provided by another embodiment of the present invention;

[0035] Figure 6 2 is a schematic diagram of a person extraction device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0036] To further illustrate the technical means and effects adopted by the present invention to achieve the predetermined purpose of the invention, the following, in conjunction with the accompanying drawings and preferred embodiments, describes in detail the specific implementation methods, structures, features and effects of the character extraction method, text reading method, conversational text generation method, device, equipment and storage medium proposed in the present invention.

[0037] It should be noted that, in this document, relational terms such as "first", "second", etc. are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. In addition, the terms "include", "comprise", or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further restrictions, the elements defined by the sentence "include..." do not exclude the presence of other identical elements in the process, method, article, or device comprising the elements.

[0038] Take the following specific text as an example (excerpt from Pride and Prejudice):

[0039] Elizabeth could not go on, though she was inwardly condemning herself for her weakness. It was Darcy who spoke first, with much reluctance: "Mr. Wickham has a very cheerful countenance, and is very good at making friends. But as to his long-lasting friendship, it is doubtful." Elizabeth replied, emphatically, "He has been very unfortunate to lose your friendship, and to be led into a situation which will probably cause him pain for the rest of his life." Darcy made no reply, as if wishing to change the subject. At this moment Sir William Lucas approached them, intending to cross the dance floor to the other side of the room, but, on seeing Mr. Darcy, he stopped, bowed politely, and praised his dancing and his choice of partner. "I am most delighted, my dear sir, to see such a good dancer as you have seldom seen. You are undoubtedly of the first order. Let me add, that your partner is very well matched to you; I hope to have such a pleasure often, especially when some good thing should happen to me, my dear Miss Elizabeth." (He glanced at her sister and Bingley) "What a scene of celebration there will be. I beg Mr. Darcy: ... But I will not interrupt you, sir. You are so absorbed in conversation with this young lady, and you will not be grateful to me if I delay you. Her bright eyes are reproaching me." Darcy almost heard the rest of the words.

[0040] Please note that the "\n" in the above text is the line separator in the original text, which is a separator used to distinguish sentences, paragraphs, etc. in the text.

[0041] In the above text, the text in double quotes is the speech content. However, it is impossible to accurately extract the person to whom the sentence containing the speech content belongs from the above text with traditional methods.

[0042] Here are some text recognition and extraction methods:

[0043] 1. Named Entity Recognition: Named entity recognition is a technique for extracting entities, and names are one type of entity. During named entity recognition, a pre-trained language model such as BERT or GPT is fine-tuned (also known as fine-tuning, which is used to fine-tune the model parameters) using training data to obtain a language model capable of recognizing names. This method can extract "he," "her sister," and "Bingley" from the eighth sentence above: "(He glanced at her sister and Bingley) 'What a lively celebration there will be. I ask Mr. Darcy: ... But I had better not disturb you, sir. You are engrossed in conversation with this young lady. You will not be grateful if I delay you. Look at her bright eyes, they are reproaching me.'" However, it does not know who spoke the words in this sentence. In addition, sentences such as the seventh sentence "'I am so happy, my dear sir, it is rare to see such a good dancer. You are undoubtedly a first-class talent. Let me say one more thing, your beautiful dance partner is really worthy of you. I really hope to have this kind of blessing often, especially when something good happens in the future, my dear Miss Elizabeth.'" are even more difficult to extract.

[0044] 2. Extracting the Subject Through Syntactic Analysis: Using tools such as LTP (a library for syntactic analysis) or HanLP (another library for syntactic analysis), the text is segmented (e.g., using the delimiter \n). Each sentence is then parsed to extract its subject. This method can identify "he" as the subject in sentence 8, thus filtering out "her sister" and "Bingley." However, it cannot extract the subject of a sentence like sentence 7, which lacks a subject; the subject is omitted. Therefore, the speaker cannot be extracted.

[0045] 3. Key Name Extraction Based on Word Segmentation and Vocabulary: Sentences are segmented using delimiters (such as \n). Each sentence is then segmented and part-of-speech identified using tools such as Jieba (a library for word segmentation) or LTP. After word segmentation, the names of individuals are extracted. Based on a pre-built name list, each name is assigned a weight, and names with a weight greater than a certain value are extracted. This method can only extract key names and cannot determine the speaker in sentences such as the seventh sentence.

[0046] 4. Character extraction based on a language model for name recognition and new word discovery: Sentences are segmented using delimiters (such as \n). A pre-trained name extraction model is used to extract a set of candidate characters for each sentence. New word discovery is performed on the specified text to obtain a new word list. Based on the candidate character set and the new word list, character information in the specified text is determined. The obtained characters are then filtered based on word frequency and new word discovery. This method can also extract "he," "her sister," and "Bingley" in the eighth sentence, but it still cannot determine the speaker. It also cannot extract the speaker in the seventh sentence.

[0047] The following summarizes the shortcomings of the aforementioned text recognition and extraction methods when performing speaker recognition and extraction:

[0048] 1. Based on named entity recognition: only the names of people that appear in the current sentence can be extracted.

[0049] 2. Based on syntactic analysis technology: For sentences without a subject, the speaker cannot be extracted.

[0050] 3. Based on word segmentation + vocabulary: Same as 1, only the names of people that appear in the current sentence can be extracted.

[0051] 4. Based on language model + new word discovery: Same as 1, only the names of people that appear in the current sentence can be extracted.

[0052] Figure 1 This is a schematic flow chart of an embodiment of the character extraction method of the present invention. In some embodiments of the present invention, please refer to Figure 1 The character extraction method of the present invention mainly includes the following steps:

[0053] Step S11: Receive a target text containing one or more utterances (also referred to as speech content). Optionally, the target text is a text input by a user of a speaker to be extracted, which may also be referred to as an original text. Note that the utterances contained in the aforementioned text may be a whole sentence or a portion of a sentence.

[0054] In step S12 , the target text is input into a pre-trained language model, and the language model is used to determine the speaker (also called speaker, speaker, or speaker) corresponding to the utterance in the target text.

[0055] The language model, also known as a text generation model, is used to infer (also known as predict) the vocabulary probability of the subsequent text using the preceding text, and determine the subsequent text based on the vocabulary probability. In some optional embodiments of the present invention, the process of the aforementioned step S12 and the process of training the language model may specifically include: using the target text or the training text as the preceding text to determine the vocabulary probability of the subsequent text, and determining the corresponding text based on the vocabulary probability as the speaker text corresponding to the utterance in the target text or the training text.

[0056] It should be noted that the present invention does not limit the specific type of the language model selected, for example, it can be a BERT language model, a GPT language model, etc.

[0057] Determining the speaker corresponding to an utterance using the language model in step S12 includes inferring (also known as predicting) the speaker corresponding to the utterance in the target text using the context of the sentence in the text input to the language model (i.e., preceding text, following text, adjacent sentences, adjacent paragraphs, etc.). Training the language model in step S12 includes inferring the speaker corresponding to the utterance in the training text using the context of the sentence in the training text input to the language model (i.e., preceding text, following text, adjacent sentences, adjacent paragraphs, etc.).

[0058] Optionally, the processing of the language model can be set to generate a complete result at one time. Or, optionally, the processing of the language model can also be set to include multiple loops, each loop only generates one word, and the subsequent text is determined word by word or word by word through multiple loops. In some optional embodiments of the present invention, the process of the aforementioned step S12 and the process of training the language model can specifically include: after using the language model to generate a part of the word unit of the speaker corresponding to the discourse, the currently generated word unit and the text currently input into the language model are input into the language model again to generate another part of the word unit of the speaker again, until the language model generates an end symbol; the word unit generated before the end symbol is used as the text of the speaker.

[0059] It should be noted that the text input to the language model includes at least the target text; and in the example of using the language model to generate the speaker word by word, the text input to the language model in the current round includes: the target text and the speaker text that has been generated.

[0060] The character extraction method proposed in the present invention uses context information as a reference for predicting the current sentence, that is, adds the previous or next context of the sentence to be predicted, fully utilizes the context characteristics of the sentence, can accurately extract and identify the speaker from the text, and can determine the speaker of a sentence with words that does not contain a person's name.

[0061] Figure 2 This is a schematic diagram of another embodiment of the character extraction method of the present invention. The method proposed in this invention primarily utilizes a language model. As an optional specific example, the language model employed can be a language model based on the Transformer architecture. This Transformer architecture is responsible for generating speaking characters based on input text. The Transformer architecture is selected because it facilitates reference to previous and subsequent text.

[0062] The method proposed in the present invention automatically generates the corresponding speaker in each sentence based on the input text. It should be noted that there is no limit on the length of the input text, that is, the number of words in the input text is not limited.

[0063] In some embodiments of the present invention, the aforementioned step S12 of inputting the target text into the pre-trained language model specifically includes: cleaning and formatting the target text, and then inputting it into the pre-trained language model. The training process of the language model includes: cleaning and formatting the training text, and then inputting it into the language model to be trained for training.

[0064] Optionally, the aforementioned text cleaning includes but is not limited to: removing blank characters, abnormal characters, and normalizing characters (full-width or half-width).

[0065] Optionally, the aforementioned formatting of text may include: segmenting the input text (ie, the aforementioned target text or training text) into sentences to obtain one or more sentences in the text.

[0066] Optionally, the aforementioned formatted text may also include: determining whether each sentence in the target text or training text contains utterances; setting a mark for sentences containing utterances, and adding the mark to the text to be input into the language model, so that the mark and the text are input into the language model together to infer the speaker.

[0067] As a specific example, the aforementioned determination of whether each sentence in the text contains speech specifically includes: identifying whether the sentences in the text include target punctuation marks, and determining that the sentences with target punctuation marks contain speech. Optionally, multiple target punctuation marks can be set for multiple languages, or corresponding target punctuation marks can be set according to the language of the text. For example, the target punctuation marks for simplified Chinese are pre-set to double quotes and single quotes, and the target punctuation marks for traditional Chinese are pre-set to angle brackets; if a sentence in the text is identified to include a pair of double quotes or a pair of single quotes, then the sentence is determined to contain speech.

[0068] Optionally, in the aforementioned formatted text, after sentence segmentation, a tag may be set for each sentence in the text to be input into the language model.

[0069] It should be noted that it is not necessary to determine whether each sentence in the text contains an utterance, thereby inferring the speaker of each sentence in the text and assuming that sentences with empty output text do not contain an utterance.

[0070] As an optional specific example of the training data format, or the input target text and the output text format obtained by using the exemplary method of the present invention, the text of the speaker to be extracted and the generated text (speaker text) are as follows:

[0071] Elizabeth could not go on, but inwardly she blamed herself for her weakness. It was Darcy who spoke first, with great reluctance: "Mr. Wickham has a very cheerful countenance, and is very good at making friends. But as to his long-lasting friendship, it is doubtful." Elizabeth replied, emphasizing, "He has been very unfortunate to lose your friendship, and to be led into a situation which will probably cause him pain for the rest of his life." Darcy made no reply, as if wishing to change the subject. At this moment Sir William Lucas approached them, and was about to cross the dance-floor to the other side of the room; but, on seeing Mr. Darcy, he stopped, bowed politely, and praised his dancing and his choice of partner. \n(g)"I am so delighted, my dear sir, that you dance so well, it is rare to see such a good dancer. You are undoubtedly a first-class talent. Let me say that your beautiful partner is really worthy of you. I really hope to have this kind of blessing often, especially when some good thing happens one day in the future, my dear Miss Elizabeth." (h) (He glanced at her sister and Bingley) "What a lively celebration there will be then. I ask Mr. Darcy: ... But I had better not disturb you, sir. You are so engrossed in conversation with this lady, and you will not be grateful to me if I delay you. Look at her bright eyes, they are also reproaching me."\nDarcy almost heard the second half of the words.

[0072] <s>c Darcy d Elizabeth g William Lucas h William Lucas <t>

[0073] Among them, the above-mentioned " <s>c Darcy d Elizabeth g William Lucas h William Lucas <t>" is the speaking character text generated by the model in this example. The symbol " <s>" is the start position identifier (or start symbol) of the speaker text, indicating that the content after the start position identifier is the speaker text generated by the language model. Optionally, a start position identifier can be preset at the end of the input text. <s>In this example, c, d, g, and h are output by the model one by one. <t>" is the end position identifier (or end symbol) of the speaker text. After the model infers the end position identifier, it is determined that the speaker generation is complete.

[0074] In some embodiments where the language model determines the speaker corresponding to an utterance in the input text on a character-by-character or word-by-word basis, the language model processes the utterance once for each character generated until the end character is generated. <t>Post-language model stop processing.

[0075] As another optional specific example, the input text and the output text obtained using the exemplary method of the present invention are as follows:

[0076] Input: (a) Elizabeth could not continue, but inwardly she blamed herself for her weakness. (b) At last Darcy spoke first, with great reluctance:\n(c) "Mr. Wickham has a very cheerful countenance, and is very good at making friends. But as to his long-lasting friendship, it is doubtful."\n(d) Elizabeth replied emphatically: "He has been very unfortunate to lose your friendship, and to be in such a state of embarrassment, that he may suffer it for the rest of his life."\n(e) Darcy did not answer, as if he wished to change the subject. (f) At this moment Sir William Lucas approached them, and was about to cross the dance floor to the other side of the room, but at the sight of Mr. Darcy he stopped, bowed politely, and praised his dancing and his choice of partner. \n(g) "I am so delighted, my dear sir, you dance so well, it is rare to see such a good dancer. You are undoubtedly a first-class talent. Let me say that your beautiful partner is very worthy of you. I really hope to have such a pleasure often, especially when some good thing happens one day in the future, my dear Miss Elizabeth." (h) (He glanced at her sister and Bingley) "What a lively celebration there will be then. I ask Mr. Darcy: ... But I had better not disturb you, sir. You are so engrossed in conversation with this lady, and you will not be grateful to me if I delay you. Look at her bright eyes, they are also reproaching me." \n(i) Darcy almost heard the second half of the words.

[0077] Output: c Darcy d Elizabeth g William Lucas h William Lucas.

[0078] Note that the "(a), (b), (c), (d), (e), (f), (g), (h), and (i)" in the preceding text are markers added during the text formatting step; they are not present in the original text. The "\n" in the preceding text is the line separator, used to separate sentences, paragraphs, and other items in the original text.

[0079] Please refer to the above example. In some optional embodiments, in the text formatting step, the tags set for sentences with spoken content may be labels such as c, d, g, and h in the aforementioned example. Optionally, the aforementioned formatted text may include: setting different tags for different sentences in the text to be input into the language model. It should be noted that in this example, although different sentences in the same paragraph of input text use different tags, sentences between different paragraphs can use the same tag. It should be noted that the present invention does not limit the position where the tag is set in the text. For example, it can be added to the beginning of the sentence (before the sentence) similar to the aforementioned example, or it can be added to the middle of the sentence or the end of the sentence. Optionally, tags can be set only for sentences with spoken content in the text, or tags can be set for each sentence in the text.

[0080] The example method of the present invention marks the sentences in the text accordingly and obtains the speakers at the marked locations, which allows the model to more easily "pay attention" to the sentences corresponding to c, d, g, and h, thereby better extracting the speakers.

[0081] Optionally, the aforementioned formatted text may also include: word segmentation of the text. For example, Chinese text may be segmented by each character and English text may be segmented by each word to obtain a list of text tokens. Tokens represent the units after text segmentation and may be called word units, word symbols, or word elements. Taking Chinese as an example, each character is a word, which corresponds to a token after word segmentation. Based on the token list, it is then converted into the corresponding identifier (or id) in the vocabulary to obtain the token id (the token is based on the index number in the vocabulary).

[0082] Note that the aforementioned vocabulary table can also be called a character table. Each row in the table contains a character, word, or symbol, and the row number is the index number of the character, word, or character. Taking Chinese as an example, all Chinese characters and symbols (generally all commonly used characters and symbols) form a Chinese vocabulary table. Each row in the Chinese vocabulary table contains a Chinese character or symbol, and the row number of the vocabulary table is the index number of the Chinese character or symbol.

[0083] Note that this specification does not distinguish between words, phrases, characters, and characters in the text of training data and user input data. In fact, a single character can also be considered a word, and both words and characters can be processed accordingly using the methods or apparatuses illustrated in the present invention. Therefore, the words and characters in the vocabulary and character tables can be collectively referred to as word units.

[0084] In some embodiments of the present invention, the method proposed by the present invention can be trained based on supervised data during the process of training the language model, by marking the text accordingly, and then obtaining the speaker with the marked parts.

[0085] As an example of language model training based on supervised data, the process of training a language model may include: receiving training data, wherein the training data includes training text, the training text includes one or more sentences, and the training data also includes the real speaker of each sentence in the training text as a label; inputting the training text into the language model to be trained to obtain an inferred speaker corresponding to the utterances in the training text, and adjusting the language model to be trained by comparing the inferred speaker with the real speaker. The aforementioned step of inputting the training text into the language model to be trained to obtain an inferred speaker corresponding to the utterances in the training text includes: using the context of the sentences in the training text input into the language model to infer the inferred speaker corresponding to the utterances in the training text.

[0086] In some embodiments of the present invention, the training corpus of the language model of the present invention includes but is not limited to novel texts. In fact, it can be corpus in any field.

[0087] In some embodiments of the present invention, the aforementioned inference of the speaker corresponding to the utterance in the target text by using the context of sentences in the text input into the language model, and the aforementioned inference of the speaker corresponding to the utterance in the training text by using the context of sentences in the training text input into the language model, may include: using an attention mechanism to perform contextual attention.

[0088] As an optional example, a unidirectional attention mechanism may be used. Specifically, the aforementioned use of the attention mechanism for contextual attention may include: setting each word in the input target text or training text, and each word in the generated speaking character text, to focus on the word before the current word.

[0089] As another optional example, a unidirectional and bidirectional attention mechanism may be used. Specifically, the aforementioned use of the attention mechanism for contextual attention may include: setting each word in the input target text or training text to focus on each other, and setting each word in the generated speaking character text to focus on the word before the current word.

[0090] Note that text is ordered. Both the input text and the generated speaker text are ordered sequences of word units. Therefore, the "word preceding the current word" refers to the word unit preceding the current word unit in this ordered sequence of text.

[0091] In addition, it should be noted that since the words in the speaker's text are all inferred (for example, word by word) from the input text (i.e., the aforementioned target text or training text) as the leading text, after the aforementioned "setting each word in the generated speaker's text to focus on the word before the current word", each word in the speaker's text focuses on all the words in the input text and focuses on the word before the current word in the speaker's text.

[0092] In some optional embodiments of the present invention, an improved attention mechanism may be used. For details, see Figure 3 The aforementioned step S12 of using the trained language model to determine the speaker corresponding to the utterance in the target text, and using the language model to be trained to infer the speaker corresponding to the utterance in the training text during the model training process, may include the following steps:

[0093] Step S21: Input the text T into the language model to obtain the attention score matrix α of the text T. The elements in the attention score matrix α are attention scores, which are used to represent the degree of attention between the words in the text T. Optionally, the elements a in the attention score matrix α are ij is the attention score of the i-th word in text T for the j-th word in text T, where i and j are the number of rows and columns of the element in the attention score matrix α.

[0094] Step S22: Use the mask matrix (also called mask matrix) M to mask the attention score matrix α to obtain the masked attention score matrix α new Among them, the masking process performed using the mask matrix is used to change the values of some elements in the attention score matrix α, that is, to change the degree of attention.

[0095] Optionally, the mask matrix includes multiple zero elements, which are used to change the degree of attention of the corresponding position in the attention score matrix α to no attention. Optionally, the style type (shape) of the mask matrix is pre-set, for example, the mask matrix of the unidirectional attention matrix is a triangular matrix. Optionally, the order (number of rows and columns) of the mask matrix can be related to the length of the text T, or to the total length of the text T and the output result. It should be noted that when generating the speaker word by word, the order of the mask matrix can be related to the length of the text input to the language model in the current round, that is, related to the sum of the lengths of the original text and the speaker text that has been generated.

[0096] Step S23, using the attention score matrix α after mask processing new To infer the speaker of the text.

[0097] By using the method proposed in the present invention, the attention score matrix can be controlled and adjusted by performing mask processing on the attention score matrix, thereby obtaining the speaking person more accurately.

[0098] In some optional embodiments of the present invention, the attention score matrix (e.g., the attention score matrix α after masking) can be new ) is applied to the vector obtained from the text to obtain a probability distribution matrix, and the probability distribution matrix is used to infer the speaker corresponding to the speech in the text. Specifically, the word vector corresponding to the text T, or the intermediate vector converted from the word vector, can be combined with the attention score matrix α after masking. new Multiply them, use the result of the multiplication as a probability distribution matrix, and use the probability distribution matrix to infer the speaker corresponding to the utterance in the text. Therefore, as a specific example, the aforementioned step S12 of using the trained language model to determine the speaker corresponding to the utterance in the target text, and inferring the speaker corresponding to the utterance in the training text using the language model to be trained during the model training process, can include the following steps:

[0099] Step S31: Convert the text T into a word vector and input the word vector of the text T into the language model to obtain a first vector V w .

[0100] Step S32: for the first vector V w Encoding (maybe called ψ encoding) to obtain the second vector (also called intermediate vector) V m , and the attention score matrix α of the text T.

[0101] It should be noted that the first vector and the second vector mentioned above are intermediate vectors in the model inference process.

[0102] Note that two models can be trained separately to convert text (or its word vector) into an intermediate vector and to convert text (or its word vector) into an attention score matrix, or one model can be trained to convert text (or its word vector) into both an intermediate vector and an attention score matrix.

[0103] Step S33: Use the mask matrix M to perform mask processing on the attention score matrix α to obtain the masked attention score matrix α new Optionally, the mask matrix includes multiple zero elements, which are used to change the attention level of the corresponding position in the attention score matrix α to no attention.

[0104] Step S34: The masked attention score matrix α new With the second vector V m Multiply and perform softmax processing to obtain the probability distribution matrix P (also called the attention weight distribution matrix).

[0105] Step S35: compare the probability distribution matrix P with the input vector V w Multiply them together to get the encoding V of the text T to get the label of the text T.

[0106] It should be noted that the present invention has no effect on the structure of the language model used in the aforementioned step S31, the first vector V w , the encoding performed in the aforementioned step S32, and the obtained second vector V m In fact, the present invention can obtain the speaking person more accurately by masking the attention score matrix and using the masked attention score matrix for model inference.

[0107] As a specific example of implementing contextual attention with an improved attention mechanism based on the Transformer model, take a text T of length L and a word vector dimension of H w For example, it should be noted that in the example where the language model generates the speaker text word by word, the text T here includes the original text and the generated speaker text.

[0108] 1. Text T is input into the Transformer model;

[0109] Get the vector representation before attention:

[0110] 2. V w After ψ encoding, we get: intermediate vector V m , and the attention score matrix α of the text T:

[0111] V m ,α=ψ(V w )in

[0112] In matrix α, the i-th row can be used to represent the attention score of the i-th character in text T with respect to each character in text T. Specifically, the element in the i-th row and j-th column of matrix α represents the attention score of the i-th character in text T with respect to the j-th character in text T. Optionally, a higher score indicates greater attention. Note that the i-th column can also be used to represent the attention score of the i-th character in text T with respect to each character in text T.

[0113] Please note that V w The ψ encoding is performed to obtain the intermediate vector V m And the attention score matrix α, in fact, is V w A series of matrix dot multiplications are performed, equivalent to V w Through the matrix A, we get α, and V w Get V through matrix B m The ψ code, matrix A, and matrix B can be obtained through deep learning.

[0114] 3. After the artificial attention score mask matrix M (also called mask matrix), where M∈R L×L Among them, R L×L Represents a matrix with L rows and L columns, where the value range of the elements in the matrix is real number R. Optionally, the values of the elements in the mask matrix are 0 or 1.

[0115] 4. Multiply the mask by the attention score matrix to get the new attention score matrix:

[0116] α new =M*α α new ∈R L×L (2)

[0117] Please note that the dot product mentioned above refers to the multiplication of the elements at corresponding positions of the two matrices. For example, the element in the mth row and nth column of the dot product matrix is the result of multiplying the elements in the mth row and nth column of the original two matrices. new The process is equivalent to changing the position score of the original attention score matrix α that takes 0 in the mask to 0, and the position score that takes 1 in the mask remains unchanged.

[0118] In the attention score matrix after mask processing, the degree of attention each word pays to other words changes, which directly affects the subsequent output vector V. By controlling the mask matrix, attention can be controlled.

[0119] 5. Then the attention score matrix α after mask processing new With the middle vector V m Multiply and perform softmax processing to obtain the probability distribution matrix P:

[0120] P=Softmax(α new *V m )P∈R L×L (3)

[0121] 6. Combine the probability distribution matrix with the input vector V w Multiply them to get the encoding V of the text T:

[0122]

[0123] The output vector V is processed by the function argmax (argmax is a function that comes with the open source machine learning framework torch) to obtain the index number (serial number) of the largest element among all elements in V. The word corresponding to the index number of the largest element is used as the generated word:

[0124] label=argmax(V).

[0125] It should be noted that in the example where the language model generates the text of the speaking person character by character or word by word, after the language model generates a character, the character generated in the current round is input into the language model together with the input text of the current round to generate the text of the speaking person for the next round (in fact, the next word).

[0126] By using the method proposed in the present invention, by utilizing the attention mechanism to realize context attention for encoding, the speakers corresponding to all sentences in the text can be generated at one time when the model is output.

[0127] Figure 4 It is a one-way attention matrix (one-way attention score matrix) used in a specific example, where the gray part is not 0 and the white part is 0. Figure 5 It is a single and bidirectional combined attention matrix (also called single + bidirectional attention matrix, single + bidirectional attention score matrix, single + bidirectional attention score matrix, single and bidirectional mixed attention matrix) used in another specific example, in which the gray part of the attention is not 0 and the white part is 0.

[0128] In some embodiments of the present invention, attention can adopt a unidirectional attention mechanism, such as Figure 4 As shown, in the process of masking the attention score matrix α using the mask matrix M in the aforementioned step S22, the mask matrix M used can be a mask matrix of unidirectional attention, so as to realize the attention score matrix α after masking used by contextual attention new It is a unidirectional attention matrix, indicating that in the sequence of input text and generated text, each word unit only pays attention to the preceding word unit before itself.

[0129] In some embodiments of the present invention, attention can use a combined unidirectional and bidirectional attention mechanism (also known as a unidirectional + bidirectional attention hybrid mechanism), using bidirectional attention for the input text and unidirectional attention for the generated speaker text. That is, each token of the input text can pay attention to each other, but for the generated speaker text, only the previous tokens are paid attention. The token mentioned in this article refers to: the unit after the text segmentation. Please refer to Figure 5 In the process of masking the attention score matrix α using the mask matrix M in the aforementioned step S22, the mask matrix M used can be a single and double combined mask matrix, so as to realize the attention score matrix α after masking used for contextual attention. new is the attention matrix of the single and bidirectional combination, and the attention score matrix α after the mask processing new In the example, for each word in the input text, attention is paid to all words in the text, and for each word in the generated speaker text, attention is paid only to the previous word. Specifically, bidirectional attention is used for the input text, while unidirectional attention is used for the generated speaker text. That is, each word in the input text (in practice, the token corresponding to the word is used, or the word is used in token form, rather than in text form) can pay attention to each other, while for the generated speaker text, only all previous words are paid attention.

[0130] As a specific example of a combined unidirectional and bidirectional attention mechanism, the mask matrix M is a combined unidirectional and bidirectional mask matrix, used to indicate that each character in the input text pays attention to each other, and that each character in the generated text pays attention to the character before the current character. Optionally, the combined unidirectional and bidirectional mask matrix may include four submatrices: a first submatrix corresponding to the degree of attention between characters in the input text, at least some of the elements in the first submatrix being non-zero (optionally, all elements in the first submatrix being 1); a second submatrix corresponding to the degree of attention between characters in the generated speaker's text, the second submatrix being a triangular matrix; a third submatrix corresponding to the degree of attention of characters in the input text to characters in the speaker's text, the elements in the third submatrix being all zero (i.e., a zero matrix); and a fourth submatrix corresponding to the degree of attention of characters in the speaker's text to characters in the input text, at least some of the elements in the fourth submatrix being non-zero (optionally, all elements in the fourth submatrix being 1).

[0131] General generation tasks are based on unidirectional attention mechanisms, such as the GPT series. However, in some embodiments of the present invention, a unidirectional and bidirectional attention mechanism is used. Because the user's input text can pay attention to each other, bidirectional attention is used for the input text, while the generated text is generated word by word, so only unidirectional attention can be used. In this way, the unidirectional and bidirectional attention mechanism of the present invention is formed. In some optional embodiments of the present invention, fine-tuning is performed on the pre-trained language model based on the Transformer architecture on the unidirectional and bidirectional attention mechanism architecture.

[0132] By using the method proposed in the present invention, the speaking person can be obtained more accurately by utilizing a single and bidirectional combined attention mechanism.

[0133] As a specific example of controlling attention by controlling a mask matrix:

[0134] Suppose the attention score matrix for "Beijing Zhongguancun" is S:

[0135] [[0.1898, 0.1937, 0.2055, 0.2017, 0.2092],

[0136] [0.1874, 0.1360, 0.2316, 0.1658, 0.2793],

[0137] [0.1717, 0.1788, 0.2620, 0.1769, 0.2106],

[0138] [0.2421, 0.2062, 0.1736, 0.1482, 0.2299],

[0139] [0.1762, 0.1389, 0.2210, 0.1778, 0.2860]]:

[0140] The meaning of this matrix is:

[0141] The first row represents the attention scores of the character "North" to each character in "Beijing Zhongguancun". The higher the score, the more attention is represented. The second row represents the attention scores of the character "Jing" to each character in "Beijing Zhongguancun".

[0142]

[0143] The i-th row represents the attention scores of the "i-th" character to each character in "Beijing Zhongguancun".

[0144] Then, if there is a 0, 1 matrix at this time and it is directly multiplied by the score matrix S, for example:

[0145] [[0, 0, 0, 1, 1]

[0146] [0, 0, 0, 1, 1]

[0147] [0, 0, 0, 1, 1]

[0148] [0, 0, 0, 0, 1]

[0149] [0, 0, 0, 0, 0] * S

[0150] Then a new score matrix is obtained:

[0151] [[0.0000, 0.0000, 0.0000, 0.2017, 0.2092]

[0152] [0.0000, 0.0000, 0.0000, 0.1658, 0.2793]

[0153] [0.0000, 0.0000, 0.0000, 0.1769, 0.2106]

[0154] [0.0000, 0.0000, 0.0000, 0.0000, 0.2299]

[0155] [0.0000, 0.0000, 0.0000, 0.0000, 0.0000]

[0156] It can be found that the degree of attention each word pays to other words has changed, which directly affects the subsequent output vector V.

[0157] In some embodiments of the present invention, the language model training process includes: a first stage of pre-training the language model; and a second stage of fine-tuning the pre-trained language model. Optionally, the aforementioned attention mechanism can be used to perform contextual attention during the fine-tuning stage.

[0158] Among them, the language model of the pre-training process can be a Transformer architecture (a neural network structure), a GPT architecture (Generative Pre-Training), a Bert architecture (Bidirectional Encoder Representations from Transformers), a CNN (Convolutional Neural Network) architecture, an RNN (Recurrent Neural Network) architecture, or an LSTM (Long Short-Term Memory Neural Network) architecture.

[0159] In some embodiments of the present invention, after step S12, the character extraction method of the present invention further includes adjusting the original target text, specifically by adding information about the identified speaker to the original target text. Furthermore, the target text may be modified to a predetermined format, such as: "A certain speaker said a certain sentence."

[0160] The character extraction method proposed in the present invention has a wide range of application scenarios, including but not limited to conversational novels, audio books, etc.

[0161] An embodiment of the present invention also provides a method for reading aloud a text, which primarily includes the following steps: obtaining a target text to be read aloud; extracting a speaker corresponding to one or more sentences in the text to be read aloud using any of the aforementioned character extraction methods; and playing the speech corresponding to the target text, wherein, when reading the text aloud, the speech in the target text is assigned a voice corresponding to the extracted speaker for reading aloud. Using the text reading aloud method of the present invention, when a reading application converts a text into an audiobook, the character in the book can be extracted, and when the character's turn to speak is played, the pre-set voice of the character is used for reading aloud.

[0162] An embodiment of the present invention also provides a method for generating a conversational text, characterized in that the method mainly includes the following steps: obtaining a target text; using any one of the embodiments of the aforementioned character extraction method to extract the speaking characters corresponding to one or more sentences in the target text; and converting the target text into a conversational text based on the extracted speaking characters, so as to present the original text to the reader in a conversational form.

[0163] An embodiment of the present invention further provides a person extraction device, which mainly includes: an acquisition module and a speaking person recognition module.

[0164] The acquisition module is used to receive a target text, wherein the target text includes one or more sentences.

[0165] The speaker identification module is configured to input a target text into a pre-trained language model and use the language model to determine the speaker corresponding to an utterance in the target text. The speaker identification module uses the language model to determine the speaker corresponding to an utterance in the target text, specifically by inferring the speaker corresponding to the utterance in the target text using the context of sentences in the text input to the language model. The language model training process includes inferring the speaker corresponding to the utterance in the training text using the context of sentences in the training text input to the language model.

[0166] In addition, the various character extraction devices shown in the embodiments of the present invention include modules and units corresponding to the methods described in the aforementioned embodiments, and their detailed descriptions and technical effects can be referred to the corresponding descriptions in the aforementioned embodiments, which will not be repeated here.

[0167] An embodiment of the present invention further provides a text reading device, which includes modules or units corresponding to executing the aforementioned text reading method.

[0168] An embodiment of the present invention further provides a conversational text generation device, which is used to execute the modules or units corresponding to the aforementioned conversational text generation.

[0169] Figure 6 FIG. 1 is a schematic block diagram illustrating a person extraction device according to an embodiment of the present invention. Figure 6 As shown, the person extraction device 100 according to an embodiment of the present disclosure includes a memory 101 and a processor 102 .

[0170] The memory 101 is used to store non-transitory computer-readable instructions. Specifically, the memory 101 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), a hard disk, flash memory, etc.

[0171] The processor 102 may be a central processing unit (CPU) or other processing unit with data processing capabilities and / or instruction execution capabilities, and may control other components in the person extraction device 100 to perform desired functions. In one embodiment of the present disclosure, the processor 102 is configured to execute the computer-readable instructions stored in the memory 101, causing the person extraction device 100 to perform all or part of the steps of the person extraction method described in the various embodiments of the present disclosure.

[0172] For detailed description and technical effects of this embodiment, please refer to the corresponding descriptions in the aforementioned embodiments, which will not be repeated here.

[0173] An embodiment of the present invention further provides a computer storage medium storing computer instructions. When the computer instructions are executed on a device, the device executes the above-mentioned related method steps to implement the person extraction method in the above-mentioned embodiment.

[0174] An embodiment of the present invention further provides a computer program product. When the computer program product is run on a computer, the computer is caused to execute the above-mentioned related steps to implement the person extraction method in the above-mentioned embodiment.

[0175] In addition, an embodiment of the present invention also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory to enable the chip to execute the character extraction method in the above-mentioned method embodiments.

[0176] Among them, the device, computer storage medium, computer program product or chip provided by the present invention are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0177] The above description is merely a preferred embodiment of the present invention and does not constitute any form of limitation to the present invention. Although the present invention has been disclosed as a preferred embodiment as above, it is not intended to limit the present invention. Any technician familiar with the present profession can make some changes or modifications to equivalent embodiments of equivalent changes using the technical contents disclosed above without departing from the scope of the technical solution of the present invention. However, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention are still within the scope of the technical solution of the present invention.< / t> < / t> < / s> < / s> < / t> < / s> < / t> < / s>

Claims

1. A method for extracting a person, characterized in that: The method comprises the following steps: receiving a target text, wherein the target text includes one or more sentences; Inputting the target text into a pre-trained language model, and using the language model to determine the speaker corresponding to the utterance in the target text; wherein determining the speaker corresponding to the utterance in the target text using the language model comprises: inferring the speaker corresponding to the utterance in the target text using the context of sentences in the text input to the language model; wherein the process of training the language model comprises: inferring the speaker corresponding to the utterance in the training text using the context of sentences in the training text input to the language model; The inference of the speaker corresponding to the utterance in the target text by using the context of the sentence in the text input to the language model, and the inference of the speaker corresponding to the utterance in the training text by using the context of the sentence in the training text input to the language model include using an attention mechanism to perform contextual attention, specifically including: Input the text T into the language model to obtain an attention score matrix α of the text T, wherein the elements in the attention score matrix α are attention scores, which are used to represent the degree of attention between words in the text T; Use the mask matrix M to mask the attention score matrix α to obtain the masked attention score matrix α new ; Wherein, the masking process is used to change the values of some elements in the attention score matrix α to change the degree of attention between words; The attention score matrix α after mask processing is used new To infer the speaker of the text; The mask matrix M is a unidirectional and bidirectional combination mask matrix, which is used to indicate that each word in the input text pays attention to each other, and each word in the generated text pays attention to the word before the current word; The unidirectional and bidirectional combined mask matrix includes four sub-matrices; the first sub-matrix corresponds to the degree of attention between the characters in the input text, and at least some elements in the first sub-matrix are not 0; the second sub-matrix corresponds to the degree of attention between the characters in the generated speaking person text, and the second sub-matrix is a triangular matrix; the third sub-matrix corresponds to the degree of attention of the characters in the input text to the characters in the speaking person text, and all elements in the third sub-matrix are 0; the fourth sub-matrix corresponds to the degree of attention of the characters in the speaking person text to the characters in the input text, and at least some elements in the fourth sub-matrix are not 0.

2. The method for extracting a person according to claim 1, wherein: The process of using the language model to determine the speaker corresponding to the utterance in the target text and training the language model specifically includes: The target text or the training text is used as a leading text to determine a vocabulary probability of a subsequent text, and a corresponding text is determined according to the vocabulary probability as a speaker text corresponding to an utterance in the target text or the training text.

3. The person extraction method according to claim 1, wherein: The use of the attention mechanism to perform contextual attention specifically includes: setting each word in the input target text or training text to pay attention to each other, and setting each word in the generated speaking character text to pay attention to the word before the current word.

4. The method for extracting a person according to claim 1, wherein: The attention score matrix α after the mask processing new To infer the speaker of the text, including: The word vector corresponding to the text T, or the intermediate vector converted from the word vector, is compared with the attention score matrix α after masking. new Multiply and use the result of multiplication to infer the speaker corresponding to the words in the text.

5. The method for extracting a person according to any one of claims 1 to 4, wherein: The inputting the target text into the pre-trained language model includes: cleaning and formatting the target text, and then inputting the target text into the pre-trained language model; The training process of the language model includes: cleaning and formatting the training data, and then inputting the training data into the language model to be trained for training; The formatting includes: determining whether each sentence in the target text or training text contains speech; setting a mark for the sentence containing speech, and adding the mark to the target text or training text, so that the mark and text are input into the language model together to infer the speaker.

6. The method for extracting a person according to any one of claims 1 to 4, wherein: The process of using the language model to determine the speaker corresponding to the utterance in the target text and training the language model includes: After using the language model to generate a part of the word units of the speaker corresponding to the discourse, the currently generated word units are input into the language model again together with the text currently input into the language model to generate another part of the word units of the speaker again until the language model generates an end symbol; the word units generated before the end symbol are used as the text of the speaker.

7. The method for extracting a person according to any one of claims 1 to 4, wherein: The language model training process includes: a first stage, pre-training the language model; and a second stage, fine-tuning the pre-trained language model; Among them, the language model of the pre-training process is Transformer architecture, GPT architecture, Bert architecture, CNN architecture, RNN architecture, or LSTM architecture.

8. A method for reading a text aloud, characterized in that: The method comprises the following steps: Get the target text; Extracting the speaking characters corresponding to one or more sentences in the target text according to the character extraction method according to any one of claims 1 to 7; The speech corresponding to the target text is played, wherein the speech in the target text is assigned a voice corresponding to the extracted speaking character for reading.

9. A method for generating conversational text, characterized in that: The method comprises the following steps: Get the target text; Extracting the speaking characters corresponding to one or more sentences in the target text according to the character extraction method according to any one of claims 1 to 7; The target text is converted into a conversational text according to the extracted speaking character.

10. A person extraction device, configured to implement the person extraction method according to any one of claims 1 to 7.

11. A text reading device, used to implement the text reading method according to claim 8.

12. A conversational text generation device, used to implement the conversational text generation method according to claim 9.

13. A person extraction device comprising: a memory for storing non-transitory computer-readable instructions; as well as A processor is used to run the computer-readable instructions, so that when the computer-readable instructions are executed by the processor, the person extraction method according to any one of claims 1 to 7 is implemented.

14. A computer storage medium, characterized in that The method comprises computer instructions, which, when executed on a device, enable the device to execute the person extraction method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Recognition method and device, device for recognition and speech synthesis method

    CN113409766A