A method, medium and system for optimizing the time dimension of a large language model
By constructing a time-event network, analyzing causal relationships, and designing a time-aware attention mechanism, the problem of poor performance of large language models in processing temporal information text data is solved, and stronger temporal dependency capture and time-related task performance are achieved. promote.
Patent Information
- Application Number
- CN202411396747.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2044-10-09
AI Technical Summary
When existing large language models process text data containing time information, it is difficult to fully capture the time dependencies contained in the text, resulting in poor performance in tasks such as time series prediction and causal analysis.
By performing time feature extraction, entity recognition and relationship extraction on the training data, a time-event network is constructed, and the causal inference algorithm is used to analyze the event sequence, calculate the conditional probability and time interval between events, and establish a causal relationship diagram. Then, the HyperLogLog algorithm and PageRank algorithm are used to calculate the node's importance index and timing influence, design a time-aware attention mechanism, and integrate these feature information to optimize the large language model.
Enhance the model's perception and utilization of time dimension information, and improve the performance of time -related tasks, including time sequence prediction and causal relationship reasoning.
Smart Images

Figure CN118916447B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of large language models, and in particular, relates to a method, medium and system for optimizing the time dimension of a large language model. Background Art
[0002] Large Language Model (LLM) has made great achievements in the field of natural language processing in recent years and is widely used in tasks such as text generation, question answering, and dialogue. This type of model is pre-trained based on massive unstructured text data and learns rich semantic and grammatical features, so that it can understand and generate text content in a more humane and intelligent way. At present, large language models have become one of the core technologies in the field of natural language processing and play an important role in various application scenarios.
[0003] However, existing large language models generally have some limitations when processing text data containing time information. For tasks such as describing the time of event occurrence, time series prediction, and causal analysis, it is often difficult to fully capture the temporal dependencies contained in the text by simply relying on semantic and grammatical features. This is because the temporal information in natural language text usually exists in an implicit way, and further temporal feature extraction and time-aware modeling are required to be effectively utilized by the model. For example, in news reports or historical documents, the time of occurrence of a large number of events and their before and after relationships are usually involved. This temporal information is crucial for understanding the causal logic and temporal evolution of events. However, existing large language models can usually only understand the semantics of the text literally and cannot deeply explore the temporal dependencies between events. This limitation will lead to poor performance of the model in tasks such as time series prediction and cause analysis. Another example is the dialogue system. Users will frequently mention time information in the dialogue, such as "the day before yesterday" and "next weekend". These time expressions are crucial for understanding the dialogue context and making appropriate responses. However, if the model cannot accurately identify and utilize this time information, it will be difficult to fully understand the temporal semantics of the dialogue, thereby affecting the interactive effect of the dialogue system.
[0004] Therefore, how to enhance the perception and utilization of time dimension information by large language models has become a technical problem that needs to be solved urgently. Summary of the invention
[0005] In view of this, the present invention provides a large language model time dimension optimization method, medium and system, which can solve the technical problem that the existing large language model has poor perception of time dimension information.
[0006] The present invention is achieved in that:
[0007] A first aspect of the present invention provides a method for optimizing the time dimension of a large language model, which comprises the following steps:
[0008] S10, extract time features, entity recognition and relationship extraction for each data item in the training data, and construct a time-event network;
[0009] S20, using a causal inference algorithm to analyze the event sequence in the time-event network, calculate the conditional probability and time interval between events, and obtain the causal relationship path between all events in the training data;
[0010] S30, establishing a directed acyclic graph according to the causal relationship path to obtain a causal relationship graph;
[0011] S40, based on the causal relationship graph, according to the traversal path of each node, using the HyperLogLog algorithm to estimate the cardinality of the nodes on each path, obtaining the estimated cardinality value of each node in the causal relationship graph as the importance index of the node, and obtaining a causal relationship HLL graph;
[0012] S50, using the PageRank algorithm to calculate the temporal influence of each node in the causal relationship HLL graph as the influence score of the corresponding node, and obtaining the causal relationship influence HLL graph;
[0013] S60, based on the causal influence HLL graph, using the node importance index, influence score and time interval information, designing a time-aware attention mechanism, calculating the attention weight, and obtaining the attention score of each node in the causal influence HLL graph;
[0014] S70, converting the causal influence HLL graph into an adjacency table, and taking the importance index, influence score and attention score of the node as feature vectors, combining them with the original text data, and establishing a fine-tuning data set;
[0015] S80: Use the fine-tuning data set to fine-tune the base large language model to obtain a large language model that takes the time dimension into consideration.
[0016] Specifically, the step S10 specifically includes: extracting time features, entity recognition and relationship extraction for each item of data in the training data one by one to construct a time-event network. First, the time expression recognition technology is used to extract time information such as date and time in the text; then, the named entity recognition algorithm is used to identify entities such as names of people, places, and organization names from the text; then, the relationship extraction method is used to analyze the semantic relationship between entities, such as causal relationship, time relationship, etc. Through the above steps, a time-event network can be constructed, in which nodes represent events, edges represent the relationship between events, and the weight of the edge reflects the time interval between events. The main purpose of this step is to fully explore the implicit time semantic information in the training data and lay the foundation for subsequent time-aware modeling and analysis.
[0017] Wherein, the step S20 specifically includes: using a causal inference algorithm to analyze the event sequence in the time-event network, calculating the conditional probability and time interval between events, and obtaining the causal relationship path between all events in the training data. For any two events in the time-event network, the conditional probability and time interval between them can be calculated, thereby obtaining the causal relationship path between events in the entire training data set. These causal relationship paths and their statistical characteristics provide an important basis for subsequent causal relationship analysis and time perception modeling.
[0018] Wherein, the step S30 specifically includes: according to the causal relationship path, a directed acyclic graph is established to obtain a causal relationship graph. Specifically, each event is regarded as a node in the graph. If there is a causal relationship between two events, a directed edge is added between the corresponding nodes, and the weight of the edge is set to the conditional probability between the two events. Through this step, a complete causal relationship graph can be obtained, in which nodes represent events and edges represent causal dependencies between events. The causal relationship graph will provide important topological structure information for subsequent temporal influence analysis and attention mechanism design.
[0019] Wherein, the step S40 specifically includes: based on the causal relationship graph, using the HyperLogLog algorithm to estimate the cardinality of each node, obtaining the estimated cardinality value of each node in the causal relationship graph as the node importance index, and forming a causal relationship HLL graph. The HyperLogLog algorithm is a cardinality estimation algorithm that can quickly estimate the cardinality of a large-scale data set. For each node in the causal relationship graph, calculate its estimated cardinality value, which reflects the position and influence of the event in the entire causal relationship network. Through this step, a "causal relationship HLL graph" is obtained, in which each node is assigned an importance score.
[0020] Wherein, the step S50 specifically includes: using the PageRank algorithm to calculate the temporal influence of each node in the causal relationship HLL graph as the influence score of the corresponding node, and obtaining the causal relationship influence HLL graph. The PageRank algorithm can calculate the influence of each node in the directed graph, and by applying it to the causal relationship graph, the influence score of each event in the time series can be obtained. These temporal influence scores reflect the importance and propagation ability of the event in the entire causal relationship network. Through this step, a "causal relationship influence HLL graph" is obtained, in which each node is assigned a temporal influence score.
[0021] Wherein, the step S60 specifically includes: based on the causal influence HLL graph, designing a time-aware attention mechanism, calculating the attention weight, and obtaining the attention score of each node in the causal influence HLL graph. A calculation formula for attention score that integrates event importance index, temporal influence, and time interval information is designed, so that the attention weight of each event can be obtained. These attention scores can better capture the temporal dependency contained in the text and provide important temporal dimension features for subsequent model fine-tuning.
[0022] Wherein, the step S70 specifically includes: converting the causal relationship influence HLL graph into an adjacency table, and combining the importance index, influence score and attention score of the node as a feature vector with the original text data to establish a fine-tuning data set. First, convert the causal relationship graph into a standard adjacency table format; then, integrate the features of each node (importance index, temporal influence score, attention score) into a feature vector; finally, splice these feature vectors with the original text data to form the final fine-tuning data set. The fine-tuning data set contains feature information of the time dimension, which will provide important training samples for subsequent model optimization.
[0023] The step S80 specifically includes: integrating the feature vector in the causal influence HLL graph into the input representation of the model. The input representation of each token is expanded into a vector, including word embedding, position encoding, node importance index, temporal influence score and attention score. In this way, when processing text information, the model can use these time dimension features to enhance the understanding of time semantics.
[0024] Furthermore, in step S80, the specific steps include:
[0025] Step S801, integrating the feature vector in the causal influence HLL graph into the input representation of the model;
[0026] Step S802: modify the attention mechanism of the model to incorporate the time-aware attention score;
[0027] Step S803: design a multi-task learning objective, and optimize language modeling, time series prediction, and causal reasoning tasks simultaneously;
[0028] Step S804: Use technologies such as gradient accumulation and mixed precision training to perform large-scale distributed training;
[0029] Step S805: adopt early stopping strategy and model checkpoint saving to prevent overfitting and retain the best model;
[0030] Step S806: Regularly evaluate the model performance on the validation set, including indicators such as perplexity, time series prediction accuracy, and causal reasoning ability;
[0031] Step S807, dynamically adjusting the learning rate according to the evaluation result;
[0032] Step S808, iterative optimization until convergence or reaching a preset number of training rounds; finally, a large language model optimized in the time dimension is obtained as the final large language model considering the time dimension.
[0033] Below is a detailed description of the steps involved in the calculation:
[0034] 1. Conditional probability and time interval calculation in step S20:
[0035] The conditional probability and time interval calculation are specifically expressed as follows:
[0036] ;
[0037] ;
[0038] In the formula, For events In Events Time interval after occurrence The conditional probability of occurrence within For events After the occurrence Events in time Number of occurrences; For events Total number of occurrences; is the time decay factor; and Respectively for events and The timestamp of the occurrence.
[0039] 2. HyperLogLog algorithm cardinality estimation in step S40:
[0040] The HyperLogLog algorithm cardinality estimation is specifically expressed as follows:
[0041] ;
[0042] In the formula, Nodes in the causal relationship graph The estimated base value of is the number of hash functions; is the deviation correction factor, ; For Node In the Maximum number of leading zeros under a hash function.
[0043] The calculation method is:
[0044] ;
[0045] in, For the A hash function, For the node A collection of all related events.
[0046] 3. Time-series influence PageRank algorithm in step S50:
[0047] The temporal influence PageRank algorithm is specifically expressed as follows:
[0048] ;
[0049] In the formula, For Node The temporal influence score of is the damping factor, usually 0.85; Point to the node A collection of nodes; For Node The out-degree of For edge The weights can be calculated using the conditional probability express; is the time decay factor; For Node arrive time interval.
[0050] 4. Time-aware attention mechanism in step S60:
[0051] The time-aware attention mechanism is specifically expressed as follows:
[0052] ;
[0053] ;
[0054] In the formula, For Node For Node The attention weight of Score for attention; is the query vector; is the key vector; is the dimension of the key vector; For Node and nodes the time interval between For Node HyperLogLog estimates the cardinality value; For Node The temporal influence score of .
[0055] function , and They are the mapping functions of time interval, importance index and time series influence, and are defined as follows:
[0056] ;
[0057] ;
[0058] ;
[0059] in, and is an adjustable hyperparameter.
[0060] 5. The modified time-aware attention mechanism in step S802:
[0061] The modified time-aware attention mechanism is specifically expressed as follows:
[0062] ;
[0063] In the formula, , , are query, key, and value matrices respectively; is the dimension of the key vector; is the time perception matrix, is the causal relationship matrix, whose elements are defined as:
[0064] ;
[0065] ;
[0066] Represents the Hadamard product (Element-wiseMultiplication), which multiplies the corresponding elements of two matrices or vectors.
[0067] in , , The definition of is the same as that in step S60.
[0068] 6. Multi-task learning objectives in step S803:
[0069] The multi-task learning objective is specifically expressed as follows:
[0070] ;
[0071] In the formula, is the total loss; Modeling loss for language; Predicting losses for time series; Reasoning about loss for causality; Perceived attention loss for time; , , , is the weight coefficient of each task.
[0072] Language Modeling Loss Using cross entropy loss:
[0073] ;
[0074] Time Series Forecasting Loss Use mean squared error:
[0075] ;
[0076] Causal Inference Loss Using binary cross entropy:
[0077] ;
[0078] Time perception attention loss Using KL divergence:
[0079] ;
[0080] in, is the sample size, is the vocabulary size, is the true value, is the predicted value, is the real timestamp, is the prediction timestamp, is the actual attention distribution, To predict the attention distribution, is the divergence operator.
[0081] 7. Dynamic adjustment of learning rate in step S807:
[0082] The dynamic adjustment of the learning rate is specifically expressed as follows:
[0083] ;
[0084] In the formula, For the The learning rate of the iteration; is the initial learning rate; is the decay rate; is the current iteration number; is the learning rate adjustment factor; and are the loss values of the current iteration and the previous iteration respectively.
[0085] The model can better understand and process text data containing time information and has stronger temporal reasoning and causal analysis capabilities.
[0086] A second aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores program instructions, and when the program instructions are run in a computer, they are used to execute the above-mentioned large language model time dimension optimization method.
[0087] A third aspect of the present invention provides a large language model time dimension optimization system, which includes the above-mentioned computer-readable storage medium.
[0088] Compared with the prior art, the present invention proposes a method for optimizing the time dimension of a large language model in response to the problems described in the background technology, aiming to design a large language model that integrates time-aware features by mining the time semantic information contained in the training data, so as to improve its performance on time-related tasks; specifically, the beneficial effects of the method, medium and system for optimizing the time dimension of a large language model provided by the present invention are: 1. Constructing a time-event network to fully mine the time information in the training data. The present invention first extracts time features, identifies entities and extracts relationships from the training data to construct a time-event network. The network uses events as nodes and the time relationships between events as edges, thereby retaining the implicit time semantic information in the training data. This lays the foundation for subsequent time-aware modeling.
[0089] 2. Analyze the causal relationship and time interval between events and establish a causal relationship graph. Based on the time-event network, the present invention uses a causal reasoning algorithm to calculate the conditional probability and time interval between events to obtain the causal relationship path between all event pairs. Then, a directed acyclic graph (DAG), i.e., a causal relationship graph, is established to reflect the causal dependency between events. These topological structure information is crucial for temporal influence analysis and attention mechanism design.
[0090] 3. Design a time-aware attention mechanism to enhance the model's perception of time dimension information. Based on the standard attention calculation formula, this invention incorporates time dimension features such as event importance index, temporal influence, and time interval between events. This time-aware attention mechanism can better capture the temporal dependency contained in the text and provide key support for subsequent model optimization.
[0091] 4. Adopt multi-task learning objectives to optimize language modeling, time series prediction and causal reasoning at the same time. In addition to the conventional language modeling task, the present invention also introduces two additional tasks, time series prediction and causal reasoning, during the model fine-tuning process. Through multi-task learning, the model can simultaneously master the capabilities of language understanding, time prediction and causal analysis, greatly enhancing the modeling and utilization of time dimension information.
[0092] 5. Apply gradient accumulation, mixed precision and other technical means to achieve large-scale distributed training. In order to solve the problem that the scale of fine-tuning data may be very large, this paper adopts technical methods such as gradient accumulation and mixed precision training to greatly improve the training efficiency and memory utilization, thereby supporting large-scale distributed training. This lays the foundation for obtaining high-performance optimization models.
[0093] In summary, the time dimension optimization method of the large language model proposed in the present invention effectively enhances the model's perception and utilization of time dimension information through innovative technical means such as constructing a time-event network, analyzing causal relationships, and designing a time-aware attention mechanism. BRIEF DESCRIPTION OF THE DRAWINGS
[0094] Figure 1 A flow chart of the method provided by the present invention;
[0095] Figure 2 is the model perplexity variation curve in the embodiment;
[0096] Figure 3 Predict the MAE change curve for time series;
[0097] Figure 4 This is the F1 score change curve for causal reasoning. DETAILED DESCRIPTION
[0098] In order to make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0099] like Figure 1 FIG. 1 is a flow chart of a method for optimizing the time dimension of a large language model provided by the present invention. The method comprises the following steps:
[0100] S10, extract time features, entity recognition and relationship extraction for each data item in the training data, and construct a time-event network;
[0101] S20, using a causal inference algorithm to analyze the event sequence in the time-event network, calculate the conditional probability and time interval between events, and obtain the causal relationship path between all events in the training data;
[0102] S30, establishing a directed acyclic graph according to the causal relationship path to obtain a causal relationship graph;
[0103] S40, based on the causal relationship graph, according to the traversal path of each node, using the HyperLogLog algorithm to estimate the cardinality of the nodes on each path, obtaining the estimated cardinality value of each node in the causal relationship graph as the importance index of the node, and obtaining a causal relationship HLL graph;
[0104] S50, using the PageRank algorithm to calculate the temporal influence of each node in the causal relationship HLL graph as the influence score of the corresponding node, and obtaining the causal relationship influence HLL graph;
[0105] S60, based on the causal influence HLL graph, using the node importance index, influence score and time interval information, designing a time-aware attention mechanism, calculating the attention weight, and obtaining the attention score of each node in the causal influence HLL graph;
[0106] S70, converting the causal influence HLL graph into an adjacency table, and taking the importance index, influence score and attention score of the node as feature vectors, combining them with the original text data, and establishing a fine-tuning data set;
[0107] S80: Use the fine-tuning data set to fine-tune the base large language model to obtain a large language model that takes the time dimension into consideration.
[0108] The specific implementation methods of the above steps are described in detail below:
[0109] Step S10: Perform time feature extraction, entity recognition and relationship extraction on each item of training data to construct a time-event network. First, perform time expression recognition on the input text data to extract time information such as date and time in the text. Then, use named entity recognition technology to identify entities such as names of people, places, and organizations from the text. Next, use the relationship extraction algorithm to analyze the semantic relationship between entities, such as causal relationship, temporary relationship, etc. Through the above steps, a time-event network can be constructed, in which nodes represent events, edges represent the relationship between events, and the weight of the edge represents the time interval between events. The main purpose of this step is to fully explore the implicit time semantic information in the training data and lay the foundation for subsequent time-aware modeling.
[0110] Step S20: Use the causal inference algorithm to analyze the event sequence in the time-event network, calculate the conditional probability and time interval between events, and obtain the causal relationship path between all events in the training data. Specifically, for any two events in the time-event network and , we can calculate the conditional probability between them and time interval . Conditional probability Indicates an event After the occurrence, in the time interval internal event The probability of occurrence is calculated as follows:
[0111] ;
[0112] In the formula, For events After the occurrence Events in time The number of occurrences, For events The total number of occurrences, is the time decay factor. Time interval Then directly calculate it as an event and events The difference in timestamps occurs, Through this step, the causal relationship probability and time interval between all event pairs in the training data can be obtained, providing an important basis for subsequent causal relationship analysis.
[0113] Step S30: According to the causal relationship path, a directed acyclic graph is established to obtain a causal relationship graph. Specifically, each event is regarded as a node in the graph. If there is a causal relationship between two events, a directed edge is added between the corresponding nodes. At the same time, the weight of the edge can be set as the conditional probability between the two events. Through this step, a complete causal relationship graph can be obtained, in which the nodes represent events and the edges represent the causal relationship between events. This causal relationship graph will provide important topological structure information for the subsequent temporal influence analysis.
[0114] Step S40: Based on the causal relationship graph, according to the traversal path of each node, the HyperLogLog algorithm is used to estimate the cardinality of the nodes on each path, and the estimated cardinality value of each node in the causal relationship graph is obtained as the node importance index to obtain the causal relationship HLL graph. The HyperLogLog algorithm is a cardinality estimation algorithm that can quickly estimate the cardinality of a large-scale data set in a constant space. For each node in the causal relationship graph, , its estimated cardinality can be calculated , the specific formula is:
[0115] ;
[0116] In the formula, is the number of hash functions, is the deviation correction factor, For Node In the The maximum number of leading zeros under a hash function. This estimate is It can be used as an importance indicator of the node, reflecting the position and influence of the event in the entire causal network. Through this step, a "causal HLL graph" is obtained, in which each node is assigned an importance score.
[0117] Step S50: Use the PageRank algorithm to calculate the temporal influence of each node in the causal relationship HLL graph as the influence score of the corresponding node, and obtain the causal relationship influence HLL graph. The PageRank algorithm was originally used for web page sorting, but it can also be applied to general directed graphs. For any node in the causal relationship graph, , its temporal influence score It can be calculated as follows:
[0118] ;
[0119] In the formula, is the damping factor, Point to the node The node set, For Node The out-degree, For edge The weight (available conditional probability express), is the time decay factor, For Node arrive This time series influence score It reflects the importance and propagation influence of the event in the entire causal network. Through this step, a "causal influence HLL graph" is obtained, in which each node is assigned a temporal influence score.
[0120] Step S60: Based on the causal influence HLL graph, using the node importance index, influence score and time interval information, design a time-aware attention mechanism, calculate the attention weight, and obtain the attention score of each node in the causal influence HLL graph. Specifically, the following time-aware attention score can be defined: :
[0121] ;
[0122] in, is the query vector, is the key vector, is the dimension of the key vector, For Node and nodes The time interval between For Node HyperLogLog estimates the cardinality of For Node The temporal influence score of . , and They are the mapping functions of time interval, importance index and time series influence, and are defined as follows:
[0123] ;
[0124] ;
[0125] ;
[0126] in, and is an adjustable hyperparameter. Through this time-aware attention mechanism, the attention weight of each node can be calculated , reflects the node For Node These attention scores will play a key role in subsequent model fine-tuning.
[0127] Step S70: Convert the causal influence HLL graph into an adjacency table, and use the importance index, influence score and attention score of the node as feature vectors, combined with the original text data, to establish a fine-tuning dataset. First, convert the causal influence HLL graph into a standard adjacency table format, where each row represents a causal edge, including information such as the source node, the target node, and the edge weight (conditional probability). Next, convert the importance index of each node into an adjacency table. , Time Series Influence Score and attention score Integrate into a feature vector as the representation of the node. Finally, these feature vectors are concatenated with the original text data to form the final fine-tuning dataset. This fine-tuning dataset will provide important training samples for subsequent model optimization.
[0128] Step S80: Use the fine-tuning data set to fine-tune the base large language model to obtain a large language model that takes the time dimension into account. This step mainly includes the following sub-steps:
[0129] Sub-step S801: Integrate the feature vector in the causal influence HLL graph into the input representation of the model. Specifically, expand the input representation of each token into a vector, including word embedding, position encoding, and the aforementioned node importance index, temporal influence score, and attention score. In this way, when processing text information, the model can use these time dimension features to enhance the understanding of temporal semantics.
[0130] Sub-step S802: Modify the attention mechanism of the model and incorporate the time-aware attention score. The time-aware factor can be introduced into the standard attention formula, as follows:
[0131] ;
[0132] in, is the time perception matrix, is the causal relationship matrix, and its elements are defined as:
[0133] ;
[0134] ;
[0135] Through such modifications, the attention mechanism can better capture dependencies in the temporal dimension.
[0136] Sub-step S803: Design a multi-task learning objective to optimize language modeling, time series prediction, and causal reasoning tasks simultaneously. The following composite loss function can be defined:
[0137] ;
[0138] in, for language modeling loss (cross entropy), is the time series prediction loss (mean square error), is the causal inference loss (binary cross entropy), is the time-aware attention loss (KL divergence). Through multi-task learning, the model can simultaneously master language modeling, time series prediction, and causal reasoning capabilities, and enhance the understanding and utilization of time dimension information.
[0139] Sub-step S804: Use technologies such as gradient accumulation and mixed precision training to perform large-scale distributed training. Since the scale of the fine-tuning data set may be large, technical means such as gradient accumulation and mixed precision training can be used to improve training efficiency and video memory utilization, thereby achieving large-scale distributed training.
[0140] Sub-step S805: Use early stopping strategy and model checkpoint saving to prevent overfitting and retain the best model. During the training process, the model performance will be regularly evaluated on the validation set. Once the performance is no longer improved (or there are signs of overfitting), the training will be stopped and the current best model checkpoint will be saved. This ensures that a model with good generalization performance is finally obtained.
[0141] Sub-step S806: Regularly evaluate the model performance on the validation set, including indicators such as perplexity, time series prediction accuracy, and causal reasoning ability. In addition to monitoring the loss function value during the training process, it is also necessary to regularly evaluate the model's performance indicators on tasks such as language modeling, time series prediction, and causal reasoning on the validation set, such as perplexity, accuracy, etc. These indicators will reflect the model's understanding and reasoning ability in the time dimension.
[0142] Sub-step S807: Dynamically adjust the learning rate and other hyperparameters based on the evaluation results. The following dynamic learning rate adjustment strategies can be used:
[0143] ;
[0144] in, For the The learning rate of the iteration, is the initial learning rate, is the attenuation rate, is the current iteration number, is the learning rate adjustment factor, and are the loss values of the current iteration and the previous iteration respectively. Through this strategy, the learning rate can be dynamically adjusted according to the changes in model performance to speed up convergence and obtain a better model.
[0145] Sub-step S808: Iterate optimization until convergence or reaching a preset number of training rounds. After completing the above steps, the model will be continuously iterated until the model converges or reaches a preset number of training rounds. In this way, a large language model optimized in the time dimension is finally obtained, which can better understand and process text data containing time information and has stronger temporal reasoning and causal analysis capabilities.
[0146] By constructing a time-event network, analyzing causal relationships, and calculating temporal influence, we finally designed a time-aware attention mechanism and integrated it into the model fine-tuning process. This method mainly includes the following key steps:
[0147] Specifically, the principle of the present invention is to fully explore the temporal semantic information contained in the training data to enhance the model's perception and utilization of temporal dimension information.
[0148] First, in step S10, the training data is subjected to time feature extraction, entity recognition, and relationship extraction to construct a time-event network. This network retains the time information of events in the text and the semantic relationship between events, laying the foundation for subsequent time-aware modeling. Specifically, the time expression recognition technology is used to extract time information such as date and time in the text as the timestamp of the event; at the same time, the named entity recognition and relationship extraction algorithms are used to identify event entities and their semantic relationships, such as causal relationships and temporary relationships. Through these steps, a time-event network is constructed, in which nodes represent events, edges represent the relationship between events, and the weight of the edges reflects the time interval between events. This network structure provides important input for subsequent time-aware analysis.
[0149] In step S20, the causal relationship of the event sequence in the time-event network is further analyzed using the causal inference algorithm. Specifically, for any two events in the network and , and calculated the conditional probability between them and time interval . Conditional probability Reflects the event After the occurrence, in the time interval internal event The probability of occurrence, and the time interval Directly indicates the event and These causal relationships and time characteristics provide important basis for subsequent causal relationship analysis.
[0150] Based on the above causal relationship information, a directed acyclic graph (DAG), the so-called causal relationship graph, is established in step S30. In this graph, nodes represent events, directed edges represent causal dependencies between events, and edge weights are conditional probabilities between corresponding event pairs. This causal relationship graph depicts the temporal logic of events in the training data, and provides key topological structure information for temporal influence analysis and attention mechanism design.
[0151] In steps S40 and S50, the HyperLogLog algorithm and PageRank algorithm are used to estimate the cardinality and calculate the temporal influence of the nodes in the causal relationship graph. The HyperLogLog algorithm can quickly estimate the cardinality of large-scale data sets, and use it to calculate the importance index of each event node. The PageRank algorithm can measure the influence of nodes in a directed graph, and is used to evaluate the propagation ability of each event in a time series. These topological-based importance indexes and temporal influence scores provide a key basis for the subsequent design of time-aware attention mechanisms.
[0152] In step S60, an attention mechanism that integrates time dimension features is designed. Specifically, factors such as event importance index, temporal influence, and time interval between events are introduced into the standard attention calculation formula. Such a time-aware attention mechanism can better capture the temporal dependency contained in the text and provide key support for model optimization.
[0153] Finally, in step S80, the pre-trained large language model is fine-tuned. First, the time dimension features (importance index, temporal influence, attention score, etc.) in the causal relationship graph are integrated into the input representation of the model so that the model can perceive this time information. Secondly, the attention mechanism of the model is modified to incorporate the aforementioned time-aware attention calculation method, further enhancing the model's ability to model time dependencies. In addition, a multi-task learning objective is designed, including tasks such as language modeling, time series prediction, and causal reasoning, in order to enable the model to simultaneously master language understanding, time prediction, and causal analysis capabilities, and give full play to the role of time dimension information.
[0154] In order to better understand and implement the present invention, a specific embodiment 1 of the method of the first aspect of the present invention is provided below. The steps of this embodiment 1 are described in detail as follows:
[0155] The first step is step S10, which is to extract time features, entity recognition and relationship extraction for each data item in the training data to build a time-event network. Among them, time feature extraction mainly involves identifying and extracting time expressions such as date and time in the text. For a given text , we can use regular expressions or deep learning-based time expression recognition models to extract the time information, which is recorded as ,in Indicates The timestamp of a time expression.
[0156] Next is entity recognition, which is to identify entities such as names of people, places, and organizations from the text. , we can use the named entity recognition (NER) model to output a series of entities and their types, denoted as ,in Indicates entity.
[0157] Finally, relation extraction is to analyze the semantic relationship between entities in the text, such as causal relationship, temporal relationship, etc. and , we can use the relation extraction model to calculate the probability of the relationship between them ,in Representing Entities and The type of relationship between them.
[0158] Through the above steps, a time-event network can be constructed , where the node Represents event entity, edge Represents the relationship between events, where Indicates an event and The time interval between occurrences. This time-event network lays the foundation for subsequent time-aware modeling and analysis.
[0159] In step S20, the event sequence in the time-event network is analyzed using a causal inference algorithm, the conditional probability and time interval between events are calculated, and the causal relationship path between all event pairs is obtained. and , we can calculate the conditional probability between them and time interval , the specific formula is as follows:
[0160] ;
[0161] ;
[0162] in, Indicates an event After the occurrence Events in time The number of occurrences, Indicates an event The total number of occurrences, is the time decay factor. Through this step, the causal relationship probability and time interval between all event pairs in the training data can be obtained, providing an important basis for subsequent causal relationship analysis.
[0163] In step S30, a directed acyclic graph (DAG), the so-called causal relationship graph, is established based on the obtained causal relationship path. Among them, the node Still represents the event entity, edge It indicates the event and The causal relationship between them is represented by the edge weight, and the edge weight is the conditional probability between them. This causal relationship graph provides key topological structure information for subsequent temporal influence analysis and attention mechanism design.
[0164] In step S40, the HyperLogLog algorithm is used to estimate the cardinality of each node in the causal relationship graph to obtain the importance index of each event. The HyperLogLog algorithm is a cardinality estimation algorithm that can quickly estimate the cardinality of a large-scale data set in a constant space. , its estimated base It can be calculated as follows:
[0165] ;
[0166] in, is the number of hash functions, is the deviation correction factor, For Node In the The maximum number of leading zeros under a hash function. This estimate is Reflects the event The importance and influence of the entire causal network. Through this step, a "causal HLL graph" is obtained, in which each node is assigned an importance score.
[0167] In step S50, the PageRank algorithm is used to calculate the temporal influence score of each node in the causal relationship HLL graph. The PageRank algorithm was originally used for web page ranking, but it can also be applied to general directed graphs. For any node in the causal relationship graph , its temporal influence score It can be calculated as follows:
[0168] ;
[0169] in, is the damping factor, Point to the node The node set, For Node The out-degree, is the time decay factor, For Node arrive This time series influence score Reflects the event The importance and propagation influence in the entire causal network. Through this step, a "causal influence HLL graph" is obtained, in which each node is assigned a temporal influence score.
[0170] In step S60, a time-aware attention mechanism is designed to calculate the attention weight of each node. Specifically, the following attention score is defined: :
[0171] ;
[0172] in, is the query vector, is the key vector, is the dimension of the key vector, For Node and nodes The time interval between For Node HyperLogLog estimates the cardinality of For Node The temporal influence score of . , and They are the mapping functions of time interval, importance index and time series influence, and are defined as follows:
[0173] ;
[0174] ;
[0175] ;
[0176] in, and is an adjustable hyperparameter. Through this time-aware attention mechanism, the attention weight of each node can be calculated , reflects the node For Node The importance of.
[0177] In step S70, the causal influence HLL graph is converted into an adjacency table, and the importance index of each node is , Time Series Influence Score and attention score As a feature vector, it is combined with the original text data to form the final fine-tuning dataset. This fine-tuning dataset contains feature information in the time dimension and will provide important training samples for subsequent model optimization.
[0178] Finally, step S80 is to fine-tune the base language model to obtain an optimized model that takes the time dimension into consideration. This step mainly includes the following sub-steps:
[0179] Sub-step S801: Integrate the feature vectors in the causal influence HLL graph into the input representation of the model. Specifically, expand the input representation of each token into a vector, including word embedding, position encoding, and node importance index. , Time Series Influence Score and attention score In this way, when processing text information, the model can use the characteristics of these time dimensions to enhance the understanding of time semantics.
[0180] Sub-step S802: Modify the attention mechanism of the model and incorporate the time-aware attention score. The time-aware factor can be introduced into the standard attention formula to obtain the following attention calculation formula:
[0181] ;
[0182] in, is the time perception matrix, is the causal relationship matrix, and its elements are defined as:
[0183]
[0184]
[0185] Through such modifications, the attention mechanism can better capture the temporal dependencies contained in the text.
[0186] Sub-step S803: Design a multi-task learning objective to optimize language modeling, time series prediction, and causal reasoning tasks simultaneously. The following composite loss function can be defined:
[0187] ;
[0188] in, for language modeling loss (cross entropy), is the time series prediction loss (mean square error), is the causal inference loss (binary cross entropy), is the time-aware attention loss (KL divergence). Through multi-task learning, the model can simultaneously master language modeling, time series prediction, and causal reasoning capabilities, and enhance the understanding and utilization of time dimension information.
[0189] Sub-step S804: Use technical means such as gradient accumulation and mixed precision training to perform large-scale distributed training. Since the scale of the fine-tuning data set may be large, technical means such as gradient accumulation and mixed precision training can be used to improve training efficiency and video memory utilization, thereby achieving large-scale distributed training.
[0190] Sub-step S805: Use early stopping strategy and model checkpoint saving to prevent overfitting and retain the best model. During the training process, the model performance will be regularly evaluated on the validation set. Once the performance is no longer improved (or there are signs of overfitting), the training will be stopped and the current best model checkpoint will be saved. This ensures that a model with good generalization performance is finally obtained.
[0191] Sub-step S806: Regularly evaluate the model performance on the validation set, including indicators such as perplexity, time series prediction accuracy, and causal reasoning ability. In addition to monitoring the loss function value during the training process, it is also necessary to regularly evaluate the model's performance indicators on tasks such as language modeling, time series prediction, and causal reasoning on the validation set, such as perplexity, accuracy, etc. These indicators will reflect the model's understanding and reasoning ability in the time dimension.
[0192] Sub-step S807: Dynamically adjust the learning rate and other hyperparameters based on the evaluation results. The following dynamic learning rate adjustment strategies can be used:
[0193] ;
[0194] in, For the The learning rate of the iteration, is the initial learning rate, is the attenuation rate, is the current iteration number, is the learning rate adjustment factor, and are the loss values of the current iteration and the previous iteration respectively. Through this strategy, the learning rate can be dynamically adjusted according to the changes in model performance to speed up convergence and obtain a better model.
[0195] A second aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores program instructions, and when the program instructions are run in a computer, they are used to execute the above-mentioned large language model time dimension optimization method.
[0196] A third aspect of the present invention provides a large language model time dimension optimization system, which includes the above-mentioned computer-readable storage medium.
[0197] In general, the time dimension optimization method of the large language model proposed in this invention is based on a technical idea of time-aware modeling. Through innovative means such as constructing a time-event network, analyzing causal relationships, and designing a time attention mechanism, the temporal semantic information contained in the training data is effectively mined and utilized, and the model's perception and modeling capabilities of time dimension information are enhanced.
[0198] In order to better understand and implement the present invention, the following is an example 2 of a specific application scenario of the present invention: R&D personnel collected data such as the technological development history, major technological breakthroughs, and related news reports of major global technology companies from 2000 to 2023, and constructed a large-scale technological development data set containing about 1 million records. The data set covers multiple cutting-edge technology fields such as artificial intelligence, quantum computing, biotechnology, and new energy. The goal of the R&D personnel is to use the time dimension optimization method proposed in the present invention to train a large language model that can predict future technological development trends.
[0199] First, the researchers preprocessed the data set according to step S10 of the invention. The Stanford NER tool was used for named entity recognition to extract key information such as company names, technical terms, and time expressions from the text. Then, the open source event extraction tool EventMiner was used to extract events from the text to identify important events such as technological breakthroughs, product launches, and strategic cooperation. Finally, based on the extracted entity and event information, the researchers constructed a time-event network with about 500,000 nodes and 2 million edges.
[0200] Next, according to steps S20-S30, the researchers used the PC algorithm to analyze the time-event network, calculated the conditional probability and time interval between events, and obtained the causal relationship diagram. In this process, the researchers set the time decay factor λ = 0.1 to balance the impact of short-term and long-term causal relationships.
[0201] In step S40, the researchers use the HyperLogLog algorithm to estimate the cardinality of each node in the causal relationship graph. The researchers set the number of hash functions m=1024 to strike a balance between accuracy and memory usage. After calculation, the researchers obtained the importance index of each technology event node, among which the top 10 nodes are shown in the following table:
[0202] Ranking Event Description Estimated cardinality 1 Google releases BERT model 1254879 2 OpenAI releases GPT-3 1198632 3 AlphaGo defeats Lee Sedol 1076543 4 Tesla launches Model 3 987654 5 iPhone is born 956789 6 SpaceX successfully recovers rocket 876543 7 IBM quantum computer breakthrough 798765 8 CRISPR gene editing technology 765432 9 Boeing 787 first flight 743210 10 Facebook Goes Public 721098
[0203] In step S50, the researchers use the PageRank algorithm to calculate the temporal influence of each node. The researchers set the damping factor d = 0.85 and the time decay factor μ = 0.05. After 100 iterations, the algorithm converged and the influence score of each node was obtained.
[0204] Combining the results of steps S40 and S50, the researchers designed a time-aware attention mechanism in step S60. The researchers defined the following mapping function:
[0205] ;
[0206] ;
[0207] ;
[0208] Among them, λ=0.1,γ=0.5. These functions are designed to balance the effects of time interval, node importance and influence.
[0209] In step S70, the researchers converted the causal influence HLL graph into an adjacency table, and combined the node features with the original text data to construct a fine-tuning dataset containing approximately 800,000 records.
[0210] Finally, in step S80, the researchers used this fine-tuning dataset to fine-tune the pre-trained base model, such as the Zhipu Qingyan ChatGlm6B-3 model. The researchers adopted the following specific strategies:
[0211] 1. The node feature vector (including importance index, influence score and attention score) is concatenated to the word input vector of each token, expanding the input representation of the model.
[0212] 2. The Transformer self-attention mechanism was modified to incorporate time-aware attention scores. Specifically, the researchers introduced the effects of time intervals and causality when calculating attention weights:
[0213] ;
[0214] Among them, T is the time perception matrix and C is the causal relationship matrix.
[0215] 3. Designed multi-task learning objectives, including:
[0216] Language Modeling Loss ;
[0217] Time Series Forecasting Loss ;
[0218] Causal Inference Loss ;
[0219] Time perception attention loss ;
[0220] The total loss function is:
[0221] ;
[0222] 4. Use mixed precision training and gradient accumulation technology to perform distributed training on 8 NVIDIA A100 GPUs. The researchers used the Adam optimizer, with an initial learning rate of 1e-5 and a batch size of 32.
[0223] 5. Evaluate model performance on the validation set every 1000 steps, including perplexity, time series prediction accuracy, and causal reasoning F1 score. Dynamically adjust the learning rate based on the evaluation results:
[0224] ;
[0225] Among them, η0 is the initial learning rate, t is the current iteration number, Lt and Lt-1 are the loss values of the current and previous iterations respectively.
[0226] 6. The training process lasted for 10 epochs, about 48 hours. The R&D staff saved a model checkpoint every epoch and selected the model with the best performance on the validation set as the final model.
[0227] After the training was completed, the R&D staff conducted a comprehensive evaluation of the model. On the reserved test set, the model achieved significant improvements in various indicators:
[0228] 1. The perplexity is reduced from 18.2 of the original ChatGlm6B-3 to 11.7, a decrease of 35.7%.
[0229] 2. The mean absolute error (MAE) of time series forecasting is 3.2 months, an improvement of 58.9% compared to 7.8 months of the baseline model.
[0230] 3. The F1 score of causal reasoning reaches 0.83, which is 33.9% higher than the baseline model’s 0.62.
[0231] In order to intuitively demonstrate the performance improvement of the model, the R&D personnel drew the curves of the changes of various indicators during the training process, such as Figure 2-4 These curves clearly show the significant advantages of the model of the present invention in various indicators. In particular, the model of the present invention performs well in time series prediction and causal reasoning, which proves the effectiveness of time dimension optimization.
[0232] In actual applications, researchers have also found that the model of the present invention performs particularly well in dealing with long-term scientific and technological development analysis. For example, when researchers asked the model to analyze the complex topic of "the impact of the evolution of Internet technology on the global economic structure from 1990 to 2023", the model was able to accurately divide the different development stages and deeply analyze the characteristics of each stage and its economic impact:
[0233] 1.1990-2000: Early stage of Internet commercialization
[0234] Characteristics: Popularization of email, rise of websites, and budding of e-commerce;
[0235] Economic impact: The rise of emerging Internet companies and the digital transformation of traditional industries;
[0236] 2.2000-2010: Web 2.0 Era
[0237] Characteristics: The rise of social media, the increase in user-generated content, and the development of cloud computing;
[0238] Economic impact: The platform economy model is formed, the long tail theory is applied, and the globalization process is accelerated;
[0239] 3.2010-2020: Mobile Internet Era
[0240] Features: Popularization of smart phones, development of mobile payments, and rise of the sharing economy;
[0241] Economic impact: The rise of the O2O model, the deep restructuring of traditional industries, and the rapid development of emerging markets;
[0242] 4.2020-2023: Digital economy in the current era
[0243] Features: Popularization of remote work, acceleration of digital transformation, and rise of the concept of the metaverse;
[0244] Economic impact: With the deep integration of online and offline, the digital divide problem is highlighted, and data security and privacy protection become the focus.
[0245] In this analysis, the model not only accurately grasps the technological characteristics of each period, but also deeply explores the impact of these technological changes on the economic structure, reflecting its powerful time series analysis and cross-domain correlation capabilities.
[0246] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
Claims
1. A method for optimizing the time dimension of a large language model, characterized in that: The following steps are involved: S10, extract time features, entity recognition and relationship extraction for each data item in the training data, and construct a time-event network; S20, using a causal inference algorithm to analyze the event sequence in the time-event network, calculate the conditional probability and time interval between events, and obtain the causal relationship path between all events in the training data; S30, establishing a directed acyclic graph according to the causal relationship path to obtain a causal relationship graph; S40, based on the causal relationship graph, according to the traversal path of each node, using the HyperLogLog algorithm to estimate the cardinality of the nodes on each path, obtaining the estimated cardinality value of each node in the causal relationship graph as the importance index of the node, and obtaining a causal relationship HLL graph; S50, using the PageRank algorithm to calculate the temporal influence of each node in the causal relationship HLL graph as the influence score of the corresponding node, and obtaining the causal relationship influence HLL graph; S60, based on the causal influence HLL graph, using the node importance index, influence score and time interval information, designing a time-aware attention mechanism, calculating the attention weight, and obtaining the attention score of each node in the causal influence HLL graph; S70, converting the causal influence HLL graph into an adjacency table, and taking the importance index, influence score and attention score of the node as a feature vector, combining it with the original text data, and establishing a fine-tuning data set; S80, fine-tuning the base large language model using the fine-tuning dataset to obtain a large language model that takes the time dimension into account; Among them, the conditional probability and time interval between events are calculated as follows: ; ; In the formula, For events In Events Time interval after occurrence The conditional probability of occurrence within For events After the occurrence Events in time Number of occurrences; For events Total number of occurrences; is the time decay factor; and Respectively for events and Timestamp of occurrence; or As subscripts, they all indicate the sequence number of the event; Among them, the time-aware attention mechanism is specifically expressed as follows: ; ; In the formula, For Node For Node The attention weight of Score for attention; is the query vector; is the key vector; is the dimension of the key vector; For Node and nodes the time interval between For Node HyperLogLog estimates the cardinality value; For Node The temporal influence score of function , and They are the mapping functions of time interval, importance index and time series influence, and are defined as follows: ; ; ; in, and is an adjustable hyperparameter; Step S80 includes the following specific steps: Step S801, integrating the feature vector in the causal influence HLL graph into the input representation of the model; Step S802: modify the attention mechanism of the model to incorporate the time-aware attention score; Step S803: design multi-task learning objectives and optimize language modeling, time series prediction, and causal reasoning tasks simultaneously; Step S804: Use technologies such as gradient accumulation and mixed precision training to perform large-scale distributed training; Step S805: adopt early stopping strategy and model checkpoint saving to prevent overfitting and retain the best model; Step S806: Regularly evaluate the model performance on the validation set, including indicators such as perplexity, time series prediction accuracy, and causal reasoning ability; Step S807: Dynamically adjust the learning rate and hyperparameters based on the evaluation results and ; Step S808, iterative optimization until convergence or reaching a preset training round; finally, a large language model optimized in the time dimension is obtained as the final large language model considering the time dimension; Among them, in step S802, the attention mechanism of the model is modified to incorporate the time-aware attention score to form a modified time-aware attention mechanism, which is specifically expressed as follows: ; In the formula, , , are query, key, and value matrices respectively; is the dimension of the key vector; is the time perception matrix, is the causal relationship matrix, whose elements are defined as: ; ; in, Represents the Hadamard product, which is the multiplication of corresponding elements of two matrices or vectors; The multi-task learning objective is specifically expressed as follows: ; In the formula, is the total loss; Modeling loss for language; Predicting losses for time series; Reasoning about loss for causality; Perceived attention loss for time; , , , is the weight coefficient of each task; Language Modeling Loss Using cross entropy loss: ; Time Series Forecasting Loss Use mean squared error: ; Causal Inference Loss Using binary cross entropy: ; Time perception attention loss Using KL divergence: ; in, is the sample size, is the vocabulary size, is the true value, is the predicted value, is the real timestamp, is the prediction timestamp, is the actual attention distribution, To predict the attention distribution, is the divergence operator; The dynamic adjustment of the learning rate is specifically expressed as follows: ; In the formula, For the The learning rate of the iteration; is the initial learning rate; is the decay rate; is the current iteration number; is the learning rate adjustment factor; and are the loss values of the current iteration and the previous iteration respectively.
2. A large language model time dimension optimization method according to claim 1, characterized in that: The cardinality estimation of the HyperLogLog algorithm is specifically expressed as follows: ; In the formula, Nodes in the causal relationship graph The estimated base value of is the number of hash functions; is the deviation correction factor, ; For Node In the The maximum number of leading zeros under a hash function; The calculation method is: ; in, For the A hash function, For the node A collection of all related events.
3. The method for optimizing the time dimension of a large language model according to claim 2, characterized in that: The temporal influence PageRank algorithm is specifically expressed as follows: ; In the formula, For Node The temporal influence score of is the damping factor, usually 0.85; To point to a node A collection of nodes; For Node The out-degree of For edge The weights of express; is the time decay factor; For Node arrive time interval.
4. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program instructions, and when the program instructions are executed in a computer, they are used to execute the large language model time dimension optimization method according to any one of claims 1 to 3.
5. A large language model time dimension optimization system, characterized in that: Contains the computer-readable storage medium of claim 4.
Citation Information
Patent Citations
Dialogue sentiment analysis method based on graph attention mechanism multi-view perception
CN117972512A
Document-level event causal relationship identification method based on graph reinforcement learning
CN118627617A