A psychological counseling method, device and terminal equipment based on controlled text generation
By combining emotion detection and scene-theme recognition models with psychological knowledge graphs, and using knowledge detection models to generate logically coherent question-and-answer data, the problem of disjointed question-and-answer data in existing psychological counseling technologies is solved, and more efficient intelligent counseling dialogue is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 徐涛
- Filing Date
- 2022-03-24
- Publication Date
- 2026-04-24
AI Technical Summary
Existing automatic text generation methods cannot guarantee the semantic coherence and logical consistency of machine-generated psychological counseling question-and-answer data, especially when generating longer texts.
By inputting sample data into a sentiment detection model and a scene topic type recognition model, combined with a psychological knowledge graph, the sentiment type and scene topic of the text are obtained. Knowledge keywords are output using a knowledge detection model, and logically coherent question-and-answer data are generated through a controlled text generation algorithm model.
It improves the relevance and fluency of psychological counseling dialogues, making the generated text semantically coherent and logically consistent, thus enhancing the effectiveness of intelligent counseling dialogues.
Smart Images

Figure CN114661864B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a psychological counseling method, apparatus, and terminal device based on controlled text generation. Background Technology
[0002] Automatic text generation is an important application area in natural language processing, such as machine translation and intelligent voice interaction technology. Intelligent voice interaction technology, in particular, provides labor for the intelligent service industry. For example, there is a significant gap between the number of practicing psychological counselors and the market demand for psychological counseling. Furthermore, due to varying levels of professional competence among counselors and limitations imposed by time and space constraints, people cannot easily access effective psychological counseling. Intelligent voice interaction technology can improve the efficiency of psychological counseling and, to some extent, fill this market gap.
[0003] However, when generating longer texts, the commonly used automatic text generation methods cannot guarantee that the machine-generated psychological counseling question-and-answer data is semantically coherent and logically consistent. Summary of the Invention
[0004] The main objective of this invention is to propose a psychological counseling method, apparatus, and terminal device based on controlled text generation, in order to solve the problem that existing automatic text generation methods cannot guarantee that the psychological counseling question-and-answer data generated by the machine is semantically coherent and logically consistent.
[0005] To achieve the above objectives, a first aspect of the present invention provides a psychological counseling method based on controlled text generation, comprising:
[0006] The sample data is input into the sentiment detection model and the scene theme type recognition model; the sentiment detection model outputs the text sentiment type and the scene theme type recognition model outputs the text scene theme.
[0007] The sample data, text sentiment type, and text scene theme are combined with a psychological knowledge graph and input into the knowledge detection model. At the same time, the sentence most relevant to the next sentence is obtained so that the knowledge detection model outputs knowledge keywords.
[0008] The knowledge keywords, text sentiment type, text scene theme and the sentence most relevant to the next sentence are concatenated to generate control information, which is then used together with the sample data to train the controlled text generation algorithm model.
[0009] The trained controlled text generation algorithm model is used to analyze the processed user-side psychological counseling question and answer data, and output the psychological counseling response from the machine-side psychological counseling question and answer data.
[0010] In conjunction with the first aspect of the present invention, in the first embodiment of the present invention, before the knowledge detection model outputs knowledge keywords, it includes:
[0011] Based on the content keywords extracted by the knowledge detection model, a trigram phrase is matched and output;
[0012] The ternary phrases are converted into sentences to obtain ternary sentence groups.
[0013] In conjunction with the first embodiment of the first aspect of the present invention, in the second embodiment of the present invention, obtaining the sentence most relevant to the next sentence includes:
[0014] Retrieve from the set of sentences with target features a sentence whose content is closest to the given trigram phrase, and use it as the sentence most relevant to the next sentence.
[0015] In conjunction with the second embodiment of the first aspect of the present invention, in the third embodiment of the present invention, the knowledge detection model outputs knowledge keywords, including:
[0016] The sentences of the ternary statement group are sorted according to the sentence most relevant to the next sentence. The sorted results are output as content keywords with a sorted order, which are the knowledge keywords.
[0017] In conjunction with the first aspect of the present invention, in the fourth embodiment of the present invention, the knowledge keywords, text sentiment type, text scene theme, and the sentence most relevant to the next sentence are concatenated to generate control information, which is then used together with the sample data to train the controlled text generation algorithm model, including:
[0018] The user-side psychological counseling question and answer data is concatenated with the control information to form a training set for training the controlled text generation algorithm model;
[0019] The next sentence information is used as the validation set for training the controlled text generation algorithm model.
[0020] In conjunction with the first aspect of the present invention, in the fifth embodiment of the present invention, before analyzing the processed user-side psychological counseling question-and-answer data using a trained controlled text generation algorithm model and outputting the psychological counseling response from the machine-side psychological counseling question-and-answer data, the following steps are included:
[0021] Obtain psychological counseling Q&A data from users through human-computer interaction;
[0022] Process the psychological counseling question and answer data on the user side.
[0023] In conjunction with the fifth embodiment of the first aspect of the present invention, in the sixth embodiment of the present invention, processing user-side psychological counseling question-and-answer data includes:
[0024] The user-side psychological counseling Q&A data is converted into the control information;
[0025] The user-side psychological counseling question and answer data is concatenated with the control information to generate processed user-side psychological counseling question and answer data.
[0026] A second aspect of the present invention provides a psychological counseling device based on controlled text generation, comprising:
[0027] The sample data processing module is used to input sample data into the sentiment detection model and the scene theme type recognition model; the sentiment detection model outputs the text sentiment type and the scene theme type recognition model outputs the text scene theme.
[0028] The knowledge keyword output module is used to input the sample data, text sentiment type, and text scene theme into the knowledge detection model in combination with the psychological knowledge graph, and at the same time obtain the sentence most relevant to the next sentence, so that the knowledge detection model outputs knowledge keywords.
[0029] The controlled text generation algorithm model training module concatenates the knowledge keywords, text sentiment type, text scene theme, and the sentence most relevant to the next sentence to generate control information, which is then used together with the sample data to train the controlled text generation algorithm model.
[0030] The psychological counseling response output module is used to analyze the processed user-side psychological counseling question and answer data through a trained controlled text generation algorithm model, and output the psychological counseling response from the machine-side psychological counseling question and answer data.
[0031] A third aspect of the present invention provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method provided in the first aspect above.
[0032] A fourth aspect of the present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method provided in the first aspect above.
[0033] This invention proposes a psychological counseling method based on controlled text generation. The output of machine-based psychological counseling question-and-answer data is converted into the output of a controlled text generation algorithm model. This model is then applied to human-computer interaction psychological counseling scenarios to improve the relevance and fluency of the content generated during psychological counseling dialogues, making it semantically coherent and logically consistent, thereby improving the effect of intelligent counseling dialogues. Attached Figure Description
[0034] Figure 1 This is a schematic diagram illustrating the implementation process of the controlled text generation-based psychological counseling method provided in an embodiment of the present invention.
[0035] Figure 2 This is a schematic diagram of the composition structure of a psychological counseling device based on controlled text generation provided in an embodiment of the present invention.
[0036] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0037] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0038] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0039] In this document, suffixes such as "module," "part," or "unit" used to denote elements are used only for the purpose of illustrative purposes and do not have any specific meaning in themselves. Therefore, "module" and "part" can be used interchangeably.
[0040] like Figure 1 As shown, a controlled text generation-based psychological counseling method first trains a controlled text generation algorithm model using sample data of psychological counseling question-and-answer data. Then, processed user-side psychological counseling question-and-answer data is used to conform to the input of the controlled text generation algorithm model, thereby applying the controlled text generation algorithm model to human-computer interaction psychological counseling scenarios. The method includes, but is not limited to, the following steps:
[0041] S101. Input the sample data into the emotion detection model and the scene / topic type recognition model;
[0042] The emotion detection model outputs the emotion type of the text, and the scene theme type recognition model outputs the scene theme of the text.
[0043] In step S101 above, the sample data is the historical psychological counseling question and answer data collected during the actual psychological counseling process, and it is organized and divided into the historical psychological counseling question and answer data on the user side and the historical psychological counseling question and answer data on the machine side corresponding to the historical psychological counseling question and answer data on the user side. The historical psychological counseling question and answer data on the machine side includes the next sentence information.
[0044] In this embodiment of the invention, the sentiment detection model and the scene topic type recognition model are trained neural network models, such as recurrent neural networks (RNNs), convolutional neural networks (CNNs), and Transformer neural network structures. For example, the training method for the sentiment detection model is as follows:
[0045] 1. Process the sample data and convert it into text with sentiment tags, which is denoted as the first sample text. Sentiment tags include, but are not limited to, basic sentiment types such as "joy", "anger", "sorrow", "happiness", "surprise", "grief" and "fear".
[0046] 2. Using the first sample text as input to the sentiment detection model, obtain the output of the sentiment detection model based on the first parameter and the sentiment label. Adjust the first parameter of the sentiment detection model according to the output and the first sample text until the output of the sentiment detection model matches the sentiment label. Its output is the conditional probability value of the sentiment label corresponding to the first sample text. Iterate the parameters of the sentiment detection model using a loss function until a convergence condition is met. The convergence condition can be that the value of the loss function is less than a preset threshold or the number of iterations reaches a preset threshold.
[0047] The training method for the scene topic type recognition model is as follows:
[0048] 1. Process the sample data to extract text data with text scene theme types, which will be used as the second sample text. The text scene theme types include, but are not limited to, over 200 scene theme types such as "marital discord", "children's gaming addiction", "how to refuse at work", "high pressure of college entrance examination", and "breakup".
[0049] In practical applications, different scenario themes can affect the results of text generation. Different scenario themes with the same emotional tags will express different meanings. For example, the scenario theme of "college entrance examination" and the scenario theme of "work" are different theme types. When the emotional tag is "high pressure", when generating dialogue, the response should be based on emphasizing the tension brought about by the college entrance examination and based on the working state of people who have entered society and are striving for a living.
[0050] 2. Use the second sample text as input to the scene topic type recognition model. Obtain the output of the scene topic type recognition model based on the second parameter and the text scene topic type. Adjust the second parameter of the scene topic type recognition model according to the output and the second sample text until the output of the scene topic type recognition model matches the label of the second sample text. Its output is the conditional probability value of the text scene topic type corresponding to the second text sample. Iterate the parameters of the scene topic type recognition model through a loss function until the convergence condition is reached. The convergence condition can be that the value of the loss function is less than a preset threshold or the number of iterations reaches a preset iteration threshold.
[0051] S102. The sample data, text sentiment type, and text scene theme are combined with the psychological knowledge graph and input into the knowledge detection model. At the same time, the sentence most relevant to the next sentence is obtained so that the knowledge detection model outputs knowledge keywords.
[0052] In step S102 above, when the sample data, text sentiment type, and text scene theme are input into the knowledge detection model in conjunction with the psychological knowledge graph, and when the sentence most relevant to the next sentence is input into the knowledge detection model, the above content is used... <s>After concatenation with connectors, the input is, for example, the sample data: "I'm about to graduate from university, and my girlfriend wants to break up with me." The text sentiment type is "sad," the text scenario theme type is "relationship breakup," and the sentence most relevant to the next sentence is "Can you tell me more about your experiences meeting her?" Then, when input into the knowledge detection model, its form is "I'm about to graduate from university, and my girlfriend wants to break up with me." <s>Emotion: Sadness <s>Subject: Breakup <s>Can you talk to me specifically about the experience of getting to know her?
[0053] In an embodiment of the present invention, the psychological knowledge graph is a triple in the field of psychology, which at least includes three words with attributes <disease, cause, manifestation> respectively, such as <depression, triggering cause, low mood>.
[0054] In an embodiment of the present invention, the knowledge keywords output by the knowledge detection model are three-word groups with an arrangement order. The three-word group at least includes three words with attributes <subject, relation, object> respectively. For example, <A, likes, B>. Therefore, before the knowledge detection model in the above step S102 outputs knowledge keywords, the generation method of knowledge keywords includes:
[0055] S1021. Match and output a three-word group according to the content keywords extracted by the knowledge detection model;
[0056] S1022. Convert the three-word group into a sentence to obtain a three-sentence group.
[0057] In an embodiment of the present invention, the acquisition of the sentence most relevant to the next sentence information is realized through a common sense generation task. Using a concept set and an automatically generated sentence that can describe this concept set, a target characteristic sentence set is formed as an alternative set of the sentence most relevant to the next sentence information. And the finally generated sentence cannot violate common sense. Therefore, the acquisition of the sentence most relevant to the next sentence information in the above step S102 includes:
[0058] Retrieve a sentence with the content closest to the three-word group from the target characteristic sentence set as the sentence most relevant to the next sentence information.
[0059] Based on this, the implementation method of the knowledge detection model in the above step S102 for outputting knowledge keywords can be:
[0060] Sort the sentences in the three-sentence group according to the sentence most relevant to the next sentence information, and output content keywords with an arrangement order through the sorting result. The content keywords with an arrangement order are the knowledge keywords.<T
[0061] In practical applications, when converting the three - word phrases into sentences through the above - mentioned step S1022, multiple results can be obtained. For example, based on <A, like, B>, sentences such as A likes B, B likes A, like A B can be obtained. Assuming that the sentence closest to the three - word phrase retrieved from the target feature sentence set is B also likes A, then the ranking of the sentence A likes B > the sentence B likes A > like A B, and the finally output knowledge keywords are [A, like, B]. Similarly, based on the sample data "I'm almost graduating from college, and my girlfriend proposed to break up with me", the knowledge keywords that can be obtained are [break up, make people feel, depressed].
[0062] S103. After splicing the knowledge keywords, text emotion type, text scene theme, and the sentence most relevant to the next - sentence information, generate control information, and use it together with the sample data to train the controlled text generation algorithm model.
[0063] In the embodiment of the present invention, the input of the controlled text generation algorithm model is the spliced knowledge keywords, text emotion type, text scene theme, the sentence most relevant to the next - sentence information, and the sample data. Based on the example in the above text, exemplarily, the content input in step S103 is "I'm almost graduating from college, and my girlfriend proposed to break up with me" <s>Breakups are always frustrating. <s>Emotion: Sadness <s>Subject: Breakup <s>Could you tell me more about your experience of getting to know her?
[0064] The sample data and control information serve as the initial signals for the additional input modules in the controlled text generation algorithm model, while the knowledge keywords act as the sequence signals for the sequence input modules. The training method for these modules is as follows:
[0065] The user-side psychological counseling question and answer data is concatenated with the control information to form a training set for training the controlled text generation algorithm model;
[0066] The next sentence information is used as the validation set for training the controlled text generation algorithm model.
[0067] It should be noted that, in this embodiment of the invention, the generation operation module of the controlled text generation algorithm model adopts a pre-trained text generation algorithm (Generative Pre-Training, GPT model). This model is an autoregressive language model, that is, it uses the words that have already appeared to predict the future words, and calculates the multilayer perceptron (MLP) loss to optimize the model parameters based on the probability of the predicted words.
[0068] In this embodiment of the invention, the training target module of the controlled text generation algorithm model uses gradient descent to update the model parameters. Specifically, η is set as the learning rate, which represents the magnitude of each parameter update. The parameters are iteratively calculated using the sample data, control information, and next sentence information until the convergence condition is reached. The convergence condition is that the loss function is less than a preset threshold or the number of training iterations is greater than a preset iteration threshold.
[0069] S104. Using the trained controlled text generation algorithm model, analyze the processed user-side psychological counseling question and answer data, and output the psychological counseling response from the machine-side psychological counseling question and answer data.
[0070] In step S104 above, the output of the psychological counseling response is generated as the output text. In this process, that is, the output of the output module, is completed by Top-p Sampling to avoid the problem that the controlled text generation algorithm model predicts a word in the output text at each stage, and the multiple texts output by the cluster search algorithm have high similarity and insufficient diversity of output text.
[0071] In practical applications, Top p Sampling uses a cumulative probability approach, sampling from words whose cumulative probability exceeds a certain threshold p. In this embodiment of the invention, the parameter p is adjusted (0 <= p <= 1). Top-PSampling increases the probability of generating words with lower occurrence probabilities, thereby increasing the diversity of the output text.
[0072] In this embodiment of the invention, the user-side psychological counseling question-and-answer data is obtained through a human-computer interactive psychological counseling process, that is, before step S104 above, it includes:
[0073] Obtain psychological counseling Q&A data from users through human-computer interaction;
[0074] Process the psychological counseling question and answer data on the user side.
[0075] The processing of the user-side psychological counseling question-and-answer data includes:
[0076] The user-side psychological counseling Q&A data is converted into the control information;
[0077] The user-side psychological counseling question and answer data is concatenated with the control information to generate processed user-side psychological counseling question and answer data.
[0078] In this embodiment of the invention, the processing of user-side psychological counseling question and answer data involves obtaining control information based on the user-side psychological counseling question and answer data through the processing methods in steps S101 to S103, namely, knowledge keywords, text sentiment type, text scene theme, and the sentence most relevant to the next sentence.
[0079] like Figure 2 As shown, this embodiment of the invention also provides a psychological counseling device 20 based on controlled text generation, comprising:
[0080] The sample data processing module 21 is used to input sample data into the sentiment detection model and the scene theme type recognition model; the sentiment detection model outputs the text sentiment type and the scene theme type recognition model outputs the text scene theme.
[0081] The knowledge keyword output module 22 is used to input the sample data, text sentiment type, and text scene theme into the knowledge detection model in combination with the psychological knowledge graph, and at the same time obtain the sentence most relevant to the next sentence, so that the knowledge detection model outputs knowledge keywords.
[0082] The controlled text generation algorithm model training module 23 concatenates the knowledge keywords, text sentiment type, text scene theme and the sentence most relevant to the next sentence to generate control information, and uses it together with the sample data to train the controlled text generation algorithm model.
[0083] The psychological counseling response output module 24 is used to analyze the processed user-side psychological counseling question and answer data through a trained controlled text generation algorithm model, and output the psychological counseling response from the machine-side psychological counseling question and answer data.
[0084] This invention also provides a terminal device including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the various steps of the psychological counseling method based on controlled text generation as described in the above embodiments.
[0085] This invention also provides a storage medium, which is a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it implements the various steps of the psychological counseling method based on controlled text generation as described in the above embodiments.
[0086] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the foregoing embodiments have described the present invention in detail, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.< / s> < / s> < / s> < / s> < / s> < / s> < / s> < / s>
Claims
1. A psychological counseling method based on controlled text generation, characterized in that, include: Input the sample data into the sentiment detection model and the scene theme type recognition model; The emotion detection model outputs the emotional type of the text, and the scene theme type recognition model outputs the scene theme of the text. The sample data, text sentiment type, and text scene theme are combined with a psychological knowledge graph and input into the knowledge detection model. At the same time, the sentence most relevant to the next sentence is obtained, and the sentence most relevant to the next sentence is input into the knowledge detection model so that the knowledge detection model outputs knowledge keywords. The knowledge keywords, text sentiment type, text scene theme and the sentence most relevant to the next sentence are concatenated to generate control information, which is then used together with the sample data to train the controlled text generation algorithm model. The trained controlled text generation algorithm model is used to analyze the processed user-side psychological counseling question and answer data, and output the psychological counseling response from the machine-side psychological counseling question and answer data. Before the knowledge detection model outputs knowledge keywords, the process includes: matching and outputting trigram phrases based on the content keywords extracted by the knowledge detection model; and converting the trigram phrases into sentences to obtain trigram sentence groups. Obtaining the sentence most relevant to the next information includes: retrieving a sentence from the target feature sentence set whose content is closest to the trigram phrase, as the sentence most relevant to the next information; The knowledge detection model outputs knowledge keywords, including: sorting the sentences of the three-element sentence group according to the sentence most relevant to the next sentence, and outputting content keywords with a sorting order based on the sorting results, wherein the content keywords with a sorting order are the knowledge keywords.
2. The psychological counseling method based on controlled text generation as described in claim 1, characterized in that, The control information is generated by concatenating the knowledge keywords, text sentiment type, text scene theme, and the sentence most relevant to the next sentence. This control information is then used together with the sample data to train the controlled text generation algorithm model. This includes: concatenating the user-side psychological counseling question and answer data with the control information as a training set for training the controlled text generation algorithm model; and using the next sentence information as a validation set for training the controlled text generation algorithm model.
3. The psychological counseling method based on controlled text generation as described in claim 1, characterized in that, The trained controlled text generation algorithm model analyzes the processed user-side psychological counseling question-and-answer data, and before outputting the machine-side psychological counseling question-and-answer data's psychological counseling response, it includes: Obtain psychological counseling Q&A data from users through human-computer interaction; Process the psychological counseling question and answer data on the user side.
4. The psychological counseling method based on controlled text generation as described in claim 3, characterized in that, Processing user-side psychological counseling question and answer data, including: The user-side psychological counseling Q&A data is converted into the control information; The user-side psychological counseling question and answer data is concatenated with the control information to generate processed user-side psychological counseling question and answer data.
5. A psychological counseling device based on controlled text generation, characterized in that, include: The sample data processing module is used to input sample data into the emotion detection model and the scene theme type recognition model; The emotion detection model outputs the emotional type of the text, and the scene theme type recognition model outputs the scene theme of the text. The knowledge keyword output module is used to input the sample data, text sentiment type, and text scene theme into the knowledge detection model in combination with the psychological knowledge graph. At the same time, it obtains the sentence most relevant to the next sentence and inputs the sentence most relevant to the next sentence into the knowledge detection model so that the knowledge detection model outputs knowledge keywords. Before the knowledge detection model outputs knowledge keywords, the process includes: matching and outputting trigram phrases based on the content keywords extracted by the knowledge detection model; and converting the trigram phrases into sentences to obtain trigram sentence groups. Obtaining the sentence most relevant to the next information includes: retrieving a sentence from the target feature sentence set whose content is closest to the trigram phrase, as the sentence most relevant to the next information; The knowledge detection model outputs knowledge keywords, including: sorting the sentences of the three-element sentence group according to the sentence most relevant to the next sentence information, and outputting content keywords with a sorting order based on the sorting result, wherein the content keywords with a sorting order are the knowledge keywords; The controlled text generation algorithm model training module concatenates the knowledge keywords, text sentiment type, text scene theme, and the sentence most relevant to the next sentence to generate control information, which is then used together with the sample data to train the controlled text generation algorithm model. The psychological counseling response output module is used to analyze the processed user-side psychological counseling question and answer data through a trained controlled text generation algorithm model, and output the psychological counseling response from the machine-side psychological counseling question and answer data.
6. A terminal device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, it implements the steps of the psychological counseling method based on controlled text generation as described in any one of claims 1 to 4.
7. A storage medium, said storage medium being a computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements each step of the psychological counseling method based on controlled text generation as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Emotion discovery and dispersion method and device in input scene
CN111241822A
Psychological disturbance scene matching method and device based on deep learning algorithm
CN111326234A