A ChatGLM2-based caring robot conversation method, device and medium
By constructing a balanced instruction dataset and fine-tuning the ChatGLM2 model using LoRA, the problems of understanding and communication experience in the interaction between emotional care robots and the elderly were solved, achieving a more natural and emotional communication and emotional care effect.
Patent Information
- Application Number
- CN202311091053.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-29
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2043-08-29
AI Technical Summary
Existing large-scale language models are unable to accurately understand the language expressions and emotional needs of the elderly in emotional care robots, resulting in a poor communication experience and privacy and security issues.
We collected real conversation data from elderly people, constructed a balanced instruction dataset, and fine-tuned the ChatGLM2 model using the LoRA method and cross-entropy loss function to optimize its emotional communication ability.
It enhances the robot's ability to communicate naturally and provide emotional support to the elderly, alleviating their loneliness and anxiety and improving their quality of life.
Smart Images

Figure CN117131941B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a care robot dialogue method, device, and medium based on ChatGLM2, belonging to the field of emotional robot technology. Background Technology
[0002] In modern society, the aging population is becoming an increasingly serious problem, and the emotional care and companionship of the elderly has become an important social issue. Large-scale model-based emotional care robots have enormous potential to provide intelligent companionship and emotional support for the elderly. However, achieving natural communication with the elderly requires overcoming the challenges of language comprehension and expression.
[0003] Currently, large language models (such as the GPT series models) have achieved great success in natural language processing tasks. However, directly applying these large models to the dialogue of emotional care robots often results in the models being unable to understand the unique language expressions and emotional needs of the elderly due to differences in training data and application scenarios.
[0004] Several research and applications have emerged regarding technologies for emotional robots or dialogue systems. Among these, deep learning-based chat engines are a typical example. They can generate answers word-by-word or character-by-character from user input and then send the response to the user. Most of these technologies employ an Encoder-Decoder model, which has the following drawbacks:
[0005] Insufficient verticality: Existing large-scale language models are often trained on large-scale general datasets, which cannot fully meet the emotional communication needs of specific domains or special user groups, and their understanding of the language expression and emotional needs of the elderly is not accurate enough.
[0006] Insufficient emotional understanding: Most existing technologies have not conducted in-depth research on emotional understanding, and cannot effectively identify and understand users' emotional states, resulting in emotional responses that are not detailed or considerate enough.
[0007] Poor communication experience: Existing dialogue engines may have mechanical and rigid responses, failing to engage in natural and emotional communication with users and lacking the ability for emotionally intelligent interaction.
[0008] Lack of datasets: There are relatively few datasets on emotional communication for the elderly, which limits the application and effectiveness of dialogue engines in the field of emotional care for the elderly.
[0009] Privacy and security issues: Some existing technologies may pose privacy and security problems in the processing and storage of user data, which may easily cause user concerns and resistance.
[0010] Inadequate adaptation to the language characteristics of the elderly: Older adults may have specific habits and idioms in their language expression, which existing technologies may struggle to understand and respond to accurately. Summary of the Invention
[0011] The purpose of this invention is to provide a care robot dialogue method, device, and medium based on ChatGLM2, which improves the emotional communication ability of the dialogue to achieve the ability of emotional care.
[0012] To achieve the above objectives, the present invention employs the following technical solution:
[0013] Collect real conversation data of the elderly, conduct random sampling, and mark the conversation data containing emotional care in the sampled data.
[0014] The labeled dialogue data is combined into an instruction dataset and preprocessed to balance the number and types of samples in the instruction dataset.
[0015] The processed instruction dataset is input into the Chatglm2-6b model, fine-tuned using the LoRA method, and then the model is trained.
[0016] The trained model is then fine-tuned sequentially using the cross-entropy loss function and the AdamW optimizer to obtain the final model.
[0017] Preferably, the instruction dataset is divided into five categories of care instruction data, including weather care, health care, social interaction, learning interest, and entertainment interest.
[0018] Preferably, the number and types of samples in the balance instruction dataset include the following methods: adjusting the number of care instructions of different categories, selecting the number of a certain category as an intermediate quantity, and controlling the fluctuation range of the number of other categories of instructions to be n, where n < 10.
[0019] Preferably, the fine-tuning using the LoRA method is specifically implemented as follows:
[0020] A pre-trained language model is constructed to map the input text to the output text representation. The model is as follows:
[0021] h=Wx;
[0022] Where: h is the output representation, W is the weight matrix of the pre-trained model, and x is the input text representation;
[0023] The LoRA operation is introduced, which fixes the parameters of the pre-trained language model during training and adds a new weight matrix.
[0024] During training, only the reduced-dimensional matrix A and the increased-dimensional matrix B are trained, while the input and output dimensions of the model remain unchanged. When outputting, matrices B and A are superimposed with the parameters of the pre-trained language model to obtain the final model parameters.
[0025] Preferably, the dimension reduction matrix A is initialized using a random Gaussian distribution, and the dimension increase matrix B is initialized using a zero matrix.
[0026] The advantages of this invention are:
[0027] A more natural communication experience. The ChatGLM2-based care robot dialogue engine, through instruction fine-tuning technology, enables the robot to engage in more natural and fluent communication with the elderly. The optimized model can more accurately understand the elderly's speech and respond in a way that better suits their context and emotional needs.
[0028] Enhanced Emotional Support Capabilities. Through fine-tuning and training, the care robot's emotional communication capabilities have been improved. The robot can now respond to elderly people's conversations in a warmer and more considerate manner, conveying more emotional support and companionship, thereby helping the elderly alleviate loneliness and anxiety, improve their mental state, and enhance their quality of life.
[0029] Solving the problem of monotonous responses. The problem of monotonous responses, common in existing technologies, is resolved. Through LoRA fine-tuning technology, the model can generate more diverse and emotional responses, avoiding single, repetitive replies in robot dialogue and improving the quality of communication. Attached Figure Description
[0030] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.
[0031] Figure 1 This is a schematic diagram of the model structure of the present invention. Detailed Implementation
[0032] 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. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0033] 1. Construction of instruction dataset
[0034] The construction of the instruction dataset is crucial, as it forms the foundation for guiding the ChatGLM2 model in learning to communicate emotionally with older adults. The following steps are necessary to ensure the quality and validity of the data when constructing the instruction dataset:
[0035] a. Collect authentic dialogue data: Gather authentic dialogue data with older adults through various channels. This can include conducting interviews in older adults' communities, collecting comments from older adults on social media platforms, or obtaining their opinions and needs through online questionnaires. This authentic dialogue data should cover aspects such as older adults' everyday language, emotional expressions, and typical questions.
[0036] b. Construct the instruction dataset:
[0037] Combine dialogue data with emotional support into an instruction dataset. Ensure the instruction dataset contains a rich variety of emotionally supportive instruction samples. Specific instruction examples in the dataset can include the following, covering areas of daily concern for older adults, such as:
[0038] Weather-related:
[0039] Type: "How's the weather today?"
[0040] Output: "It's quite cold today, remember to keep warm."
[0041] Health care category:
[0042] Input: "How to maintain good health?"
[0043] Output: "Maintaining a regular diet and moderate exercise are key to maintaining good health."
[0044] Social interaction category:
[0045] Type: "I feel a bit lonely, do you have any social activities you would recommend?"
[0046] Output: "Consider participating in community activities, making new friends, or joining hobby groups. Interacting with people will make you feel warmer."
[0047] Learning interest category:
[0048] Input: "I want to learn how to use a mobile phone. Are there any recommended learning resources?"
[0049] Output: "There are many online tutorials and video lessons that can help you learn to use your phone. I can help you find some learning resources."
[0050] Entertainment and hobby categories:
[0051] Input: "I like listening to music, can you recommend some classic old songs for me?"
[0052] Output: "Of course, I recommend some classic old songs, such as... I hope you will like them."
[0053] c Balanced dataset:
[0054] When constructing the instruction dataset, it is important to balance the number and types of samples to ensure that the model improves its domain-specific capabilities while maintaining its general domain-specific capabilities.
[0055] Category balance: This ensures that the number of instruction samples across different emotional care domains is roughly equal, preventing any particular domain from appearing too frequently and causing the model to be biased towards that specific domain. To prevent the model from losing its generality during fine-tuning, a general domain dataset is included, with the ratio of the care dataset to the general dataset being 1:5. The general dataset uses the open-source COIG-PC dataset, which includes translation instructions, exam instructions, and human value alignment instructions.
[0056] Random sampling: Samples are randomly drawn from the collected real dialogue data to maintain data diversity while avoiding over-concentration on certain specific dialogue scenarios.
[0057] Frequently Asked Questions Coverage: Ensure that the instruction dataset covers common questions and areas of concern for older adults in order to provide comprehensive emotional support.
[0058] By using the methods described above, a balanced instruction dataset can be constructed, ensuring that the model has sufficient samples to learn from in various emotional care domains, thereby enabling it to better respond to users' questions.
[0059] The instruction dataset constructed through the above steps will serve as training data for the instruction fine-tuning process, guiding the ChatGLM2 model to learn emotionally caring communication with the elderly, thus achieving more considerate and warm dialogue responses. The data is constructed in JSON format, as shown in the example below:
[0060] {"input": "How's the weather today?",
[0061] Output: "It's cold today, remember to wear warm clothes and take care of your health."
[0062] },
[0063] 2. Fine-tuning the Chatglm2-6b model using the LoRA method:
[0064] The constructed instruction dataset is input into the model for fine-tuning using LoRA. The principle of LoRA is not complicated. Its core idea is to add a bypass next to the original pre-trained language model and perform a dimensionality reduction and then dimensionality increase operation to simulate the so-called intrinsic rank (the process of the pre-trained model generalizing on various downstream tasks is actually optimizing a very small number of free parameters in the common low-dimensional intrinsic subspace of various tasks).
[0065] First, we have a pre-trained language model, which can be viewed as a function that maps the input text to the output text representation. This function can be expressed as: h = Wx (e.g., ... Figure 1 The blue part represents the area.
[0066] Where h is the output representation, W is the weight matrix of the pre-trained model, and x is the input text representation. Now, we want to fine-tune this model for a specific task to better adapt it to that task. We introduce the LoRA operation, where the parameters of the pre-trained language model are fixed during training, and a new weight matrix is added. This operation can be represented as: h' = BAx. During training, only the dimensionality reduction matrix A and the dimensionality increase matrix B are trained. The input and output dimensions of the model remain unchanged, and the output is the superposition of BA and the parameters of the pre-trained language model. A is initialized with a random Gaussian distribution, and B is initialized with a zero matrix. This ensures that at the beginning of training, the newly added pathway BA = 0, without affecting the model results.
[0067] During inference, the results of the left and right parts are simply added together: h = Wx + BAx = (W + BA)x. Therefore, the trained matrix product BA is added to the original weight matrix W as the new weight parameter to replace the W of the original pre-trained language model, without increasing additional computational resources. The biggest advantage of LoRA is its faster speed and lower memory usage. The LoRA used during training has a rank of 8.
[0068] 3. Fine-tune the model using the cross-entropy loss function.
[0069] The task of a language model is to predict the probability distribution of the next word or character based on the preceding context. Suppose we have a sequence of words or characters as input, we want the model to generate the probability distribution of the next word based on the preceding context. The cross-entropy loss function is used to measure the difference between the probability distribution generated by the model and the true probability distribution of the next word.
[0070] 4. Fine-tune using the AdamW optimizer.
[0071] This application utilizes a large language model, ChatGLM2, combined with LoRa technology to construct a fine-tuning model based on a command-based dataset to improve the caring dialogue capability. This method enhances domain-specific capabilities, enabling the caring robot dialogue engine to exhibit stronger adaptability and professionalism in specific domains, particularly in emotional care communication with the elderly. It can better provide emotional care services to the elderly, meeting their needs for emotional communication and thus better accompanying and caring for their mental health. This has a positive impact on improving the quality of life and well-being of the elderly.
[0072] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A dialogue method for a care robot based on ChatGLM2, characterized in that, include: Collect real conversation data of the elderly, conduct random sampling, and mark the conversation data containing emotional care in the sampled data. The labeled dialogue data is combined into an instruction dataset and preprocessed to balance the number and types of samples in the instruction dataset. The processed instruction dataset is input into the Chatglm2-6b model, fine-tuned using the LoRA method, and then the model is trained. The trained model is then fine-tuned sequentially using the cross-entropy loss function and the AdamW optimizer to obtain the final model. The specific method for fine-tuning using the LoRA method is as follows: A pre-trained language model is constructed to map the input text to the output text representation. The language model is as follows: h=Wx; Where: h is the output representation, W is the weight matrix of the pre-trained model, and x is the input text representation; The LoRA operation is introduced, which fixes the parameters of the pre-trained language model during training and adds a new weight matrix. During training, only the reduced-dimensional matrix A and the increased-dimensional matrix B are trained, while the input and output dimensions of the model remain unchanged. When outputting, matrices B and A are superimposed with the parameters of the pre-trained language model to obtain the final model parameters.
2. The care robot dialogue method based on ChatGLM2 according to claim 1, characterized in that, The instruction dataset is divided into five categories of care instruction data, including weather care, health care, social interaction, learning interest, and entertainment interest.
3. The care robot dialogue method based on ChatGLM2 according to claim 2, characterized in that, The number and types of samples in the weighing instruction dataset are determined in the following ways: the number of care instructions in different categories is adjusted, a certain category is selected as an intermediate quantity, and the fluctuation range of the number of instructions in other categories is controlled to be n, where n < 10.
4. The care robot dialogue method based on ChatGLM2 according to claim 3, characterized in that, The dimension reduction matrix A is initialized using a random Gaussian distribution, and the dimension increase matrix B is initialized using a zero matrix.
5. A chatbot dialogue device based on ChatGLM2, comprising a processor and a memory storing program instructions, characterized in that, The processor is configured to execute the ChatGLM2-based care robot dialogue method as described in any one of claims 1 to 4 when running the program instructions.
6. A care robot dialogue device based on ChatGLM2, characterized in that, include: Product itself; The ChatGLM2-based care robot dialogue device as described in claim 5 is installed on the product body.
7. A storage medium storing program instructions, characterized in that, When the program instructions are executed, they perform the care robot dialogue method based on ChatGLM2 as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Neural network quantization method and device and electronic equipment
CN115983324A
Predictive maintenance method for robot
CN116175641A