Text emotion recognition method, device and electronic equipment

CN116011440BActive Publication Date: 2026-09-25阳光保险集团股份有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211513326.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-29
Publication Date
2026-09-25
Estimated Expiration
2042-11-29

AI Technical Summary

Technical Problem

所以,当处理不同叙述方式的文本时,上述方法均具有局限性,导致情绪识别结果不准确或是效率低下

Benefits of technology

[0013]本发明提供了一种文本情绪识别方法、装置及电子设备,该方法包括:获取训练文本、验证文本以及测试文本;分别将上述训练文本、上述验证文本以及上述测试文本从第一个字符开始按照预设的第一字符长度向后截取,得到多个第一字符串数据;分别将上述训练文本、上述验证文本以及上述测试文本从最后一个字符开始按照预设的第二字符长度向前截取,得到多个第二字符串数据;将上述多个第一字符串数据与上述多个第一字符串数据对应的上述多个第二字符串进行拼接,得到待处理数据集;根据上述待处理数据集训练、验证并测试预设的初始模型,直至满足预设的结束条件,得到训练好的第一中间模型以及上述第一中间模型对应的第一准确率及第一损失值;搜索步骤1:按照下述公式调整上述第一字符长度和上述第二字符长度:Si+1=Si+step;ei+1=total-Si+1;其中,Si+1表示第i次调整后的上述第一字符长度,Si表示第i次调整前的上述第一字符长度,ei+1表示第i次调整后的上述第二字符长度,total表示上述第一字符长度与上述第二字符长度的和,step表示预设的调整步长;分别将上述训练文本、上述验证文本以及上述测试文本从第一个字符开始按照上述调整后的第一字符长度向后截取,得到多个第三字符串数据;分别将上述训练文本、上述验证文本以及上述测试文本从最后一个字符开始按照调整后的第二字符长度向前截取,得到多个第四字符串数据;将上述多个第三字符串数据与上述多个第三字符串数据对应的上述多个第四字符串进行拼接,得到调整后的待处理数据集;根据上述调整后的待处理数据集训练、验证并测试上述第一中间模型,直至满足预设的结束条件,得到训练好的第二中间模型以及上述第二中间模型对应的第二准确率及第二损失值;判断上述第二准确率是否大于上述第一准确率及上述第二损失值是否小于上述第一损失值;如果是,则将上述第二准确率及上述第二损失值保存为上述第一准确率及上述第一损失值,重复执行上述搜索步骤1;如果否,则执行下述搜索步骤2;搜索步骤2:继续调整上述第一字符长度以及上述第二字符长度的步骤,包括:s'i+1=s'i–step;e'i+1=total-s'i+1,i>=0;其中,s'i+1表示第i次继续调整后的上述第一字符长度,s'i表示第i次继续调整前的上述第一字符长度,e'i+1表示第i次继续调整后的上述第二字符长度,其中i≥0;分别将上述训练文本、上述验证文本以及上述测试文本从第一个字符开始按照继续调整后的第一字符长度向后截取,得到多个第五字符串数据;分别将上述训练文本、上述验证文本以及上述测试文本从最后一个字符开始按照继续调整后的第二字符长度向前截取,得到多个第六字符串数据;将上述多个第五字符串数据与上述多个第五字符串数据对应的上述多个第六字符串进行拼接,得到继续调整后的待处理数据集;根据上述继续调整后的待处理数据集训练、验证并测试上述第二中间模型,直至满足预设的结束条件,得到训练好的第三中间模型以及上述第三中间模型对应的第三准确率及第三损失值;判断上述第三准确率是否大于上述第一准确率及上述第三损失值是否小于上述第一损失值;如果是,则将上述第三准确率及上述第三损失值保存为上述第一准确率及上述第一损失值,重复执行上述搜索步骤2;如果否,则参数搜索结束,将上述第一准确率及上述第一损失值对应的第一字符长度Sbest以及上述第二字符长度Ebest为最终参数搜索结果;将上述第一准确率及上述第一损失值对应的中间模型Mbest确定为文本情绪识别模型;获取待识别文本;将上述待识别文本从第一个字符开始按照上述参数搜索得到的结果对应的上述第一字符长度Sbest向后截取,得到第一待识别字符串;并且,将上述待识别文本从最后一个字符开始按照上述参数搜索得到的结果对应的上述第二字符长度Ebest向前截取,得到第二待识别字符串;将上述第一待识别字符串以及上述第二待识别字符串进行拼接,得到模型输入文本;将上述模型输入文本输入上述文本情绪识别模型Mbest中,输出情绪识别结果。该方法通过动态调整文本模型的构建参数,从而基于该模型提高识别待识别文本的准确率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116011440B_ABST
    Figure CN116011440B_ABST
Patent Text Reader

Abstract

The application provides a text emotion recognition method and device and electronic equipment, the method comprises the following steps: respectively cutting the training text, the verification text and the test text from the first character according to the preset first character length backward, obtaining a plurality of first character string data; respectively cutting the training text, the verification text and the test text from the last character according to the preset second character length forward, obtaining a plurality of second character string data; the plurality of first character string data and the plurality of second character string corresponding to the plurality of first character string data are spliced to obtain a to-be-processed data set; then a text emotion recognition model is constructed through the to-be-processed data set, and the values of the first character length and the second character length are continuously adjusted in the process to determine the text emotion recognition model; the to-be-recognized text is recognized through the text emotion recognition model, so that the accuracy of the emotion recognition result is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electronic application technology, and in particular to a text emotion recognition method, apparatus, and electronic device. Background Technology

[0002] With the rapid development and application of intelligent AI robots, how to enable robots to quickly and accurately judge human emotional states and respond accurately to human emotions, truly achieving intelligent, warm, and human-centered human-computer interaction, has become a key research and application area in academia and industry in recent years. Text emotion recognition technology can endow intelligent technology products with the ability to perceive users' emotions in real time and accurately, providing a foundation for subsequent appropriate responses and making the user experience of intelligent technology products more friendly and warm.

[0003] Existing text recognition methods typically input the entire text to be recognized into a text sentiment recognition model to obtain its sentiment. When the text is too long and exceeds the model's limits, these methods need to first summarize the document before recognition. The summarization method is generally fixed at the beginning or end of the text, or a summary is generated through model computation. Therefore, these methods have limitations when processing texts with different narrative styles, leading to inaccurate or inefficient sentiment recognition results. Summary of the Invention

[0004] The purpose of this invention is to provide a text emotion recognition method, apparatus, and electronic device to improve the accuracy of text emotion recognition.

[0005] In a first aspect, embodiments of the present invention provide a text emotion recognition method, comprising: acquiring training text, verification text, and test text; truncating the training text, verification text, and test text from the first character according to a preset first character length to obtain multiple first string data; truncating the training text, verification text, and test text from the last character according to a preset second character length to obtain multiple second string data; concatenating the multiple first string data with the multiple second strings corresponding to the multiple first string data to obtain a dataset to be processed; training, verifying, and testing a preset initial model based on the dataset to be processed until a preset termination condition is met to obtain a trained first intermediate model and a first accuracy and a first loss value corresponding to the first intermediate model; search step 1: adjusting the first character length and the second character length according to the following formula: S i+1 =S i +step; e i+1 =total-S i+1 Among them, Si+1 S represents the length of the first character after the i-th adjustment. i e represents the length of the first character before the i-th adjustment. i+1 Let represent the length of the second character after the i-th adjustment, total represent the sum of the lengths of the first and second characters, and step represent the preset adjustment step size. The training text, verification text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple third string data. The training text, verification text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple fourth string data. The multiple third string data are concatenated with the corresponding multiple fourth strings to obtain the adjusted... Data set to be processed; train, validate, and test the first intermediate model based on the adjusted data set to be processed until the preset termination condition is met, to obtain the trained second intermediate model and the corresponding second accuracy and second loss value; determine whether the second accuracy is greater than the first accuracy and whether the second loss value is less than the first loss value; if yes, save the second accuracy and the second loss value as the first accuracy and the first loss value, and repeat the above search step 1; if no, execute the following search step 2; Search step 2: continue the steps of adjusting the first character length and the second character length, including: s' i+1 =s' i –step;e' i+1 =total-s' i+1 , i>=0; where s' i+1 s' represents the length of the first character after the i-th adjustment. i e' represents the length of the first character before the i-th adjustment. i+1Let represent the length of the second character after the i-th adjustment, where i ≥ 0; The training text, validation text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple fifth string data; The training text, validation text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple sixth string data; The multiple fifth string data are concatenated with the corresponding multiple sixth strings to obtain the adjusted dataset; The second intermediate model is trained, validated, and tested based on the adjusted dataset until a preset termination condition is met, resulting in a trained third intermediate model and its corresponding third accuracy and third loss value; It is determined whether the third accuracy is greater than the first accuracy and whether the third loss value is less than the first loss value; If yes, the third accuracy and third loss value are saved as the first accuracy and first loss value, and the search step 2 is repeated; If no, the parameter search ends, and the first character length S corresponding to the first accuracy and first loss value is... best And the length E of the second character mentioned above best For the final parameter search results; the intermediate model M corresponding to the above first accuracy and the above first loss value. best The model is identified as a text emotion recognition model; the text to be recognized is obtained; starting from the first character of the text to be recognized, the length S of the first character corresponding to the result obtained according to the above parameters is searched. best Extract the first character to be recognized by truncating it; and then, starting from the last character of the text to be recognized, search for the second character of the same length E corresponding to the result obtained according to the above parameters. best The first string to be identified is truncated to obtain the second string to be identified; the first string to be identified and the second string to be identified are concatenated to obtain the model input text; the model input text is input into the text emotion recognition model Mbest, and the emotion recognition result is output.

[0006] In conjunction with the first aspect, the present invention provides a first possible implementation of the first aspect, wherein, before the step of obtaining preset training text, verification text, and test text, the method includes: obtaining preset training original text, verification original text, and test original text; preprocessing the training original text, verification original text, and test original text to obtain the training text, verification text, and test text; wherein the preprocessing method includes removing spaces and removing special characters.

[0007] In conjunction with the first aspect, this embodiment of the invention provides a second possible implementation of the first aspect, wherein, before the step of obtaining the text to be recognized, the method further includes: obtaining the original text; preprocessing the original text to obtain the text to be recognized; wherein the preprocessing method includes removing spaces and removing special characters.

[0008] In conjunction with the first aspect, this embodiment of the invention provides a second possible implementation of the first aspect, wherein, after acquiring the text to be recognized, the method further includes: determining whether the text to be recognized exceeds a preset threshold; if not, inputting the text to be recognized into the text emotion recognition model M. best The system outputs the emotion recognition results.

[0009] Secondly, embodiments of the present invention provide a text emotion recognition device, comprising: a model building module, configured to acquire training text, verification text, and test text; truncate the training text, verification text, and test text from the first character according to a preset first character length to obtain multiple first string data; truncate the training text, verification text, and test text from the last character according to a preset second character length to obtain multiple second string data; concatenate the multiple first string data with the multiple second strings corresponding to the multiple first string data to obtain a dataset to be processed; train, verify, and test a preset initial model based on the dataset to be processed until a preset termination condition is met to obtain a trained first intermediate model and a first accuracy and a first loss value corresponding to the first intermediate model; search step 1: adjust the first character length and the second character length according to the following formula: S i+1 =S i +step; e i+1 =total-S i+1 Among them, S i+1 S represents the length of the first character after the i-th adjustment. i e represents the length of the first character before the i-th adjustment. i+1Let represent the length of the second character after the i-th adjustment, total represent the sum of the lengths of the first and second characters, and step represent the preset adjustment step size. The training text, verification text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple third string data. The training text, verification text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple fourth string data. The multiple third string data are concatenated with the corresponding multiple fourth strings to obtain the adjusted... Data set to be processed; train, validate, and test the first intermediate model based on the adjusted data set to be processed until the preset termination condition is met, to obtain the trained second intermediate model and the corresponding second accuracy and second loss value; determine whether the second accuracy is greater than the first accuracy and whether the second loss value is less than the first loss value; if yes, save the second accuracy and the second loss value as the first accuracy and the first loss value, and repeat the above search step 1; if no, execute the following search step 2; Search step 2: continue the steps of adjusting the first character length and the second character length, including: s' i+1 =s' i –step;e' i+1 =total-s' i+1 , i>=0; where s' i+1 s' represents the length of the first character after the i-th adjustment. i e' represents the length of the first character before the i-th adjustment. i+1Let represent the length of the second character after the i-th adjustment, where i ≥ 0; The training text, validation text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple fifth string data; The training text, validation text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple sixth string data; The multiple fifth string data are concatenated with the corresponding multiple sixth strings to obtain the adjusted dataset; The second intermediate model is trained, validated, and tested based on the adjusted dataset until a preset termination condition is met, resulting in a trained third intermediate model and its corresponding third accuracy and third loss value; It is determined whether the third accuracy is greater than the first accuracy and whether the third loss value is less than the first loss value; If yes, the third accuracy and third loss value are saved as the first accuracy and first loss value, and the search step 2 is repeated; If no, the parameter search ends, and the first character length S corresponding to the first accuracy and first loss value is... best And the length E of the second character mentioned above best For the final parameter search results; the intermediate model M corresponding to the above first accuracy and the above first loss value. best The model is identified as a text emotion recognition model; the text acquisition module is used to acquire the text to be recognized; the text truncation module is used to extract the length S of the first character obtained by searching the text from the first character according to the parameters mentioned above. best Extract the first character to be recognized by truncating it; and then, starting from the last character of the text to be recognized, search for the second character of the same length E corresponding to the result obtained according to the above parameters. best The system first extracts the first string to be recognized, obtaining the second string to be recognized. The text concatenation module then concatenates the first and second strings to be recognized to obtain the model input text. The recognition result output module then inputs the model input text into the text emotion recognition model M. best The system outputs the emotion recognition results.

[0010] Thirdly, embodiments of the present invention provide an electronic device, wherein the electronic device includes a processor and a memory, the memory storing computer-executable instructions executable by the processor, and the processor executing the computer-executable instructions to implement the text emotion recognition method of any one of the first aspects to the third possible implementation of the first aspect.

[0011] Fourthly, embodiments of the present invention provide a computer storage medium, wherein the computer storage medium stores a computer program, the computer program including program instructions, and when the program instructions are executed by a processor, the processor performs a text emotion recognition method as described in any of the first to third possible embodiments of the first aspect.

[0012] The embodiments of the present invention bring the following beneficial effects:

[0013] This invention provides a text emotion recognition method, apparatus, and electronic device. The method includes: acquiring training text, verification text, and test text; truncating the training text, verification text, and test text from the first character according to a preset first character length to obtain multiple first string data; truncating the training text, verification text, and test text from the last character according to a preset second character length to obtain multiple second string data; concatenating the multiple first string data with the corresponding multiple second strings to obtain a dataset to be processed; training, verifying, and testing a preset initial model based on the dataset to be processed until a preset termination condition is met to obtain a trained first intermediate model and a first accuracy and a first loss value corresponding to the first intermediate model; Search step 1: adjusting the first character length and the second character length according to the following formula: S i+1 =S i +step; e i+1 =total-S i+1 Among them, S i+1 S represents the length of the first character after the i-th adjustment. i e represents the length of the first character before the i-th adjustment. i+1Let represent the length of the second character after the i-th adjustment, total represent the sum of the lengths of the first and second characters, and step represent the preset adjustment step size. The training text, verification text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple third string data. The training text, verification text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple fourth string data. The multiple third string data are concatenated with the corresponding multiple fourth strings to obtain the adjusted... Data set to be processed; train, validate, and test the first intermediate model based on the adjusted data set to be processed until the preset termination condition is met, to obtain the trained second intermediate model and the corresponding second accuracy and second loss value; determine whether the second accuracy is greater than the first accuracy and whether the second loss value is less than the first loss value; if yes, save the second accuracy and the second loss value as the first accuracy and the first loss value, and repeat the above search step 1; if no, execute the following search step 2; Search step 2: continue the steps of adjusting the first character length and the second character length, including: s' i+1 =s' i –step;e' i+1 =total-s' i+1 , i>=0; where s' i+1 s' represents the length of the first character after the i-th adjustment. i e' represents the length of the first character before the i-th adjustment. i+1Let represent the length of the second character after the i-th adjustment, where i ≥ 0; The training text, validation text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple fifth string data; The training text, validation text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple sixth string data; The multiple fifth string data are concatenated with the corresponding multiple sixth strings to obtain the adjusted dataset; The second intermediate model is trained, validated, and tested based on the adjusted dataset until a preset termination condition is met, resulting in a trained third intermediate model and its corresponding third accuracy and third loss value; It is determined whether the third accuracy is greater than the first accuracy and whether the third loss value is less than the first loss value; If yes, the third accuracy and third loss value are saved as the first accuracy and first loss value, and the search step 2 is repeated; If no, the parameter search ends, and the first character length S corresponding to the first accuracy and first loss value is... best And the length E of the second character mentioned above best For the final parameter search results; the intermediate model M corresponding to the above first accuracy and the above first loss value. best The model is identified as a text emotion recognition model; the text to be recognized is obtained; starting from the first character of the text to be recognized, the length S of the first character corresponding to the result obtained according to the above parameters is searched. best The first string to be recognized is obtained by truncating the text backwards. Then, starting from the last character, the second string to be recognized is truncated forwards according to the second character length Ebest obtained from the search using the aforementioned parameters, resulting in the second string to be recognized. The first and second strings to be recognized are concatenated to obtain the model input text. This model input text is then input into the text emotion recognition model Mbest, and the emotion recognition result is output. This method improves the accuracy of recognizing text by dynamically adjusting the construction parameters of the text model.

[0014] Other features and advantages disclosed in this embodiment will be set forth in the following description, or some features and advantages may be inferred from the description or determined without doubt, or may be learned by practicing the techniques described above.

[0015] To make the above-mentioned objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0016] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0017] Figure 1 This is a flowchart illustrating a text emotion recognition method provided in an embodiment of the present invention.

[0018] Figure 2 A flowchart illustrating another text emotion recognition method provided in an embodiment of the present invention;

[0019] Figure 3 This is a schematic diagram of the structure of a text emotion recognition device provided in an embodiment of the present invention;

[0020] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.

[0021] Icons: 31-Model building module; 32-Text acquisition module; 33-Text extraction module; 34-Text splicing module; 35-Recognition result output module; 41-Memory; 42-Processor; 43-Bus; 44-Communication interface. Detailed Implementation

[0022] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0023] Currently, the method for emotion recognition in long texts involves directly truncating the text and inputting the initial portion into a pre-defined classification model for emotion recognition. This approach is based on the following considerations: since the structure of long texts is generally clear, the first one or two paragraphs are essentially summaries of the later content, i.e., the main idea, so directly extracting the first part for recognition is meaningful. However, this method is clearly unsuitable for texts that use a segmented approach followed by a summary, or texts with a turning point in the latter half. Further improvements have emerged based on these methods. Specifically, the first step is to summarize the long text, and then perform emotion recognition on the summarized content. This improved technique effectively enhances the accuracy of recognition, but the introduction of the text summarization step increases computational complexity and reduces the efficiency of emotion recognition.

[0024] Based on this, embodiments of the present invention provide a text emotion recognition method, apparatus, and electronic device. This technology can alleviate the aforementioned technical problems and improve the accuracy of text emotion recognition. To facilitate understanding of the embodiments of the present invention, a text emotion recognition method disclosed in the embodiments of the present invention will first be described in detail.

[0025] Example 1

[0026] This invention provides a text emotion recognition method. The text emotion recognition method includes the following steps S101 to S107:

[0027] Step S101: Obtain training text, verification text, and test text.

[0028] Step S102: Extract the training text, the verification text, and the test text from the first character and cut them out according to a preset first character length to obtain multiple first string data; extract the training text, the verification text, and the test text from the last character and cut them out according to a preset second character length to obtain multiple second string data.

[0029] Step S103: Concatenate the above-mentioned multiple first string data with the above-mentioned multiple second strings corresponding to the above-mentioned multiple first string data to obtain the dataset to be processed.

[0030] Step S104: Train, validate and test the preset initial model based on the above dataset to be processed until the preset termination condition is met, and obtain the trained first intermediate model and the first accuracy and first loss value corresponding to the first intermediate model.

[0031] Step S105: Search Step 1.

[0032] In the search step 1 above, the lengths of the first character and the second character are adjusted according to the following formula:

[0033] S i+1 =S i +step

[0034] e i+1 =total-S i+1

[0035] Among them, S i+1 S represents the length of the first character after the i-th adjustment. i e represents the length of the first character before the i-th adjustment. i+ 1 represents the length of the second character after the i-th adjustment, total represents the sum of the lengths of the first and second characters, and step represents the preset adjustment step size.

[0036] Step S106: Extract the training text, verification text, and test text from the first character according to the adjusted first character length to obtain multiple third string data; extract the training text, verification text, and test text from the last character according to the adjusted second character length to obtain multiple fourth string data.

[0037] Step S107: Concatenate the above-mentioned multiple third string data with the above-mentioned multiple fourth strings corresponding to the above-mentioned multiple third string data to obtain the adjusted dataset to be processed.

[0038] Step S108: Train, validate, and test the first intermediate model based on the adjusted dataset to be processed until the preset termination condition is met, and obtain the trained second intermediate model and the second accuracy and second loss value corresponding to the second intermediate model.

[0039] Step S109: Determine whether the second accuracy rate is greater than the first accuracy rate and whether the second loss value is less than the first loss value.

[0040] Step S1091: If so, save the second accuracy and the second loss value as the first accuracy and the first loss value, and repeat the search step 1.

[0041] Step S1092: If not, proceed to search step 2 below.

[0042] Step S110: Search Step 2.

[0043] The search step 2 mentioned above includes the step of continuing to adjust the length of the first character and the length of the second character, including:

[0044] s' i+1 =s' i -step

[0045] e' i+1 =total-s' i+1 , i>=0

[0046] Among them, s' i+1 s' represents the length of the first character after the i-th adjustment. i e' represents the length of the first character before the i-th adjustment. i+1 Let represent the length of the second character after the i-th adjustment, where i ≥ 0.

[0047] Step S111: Extract the training text, verification text, and test text from the first character and cut them backward according to the adjusted length of the first character to obtain multiple fifth string data; extract the training text, verification text, and test text from the last character and cut them backward according to the adjusted length of the second character to obtain multiple sixth string data.

[0048] Step S112: Concatenate the above-mentioned multiple fifth string data with the above-mentioned multiple sixth strings corresponding to the above-mentioned multiple fifth string data to obtain the dataset to be processed after further adjustment.

[0049] Step S113: Train, validate, and test the second intermediate model based on the adjusted dataset until the preset termination condition is met, and obtain the trained third intermediate model and the third accuracy and third loss value corresponding to the third intermediate model.

[0050] Step S114: Determine whether the third accuracy rate is greater than the first accuracy rate and whether the third loss value is less than the first loss value.

[0051] Step S1141: If so, save the above third accuracy and the above third loss value as the above first accuracy and the above first loss value, and repeat the above search step 2.

[0052] Step S1142: If not, the parameter search ends, and the first character length S corresponding to the first accuracy and the first loss value is set. best And the length E of the second character mentioned above best Search results for the final parameters.

[0053] Step S115: The intermediate model M corresponding to the first accuracy and the first loss value mentioned above... best It was determined to be a text-based emotion recognition model.

[0054] Step S116: Obtain the text to be recognized.

[0055] Step S117: Starting from the first character, search the text to be recognized according to the parameters to obtain the result corresponding to the length S of the first character. best Extract the first character to be recognized by truncating it; and then, starting from the last character of the text to be recognized, search for the second character of the same length E corresponding to the result obtained according to the above parameters. best Cut forward to obtain the second string to be recognized.

[0056] Step S118: Concatenate the first string to be recognized and the second string to be recognized to obtain the model input text.

[0057] Step S119: Input the above text into the above text emotion recognition model M. best The system outputs the emotion recognition results.

[0058] For ease of understanding, Figure 1 This is a flowchart illustrating a text emotion recognition method provided in an embodiment of the present invention.

[0059] This invention provides a text emotion recognition method, which includes: acquiring training text, verification text, and test text; truncating the training text, verification text, and test text from the first character according to a preset first character length to obtain multiple first string data; truncating the training text, verification text, and test text from the last character according to a preset second character length to obtain multiple second string data; concatenating the multiple first string data with the corresponding multiple second strings to obtain a dataset to be processed; training, verifying, and testing a preset initial model based on the dataset to be processed until a preset termination condition is met to obtain a trained first intermediate model and a first accuracy and a first loss value corresponding to the first intermediate model; Search step 1: adjusting the first character length and the second character length according to the following formula: S i+1 =S i +step; e i+1 =total-S i+1 Among them, S i+1 S represents the length of the first character after the i-th adjustment. i e represents the length of the first character before the i-th adjustment. i+1Let represent the length of the second character after the i-th adjustment, total represent the sum of the lengths of the first and second characters, and step represent the preset adjustment step size. The training text, validation text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple third string data. The training text, validation text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple fourth string data. The multiple third string data are concatenated with the corresponding multiple fourth strings to obtain the adjusted dataset to be processed. Based on the above adjustments... The adjusted dataset is used to train, validate, and test the first intermediate model until the preset termination condition is met, resulting in a trained second intermediate model and its corresponding second accuracy and second loss value. It is then determined whether the second accuracy is greater than the first accuracy and whether the second loss value is less than the first loss value. If yes, the second accuracy and the second loss value are saved as the first accuracy and the first loss value, and search step 1 is repeated. If no, search step 2 is executed. Search step 2: Continue adjusting the length of the first character and the length of the second character, including: s'i+1 = s'i – step; e'i+1 = total - s'i+1, i>=0; where s'i+1 represents the length of the first character after the i-th adjustment, s'i represents the length of the first character before the i-th adjustment, and e'i+1 represents the length of the second character after the i-th adjustment, where i≥0; the training text, the verification text, and the test text are each truncated from the first character according to the adjusted length of the first character to obtain multiple fifth string data; the training text, the verification text, and the test text are each truncated from the last character according to the adjusted length of the second character to obtain multiple sixth string data; the multiple fifth string data are combined with the multiple fifth string data. The corresponding sixth strings are concatenated to obtain the adjusted dataset to be processed. The second intermediate model is trained, validated, and tested based on this adjusted dataset until a preset termination condition is met, resulting in a trained third intermediate model and its corresponding third accuracy and third loss value. It is then determined whether the third accuracy is greater than the first accuracy and whether the third loss value is less than the first loss value. If yes, the third accuracy and third loss value are saved as the first accuracy and first loss value, and search step 2 is repeated. If no, the parameter search ends, and the first character length S corresponding to the first accuracy and first loss value is recorded. best And the length E of the second character mentioned abovebest For the final parameter search results; the intermediate model M corresponding to the above first accuracy and the above first loss value. best The model is identified as a text emotion recognition model; the text to be recognized is obtained; starting from the first character of the text to be recognized, the length S of the first character corresponding to the result obtained according to the above parameters is searched. best Extract the first character to be recognized by truncating it; and then, starting from the last character of the text to be recognized, search for the second character of the same length E corresponding to the result obtained according to the above parameters. best Extract the first string to be identified by truncating the second string; concatenate the first and second strings to be identified to obtain the model input text; input the model input text into the text emotion recognition model M. best The method outputs emotion recognition results. It improves the accuracy of text recognition by dynamically adjusting the construction parameters of the text model.

[0060] Example 2

[0061] exist Figure 1 Based on the method shown, this invention also provides another text emotion recognition method. For example... Figure 2 As seen, the method includes the following steps:

[0062] Step S201: Obtain preset training text, verification text, and test text.

[0063] Step S202: Preprocess the above-mentioned training original text, the above-mentioned verification original text, and the above-mentioned test original text to obtain the above-mentioned training text, the above-mentioned verification text, and the above-mentioned test text; wherein, the preprocessing method includes removing spaces and removing special characters.

[0064] Step S203: Obtain the above training text, the above verification text, and the above test text.

[0065] Step S204: Extract the training text, the verification text, and the test text from the first character and cut them out according to a preset first character length to obtain multiple first string data; extract the training text, the verification text, and the test text from the last character and cut them out according to a preset second character length to obtain multiple second string data.

[0066] Step S205: Concatenate the above-mentioned multiple first string data with the above-mentioned multiple second strings corresponding to the above-mentioned multiple first string data to obtain the dataset to be processed.

[0067] Step S205: Train, validate and test the preset initial model based on the above dataset to be processed until the preset termination condition is met, and obtain the trained first intermediate model and the first accuracy and first loss value corresponding to the first intermediate model.

[0068] Step S207: Search Step 1.

[0069] In the search step 1 above, the lengths of the first character and the second character are adjusted according to the following formula:

[0070] S i+1 =S i +step

[0071] e i+1 =total-S i+1

[0072] Among them, S i+1 S represents the length of the first character after the i-th adjustment. i e represents the length of the first character before the i-th adjustment. i+1 The length of the second character after the i-th adjustment is given, total represents the sum of the lengths of the first and second characters, and step represents the preset adjustment step size.

[0073] Step S208: Extract the training text, verification text, and test text from the first character according to the adjusted first character length to obtain multiple third string data; extract the training text, verification text, and test text from the last character according to the adjusted second character length to obtain multiple fourth string data.

[0074] Step S209: Concatenate the above-mentioned multiple third string data with the above-mentioned multiple fourth strings corresponding to the above-mentioned multiple third string data to obtain the adjusted dataset to be processed.

[0075] Step S210: Train, validate, and test the first intermediate model based on the adjusted dataset to be processed, until the preset termination condition is met, to obtain the trained second intermediate model and the second accuracy and second loss value corresponding to the second intermediate model.

[0076] Step S211: Determine whether the second accuracy rate is greater than the first accuracy rate and whether the second loss value is less than the first loss value.

[0077] Step S2111: If so, save the second accuracy and the second loss value as the first accuracy and the first loss value, and repeat the search step 1.

[0078] Step S2112: If not, proceed to search step 2 below.

[0079] Step S212: Search Step 2

[0080] The search step 2 mentioned above includes the step of continuing to adjust the length of the first character and the length of the second character, including:

[0081] s' i+1 =s' i -step

[0082] e' i+1 =total-s' i+1 , i>=0

[0083] Among them, s' i+1 s' represents the length of the first character after the i-th adjustment. i e' represents the length of the first character before the i-th adjustment. i+1 Let represent the length of the second character after the i-th adjustment, where i ≥ 0.

[0084] Step S213: Cut off the training text, the verification text, and the test text from the first character and continue cutting off the length of the first character after adjustment to obtain multiple fifth string data; cut off the training text, the verification text, and the test text from the last character and continue cutting off the length of the second character after adjustment to obtain multiple sixth string data.

[0085] Step S214: Concatenate the above-mentioned multiple fifth string data with the above-mentioned multiple sixth strings corresponding to the above-mentioned multiple fifth string data to obtain the dataset to be processed after further adjustment.

[0086] Step S215: Train, validate, and test the second intermediate model based on the adjusted dataset until the preset termination condition is met, and obtain the trained third intermediate model and the third accuracy and third loss value corresponding to the third intermediate model.

[0087] Step S216: Determine whether the third accuracy rate is greater than the first accuracy rate and whether the third loss value is less than the first loss value.

[0088] Step S2161: Save the above third accuracy and the above third loss value as the above first accuracy and the above first loss value, and repeat the above search step 2.

[0089] Step S2162: If not, the parameter search ends, and the first character length S corresponding to the first accuracy and the first loss value is set.best And the length E of the second character mentioned above best Search results for the final parameters.

[0090] Step S217: The intermediate model M corresponding to the first accuracy and the first loss value mentioned above... best It was determined to be a text-based emotion recognition model.

[0091] In one embodiment, after step S217, the method further includes: first, obtaining the original text; then, preprocessing the original text to obtain the text to be recognized; wherein the preprocessing includes removing spaces and removing special characters.

[0092] Step S218: Obtain the text to be recognized.

[0093] In one embodiment, after step S218, the method further includes: first, determining whether the identified text exceeds a preset threshold. If not, inputting the identified text into the text emotion recognition model M. best The system outputs the emotion recognition results.

[0094] Step S219: Starting from the first character, search the text to be recognized according to the parameters to obtain the result corresponding to the length S of the first character. best Extract the first character to be recognized by truncating it; and then, starting from the last character of the text to be recognized, search for the second character of the same length E corresponding to the result obtained according to the above parameters. best Cut forward to obtain the second string to be recognized.

[0095] Step S220: Concatenate the first string to be recognized and the second string to be recognized to obtain the model input text.

[0096] Step S221: Input the above text into the above text emotion recognition model M. best The system outputs the emotion recognition results.

[0097] For ease of understanding, Figure 2 A flowchart illustrating another text emotion recognition method provided in this embodiment of the invention.

[0098] Furthermore, let's take the following text recognition process as an example, using the above method:

[0099] Text to be identified 1: Chongqing is a mountain city, where mountains and people are intertwined without clear boundaries. Therefore, the wildfire was an imminent crisis for the people of Chongqing, inspiring a united effort to protect their homeland. In this operation to extinguish the wildfire, the frontline fighters were firefighters, armed police officers, People's Liberation Army soldiers, and medical personnel. Behind them was a solid support system spontaneously formed by volunteers—motorcycle riders carrying supplies with five-star red flags, fathers and sons using chainsaws to create firebreaks, girls coordinating supplies with loudspeakers, and others delivering food, cooking, handing out water, and operating excavators… Among those selfless figures rushing against the tide were soldiers, Party members, and ordinary people from all walks of life and of different ages. Faced with the raging wildfire, they united as one. This "heroic spirit" belongs not only to Chongqing but also to all Chinese people. This "epic firefighting" in the eyes of netizens was supported by the entire nation. Due to the severity and urgency of the fire situation, from national ministries and commissions to brother provinces such as Gansu and Yunnan, Chongqing received substantial support, providing crucial assistance in quickly extinguishing the open flames. Meanwhile, online, cheers of "Chongqing, stand strong!" resounded, and countless moving scenes continuously went viral on social media. Indeed, without a touch of heroism, these moments could not have been achieved through staged photos. What truly resonated was the courage, will, and unity shared by the Chinese people in the face of disaster or foreign enemies, shining through these ordinary yet brave individuals. The emotion derived from the aforementioned text 1 is: pride.

[0100] The text to be identified, 1, has a "general-specific-general" structure; therefore, a strategy of extracting the first and second parts of the text is adopted. The relevant parameters are preset as total=256, s=128, e=128, step=8. A BERT pre-trained language model is used as the emotion recognition algorithm model.

[0101] go through Figure 1 The parameter search and model building process yielded the following results: the first accuracy was 0.8475 and the first loss was 0.3365.

[0102] The corresponding parameter search result is: first character length S best The length of the second character is 96 and E. best The value is 160; the corresponding text emotion recognition model is model.ckpt-5217. That is, when performing emotion recognition on the above-mentioned text 1 and text 2 to be recognized, the text is first truncated, and the first 96 characters and the last 160 characters are extracted; then the truncated text is concatenated into a single text and sent to the model model.ckpt-5217 for emotion recognition, and the recognition result is output.

[0103] This invention provides a text emotion recognition method, which includes: acquiring preset training original text, verification original text, and test original text; preprocessing the training original text, verification original text, and test original text to obtain the training text, verification text, and test text; wherein, the preprocessing method includes removing spaces and removing special characters; acquiring the training text, verification text, and test text; truncating the training text, verification text, and test text from the first character according to a preset first character length to obtain multiple first string data; truncating the training text, verification text, and test text from the last character according to a preset second character length to obtain multiple second string data; concatenating the multiple first string data with the multiple second strings corresponding to the multiple first string data to obtain a dataset to be processed; training, verifying, and testing a preset initial model based on the dataset to be processed until a preset termination condition is met to obtain a trained first intermediate model and a first accuracy and a first loss value corresponding to the first intermediate model; search step 1: adjusting the first character length and the second character length according to the following formula: S i+1 =S i +step; e i+1 =total-S i+1 Among them, S i+1 S represents the length of the first character after the i-th adjustment. i e represents the length of the first character before the i-th adjustment. i+1Let represent the length of the second character after the i-th adjustment, total represent the sum of the lengths of the first and second characters, and step represent the preset adjustment step size. The training text, verification text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple third string data. The training text, verification text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple fourth string data. The multiple third string data are concatenated with the corresponding multiple fourth strings to obtain the adjusted pending processing. Dataset; Train, validate, and test the first intermediate model based on the adjusted dataset until the preset termination condition is met, obtaining the trained second intermediate model and the corresponding second accuracy and second loss value; Determine whether the second accuracy is greater than the first accuracy and whether the second loss value is less than the first loss value; If yes, save the second accuracy and the second loss value as the first accuracy and the first loss value, and repeat the search step 1; If no, execute the following search step 2; Search step 2: Continue adjusting the first character length and the second character length, including: s'i+1=s' i–step; e'i+1=total-s'i+1, i>=0; where s'i+1 represents the length of the first character after the i-th adjustment, s'i represents the length of the first character before the i-th adjustment, and e'i+1 represents the length of the second character after the i-th adjustment, where i≥0; the training text, the verification text, and the test text are each truncated from the first character according to the adjusted length of the first character to obtain multiple fifth string data; the training text, the verification text, and the test text are each truncated from the last character according to the adjusted length of the second character to obtain multiple sixth characters. String data; concatenate the above-mentioned multiple fifth string data with the above-mentioned multiple sixth strings corresponding to the above-mentioned multiple fifth string data to obtain the dataset to be processed after further adjustment; train, verify and test the above-mentioned second intermediate model based on the above-mentioned adjusted dataset to be processed until the preset termination condition is met, to obtain the trained third intermediate model and the third accuracy and third loss value corresponding to the above-mentioned third intermediate model; determine whether the above-mentioned third accuracy is greater than the above-mentioned first accuracy and whether the above-mentioned third loss value is less than the above-mentioned first loss value; if so, save the above-mentioned third accuracy and the above-mentioned third loss value as the above-mentioned first accuracy and the above-mentioned first loss value, and repeat the above-mentioned search step 2;If not, the parameter search ends, and the first character length Sbest corresponding to the first accuracy and the first loss value, and the second character length Ebest are taken as the final parameter search results; the intermediate model Mbest corresponding to the first accuracy and the first loss value is determined as the text emotion recognition model; the text to be recognized is obtained; the text to be recognized is truncated from the first character according to the first character length Sbest corresponding to the result of the parameter search, to obtain the first string to be recognized; and the text to be recognized is truncated from the last character according to the second character length Ebest corresponding to the result of the parameter search, to obtain the second string to be recognized; the first string to be recognized and the second string to be recognized are concatenated to obtain the model input text; the model input text is input into the text emotion recognition model M. best The method outputs emotion recognition results. By preprocessing the raw data, this method further improves the accuracy of recognizing the text to be identified.

[0104] Example 3

[0105] This invention also provides a text emotion recognition device. For example... Figure 3 The diagram shown is a structural schematic of a text emotion recognition device provided in an embodiment of the present invention. The device includes:

[0106] Model building module 31 is used to acquire training text, validation text, and test text; it truncates each of the training text, validation text, and test text from the first character along a preset first character length to obtain multiple first string data; it then truncates each of the training text, validation text, and test text from the last character along a preset second character length to obtain multiple second string data; it concatenates the multiple first string data with the corresponding multiple second strings to obtain a dataset to be processed; it trains, validates, and tests a preset initial model based on the dataset to be processed until a preset termination condition is met, obtaining a trained first intermediate model and its corresponding first accuracy and first loss value; Search step 1: Adjust the first character length and the second character length according to the following formula: S i+1 =S i +step; e i+1 =total-S i+1 Among them, S i+1 S represents the length of the first character after the i-th adjustment. i e represents the length of the first character before the i-th adjustment. i+1Let represent the length of the second character after the i-th adjustment, total represent the sum of the lengths of the first and second characters, and step represent the preset adjustment step size. The training text, verification text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple third string data. The training text, verification text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple fourth string data. The multiple third string data are concatenated with the corresponding multiple fourth strings to obtain the adjusted... Data set to be processed; train, validate, and test the first intermediate model based on the adjusted data set to be processed until the preset termination condition is met, to obtain the trained second intermediate model and the corresponding second accuracy and second loss value; determine whether the second accuracy is greater than the first accuracy and whether the second loss value is less than the first loss value; if yes, save the second accuracy and the second loss value as the first accuracy and the first loss value, and repeat the above search step 1; if no, execute the following search step 2; Search step 2: continue the steps of adjusting the first character length and the second character length, including: s' i+1 =s' i –step;e' i+1 =total-s' i+1 , i>=0; where s' i+1 s' represents the length of the first character after the i-th adjustment. i e' represents the length of the first character before the i-th adjustment. i+1Let represent the length of the second character after the i-th adjustment, where i ≥ 0; The training text, validation text, and test text are each truncated from the first character according to the adjusted first character length, resulting in multiple fifth string data; The training text, validation text, and test text are each truncated from the last character according to the adjusted second character length, resulting in multiple sixth string data; The multiple fifth string data are concatenated with the corresponding multiple sixth strings to obtain the adjusted dataset; The second intermediate model is trained, validated, and tested based on the adjusted dataset until a preset termination condition is met, resulting in a trained third intermediate model and its corresponding third accuracy and third loss value; It is determined whether the third accuracy is greater than the first accuracy and whether the third loss value is less than the first loss value; If yes, the third accuracy and third loss value are saved as the first accuracy and first loss value, and the search step 2 is repeated; If no, the parameter search ends, and the first character length S corresponding to the first accuracy and first loss value is... best And the length E of the second character mentioned above best For the final parameter search results; the intermediate model M corresponding to the above first accuracy and the above first loss value. best It was determined to be a text-based emotion recognition model.

[0107] The text to be recognized module 32 is used to acquire the text to be recognized.

[0108] The text extraction module 33 is used to extract the first character of the text to be recognized, starting from the first character and searching according to the parameters to obtain the length S of the first character. best Extract the first character to be recognized by truncating it; and then, starting from the last character of the text to be recognized, search for the second character of the same length E corresponding to the result obtained according to the above parameters. best Cut forward to obtain the second string to be recognized.

[0109] The text concatenation module 34 concatenates the first string to be recognized and the second string to be recognized to obtain the model input text.

[0110] The recognition result output module 35 is used to input the above model input text into the above text emotion recognition model Mbest and output the emotion recognition result.

[0111] The model construction module 31, the text acquisition module 32, the text extraction module 33, the text splicing module 34, and the recognition result output module 35 are connected in sequence.

[0112] In one embodiment, the model building module 31 is further configured to obtain preset training original text, verification original text and test original text; preprocess the training original text, the verification original text and the test original text to obtain the training text, the verification text and the test text; wherein the preprocessing method includes removing spaces and removing special characters.

[0113] In one embodiment, the text acquisition module 32 is further configured to acquire the original text; preprocess the original text to obtain the text to be identified; wherein the preprocessing method includes removing spaces and removing special characters.

[0114] In one embodiment, the text acquisition module 32 is further configured to determine whether the text to be identified exceeds a preset threshold; if not, the text to be identified is input into the text emotion recognition model M. best The system outputs the emotion recognition results.

[0115] The text emotion recognition device provided in this embodiment of the invention has the same technical features as the text emotion recognition method provided in the above embodiments, and therefore can solve the same technical problems and achieve the same technical effects. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the device described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0116] Example 4

[0117] This embodiment provides an electronic device, including a processor and a memory. The memory stores computer-executable instructions that can be executed by the processor. The processor executes the computer-executable instructions to implement the steps of a text emotion recognition method for a storage chip.

[0118] See Figure 4 The diagram shows the structure of an electronic device, which includes a memory 41 and a processor 42. The memory stores a computer program that can run on the processor 42. When the processor executes the computer program, it implements the steps provided by the above-mentioned text emotion recognition method for memory chips.

[0119] like Figure 4 As shown, the device also includes a bus 43 and a communication interface 44, with the processor 42, the communication interface 44 and the memory 41 connected via the bus 43; the processor 42 is used to execute executable modules, such as computer programs, stored in the memory 41.

[0120] The memory 41 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 44 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc.

[0121] Bus 43 can be an ISA bus, PCI bus, or EISA bus, etc. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 4 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.

[0122] The memory 41 stores the program, and the processor 42 executes the program after receiving the execution instruction. The method executed by the text emotion recognition device with a memory chip disclosed in any of the foregoing embodiments of the present invention can be applied to the processor 42, or implemented by the processor 42. The processor 42 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit in the hardware of the processor 42 or by instructions in the form of software. The processor 42 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this invention can be directly manifested as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory 41, and processor 42 reads information from memory 41 and, in conjunction with its hardware, completes the steps of the above method.

[0123] Furthermore, this embodiment of the invention also provides a computer storage medium storing a computer program, the computer program including program instructions, which, when executed by processor 42, cause processor 42 to execute the above-mentioned text emotion recognition method for the storage chip.

[0124] The storage chip text emotion recognition device and the verification device for the storage text emotion recognition method provided in this embodiment of the invention have the same technical features, so they can also solve the same technical problems and achieve the same technical effects.

[0125] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.

[0126] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

Claims

1. A text emotion recognition method, characterized in that, include: Obtain training text, validation text, and test text; The training text, the verification text, and the test text are each truncated from the first character according to a preset first character length to obtain multiple first string data. The training text, the verification text, and the test text are each truncated from the last character forward according to a preset second character length to obtain multiple second string data; The plurality of first string data are concatenated with the plurality of second strings corresponding to the plurality of first string data to obtain the dataset to be processed; The preset initial model is trained, validated, and tested based on the dataset to be processed until the preset termination condition is met, resulting in a trained first intermediate model and the first accuracy and first loss value corresponding to the first intermediate model. Search Step 1: Adjust the lengths of the first character and the second character according to the following formula: in, Indicates the first The length of the first character after the adjustment Indicates the first The length of the first character before the adjustment Indicates the first The second character length after the second adjustment This represents the sum of the lengths of the first character and the second character. Indicates the preset adjustment step size; The training text, the verification text, and the test text are each truncated from the first character according to the adjusted first character length to obtain multiple third string data; the training text, the verification text, and the test text are each truncated from the last character according to the adjusted second character length to obtain multiple fourth string data. The plurality of third string data are concatenated with the plurality of fourth strings corresponding to the plurality of third string data to obtain the adjusted dataset to be processed; The first intermediate model is trained, validated, and tested based on the adjusted dataset to be processed until the preset termination condition is met, so as to obtain the trained second intermediate model and the second accuracy and second loss value corresponding to the second intermediate model. Determine whether the second accuracy rate is greater than the first accuracy rate and whether the second loss value is less than the first loss value; If so, the second accuracy and the second loss value are saved as the first accuracy and the first loss value, and the search step 1 is repeated; If not, proceed to search step 2 below; Search step 2: Continue adjusting the length of the first character and the length of the second character, including: s' i+1 =s' i - step e' i+1 =total-s' i+1 ,i>=0 in, s' i+1 Indicates the first The length of the first character after further adjustment. s' i Indicates the first The length of the first character before the next adjustment. e' i+1 Indicates the first The second character length is adjusted again, where ; The training text, the verification text, and the test text are each truncated from the first character according to the adjusted length of the first character to obtain multiple fifth string data; the training text, the verification text, and the test text are each truncated from the last character according to the adjusted length of the second character to obtain multiple sixth string data. The plurality of fifth string data are concatenated with the plurality of sixth strings corresponding to the plurality of fifth string data to obtain the dataset to be processed after further adjustment; The second intermediate model is trained, validated, and tested based on the adjusted dataset until the preset termination condition is met, resulting in a trained third intermediate model and the corresponding third accuracy and third loss value. Determine whether the third accuracy rate is greater than the first accuracy rate and whether the third loss value is less than the first loss value; If so, the third accuracy and the third loss value are saved as the first accuracy and the first loss value, and the search step 2 is repeated. If not, the parameter search ends, and the first character length corresponding to the first accuracy and the first loss value is calculated. S best and the length of the second character E best Search results for the final parameters; The intermediate model corresponding to the first accuracy and the first loss value M best It was determined to be a text-based emotion recognition model; Obtain the text to be recognized; The length of the first character corresponding to the result obtained by searching the text to be recognized starting from the first character according to the above parameters. S best The text is truncated to obtain the first string to be recognized; and the second character length corresponding to the result obtained by searching the text to be recognized starting from the last character according to the above parameters is then calculated. E best Extract the second string to be recognized by cutting forward. The first string to be recognized and the second string to be recognized are concatenated to obtain the model input text; Input the text into the text emotion recognition model. M best In the process, the emotion recognition results are output; After obtaining the text to be recognized, the method further includes: Determine whether the identified text exceeds a preset threshold; If not, input the identified text into the text emotion recognition model. M best The system outputs the emotion recognition results.

2. The text emotion recognition method according to claim 1, characterized in that, Before the steps of obtaining preset training text, validation text, and test text, the method includes: Obtain the preset training text, verification text, and test text; The training text, the verification text, and the test text are preprocessed to obtain the training text, the verification text, and the test text; wherein the preprocessing method includes removing spaces and removing special characters.

3. The text emotion recognition method according to claim 1, characterized in that, Before the step of obtaining the text to be recognized, the method further includes: Get the original text; The original text is preprocessed to obtain the text to be recognized; the preprocessing methods include removing spaces and removing special characters.

4. A text emotion recognition device, characterized in that, include: The model building module is used to obtain training text, validation text, and test text; The training text, the verification text, and the test text are each truncated from the first character according to a preset first character length to obtain multiple first string data. The training text, the verification text, and the test text are each truncated from the last character forward according to a preset second character length to obtain multiple second string data; The plurality of first string data are concatenated with the plurality of second strings corresponding to the plurality of first string data to obtain the dataset to be processed; Train, validate, and test a preset initial model based on the dataset to be processed until a preset termination condition is met, to obtain a trained first intermediate model and the corresponding first accuracy and first loss value; Search step 1: Adjust the first character length and the second character length according to the following formula: ; ;in, Indicates the first The length of the first character after the adjustment Indicates the first The length of the first character before the adjustment Indicates the first The second character length after the second adjustment This represents the sum of the lengths of the first character and the second character. The preset adjustment step size is indicated; the training text, the verification text, and the test text are each truncated from the first character according to the adjusted first character length to obtain multiple third string data; the training text, the verification text, and the test text are each truncated from the last character according to the adjusted second character length to obtain multiple fourth string data; the multiple third string data are concatenated with the multiple fourth strings corresponding to the multiple third string data to obtain the adjusted dataset to be processed; the first intermediate model is trained, verified, and tested according to the adjusted dataset to be processed until the preset termination condition is met to obtain the trained second intermediate model and the second accuracy and second loss value corresponding to the second intermediate model; it is determined whether the second accuracy is greater than the first accuracy and whether the second loss value is less than the first loss value; if yes, the second accuracy and the second loss value are saved as the first accuracy and the first loss value, and the search step 1 is repeated; if no, the following search step 2 is executed; Search step 2: the steps of continuing to adjust the first character length and the second character length include: s' i+1 =s' i – step ; e' i+1 = total-s' i+1 ,i>=0 ;in, s' i+1 Indicates the first The length of the first character after further adjustment. s' i Indicates the first The length of the first character before the next adjustment. e' i+1 Indicates the first The second character length is adjusted again, where The training text, verification text, and test text are each truncated from the first character according to the adjusted first character length to obtain multiple fifth string data. The training text, verification text, and test text are each truncated from the last character according to the adjusted second character length to obtain multiple sixth string data. The multiple fifth string data are concatenated with the corresponding multiple sixth strings to obtain the adjusted unprocessed dataset. The second intermediate model is trained, verified, and tested based on the adjusted unprocessed dataset until a preset termination condition is met, resulting in a trained third intermediate model and its corresponding third accuracy and third loss value. It is determined whether the third accuracy is greater than the first accuracy and whether the third loss value is less than the first loss value. If yes, the third accuracy and the third loss value are saved as the first accuracy and the first loss value, and the search step 2 is repeated. If no, the parameter search ends, and the first character length corresponding to the first accuracy and the first loss value is... S best and the length of the second character E best For the final parameter search results; the intermediate model corresponding to the first accuracy and the first loss value. M best It was determined to be a text-based emotion recognition model; The text to be recognized acquisition module is used to acquire the text to be recognized; The text extraction module is used to extract the length of the first character corresponding to the result obtained by searching the text to be recognized starting from the first character according to the above parameters. S best The text is truncated to obtain the first string to be recognized; and the second character length corresponding to the result obtained by searching the text to be recognized starting from the last character according to the above parameters is then calculated. E best Extract the second string to be recognized by cutting forward. The text concatenation module concatenates the first string to be recognized and the second string to be recognized to obtain the model input text; The recognition result output module is used to input the model input text into the text emotion recognition model. M best In the process, the emotion recognition results are output; The text acquisition module is further configured to: determine whether the text to be recognized exceeds a preset threshold; if not, input the text to be recognized into the text emotion recognition model. M best The system outputs the emotion recognition results.

5. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory storing computer-executable instructions that can be executed by the processor, the processor executing the computer-executable instructions to implement the text emotion recognition method according to any one of claims 1 to 3.

6. A computer storage medium, characterized in that, The computer storage medium stores a computer program, which includes program instructions that, when executed by a processor, cause the processor to perform the text emotion recognition method as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Paper classification method and device based on classification model, electronic equipment and medium

    CN111639181A

  • Insurance sales task verbal skill recommendation method, system and equipment based on context semantic understanding

    CN113688222A