Psychological support question and answer generation method and system based on two-stage retrieval enhanced LLM

By conducting two-stage search in the external resource library, obtaining professional resources and guiding LLM to generate psychological support answers, the problem of professionalism and targeted responses that are difficult to control in LLM generation, achieving more efficient hardware resource utilization and better answer quality.

CN119760102AActive Publication Date: 2025-04-04豫章师范学院

Patent Information

Application Number
CN202510261082.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-06
Publication Date
2025-04-04
Estimated Expiration
2045-03-06

AI Technical Summary

Technical Problem

The prior art is difficult to accurately control the professionalism and pertinence of psychological support answers generated by large language models (LLM), and the high consumption of hardware resources by fine-tuning LLMs limits its application promotion.

Method used

A psychological support question-and-answer generation method based on two-stage search enhancement LLM is proposed. By conducting two-stage search in an external resource library, professional resources are obtained and LLM is guided to generate more professional and personalized psychological support answers.

Benefits of technology

The professionalism, relevance and empathy ability of generating answers was significantly improved. The evaluation results showed that the BLEU value was significantly improved, the accuracy and standardization of the answers were improved, and the help and empathy were also improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119760102A_ABST
    Figure CN119760102A_ABST
Patent Text Reader

Abstract

The invention provides a psychological support question and answer generation method and system based on two-stage retrieval enhanced LLM, and the method comprises the steps: carrying out a first-stage retrieval operation from an external resource library by taking an original question as a retrieval query condition, constructing a prompt by taking the original question and a retrieval result as a context prompt, and inputting the prompt into the LLM to generate a plurality of generated answers; the original question and the generated answer are fused to serve as a retrieval query condition to conduct second-stage retrieval operation from an external resource library, then the original question and a retrieval result serve as context prompts to construct prompts, the prompts are input into LLM to generate a final answer, and a psychological support answer is obtained. In order to solve the problem that the professionality and pertinence of answer generation are difficult to accurately control by purely using LLM to generate psychological support answers, professional resources are obtained from an external resource library through a two-stage retrieval enhancement method, the LLM is guided to generate more professional and personalized psychological support answers, and the psychological support answer generation efficiency is improved. Therefore, the overall performance of automatically generating psychological support answers by the LLM is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of natural language processing, and in particular to a method and system for generating psychological support questions and answers based on two-stage retrieval enhanced LLM. Background Art

[0002] Since traditional community interaction models often fail to meet users' needs for immediacy and personalization, the anonymity and convenience of online psychological support platforms have led more and more people with psychological or emotional distress to confide in these platforms. However, the rapid development of the platform has also led to increasing user requirements for service quality and efficiency. Faced with a large number of user questions and diverse mental health issues, professional psychological counselors and community managers are often unable to respond quickly and comprehensively. This not only affects the user experience, but may also lead to the failure to meet user needs in some emergency situations. Against this background, the automatic question-and-answer system for psychological support came into being. With its instant response and all-weather service, it has become a new way to solve mental health problems. Compared with manual consultation services, the automatic question-and-answer system for psychological support can quickly respond to user questions, provide personalized psychological support and suggestions, and greatly improve the convenience and accessibility of services. In addition, the automatic question-and-answer system can process a large amount of user data, analyze mental health trends, and provide users with more accurate services through artificial intelligence technology.

[0003] Large Language Model (LLM) is a natural language processing technology based on deep learning. By training a large-scale corpus, the model parameters range from billions to hundreds of billions. By learning the structure, grammar and semantics of the language, it can understand and generate natural language text. Currently, the commonly used LLMs include the GPT series (GPT-3, GPT-3.5, GPT-4, GTP-4o, etc.), LLaMA series and Claude from abroad, as well as Wenxin Yiyan, Zhipu Qingyan, Tongyi Qianwen, Doubao and Baichuan from China. With the rapid development and wide application of LLM, LLM for psychological support has also attracted more and more attention from scholars. Based on the five elements of human emotions: self-awareness, self-regulation, motivation, empathy and social skills, some scholars have applied the theory to LLM prompt engineering through the Chain of Thought (CoT), guiding LLM to generate more empathetic psychological support answers. Some scholars have combined cognitive behavioral therapy (CBT) in psychology with LLM prompt engineering to build a large language model for psychological support question and answer designed specifically for cognitive behavioral therapy. Other scholars have used the psychological support dialogue dataset to fine-tune the LLM and thus built an empathy dialogue LLM that includes multiple emotional support scenarios.

[0004] However, it is often difficult to accurately control the professionalism and pertinence of the generated answers by prompting LLM. In order to prompt LLM to generate more professional and personalized answers, users usually need to add some psychological professional-related content in the prompt. This method has caused new problems; the more prompt information provided, the more likely the generated support answer will focus on describing the given content, which limits the personalization and pertinence of the answer. At the same time, the requirement and high consumption of hardware resources for the method of fine-tuning LLM to generate psychological support answers limit its promotion and popularization in practical applications. Summary of the invention

[0005] In view of the above situation, the main purpose of the present invention is to propose a psychological support question and answer generation method and system based on two-stage retrieval enhanced LLM to solve the above technical problems.

[0006] The present invention proposes a psychological support question and answer generation method based on two-stage retrieval enhanced LLM, the method comprising the following steps: Step 1: Given an external resource library and the original problem; Step 2: Perform the first phase of search operation from the external resource library using the original question as the search query condition; In the first stage of retrieval, preliminary screening is performed from the external resource library based on the original question to obtain candidate answers, and then the local word order information and global semantic information of each word in the original question are used to screen again to obtain the first candidate answer; Step 3: Use the original question and the first candidate answer as contextual prompts to construct prompts, and input them into the LLM to generate several generated answers; Step 4: The original question and the generated answer are combined as search query conditions to perform a second-stage search operation from an external resource library to obtain a second candidate answer; Step 5: Use the original question and the second candidate answer as contextual prompts to construct prompts, and input them into LLM to generate the final answer to obtain the psychological support answer.

[0007] The present invention also proposes a psychological support question and answer generation system based on two-stage retrieval enhanced LLM, wherein the system applies the psychological support question and answer generation method based on two-stage retrieval enhanced LLM as described above, and the system comprises: Data acquisition module, used to: Given an external repository and the original problem; The first stage retrieval module is used to: Perform the first stage of retrieval operation from the external resource library using the original question as the retrieval query condition; In the first stage of retrieval, preliminary screening is performed from the external resource library based on the original question to obtain candidate answers, and then the local word order information and global semantic information of each word in the original question are used to screen again to obtain the first candidate answer; The first stage generates modules for: Use the original question and the first candidate answer as contextual prompts to construct prompts, and input them into the LLM to generate several generated answers; The second stage retrieval module is used to: The original question and the generated answer are combined as search query conditions to perform a second-stage search operation from an external resource library to obtain a second candidate answer; The second stage generates modules for: The original question and the second candidate answer were used as contextual prompts to construct prompts, which were input into LLM to generate the final answer and obtain the psychological support answer.

[0008] Compared with the prior art, the present invention has the following beneficial effects: The present invention aims at the problem that it is often difficult to accurately control the professionalism and pertinence of the generated answers when simply using LLM to generate psychological support answers. The present invention proposes a two-stage retrieval enhancement method, obtains professional resources through retrieval from an external resource library, and effectively uses professional resources to guide LLM to generate more professional and personalized psychological support answers, thereby improving the overall performance of LLM automatically generating psychological support answers. The professionalism, relevance and empathy of the generated answers are effectively improved. In terms of automatic evaluation, BLEU, ROUGE, D-1, and D-2 indicators are used for comprehensive evaluation. The evaluation results show that the BLEU value of the two-stage retrieval enhancement method proposed in the present invention has been significantly improved, which indicates that the generated psychological support answers are closer to the reference text at the vocabulary and phrase levels, and the accuracy and standardization of the answers have been improved. In terms of manual evaluation, pertinence, relevance, helpfulness and empathy indicators are used for evaluation. The evaluation results show that the present invention has achieved a good improvement in helpfulness and empathy, indicating that the present invention can more effectively identify and solve the psychological problems of the help-seekers, and the suggestions and strategies provided are more in line with the needs of the help-seekers. At the same time, it has also been well improved in understanding human emotions and care.

[0009] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description or learned through embodiments of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] Figure 1 It is a flow chart of the psychological support question and answer generation method based on two-stage retrieval enhanced LLM proposed by the present invention; Figure 2This is an architecture diagram of the psychological support question and answer generation method based on two-stage retrieval enhanced LLM proposed by the present invention; Figure 3 This is a schematic diagram of the structure of the psychological support question and answer generation system based on two-stage retrieval enhanced LLM proposed in the present invention. DETAILED DESCRIPTION

[0011] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.

[0012] These and other aspects of the embodiments of the present invention will be apparent with reference to the following description and accompanying drawings. In these descriptions and accompanying drawings, some specific implementations of the embodiments of the present invention are specifically disclosed to represent some ways of implementing the principles of the embodiments of the present invention, but it should be understood that the scope of the embodiments of the present invention is not limited thereto.

[0013] See also Figure 1 and Figure 2 This embodiment provides a psychological support question and answer generation method based on two-stage retrieval enhanced LLM, the method comprising the following steps: Step 1: Given an external resource library and the original problem; Step 2: Perform the first-stage search operation from the external resource library using the original question as the search query condition to obtain the first candidate answer; As a preferred embodiment of the present invention, the process corresponding to the first-stage search operation from the external resource library using the original question as the search query condition has the following relationship:

[0014] in, Represents the first stage of retrieval operation, Indicates the original problem, According to the original question q The previous results retrieved from the external resource library k The first candidate answer is formed by candidate answers. represents a collection of issues in an external repository, express Length.

[0015] As a preferred embodiment of the present invention, the first stage search operation specifically includes the following steps: The original question is used as the search query condition, and the BM25 search method is used to calculate the similarity between the original question and each question in the external resource library to obtain the BM25 score. The corresponding process has the following relationship: ; in, Represents the original problem q A word in Expressive words t In question The word frequency in represents the average document length of the entire collection, represents two different hyperparameters, Representation problem Length, Expressive words t The inverse document frequency of the word t The calculation process of the inverse document frequency has the following relationship: ; in, represents the logarithmic function, ; Indicates that the external resource library contains the word t The number of questions.

[0016] Get the first several candidate answers based on BM25 score ; Traverse the candidate answers and obtain the occurrence position of the word in the candidate answers; According to the position of the word in the candidate answer, calculate the position of each word pair in the original question in the candidate answer The minimum distance in the answer is calculated, and the context window score is calculated based on the minimum distance and the frequency of occurrence of the word in the candidate answer. The corresponding process has the following relationship: ; in, Represents a word pair, Represents several candidate answers obtained based on BM25 scores. represents the context window score, Expressive words In the candidate answer The frequency of occurrence in Expressive words In the candidate answer The frequency of occurrence in Representing word pairs In the candidate answer The minimum distance that appears in ; According to the consistency between the word order in the candidate answer and the original question word, the corresponding word order weight is assigned, and the context window score is adjusted using the word order weight to obtain the adjusted context window score. The corresponding process has the following relationship: ; in, represents the adjusted context window score, represents the order factor, Indicates that the order is consistent. Indicates that the order is inconsistent; The context window scores of all word pairs are accumulated to obtain the final context window score. The corresponding process has the following relationship: ; in, represents the final context window score; The pre-trained DPR model is used to encode the original question and candidate answers respectively to generate semantic embedding vectors of the original question and candidate answers. The corresponding process has the following relationship: ; in, represents the query encoder, represents a paragraph encoder, The semantic embedding vector representing the original question, The semantic embedding vector representing the candidate answer; The context window score of the candidate answer is concatenated as a scalar feature into the semantic embedding vector of the candidate answer to obtain the enhanced semantic embedding vector of the candidate answer. The corresponding process has the following relationship: ; in, The semantic embedding vector representing the enhanced candidate answer, Represents a splicing operation; According to the semantic embedding vector of the original question and the semantic embedding vector of the enhanced candidate answer, the cosine similarity is used to calculate the semantic relevance of the original question and the candidate answer to obtain the semantic embedding score. The corresponding process has the following relationship: ; in, represents the semantic embedding score, represents the norm; The BM25 score, the final context window score, and the semantic embedding score are combined to obtain the final candidate answer score. The corresponding process has the following relationship: ; in, represents the final candidate answer score, represents the BM25 score, represents the final context window score, represents the semantic embedding score, They represent the weight coefficients corresponding to the BM25 score, the final context window score, and the semantic embedding score, respectively. Indicates the original problem, Represents each issue in the external repository; According to the final candidate answer score, select the top k The candidate answer is the first candidate answer .

[0017] In the above scheme, in order to find a balance between efficiency and effect, the present invention adopts a phased retrieval strategy, that is, firstly, the candidate answers are quickly screened out by an efficient algorithm, and then the candidate answers are finely sorted by the algorithm. This method can significantly reduce the computing cost while retaining a high retrieval performance.

[0018] Among them, BM25 is a very efficient retrieval algorithm. It is based on inverted index calculation and can quickly process large-scale corpora. Through the phased retrieval method, using BM25's efficient initial screening ability and context window and semantic embedding deep fine sorting ability, efficient and accurate candidate answer retrieval can be achieved in large-scale corpora.

[0019] In order to ensure better screening effect, the present invention takes into account word order and word frequency in the process of calculating the context window score, so as to take into account both global semantic relevance and local word arrangement relationship, which is more suitable for phrase-type scenarios and further enhances its effect and expression ability.

[0020] In addition, the context window score is a scalar feature, and the splicing operation is simple, which has little impact on the model's computational overhead. In order to ensure better performance in phrase-based scenarios, the context window score is spliced ​​with the embedding vectors of the word and candidate answer. The context window score provides the positional relationship of the query word in the candidate answer, which can help the model to more accurately evaluate the matching of phrases and word combinations. The spliced ​​vector contains both the global semantic information of the DPR model and the local word order information of the context window, which can more comprehensively measure the relevance of the candidate answers. It has a significant effect on phrase-based queries and multi-word queries, and can better match relevant candidate answers. And in the sorting task, the top k The relevance of candidate answers is improved, and the user experience is improved.

[0021] Step 3: Use the original question and the first candidate answer as contextual prompts to construct prompts, and input them into the LLM to generate several generated answers; As a preferred embodiment of the present invention, the original question and the first candidate answer are used as context prompts to construct prompts, and the prompts are input into the LLM to generate several generated answers. The corresponding process has the following relationship: ; in, Generates an answer. represents a large language model, Indicates task instructions. Indicates the use of task instructions s , original question q and the first candidate answer retrieved The built prompt, Indicates the first n Answers.

[0022] Examples of LLM prompts of the present invention are shown in the following table.

[0023]

[0024] Step 4: The original question and the generated answer are combined as search query conditions to perform a second-stage search operation from an external resource library to obtain a second candidate answer; As a preferred embodiment of the present invention, the original question and the generated answer are merged as search query conditions to perform a second-stage search operation from an external resource library, and obtaining the second candidate answer specifically includes the following steps: The original question and each of the generated answers are connected to obtain an enhanced query. The corresponding process has the following relationship: ; in, Indicates enhanced query, Indicates a connection operation; Based on the enhanced query, the second stage of retrieval operation is performed in the external resource library to obtain the second candidate answer. The corresponding process has the following relationship: ; here, Indicates the top results retrieved from the external resource library based on the enhanced query. m The second candidate answer is formed by candidate answers. express Length, Represents a second-stage retrieval operation.

[0025] In this embodiment, the second stage search operation is performed in the same manner as the first stage search operation, with the only difference being the number of second candidate answers formed by inputting and finally selecting candidate answers. Therefore, no further elaboration will be given.

[0026] Step 5: Use the original question and the second candidate answer as contextual prompts to construct prompts, and input them into LLM to generate the final answer to obtain the psychological support answer.

[0027] As a preferred embodiment of the present invention, the original question and the second candidate answer are used as context prompts to construct prompts, and are input into the LLM to generate the final answer. The process corresponding to the psychological support answer is as follows: ; in, Indicates the final answer, Indicates that the enhanced query retrieves the results from the external resource library m Candidate answers.

[0028] Please refer to Figure 3 This embodiment also provides a psychological support question and answer generation system based on two-stage retrieval enhanced LLM, wherein the system applies the psychological support question and answer generation method based on two-stage retrieval enhanced LLM as described above, and the system includes: Data acquisition module, used to: Given an external repository and the original problem; The first stage retrieval module is used to: Perform the first stage of retrieval operation from the external resource library using the original question as the retrieval query condition; In the first stage of retrieval, preliminary screening is performed from the external resource library based on the original question to obtain candidate answers, and then the local word order information and global semantic information of each word in the original question are used to screen again to obtain the first candidate answer; The first stage generates modules for: Use the original question and the first candidate answer as contextual prompts to construct prompts, and input them into the LLM to generate several generated answers; The second stage retrieval module is used to: The original question and the generated answer are combined as search query conditions to perform a second-stage search operation from an external resource library to obtain a second candidate answer; The second stage generates modules for: The original question and the second candidate answer were used as contextual prompts to construct prompts, which were input into LLM to generate the final answer and obtain the psychological support answer.

[0029] In order to illustrate the advantages of the present invention over the prior art in more detail, in this embodiment, ChatGPT3.5 is used as the LLM for the entire two-stage retrieval enhancement, and ChatGPT3.5 is operated by calling the API interface provided by OpenAI.

[0030] The external resource library integrates three widely used psychological support question and answer datasets, namely the PsyQA dataset constructed by Tsinghua University, the EfaQA jointly constructed by Stanford University, UCLA, and Fu Jen Catholic University Clinical Psychology, and the SoulChatCorpus dataset constructed by South China University of Technology. After data preprocessing, a comprehensive psychological support question and answer resource library named PesQA is constructed, covering a wide range of psychological topics and a variety of question and answer categories. The resource library exists in the form of question and answer pairs, including the content of the help-seekers' questions and the corresponding answers of the psychological counselors to the questions, as an external professional psychological support question and answer resource library used for retrieval enhancement.

[0031] The present invention adopts two methods of automatic evaluation and manual evaluation for evaluation. The automatic evaluation indicators are BLEU, ROUGE, Distinct-1 (D1), and Distinct-2 (D2).

[0032] (1) BLEU (Bilingual Evaluation Understudy): A bilingual evaluation auxiliary tool. The core idea is to compare the candidate translation with the reference translation. n-gram (continuous n The higher the overlap, the higher the translation quality. Unigram is used to measure the accuracy of word translation. n-gram It is used to measure the fluency of sentence translation. n =1~4, and then take a weighted average of the results. The calculation formula of BLEU is as follows: ; in, P Represents continuous generation n The penalty coefficient ranges from 0 to 1. When the length of the generated result is the same as the target result, the value is 1. When the generated result is shorter than the target result, the value is less than 1. weight is a weight assigned to each gram. BLEU ranges from 0 to 1. The larger the value, the better the generated result.

[0033] (2) ROUGE (Recall-Oriented Understudy for Gisting Evaluation): It can be considered an improved version of BLEU, focusing on recall rather than precision. It mainly calculates how many n-grams in the original reference sentence appear in the output. ROUGE is roughly divided into four types: ROUGE-N (optimizes BLEU's precision to recall), ROUGE-L (optimizes BLEU's n-gram optimized for common subsequences), ROUGE-W (giving higher rewards to consecutive matches of ROUGE-L), and ROUGE-S (allowing n-gram The present invention uses ROUGE-N as the evaluation index. "N" refers to n- gram , which is calculated in a similar way to BLEU, except that BLEU is based on precision, while ROUGE is based on recall.

[0034] (3) Distinct: In the process of text generation, we also need to pursue the diversity of the text. The Distinct indicator is used to evaluate the diversity of the text. The definition of Distinct is as follows: ; in, Indicates that the generated text is not repeated n-gram quantity, Indicates that the generated text n-gram The total number of words. Distinct-1 means 1-gram , Distinct-2 means 2-gram . Distinct- n The larger the value, the higher the diversity generated. The present invention uses Distinct-1 (D-1) and Distinct-2 (D-2) as evaluation indicators.

[0035] In order to better evaluate the quality of the generated answers, the present invention also performs manual evaluation. In the manual evaluation task, the present invention mainly evaluates the generation effect of the psychological support answers generated by LLM. The manual evaluation indicators used by the present invention include: (1) Targetedness: Whether the answer is targeted and personalized to the user; (2) Relevance: whether the answer is relevant to the user’s question; (3) Helpfulness: whether the answer can provide helpful suggestions; (4) Empathy: Whether the answer has appropriate emotions or empathic responses, such as warmth, sympathy, and concern. A 10-point scale is used, where 1-3 points represent a "poor" answer and 8-10 points represent a "good" answer.

[0036] 1. Experimental results This paper conducts a comparative experiment on the proposed two-stage retrieval enhanced LLM method (abbreviated as index-2), and the comparison method used is as follows: (1) Zero-shot: Zero-shot prompting method, which directly asks the original question of the person seeking help. q The corresponding task description is input to the LLM without adding any other contextual conditions. This method relies only on the LLM's own text understanding and processing capabilities to generate the original question. q The corresponding answer.

[0037] (2) Few-shot: The few-shot prompting method provides the LLM with several task-related input-output pairs. In this task, the LLM is fed with several similar examples of help-seeker questions and corresponding answer posts. The LLM is then prompted by the examples and the corresponding task descriptions to learn the rules of the task and generate the original question. q The corresponding answer.

[0038] (3) CoT (Chain of Thought): This method uses the prompt “Please answer step by step” to ask LLM to first provide an idea or reasoning process for answering the question before generating the final answer, so as to better understand and generate the corresponding answer.

[0039] (4) Index-1: One-stage search enhancement method, which is a simplified version of the two-stage search enhancement LLM method (index-2) of the present invention, that is, only the first-stage search is performed without the second-stage enhanced query. The purpose of performing index-1 comparison is to verify the effectiveness of the second-stage enhanced query.

[0040] The automatic evaluation experiment results are shown in the following table.

[0041]

[0042] The results of the manual evaluation experiment are shown in the following table.

[0043]

[0044] In view of the problem that it is difficult to accurately control the professionalism and personalization of answers when only LLM prompts are used to generate psychological support answers, the present invention proposes a psychological support question and answer generation method based on two-stage retrieval enhanced LLM. First, a professional external psychological support question and answer resource library PesQA is constructed, and then the original question is used as a query condition to perform a two-stage retrieval enhanced query in the external resource library PesQA. By adding professional resources in the external resource library, LLM is guided and stimulated to generate more professional and personalized psychological support answers, thereby improving the overall performance of LLM in automatically generating psychological support answers. The present invention has important practical significance for improving the generation effect and quality of the online psychological support automatic question and answer model, as well as the in-depth development of the online psychological support automatic question and answer technology, and at the same time provides useful insights and references for the automation and high-quality development of the online psychological support platform.

[0045] It should be understood that, although each step in the flow chart of each embodiment of the present invention is shown in sequence according to the indication of the arrow, these steps are not necessarily performed in sequence according to the order indicated by the arrow. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be performed in other orders. Moreover, at least a portion of the steps in each embodiment may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these sub-steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with at least a portion of other steps or sub-steps or stages of other steps.

[0046] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0047] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.

[0048] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

Claims

1. A psychological support question and answer generation method based on two-stage retrieval enhanced LLM, characterized in that: The method comprises the following steps: Step 1: Given an external resource library and the original problem; Step 2: Perform the first phase of search operation from the external resource library using the original question as the search query condition; In the first stage of retrieval, preliminary screening is performed from the external resource library based on the original question to obtain candidate answers, and then the local word order information and global semantic information of each word in the original question are used to screen again to obtain the first candidate answer; Step 3: Use the original question and the first candidate answer as contextual prompts to construct prompts, and input them into the LLM to generate several generated answers; Step 4: The original question and the generated answer are combined as search query conditions to perform a second-stage search operation from an external resource library to obtain a second candidate answer; Step 5: Use the original question and the second candidate answer as contextual prompts to construct prompts, and input them into LLM to generate the final answer to obtain the psychological support answer.

2. The psychological support question and answer generation method based on two-stage retrieval enhanced LLM according to claim 1 is characterized in that: In step 2, the process corresponding to the first-stage search operation from the external resource library using the original question as the search query condition has the following relationship: ; in, Represents the first stage of retrieval operation, Indicates the original problem, According to the original question q The previous results retrieved from the external resource library k The first candidate answer is formed by candidate answers. represents a collection of issues in an external repository, express Length.

3. The psychological support question and answer generation method based on two-stage retrieval enhanced LLM according to claim 2 is characterized in that: The first stage of retrieval operation specifically includes the following steps: Use the original question as the search query condition, use the BM25 search method to calculate the similarity between the original question and each question in the external resource library, and obtain the BM25 score; Get the first several candidate answers based on BM25 score ; Calculate the final context window score of each candidate answer relative to the original question; Calculate the semantic embedding score of each candidate answer relative to the original question; The BM25 score, the final context window score, and the semantic embedding score are combined to obtain the final candidate answer score. The corresponding process has the following relationship: ; in, represents the final candidate answer score, represents the BM25 score, represents the final context window score, represents the semantic embedding score, They represent the weight coefficients corresponding to the BM25 score, the final context window score, and the semantic embedding score, respectively. Represents several candidate answers obtained based on BM25 scores. Represents each issue in the external repository; According to the final candidate answer score, select the top k The candidate answer is the first candidate answer .

4. The psychological support question and answer generation method based on two-stage retrieval enhanced LLM according to claim 3 is characterized in that: The BM25 score calculation process has the following relationship: ; in, Indicates the original problem q A word in Expressive words t The inverse document frequency of Expressive words t In question The word frequency in represents the average document length of the entire collection, represents two different hyperparameters, Representation problem Length.

5. The psychological support question and answer generation method based on two-stage retrieval enhanced LLM according to claim 4 is characterized in that: word t The calculation process of the inverse document frequency has the following relationship: ; in, represents the logarithmic function, ; Indicates that the external resource library contains the word t The number of questions.

6. The psychological support question and answer generation method based on two-stage retrieval enhanced LLM according to claim 5 is characterized in that: The specific steps for calculating the final context window score of each candidate answer relative to the original question are as follows: Traverse the candidate answers and obtain the occurrence position of the word in the candidate answers; According to the position of the word in the candidate answer, the minimum distance of each word pair in the original question in the candidate answer is calculated, and the context window score is calculated according to the minimum distance and the frequency of the word in the candidate answer. The corresponding process has the following relationship: ; in, Represents a word pair, represents the context window score, Expressive words In the candidate answer The frequency of occurrence in Expressive words In the candidate answer The frequency of occurrence in Representing word pairs In the candidate answer The minimum distance that appears in ; According to the consistency between the word order in the candidate answer and the original question word, the corresponding word order weight is assigned, and the context window score is adjusted using the word order weight to obtain the adjusted context window score. The corresponding process has the following relationship: ; in, represents the adjusted context window score, represents the order factor, Indicates that the order is consistent. Indicates that the order is inconsistent; The context window scores of all word pairs are accumulated to obtain the final context window score. The corresponding process has the following relationship: ; in, Represents the final context window score.

7. The psychological support question and answer generation method based on two-stage retrieval enhanced LLM according to claim 6 is characterized in that: The specific steps for calculating the semantic embedding score of each candidate answer relative to the original question are as follows: The pre-trained DPR model is used to encode the original question and candidate answers respectively to generate semantic embedding vectors of the original question and candidate answers. The corresponding process has the following relationship: ; in, represents the query encoder, represents a paragraph encoder, The semantic embedding vector representing the original question, The semantic embedding vector representing the candidate answer; The context window score of the candidate answer is concatenated as a scalar feature into the semantic embedding vector of the candidate answer to obtain the enhanced semantic embedding vector of the candidate answer. The corresponding process has the following relationship: ; in, The semantic embedding vector representing the enhanced candidate answer, Represents a splicing operation; According to the semantic embedding vector of the original question and the semantic embedding vector of the enhanced candidate answer, the cosine similarity is used to calculate the semantic relevance of the original question and the candidate answer to obtain the semantic embedding score. The corresponding process has the following relationship: ; in, represents the semantic embedding score, Represents the norm.

8. The psychological support question and answer generation method based on two-stage retrieval enhanced LLM according to claim 7 is characterized in that: In step 3, using the original question and the first candidate answer The process of constructing a prompt as a contextual prompt and inputting it into the LLM to generate several generated answers has the following relationship: ; in, Generates an answer. represents a large language model, Indicates task instructions. Indicates the use of task instructions s , original question q and the first candidate answer retrieved The built prompt, Indicates the first n Answers.

9. The psychological support question and answer generation method based on two-stage retrieval enhanced LLM according to claim 8, characterized in that: In step 4, the original question and the generated answer are merged as search query conditions to perform a second-stage search operation from an external resource library, and obtaining the second candidate answer specifically includes the following steps: The original question and each of the generated answers are connected to obtain an enhanced query. The corresponding process has the following relationship: ; in, Indicates enhanced query, Indicates a connection operation; Based on the enhanced query, the second stage of retrieval operation is performed in the external resource library to obtain the second candidate answer. The corresponding process has the following relationship: ; here, Indicates the top results retrieved from the external resource library based on the enhanced query. m The second candidate answer is formed by the candidate answers. express Length, Represents a second-stage retrieval operation.

10. A psychological support question and answer generation system based on two-stage retrieval enhanced LLM, characterized in that: The system applies the psychological support question and answer generation method based on two-stage retrieval enhanced LLM as described in any one of claims 1 to 9, and the system comprises: Data acquisition module, used to: Given an external repository and the original problem; The first stage retrieval module is used to: Perform the first stage of retrieval operation from the external resource library using the original question as the retrieval query condition; In the first stage of retrieval, preliminary screening is performed from the external resource library based on the original question to obtain candidate answers, and then the local word order information and global semantic information of each word in the original question are used to screen again to obtain the first candidate answer; The first stage generates modules for: Use the original question and the first candidate answer as contextual prompts to construct prompts, and input them into the LLM to generate several generated answers; The second stage retrieval module is used to: The original question and the generated answer are combined as search query conditions to perform a second-stage search operation from an external resource library to obtain a second candidate answer; The second stage generates modules for: The original question and the second candidate answer were used as contextual prompts to construct prompts, which were input into LLM to generate the final answer and obtain the psychological support answer.

Citation Information

Patent Citations

  • Text similarity measure method combining word clustering and word combination semantic features

    CN108399163A

  • Multi-engine intelligent question answering system for multi-type knowledge base

    CN115238101A

  • Context window-based large language model construction method and system

    CN117932038A

  • Data enhancement method and device based on large model and multi-order retrieval

    CN118193695A

  • Question and answer pair generation method and system based on large language model

    CN118332086A

Cited By

  • Automatic psychological support answer generation method based on LLMs iterative correction

    CN121117165A

  • Psychological support answer automatic generation method based on LLMs iterative correction

    CN121117165B

  • Multi-strategy fusion large model retrieval enhancement generation method

    CN121166867A