User memory data generation method, computer equipment and readable storage medium
By extracting original information in the form of triples from user input information in the field of artificial intelligence, and using knowledge graph libraries and large language models to generate user memory data in the form of natural language text, the problem of single user memory data in traditional methods is solved. It achieves accurate portrayal of user portraits and data support for intelligent interaction.
Patent Information
- Application Number
- CN202410196529.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-22
- Publication Date
- 2024-10-01
AI Technical Summary
Traditional memory methods are difficult to accurately portray user portraits in the field of artificial intelligence, resulting in insufficient data support for intelligent interaction and accurate recommendations.
By obtaining the user's input information, extract the original information in the form of triples, retrieve the candidate extended information in the preset knowledge graph library, input the large language model to generate the target extended information, and finally convert it into user memory in the form of natural language text Data enriches user memory.
Generating richer and more accurate user memory data, it can accurately portray user portraits, provide better intelligent interaction and accurate recommendation support, and meet the personalized needs of users.
Smart Images

Figure CN118733703A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method for generating user memory data, a computer device and a readable storage medium. Background Art
[0002] With the rapid development of artificial intelligence and machine learning technologies, the processing of data and information has become more intelligent and personalized. In the field of artificial intelligence, the memory function in traditional dialogue systems or AI assistants has become the key to achieving intelligent interaction and accurate recommendations.
[0003] However, traditional memory methods usually only store user input data, resulting in the user memory data stored in the memory bank being relatively simple, making it difficult to accurately portray user portraits, and thus difficult to provide sufficient data support for intelligent interaction, accurate recommendations, etc. Summary of the invention
[0004] The problem solved by the present invention is how to enrich user memory data.
[0005] In order to solve the above problems, the present invention provides a method for generating user memory data, comprising:
[0006] Obtaining user input information, and extracting original information in the form of triples from the user input information;
[0007] Based on the original information, searching in a preset knowledge graph library to obtain candidate extended information in the form of triples;
[0008] The candidate extension information is input into a preset large language model to obtain target extension information in the form of triples, and user memory data is generated according to the target extension information.
[0009] Optionally, generating user memory data according to the target extended information includes:
[0010] The target extended information is converted into user memory data in the form of natural language text.
[0011] Optionally, converting the target extended information into user memory data in natural language text form includes:
[0012] Generate a conversion template according to the user's input information;
[0013] The conversion template is filled based on the target extended information to generate user memory data in natural language text form.
[0014] Optionally, converting the target extended information into user memory data in natural language text form includes:
[0015] Each data element in the target extended information in the form of triples is spliced according to the grammatical rules of natural language to generate user memory data in the form of natural language text.
[0016] Optionally, the searching in a preset knowledge graph library based on the original information to obtain candidate extended information in triple form includes:
[0017] Based on the original information, a search is performed in a preset knowledge graph library to obtain temporary extended information in the form of triples;
[0018] When the correlation score between the temporary extended information and the original information is greater than or equal to a preset threshold, taking the temporary extended information as the candidate extended information;
[0019] When the correlation score between the temporary extended information and the original information is less than the preset threshold, the temporary extended information is deleted.
[0020] Optionally, after generating the user memory data according to the target extension information, the step further includes:
[0021] Semantically matching the user memory data with the historical memory data in the memory bank;
[0022] If there is historical user memory data with opposite semantics to the user memory data, the historical user memory data will be deleted.
[0023] Optionally, the step of inputting the candidate extended information into a preset large language model to obtain target extended information in triple form includes:
[0024] Based on a preset logic template, generating target prompt information according to the user's input information and the candidate extended information;
[0025] The target prompt information is input into the preset large language model to obtain the target extension information.
[0026] Optionally, the step of obtaining the user's input information and extracting the original information in triple form from the user's input information further includes:
[0027] Acquire the domain information of the original information, and determine whether the domain information exists in the preset domain list;
[0028] If so, the step of searching in a preset knowledge graph library based on the original information to obtain candidate extended information in triple form is performed;
[0029] If not present, the user's input information is stored as the user memory data.
[0030] In order to solve the above technical problems, the present invention further provides a computer device, comprising:
[0031] The memory is used to store computer programs;
[0032] The processor is used to implement the user memory data generating method when executing the computer program.
[0033] In order to solve the above technical problems, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the user memory data generating method is implemented.
[0034] Compared with the prior art, the present invention has at least the following beneficial effects:
[0035] By extracting the original information in the form of triples from the user's input information, and searching in the preset knowledge graph library based on the original information, and expanding the original information through the knowledge graph library, we can obtain candidate extension information with higher relevance, richer and more detailed information, and input these candidate extension information into the preset large language model for screening to obtain target extension information with a higher relevance to the user input information, and then integrate and store the target extension information as user memory data, and finally generate richer and more accurate user memory data to accurately characterize the user portrait, and then provide sufficient data support for intelligent interaction, accurate recommendation, etc., so as to provide support for users' personalized needs and intelligent services. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 This is one of the flow charts of the method for generating user memory data in an embodiment of the present invention;
[0037] Figure 2 This is the second flowchart of the method for generating user memory data in an embodiment of the present invention;
[0038] Figure 3 1 is a diagram showing the internal structure of a computer device in an embodiment of the present invention. DETAILED DESCRIPTION
[0039] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0040] like Figure 1 As shown, in one embodiment, a method for generating user memory data is provided, comprising the following steps:
[0041] Step S1, obtaining user input information, and extracting original information in the form of triples from the user input information.
[0042] Specifically, the user's input information is obtained, which may be text input, voice input or other forms of information input by the user. From the user's input information, the original information in the form of triples is extracted. The original information includes entities, attribute information and relationship information between entities, such as the subject-predicate-object structure, where the subject and the object can be entities and the predicate is attribute information. For example, if I like singer A, the subject is me and the object is singer A, that is, both the subject and the object are entities, the predicate is like, and it is attribute information, that is, the attributes and hobbies of the user.
[0043] In some embodiments, a corresponding extraction mode (schema) can be set, and it can be set according to types such as hobbies, dislikes, skills and ideas, that is, the user's input information can be extracted according to types such as hobbies, dislikes, skills and ideas. These extraction types can help the system better understand and remember the user's relevant information, that is, the system can extract things that the user likes or dislikes, or skills that the user is good at, or the user's ideas, etc. from the user's input information. For example, if the user's input information is: "I can play the piano", the extracted original information in the form of a triple is: (I, skills, playing the piano); if the user's input information is: "I want to travel", the extracted original information in the form of a triple is: (I, ideas, travel); if the user's input information is: "I love singing", the extracted original information in the form of a triple is: (I, like, singing). This extraction method can effectively capture the user's personal information and hobbies. The extraction process can analyze the user's input information to obtain entities, attribute information, and relationship information between entities, and directly extract based on this information. You can also choose to complete the extraction process through a small model, such as the PaddleUie model, BERT model, and RoBERTa model. The specific extraction method can be determined according to the actual situation.
[0044] Step S2: searching in a preset knowledge graph library based on the original information to obtain candidate extended information in the form of triples.
[0045] Specifically, based on these original information, a search is performed in the preset knowledge graph library to find candidate extended information related to the original information. The preset knowledge graph library usually organizes and stores data in the form of a graph, which can provide structured information, including entities, attributes, and the relationship between the two. This structured data can be retrieved, reasoned, and analyzed more easily, which is conducive to accurately obtaining relevant information. In addition, the data in the knowledge graph library is rich in associations. An entity is usually connected to multiple attributes and relationships. For example, I like city A. Here, the entity "city A" may be connected to multiple attributes and relationships. For example, through attributes related to population size, the population size of city A can be understood; through attributes related to geographical location, the geographical situation of city A can be understood; and through relationships related to historical events, the historical evolution of city A can be understood.
[0046] Searching through the preset knowledge graph library can obtain more comprehensive and richer relevant information, which helps to meet diverse query needs and obtain a more comprehensive perspective. It can also help organize and manage knowledge, integrate knowledge from different fields and sources, and form a unified knowledge system, which in turn helps to search and obtain information from different angles. In addition, the data in the preset knowledge graph library can be used for intelligent reasoning and completion. Through the existing related information, the query content (original information) can be inferred to obtain more relevant information. Therefore, the preset knowledge graph library can obtain more accurate and comprehensive candidate extension information based on the original information through its structured, rich associations, knowledge organization and management, and intelligent reasoning and completion characteristics.
[0047] Step S3: input the candidate extension information into a preset large language model to obtain target extension information in the form of triples, and generate user memory data according to the target extension information.
[0048] Specifically, the candidate extension information is input into the preset large language model to obtain the target extension information in the form of triples. Among them, the large language model can be a trained artificial intelligence model, which can infer the candidate extension information table returned in the preset knowledge graph library, determine the information that the user is most interested in, that is, the target extension information, and convert this information into user memory data for storage. Through the stored user memory data, the system can not only understand the user's memory and needs, but also improve the user experience. These memory data can be used in personal knowledge management, intelligent assistants, personalized recommendations, etc., so as to improve the user's life efficiency and experience and provide users with more personalized services.
[0049] In this embodiment, by extracting the original information in the form of triples from the user's input information, and searching in the preset knowledge graph library based on the original information, the original information is expanded through the knowledge graph library to obtain candidate extension information with higher relevance, richer and more detailed information, and these candidate extension information are input into the preset large language model for screening to obtain target extension information with a higher relevance to the user input information, and then the target extension information is integrated and stored as user memory data, ultimately generating richer and more accurate user memory data, accurately portraying the user portrait, and then providing sufficient data support for intelligent interaction, accurate recommendation, etc., thereby providing support for users' personalized needs and intelligent services.
[0050] In some embodiments, in step S3, generating user memory data according to the target extension information includes:
[0051] Step S33, converting the target extended information into user memory data in the form of natural language text.
[0052] Specifically, the target extended information in the form of triples obtained through knowledge graph retrieval and language model analysis is converted into user memory data in the form of natural language text. These memory data enable the system to more conveniently understand and remember the user's input information and related information, and can use the user's input information and related information to communicate with the user, thereby improving the user experience.
[0053] For example, the target extended information involves music, and the user memory data may include relevant information about music, such as the musician's life, representative works, music style, etc. The system can combine the target extended information and use natural language generation technology to convert these contents into easy-to-understand and easy-to-remember natural language texts, such as paragraphs, stories, answers to questions, etc., in order to better understand and store this information, so that the system can better acquire, digest and retain knowledge through data in the form of natural language text.
[0054] In some embodiments, step S33 includes:
[0055] Step S331, generating a conversion template according to the user's input information.
[0056] Step S332, filling the conversion template based on the target extended information to generate user memory data in the form of natural language text.
[0057] Specifically, according to the user's input information, corresponding conversion templates can be designed for different types of input information, such as hobbies, dislikes, skills, ideas, etc. These conversion templates can be some predefined sentence patterns or rules, which are used to convert the target extended information in the form of triples into sentences that conform to natural language habits. According to the conversion template, each data element in the target extended information is filled to generate a sentence that conforms to the grammatical rules of natural language. For example, the triple "user-hobby-basketball" for hobbies can be converted into: "user likes to play basketball" through the conversion template.
[0058] In some embodiments, in step S33, converting the target extended information into user memory data in natural language text form includes:
[0059] Step S333, concatenate the data elements in the target extended information in triple form according to the grammatical rules of natural language to generate user memory data in the form of natural language text.
[0060] Specifically, the target extended information is converted into user memory data in the form of natural language text, and can also be simply spliced according to the grammatical rules of natural language to ensure that the generated text-based user memory data is accurate and natural. Through this process, the structured triple information understood by the machine can be converted into a natural language form that is easier to understand and remember, thereby improving the user experience and information communication effect.
[0061] It should be noted that the specific conversion process (converting the target extended information into user memory data in the form of natural language text) can be set according to actual conditions.
[0062] In some embodiments, step S2 includes:
[0063] Step S21, searching in a preset knowledge graph library based on the original information to obtain temporary extended information in the form of triples.
[0064] Step S22: When the correlation score between the temporary extended information and the original information or the user's input information is greater than or equal to a preset threshold, the temporary extended information is used as the candidate extended information.
[0065] Step S23: when the correlation score between the temporary extended information and the original information or the user's input information is less than the preset threshold, the temporary extended information is deleted.
[0066] Specifically, the original information is used to search in the preset knowledge graph library to find temporary extended information in the form of triples related to the original information. These temporary extended information may involve richer descriptions of the original information, related entities and relationships, etc. For each set of temporary extended information, its relevance to the original information is evaluated to obtain a relevance score, which can be calculated based on factors such as the degree of association between triples, the relationship between entities, and the co-occurrence frequency. The relevance of the temporary extended information to the user's input information can also be evaluated to obtain a relevance score. Specifically, the text similarity between the temporary extended information and the user's input information can be calculated as the relevance score.
[0067] When the relevance score of the temporary extended information is greater than or equal to the preset threshold, it means that it is highly associated with the original information and has a high relevance, so it is suitable for subsequent processing and analysis as candidate extended information. On the contrary, if the relevance score of the temporary extended information is less than the preset threshold, it means that its relevance is low and may not be accurate or important enough. In this case, the temporary extended information is deleted and is not processed as candidate extended information. Filtering by the preset threshold can ensure that the obtained candidate extended information has a certain relevance, which can effectively improve the efficiency and accuracy of subsequent processing and analysis.
[0068] In some embodiments, for the returned candidate extended information, the relevance score of each group of candidate extended information and the original information can be calculated by the BM25 algorithm, and the score range is [0,1]. The score reflects the degree of match between each data element in the candidate extended information and the original information. The candidate extended information is sorted by the relevance score (such as from large to small), and compared with each relevance score according to a preset threshold, and the candidate extended information corresponding to the value greater than or equal to the preset threshold is retained, and the remaining candidate extended information is deleted, which can effectively filter out data that is not very relevant to the query (original information). And when the preset threshold condition is met, the number of retrievals can also be selected, that is, the first preset number with the highest score is returned as the final retrieval result, which not only guarantees the number of results, but also guarantees the quality of the results, that is, it can effectively extract the knowledge graph data that is most relevant to the query and has the highest information richness.
[0069] In some embodiments, first, entities in the original information are disambiguated before retrieval, in order to resolve the problem of inconsistency between entity names in the text and entity names in the knowledge base. For example, if the user mentions "singer A" (entity), the default knowledge graph database stores "singer A (such as a Chinese pop male singer, musician, actor, director, screenwriter)".
[0070] During the search process, the search topic can be determined first, which can be determined based on the user's input information or original information, such as music, sports or sports, etc. The topic here can also be field information, such as music field, chat field, etc. The specific selection of topics or fields can be set according to actual conditions. Construct a suitable query language based on the search topic and original information to retrieve relevant information from the knowledge graph. Query statements can be keywords, phrases, entities, and relationships. For example, the keywords are singer A and music (music field), and the information returned is "singer A, representative work, song A", "singer A, representative work, song B" and other groups of candidate extension information. By retrieving relevant information (candidate extension information) in the knowledge graph library, you can obtain candidate extension information related to the user's input information (subject-predicate-object or entity-attribute-attribute value).
[0071] In some embodiments, in step S3, after generating user memory data according to the target extension information, the method further includes:
[0072] Step S4, semantically matching the user memory data with the historical memory data in the memory library.
[0073] Step S5: If there is historical user memory data with opposite semantics to the user memory data, the historical user memory data is deleted.
[0074] Specifically, semantic matching is performed between the newly generated user memory data and the historical memory data in the memory bank, which can be achieved through natural language processing technology and semantic similarity calculation, etc. For example, a word embedding model or a text semantic similarity algorithm can be used to compare the semantic similarity between the new memory data and the historical memory data.
[0075] If historical user memory data with opposite semantics to the newly generated user memory data is found during semantic matching, it means that there is opposite semantic information between the newly generated memory data and the historical data. For example, an event is described as "like" but described as "hate" in the historical record, and subsequent processing is required.
[0076] When it is found that there is historical user memory data with opposite semantics to the new user memory data, it can be processed according to actual needs and business rules. In one embodiment, the historical user memory data with opposite semantics is deleted, so that the historical data in the memory library is consistent with the new data to avoid semantic contradictions. For example, if the historical memory data contains "I like singer B and his songs", then all of his songs may exist in the memory library, and now the user input or newly generated user memory data is "I hate singer B", then the singer B and related data in the historical user memory data may need to be deleted.
[0077] Through such semantic matching and processing, it can be ensured that the historical user memory data in the memory bank is consistent with the newly generated user memory data and conforms to the user's actual cognition and ideas. This helps to improve the accuracy, consistency and user experience of memory data.
[0078] In some embodiments, in step S3, inputting the candidate extension information into a preset large language model to obtain target extension information in triple form includes:
[0079] Step S31 : generating target prompt information based on a preset logic template and according to the user's input information and the candidate extended information.
[0080] Step S32: input the target prompt information into the preset large language model to obtain the target extension information.
[0081] Specifically, logical templates are pre-designed to ensure that the generated prompt information meets the specifications and relevance. The logical template may contain a series of rules and patterns for combining user input information with candidate extension information to generate target prompt information. These logical templates may be designed according to specific situations and tasks to ensure that the generated prompt information can guide the large language model to obtain the target extension information more accurately. By pre-setting the large language model for reasoning, the accuracy of the information can be improved, making the user's memory data more complete and useful.
[0082] In some embodiments, a concise screening template (target prompt information) can be constructed, for example, the logic of constructing a prompt template (screening template) includes: 1. Task description, that is, describing the purpose of this template, for example, by screening candidate extension information to obtain the target extension information that the user is interested in. 2. Task requirements, that is, specifying the task requirements, for example, the output of the model is returned in json text format, or the returned data does not exceed 100 characters or the range of returned data, etc. For example, construct a prompt template, task description: filter candidate extension information to obtain target extension information that the user is interested in; task requirements: the returned data must belong to the candidate extension information and be output in the format of a dictionary (the format of the dictionary is: {"filter_triple":[]}"). For example: the user's input information is "I like singer A", and the candidate extension information is "((singer A, real name, singer A), (singer A, birthplace, A province A city), (singer A, agency, a certain music company)(singer A, representative works, song C), (singer A, representative works, song D)), after inputting the preset large language model, we get, {"filter_triple": ((singer A, agency, a certain music company)(singer A, representative works, song C), (singer A, representative works, song D)). Filter out the target extension information that best meets the user's needs based on the user's intent (input information). Then convert the target extension information into user memory data in natural language form and store it in the memory bank, so that the system can better understand and respond to users' questions and provide answers that better meet user needs.
[0083] Before using the preset large language model, you can fine-tune the preset large language model by constructing a small amount of SFT fine-tuning datasets (self-supervised fine-tuning datasets) to improve the accuracy of information extraction.
[0084] Fine-tuning the preset large language model through the SFT fine-tuning dataset mainly includes parameter parsing, model initialization, data preparation, training, evaluation, and result preservation.
[0085] For example, parameter parsing: Use Hf Argument Parser (Hf Argument Parser is a Python library for parsing command line parameters. Its use can help us more conveniently process user input parameters when writing scripts) to create a parameter parser to process command line parameters. These parameters include model parameters, data parameters, and custom training parameters. After parsing, these parameters will be stored in the corresponding data class for subsequent processing and setting.
[0086] Configuration and preparation: First check whether the name or path of the tokenizer is specified, configure logging, and set the random number seed to ensure the reproducibility of the results. Then configure the parameters of the tokenizer and create a data collector to process the input data.
[0087] Initialize the model and Trainer object (Trainer parameters are all hyperparameters for training and evaluation): Create a pre-trained sequence generation model based on the specified model name or path, and enable the gradient checkpoint function to optimize memory usage and training speed. Then create a Trainer object that integrates the model, training parameters, training dataset, evaluation dataset, tokenizer, and data collector for actual model training and evaluation.
[0088] Model training and evaluation: If the do_train (command line parameter, instructing the program to perform training tasks) parameter is set to True, the model training process is executed; if the do_eval (optional parameter) parameter is set to True, the model evaluation process is executed and various evaluation indicators, such as perplexity, are calculated.
[0089] Result saving: Finally, save the trained model and related files, and generate a JSON file (JSON file is a file of simple data structures and objects stored in JavaScript Object Notation (JSON) format, which is a standard data exchange format) to record the key results and configuration information of the experiment.
[0090] The above process covers the entire process of model training and evaluation, including parameter analysis, model initialization, data preparation, training, evaluation, and result preservation. This systematic training process helps improve work efficiency, ensure the repeatability of experimental results, and facilitate subsequent experimental analysis and reporting.
[0091] In some embodiments, in step S1, after obtaining the user's input information and extracting the original information in triple form from the user's input information, the method further comprises the following steps:
[0092] The domain information of the original information is obtained, and it is determined whether the domain information exists in a preset domain list.
[0093] If it exists, the step of searching in a preset knowledge graph library based on the original information to obtain candidate extended information in the form of triples is executed.
[0094] If not present, the user's input information is stored as the user memory data.
[0095] Specifically, through natural language processing technology or other information extraction methods, relevant domain information is extracted from the original information to determine the specific field or subject to which the original information belongs. For example, the original information may involve different fields such as health, tourism, technology, and entertainment. The extracted domain information is judged to see whether it exists in the preset domain list. The preset domain list may predefine the scope of domains known to the system, including various themes and topics.
[0096] Different processing is performed based on the judgment result of the domain information: if the domain information of the original information exists in the preset domain list, it means that the information belongs to a domain known to the system. In this case, the step of searching the knowledge graph library based on the original information to obtain candidate extended information in the form of triples can be continued; if the domain information of the original information does not exist in the preset domain list, it means that the information may belong to a domain or topic unknown to the system. In this case, the user's input information can be stored as user memory data to ensure that the system can receive and record information in unknown domains, so as to achieve more comprehensive and flexible user memory data management.
[0097] In some embodiments, the domain information of the original information can be obtained through the classification model, for example, through the PaddlePaddle classification model. Before using the PaddlePaddle classification model, the model is trained first. The specific process is: first build a data set, including a training set, a validation set, and a test set; the original model is built based on ERNIE 3.0Medium for intent analysis classification. And the Auto module in PaddleNLP (including AutoModel (automated model), AutoTokenizer (large model basic component) and various downstream task classes) can be used directly to call pre-trained models of different network structures and corresponding word segmenters. AutoModel For Sequence Classification (automatic model for sequence classification) can be used for text classification. The representation of the input text is obtained through the pre-trained model, and then the text representation is classified. Among them, ERNIE3.0 is a pre-trained language representation model based on large-scale data self-supervised learning. It is a multi-domain, multi-task general language understanding model that can show excellent performance in various natural language processing tasks.
[0098] Among them, PaddlePaddle is a deep learning platform launched by Baidu, which provides a wealth of deep learning models and tools that can be used to build and train various types of machine learning models, including classification models. PaddleNLP is a natural language processing (NLP) tool library based on the PaddlePaddle deep learning platform. It provides a series of pre-trained models, model components, and tool functions for tasks such as text processing, text classification, sentiment analysis, machine translation, and text generation.
[0099] Before building a dataset, the training data needs to be preprocessed, that is, the word segmenter is used to segment the text (original information), and each word segment is mapped to the index ID (identity identifier) in the word segmenter's dictionary, and the label data in the dataset is one-hot encoded. The introduction of the index ID makes it easier for the model to find the vector representation corresponding to the word segmentation according to the index ID, and the ERNIE 3.0 model segments the model by Chinese characters by default.
[0100] Before training, the model needs to be configured accordingly, such as the computing resources that may be used, as well as the model optimizer, loss function, and optimization indicators. Among them, the optimizer can select AdamW as the optimizer, which combines the Adam optimizer and the weight decay (Weight Decay) technology to effectively balance the gradient update and regularization terms. The loss function can be selected as BCE WithLogits Loss, which represents the binary cross entropy loss plus the loss of Logits. In deep learning, the cross entropy loss function is usually used for binary classification tasks. BCEWithLogitsLoss combines the Sigmoid activation function and the binary cross entropy loss, which is suitable for the case where the output of the last layer of the neural network is the original score (logits) without the activation function. The purpose of this is to improve numerical stability. Specifically, BCE With Logits Loss first performs Sigmoid activation on the input, converts the original score into a probability value, and then calculates the binary cross entropy loss between these probability values and the label.
[0101] Adjust the model's hyperparameters accordingly. For example, max_seq_length indicates the maximum length of the input sequence. By adjusting max_seq_length, it can adapt to input data of different lengths. Longer sequences may contain more information, but they will also increase computational complexity and memory consumption. According to experimental results, setting max_seq_length to 128 can control computational complexity while ensuring certain performance. In classification tasks, the length of text often does not exceed 128 words. By limiting the sequence length, we can reduce the amount of information that the model needs to process, thereby improving training speed and efficiency; batch_size indicates the number of samples used in each iteration of training. A larger batch_size can speed up training, but it may also cause insufficient memory or video memory overflow. According to experimental results, setting batch_size to 64 can control memory consumption while ensuring certain performance. epochs indicates the number of training iterations. A larger epochs can increase the model training time, but it may also cause overfitting. According to experimental results, setting epochs to 10 can control training time and overfitting risk while ensuring certain performance. The learning rate (learning_rate) determines the magnitude of parameter updates in each iteration. A smaller learning rate may lead to a slow convergence speed, while a larger learning rate may lead to failure to converge or oscillation. According to experimental results, setting the learning rate to 1e-4 can control the convergence speed while ensuring a certain performance.
[0102] Training process: By printing training logs at regular intervals of steps, performing model evaluation regularly, and saving the model with the best performance in the evaluation, the training process can be made more controllable and observable, and the model with the best performance on the validation set is retained, providing the best model for subsequent testing and practical applications. The specific process is as follows: 1. Print a training log every log_steps: log_steps refers to printing a training log at regular intervals of steps during the training process. These logs usually include training metrics such as the current number of training batches, the current loss, accuracy, etc., in order to observe the training situation of the model in real time. 2. Perform a model evaluation on the validation set every eval_steps: eval_steps refers to performing an evaluation on the trained model at regular intervals of steps during the training process. During the evaluation process, the model will use the data of the validation set to verify the model and calculate the performance metrics of the model on the validation set (such as accuracy, precision, recall, F1 score, etc.), in order to timely understand the generalization performance of the model and perform hyperparameter tuning, etc. 3. Save the model with the best F1 score in the evaluation during the training process. During the model evaluation process, the F1 score (or other metrics) of the model on the validation set is usually recorded. If it is found that the best F1 score is obtained in the current evaluation, the model will be saved for subsequent use of the best-performing model in the test set or practical applications.
[0103] During the inference process, a threshold can be set, for example, 0.90. It means that if the probability that the model predicts a certain sample belongs to a certain domain exceeds 0.9 during the inference process, then the sample is classified as that domain. For example, if the probability that the model predicts "Qilixiang" belongs to the music domain exceeds 0.9, then it is classified as the music domain, that is, accurate classification judgment is made according to the set threshold.
[0104] In some embodiments, in step S1, the extracting the original information in the form of triples from the user's input information further includes:
[0105] Extracting the original information in the form of triples from the user's input information according to a preset extraction model.
[0106] Specifically, the preset extraction model can select the PaddleUie model (information extraction model). Before training the model, it is necessary to adjust the hyperparameters in the model according to the task requirements and the characteristics of the data set. That is, some common hyperparameters and their default values when training a deep learning model. For example: batch_size (batch size): It refers to the number of samples used to update the model parameters in each training step. Smaller batch sizes can provide more frequent parameter updates, but require more training steps to converge; conversely, larger batch sizes can reduce the number of training steps, but may cause memory problems. The default value of 16 is a common compromise choice that is less likely to cause memory problems and provides relatively stable gradient updates. learning_rate (learning rate): The learning rate is a parameter that controls the step size of the model parameter update. A higher learning rate may speed up the convergence of the model, but may miss the optimal solution; while a lower learning rate may slow down the convergence. The default value of 1e-5 is an empirical value that can provide good results in many cases. max_seq_len (maximum sequence length): It is the maximum length of the input sequence that the model can handle. Longer sequences may contain more information, but are also more computationally expensive. The default value of 512 is a common choice in Transformer models, which works well for most tasks and does not cause too much computational burden. num_epochs (number of training rounds): It controls the number of rounds of training performed on the entire dataset. A larger num_epochs can increase the degree of training of the model, but may cause overfitting; a smaller num_epochs may not fully learn features. The default value of 100 is an empirical value that performs well in many information extraction tasks. seed (random seed): Setting a fixed random number seed can ensure the reproducibility of experimental results. The default value of 1000 is just an arbitrarily chosen number, where Transformer is a sequence model based on the attention mechanism.
[0107] These hyperparameters need to be adjusted according to the specific task, dataset, and model architecture to achieve the best results. The default values are usually selected based on experience and extensive experimental results, but in practice, for each specific task, the optimal hyperparameter values may be different and need to be adjusted according to actual conditions.
[0108] When training a preset extraction model, first construct a dataset, which includes training data and label data, and is divided into a training set, a validation set, and a test set according to a preset ratio. For example, if the number of datasets is 200, it is divided into a training set, a validation set, and a test set according to a ratio of 8:1:1, that is, 160 pieces of data are used as training data, 20 pieces of data are used as validation data, and 20 pieces of data are used as test data. Among them, the labeled data can be manually labeled to indicate the entities contained in each piece of data and the relationships between the entities. For example, the labeled data is as follows:
[0109] {"id":15096,"text":"Your interest is listening to music","entities":[{"id":1978,"label":"Hobby","start_offset":5,"end_offset":8},
[0110] {"id":3422,"label":"Subject","start_offset":0,"end_offset":1}],"relations":[]}
[0111] Among them, "id":15096: represents the unique identifier of this data.
[0112] "text":"Your interest is listening to music": represents the text content to be labeled, that is, "Your interest is listening to music".
[0113] "entities": represents the information of the entities, which includes the unique identifier, label, start position, and end position of the entities. In this example, there are two entities:
[0114] {"id":1978,"label":"Hobby","start_offset":5,"end_offset":8}: represents an entity with the label "Hobby", starting at the 5th character and ending at the 8th character in the text. That is, the entity is "listening to music".
[0115] {"id":3422,"label":"Subject","start_offset":0,"end_offset":1}: represents an entity with the label "Subject", starting at the 0th character and ending at the 1st character in the text. That is, the entity is "you".
[0116] "relations": represents the relationship information between the entities. In this example, no relationships are defined.
[0117] Such labeled data can be used to train and evaluate natural language processing models, helping the models understand the entities in the text and the relationships between them.
[0118] Before model training, the dataset needs to be preprocessed to prepare the raw text data in a format suitable for the model's input. Common preprocessing operations may include:
[0119] 1. Text Cleaning: Remove unwanted special characters, punctuation marks, HTML tags, links, numbers, etc. to purify the text data.
[0120] 2. Tokenization: Split the text into words, phrases, or characters to form a tokenized sequence so that the computer can understand and process it. This helps convert the text data into a form that can be understood by the model.
[0121] 3. Removing Stopwords: Stopwords are words that frequently appear in natural language but have no actual semantic meaning (such as "de", "he", "le", etc.). Removing stopwords helps reduce data noise and enables the model to focus more on semantically valuable words.
[0122] 4. Stemming and Lemmatization: These operations help convert words into their basic forms to reduce lexical diversity and provide consistent input. Stemming directly obtains the root word by removing affixes, while lemmatization restores the word to its standard form based on the word's form and meaning.
[0123] 5. Numericalization: Convert the text into a numerical form, usually by encoding the text through word embeddings or the bag-of-words model so that the computer can perform numerical calculations.
[0124] 6. Padding and Truncating: For word sequence data, it is usually necessary to standardize their lengths. Padding and truncating are common operations to ensure that the lengths of the sequences are consistent.
[0125] The above preprocessing operations can ensure that the text data can be correctly understood and processed by the model, improving the training effect and generalization ability of the model. For specific application scenarios and models, more specific preprocessing operations may be involved.
[0126] In another embodiment, as Figure 2 shown, the specific steps of the user memory data generation method are as follows:
[0127] The user's input information is obtained, and the user's input information is extracted through a preset extraction model to obtain original information in the form of triples; the original information is classified by domains through a preset classification model to obtain domain information, and it is determined whether the domain information exists in a preset domain list. If not, the user's input information is stored as the user memory data.
[0128] If it exists, the original information is searched in the preset knowledge graph library to obtain candidate extension information in the form of triples, and then the candidate extension information is screened according to the preset large language model to obtain the target extension information, and the target extension information is converted into user memory data in the form of natural language text and stored in the memory library.
[0129] In this embodiment, by extracting the original information in the form of triples from the user's input information, and searching in the preset knowledge graph library based on the original information, the original information is expanded through the knowledge graph library to obtain candidate extension information with higher relevance, richer and more detailed information, and these candidate extension information are input into the preset large language model for screening to obtain target extension information with a higher relevance to the user input information, and then the target extension information is integrated and stored as user memory data, ultimately generating richer and more accurate user memory data, accurately portraying the user portrait, and then providing sufficient data support for intelligent interaction, accurate recommendation, etc., thereby providing support for users' personalized needs and intelligent services.
[0130] Yet another embodiment of the present invention provides a computer device, comprising a memory and a processor: the memory is used to store a computer program; the processor is used to implement the user memory data generating method when executing the computer program.
[0131] It should be noted that the computer device may be a server, a mobile terminal or other computer device.
[0132] Figure 3The internal structure diagram of a computer device in one embodiment is shown. The computer device includes a processor, a memory, a network interface, an input device and a display screen connected via a system bus. Among them, the memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program, which, when executed by the processor, enables the processor to implement the above-mentioned user memory data generation method. The internal memory may also store a computer program, which, when executed by the processor, enables the processor to execute the user memory data generation method. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covered on the display screen, or a button, trackball or touchpad provided on the housing of the computer device, or an external keyboard, touchpad or mouse, etc.
[0133] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned user memory data generating method are implemented.
[0134] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM) and memory bus dynamic RAM (RDRAM).
[0135] It should be noted that, in this article, terms such as "comprises", "includes" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0136] The above description is only a specific embodiment of the present invention, so that those skilled in the art can understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but should conform to the widest scope consistent with the principles and novel features invented herein.
[0137] Although the present invention is disclosed as above, the protection scope of the present invention is not limited thereto. Those skilled in the art may make various changes and modifications without departing from the spirit and scope of the present invention, and these changes and modifications will fall within the protection scope of the present invention.
Claims
1. A method for generating user memory data, characterized in that: The steps include: Obtaining user input information, and extracting original information in the form of triples from the user input information; Based on the original information, searching in a preset knowledge graph library to obtain candidate extended information in the form of triples; The candidate extension information is input into a preset large language model to obtain target extension information in the form of triples, and user memory data is generated according to the target extension information.
2. The method for generating user memory data according to claim 1, characterized in that: The generating user memory data according to the target extension information comprises: The target extended information is converted into the user memory data in the form of natural language text.
3. The method for generating user memory data according to claim 2, characterized in that: The step of converting the target extended information into the user memory data in natural language text form comprises: Generate a conversion template according to the user's input information; The conversion template is filled based on the target extension information to generate the user memory data in natural language text form.
4. The method for generating user memory data according to claim 2, characterized in that: The step of converting the target extended information into the user memory data in natural language text form comprises: Each data element in the target extended information in triple form is concatenated according to the grammatical rules of natural language to generate the user memory data in the form of natural language text.
5. The method for generating user memory data according to any one of claims 1 to 4, characterized in that: The candidate extended information in the form of triples obtained by searching in a preset knowledge graph library based on the original information includes: Based on the original information, a search is performed in the preset knowledge graph library to obtain temporary extended information in the form of triples; When the correlation score between the temporary extended information and the original information is greater than or equal to a preset threshold, taking the temporary extended information as the candidate extended information; When the correlation score between the temporary extended information and the original information is less than the preset threshold, the temporary extended information is deleted.
6. The method for generating user memory data according to any one of claims 1 to 4, characterized in that: After generating the user memory data according to the target extension information, the method further includes: Semantically matching the user memory data with historical memory data in a preset memory library; If there is historical user memory data with opposite semantics to the user memory data, the historical user memory data will be deleted.
7. The method for generating user memory data according to claim 1, characterized in that: The step of inputting the candidate extended information into a preset large language model to obtain target extended information in the form of a triplet includes: Based on a preset logic template, generating target prompt information according to the user's input information and the candidate extended information; The target prompt information is input into the preset large language model to obtain the target extension information.
8. The method for generating user memory data according to any one of claims 1 to 4, characterized in that: After obtaining the user's input information and extracting the original information in triple form from the user's input information, the method further includes: Acquire the domain information of the original information, and determine whether the domain information exists in the preset domain list; If so, the step of searching in a preset knowledge graph library based on the original information to obtain candidate extended information in triple form is performed; If not present, the user's input information is stored as the user memory data.
9. A computer device, characterized in that: include: The memory is used to store computer programs; The processor is used to implement the user memory data generating method according to any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the user memory data generating method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Orient field self body intelligence library article search method
CN106446162A
Intelligent question-answering system based on business knowledge graph retrieval
CN106951470A
Man-machine conversation generation method and device, electronic equipment and storage medium
CN114969250A
Personalized dialogue method and system based on dynamic user portrait
CN117150045A
Question and answer consulting method and system based on user portraits
CN117539996A
