Traffic flow prediction method based on space-time knowledge graph and anchoring soft prompt project
By combining spatiotemporal knowledge graphs and anchored soft prompting engineering with spatiotemporal knowledge graph encoders and convolutional autoencoders, the problems of multi-source heterogeneous spatiotemporal information modeling and local structural dynamic characteristics capture in traffic flow prediction were solved, achieving high-precision long-term traffic flow prediction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING UNIV OF TECH
- Filing Date
- 2026-01-28
- Publication Date
- 2026-05-12
Smart Images

Figure CN122024497A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of traffic flow prediction technology, specifically to a traffic flow prediction method based on spatiotemporal knowledge graphs, convolutional autoencoders, anchored soft cueing engineering, and pre-trained language models. It is applicable to dynamic traffic flow prediction tasks involving multiple time steps and multiple road segments in complex urban road networks. Background Technology
[0002] With the development of smart city construction, accurate traffic flow prediction plays a crucial role in scenarios such as intelligent scheduling, route planning, and traffic signal control. Traditional machine learning-based methods (such as support vector machines) or neural networks (such as feedforward neural networks) have certain effectiveness in short-term predictions. However, in scenarios with longer prediction time spans and the need to simultaneously model the coupling characteristics of multiple road segments at the road network level, traditional methods exhibit significant performance bottlenecks due to their limited linear or shallow nonlinear modeling capabilities.
[0003] In recent years, emerging methods such as graph neural networks, spatiotemporal graph convolutional networks, and attention networks have transformed traffic flow prediction tasks into graph spatiotemporal sequence learning problems by explicitly embedding road topology and spatiotemporal dependencies. To a certain extent, these methods have improved the ability to model the spatial structure of traffic networks. However, they still face significant challenges in the following three aspects: (1) Existing research has limited ability to model multi-source heterogeneous spatiotemporal information such as weather, holidays, traffic accidents, and point of interest (POI) distribution, which restricts the generalization performance of the model; (2) It is difficult to coordinate the modeling of structured traffic data and unstructured semantic features, and there is a lack of a unified semantic representation mechanism, which limits the model's representation ability and prediction accuracy; (3) Existing work generally adopts global loss functions such as mean square error (MSE) or mean absolute error (MAE), which ignores the local structural dynamic characteristics of traffic states in the spatiotemporal dimension, making it difficult to capture long-distance spatiotemporal dependencies, resulting in the accumulation of long-term prediction errors and a decrease in robustness in transfer or fine-tuning scenarios.
[0004] Meanwhile, pretrained language models (PLMs) such as GPT and LLaMA have demonstrated powerful context modeling and generalization capabilities in natural language processing, code generation, and cross-modal learning tasks. Their Transformer architecture, trained on large-scale corpora, shows significant potential in modeling temporal dependencies. However, raw traffic flow data is a high-dimensional structured numerical sequence that cannot be directly input into language models. Furthermore, there is currently a lack of effective prompt word engineering methods to transform multi-source heterogeneous spatiotemporal information into input that language models can understand.
[0005] Therefore, there is an urgent need for a novel traffic flow prediction method that can deeply integrate unified spatiotemporal representation of multi-source heterogeneous data, anchoring soft cueing engineering, structured auxiliary loss function and the reasoning ability of pre-trained language models, in order to improve the accuracy and adaptability of traffic flow prediction in complex urban road networks. Summary of the Invention
[0006] The present invention aims to solve the following technical difficulties: (1) how to model high-dimensional structured traffic flow data and other heterogeneous spatiotemporal information into a unified low-dimensional spatiotemporal representation, which not only retains the local spatiotemporal correlation in the original data, but also maps it to a semantic space aligned with PLM; (2) how to design an effective traffic domain-specific prompt word construction method to generate prompt words that have clear traffic semantic information and are compatible with PLM input format, taking into account interpretability and modeling efficiency; (3) how to design a loss function that combines local dynamic changes and global structural constraints, so that the model can accurately capture spatiotemporal non-stationary changes and suppress error accumulation, while making full use of PLM's long-distance dependency capability to achieve robust long-range prediction and transfer fine-tuning.
[0007] The technical solution adopted in this invention is a traffic flow prediction method based on spatiotemporal knowledge graphs and anchor-guided soft-hint engineering, characterized by comprising the following three steps:
[0008] Step 1: Construct a unified spatiotemporal representation module;
[0009] Step 2, anchoring soft prompt engineering mechanism;
[0010] Step 3: Structured Assistance PLM Fine-tuning Strategy;
[0011] In step 1, the unified spatiotemporal representation module includes:
[0012] (1) Spatiotemporal knowledge graph encoder;
[0013] Sudden weather changes, holiday travel peaks, unexpected accidents, and external factors such as surrounding Points of Interest (POIs) significantly impact road traffic conditions in intelligent transportation systems. The Spatiotemporal Knowledge Graph Encoder (STKGE) integrates seemingly fragmented, multi-source, heterogeneous spatiotemporal information into a spatiotemporal knowledge graph, ultimately refining it into low-dimensional vector representations of external feature embeddings, which serve as auxiliary inputs for traffic flow prediction. The algorithm quickly extracts all facts related to its spatiotemporal neighborhood, and then uses an attention mechanism to weighted aggregate them to generate external feature embeddings.
[0014] The STKGE encoding process is divided into three layers: (1) Graph construction layer: First, through entity-relation modeling, external information such as weather, holidays, POI, accidents, and spatiotemporal index information is uniformly encoded into nodes and edges in the graph, forming a structured spatiotemporal quintuple set; (2) Embedding learning layer: Based on the TransE structure, spatial and temporal context information is fused to learn unified entity and relation embedding; (3) Feature aggregation layer: At a specific sensor-time slot location, the attention mechanism is used to weight and aggregate relevant graph facts in its neighborhood to generate semantic external feature vectors, which are used as auxiliary inputs for traffic prediction.
[0015] (2) Spatiotemporal convolutional autoencoder;
[0016] To extract deep spatiotemporal features from traffic flow data, a spatiotemporal convolutional autoencoder (STCAE) is introduced, which is combined with the external spatiotemporal feature embedding matrix extracted by the spatiotemporal knowledge graph encoder. To explore the spatiotemporal dependencies in traffic sequences.
[0017] In step 2, learnable soft cues and structured template cues are combined. Natural language template cues with traffic semantics serve as anchors, while trainable soft cues are used as supplements to guide the model in completing complex traffic flow prediction.
[0018] In step 3, a structured auxiliary loss function and a PFT strategy are used to jointly optimize the soft cue embedding and model prediction results, fine-tuning the cue-driven language model to achieve multi-step prediction of traffic conditions.
[0019] The specific implementation steps of the spatiotemporal knowledge graph encoder are as follows:
[0020] (a) Map construction layer
[0021] In STKGE's graph construction layer, the multi-source, heterogeneous external spatiotemporal information is first structured into a unified knowledge graph. This requires defining a set of heterogeneous entities. Relation sets And the basic spatiotemporal quintuple structure in the graph to support semantic reasoning across time and space.
[0022] Entity Collection External spatiotemporal information is divided into six major categories and seventeen subcategories of computable nodes, i.e., entities. The set of all entities is denoted as .
[0023]
[0024] Relation set To give facts direction and meaning to relationships.
[0025] The set of all relations is denoted as ,
[0026]
[0027] Spacetime quintuple set A single fact record is a snapshot of spacetime, and each fact is represented as a spacetime quintuple. ,in Represents the set of all facts. Indicates the head and tail entities. Indicates a relationship. Represents a discrete time slot. Indicates the sensor / road segment number.
[0028] (b) Embedded learning layer
[0029] To achieve unified modeling of heterogeneous spatiotemporal entities, STKGE, based on the knowledge graph embedding method TransE, proposes a spatiotemporal embedding scheme suitable for traffic scenarios by combining temporal and spatial embedding mechanisms in the graph embedding learning layer. This scheme is designed for constructing a quintuple fact set. This method embeds and expresses multidimensional information between entities, enhancing the modeling capabilities of traditional graph embedding in the spatiotemporal dimension and making it more consistent with the actual semantic structure of traffic flow scenarios.
[0030] First, all entities and relations are discrete information types, represented using a lookup table embedding method, with each head and tail entity... and each relationship The corresponding learnable embeddings are respectively , and .
[0031] Secondly, regarding the time slots in the quintuple. ,use The algorithm performs sinusoidal position encoding, thereby mapping discrete time to a continuous vector while preserving periodic patterns and sequence information. Specifically, it is expressed as follows:
[0032]
[0033] For spatial information, i.e., sensor or road segment number ,use Algorithm generates spatial embedding This is done to preserve the topological adjacency characteristics of the road network. Specifically, it is expressed as:
[0034]
[0035] A random walk strategy is performed on the road network graph to sample the set of context neighbors for each node. Based on the skip-gram principle, its goal is to maximize the prediction probability of a node in the context, that is:
[0036]
[0037] in Indicates at a given central node Predicting context nodes under the embedding The probability can be approximated using softmax or negative sampling. After training, the resulting spatial embedding matrix is: ∈ This embedding can compress the structural information of the original spatial nodes into a low-dimensional semantic space, serving as a spatial representation of nodes in the graph.
[0038] By introducing learnable weighting factors into the scoring function, dynamic adjustment of the contributions of entities, relations, and temporal and spatial embeddings can be achieved. In summary, for any quintuple... The scoring function, i.e., the confidence level that the fact is true in the graph, is defined as:
[0039]
[0040] in, · It is the L2 norm. , , and These represent the learnable weight factors for the four types of embeddings.
[0041] The scoring function follows TransE's "vector translation" concept, modeling each real fact in the spatiotemporal graph as a vector translation structure of head entity + relation ≈ tail entity, and introducing temporal and spatial embeddings to jointly construct the semantic translation path. The training objective is to maximize the score of valid quintuples and minimize the score of negatively sampled quadruples to enhance the discriminative power of the embeddings. The loss function is defined as:
[0042]
[0043] in, It is achieved by randomly replacing the head entity. or tail entity Constructed negative samples, It is a preset interval hyperparameter.
[0044] (c) Feature aggregation layer
[0045] In the STKGE feature aggregation layer, the model constructs a local correlation subgraph at each spatial node-temporal slot location, extracts relevant quintuple facts from its spatiotemporal neighborhood graph, and aggregates its semantic embeddings through an attention mechanism to form the final external feature vector representation, which serves as the semantic auxiliary input for the downstream prediction module. Specifically, for a given sensor... and time slot From the set of quintuples The relevant subset of facts is selected from the data to form a subgraph of its association:
[0046]
[0047] in, It is the allowed temporal neighborhood window size. Represents nodes In the time slot All related graph facts in the vicinity.
[0048] For each map fact Extract its graph embedding, including: head entity embedding. Relational embedding Time embedding Next, to measure the impact of different facts on the current node state, an attention mechanism is introduced to assign weights. For each fact... Its attention weight Calculated using the following formula:
[0049]
[0050] in For activation function, For learnable attention parameter vectors, This represents a vector concatenation operation. Finally, the tail entities corresponding to all facts in the subgraph are embedded. Perform a weighted summation to obtain the nodes. In the time slot external feature embedding :
[0051]
[0052] in = This indicates consistency with the entity embedding dimension.
[0053] The external feature vectors of all nodes are integrated across all time slots to form a global external feature embedding tensor. ,in It is the number of time slots. It is the number of spatial nodes.
[0054] The specific implementation process of the spatiotemporal convolutional autoencoder is as follows:
[0055] (a) Given input data as a sequence of multi-segment traffic flow data across multiple consecutive time steps, for example, with the following dimensions: ,in This indicates the length of the input historical time step. For the number of road segments, This represents the number of features for each road segment at each time step. (b) To enhance the model's generalization ability in real-world scenarios with sensor failures and missing data, a random spatiotemporal masking mechanism is introduced during training. This involves generating a masking matrix by randomly masking several road segments or time slices of the input data using a Bernoulli mask, and then masking the original input.
[0056]
[0057] in Represents element-wise multiplication. It is a masking matrix, each element Following a Bernoulli distribution, the masking probability Commonly used Input after masking With external feature embedding To splice,
[0058]
[0059] Will The data is fed into the encoder to extract its deep spatiotemporal feature representation, providing a more robust semantic foundation for subsequent predictions.
[0060] (c) The encoder consists of m-level spatiotemporal convolutional blocks Stacked together, each Each consists of a spatial graph convolutional layer (GCN) and a temporal convolutional layer (TCN).
[0061]
[0062] in It is a unified spatiotemporal representation with latent semantics after compression, providing a semantic basis for subsequent predictions.
[0063] Specifically, firstly, regarding the first Input data of layer GCN Every time slice Perform graph convolution processing:
[0064] in It is an adjacency matrix of the road network map, representing the connection relationships between sensors or road segments. Let represent the adjacency matrix after adding self-loops, where It is the identity matrix; This represents the corresponding degree matrix. Indicates the first layer The weight matrix of the convolutional layer in the Chinese image. ,express The A time slice, Indicates the upper level The output feature representation of the first A time slice, in which yes The feature dimension size set in the intermediate layer, Indicates the first The time slice has passed the first The node feature representation after GCN processing. Then, the graph convolution outputs of all time slices are concatenated along the time dimension to obtain the result. Next, one-dimensional causal convolution is performed along the time dimension, i.e., Temporal Convolutional Network (TCN). Each TCN module includes convolution operations, pooling, and non-linear activation function operations. To enhance training stability, LayerNorm and Dropout are introduced after the TCN modules, and input features are preserved through residual structures.
[0065]
[0066] +
[0067] in, These are time-series features that have undergone regularization. For the present The input features are then superimposed through residual connections to form the current... Output .
[0068] (d) Decoder and reconstruction loss: The decoder uses a multilayer perceptron. Unified spatiotemporal representation Reconstruct the original input data.
[0069]
[0070] Reconstruction error uses mean square error The loss function is defined as follows:
[0071]
[0072] in, The original input value, This is the result of the decoder reconstruction.
[0073] Step 2 includes:
[0074] (1) Unifying the spatiotemporal representation of traffic conditions As a trainable soft cue embedding:
[0075]
[0076] Used to guide language models to perform task specialization.
[0077] (2) At the same time, structured prompt words are constructed, that is, natural language template prompt words containing traffic semantics. The prompt words are processed by a word segmenter to obtain the corresponding word segmentation codes: The word segmentation encoding is then mapped to a fixed anchor hint embedding:
[0078]
[0079] (3) Embed soft prompts and anchor hint embedding Concatenate as an anchor soft prompt embedded in the input PLM :
[0080]
[0081] in This indicates the length of the constructed anchor soft prompt sequence, the length of the unified spatiotemporal representation containing multi-source heterogeneous information, and the length of the word segmentation sequence for natural language template prompts. This indicates the embedding dimension, which aligns with the dimension of the input to the pre-trained language model.
[0082] The specific implementation steps in step 3 are as follows:
[0083] (1) Predictive decoder;
[0084] By leveraging the long-range dependency capabilities of pre-trained language models, latent semantic embedding vectors are extracted to facilitate traffic flow prediction. Specifically, cue words are embedded... enter :
[0085]
[0086] in, The latent semantic embedding vectors output by the pre-trained language model. Represents the number of future time steps to be predicted. This represents the dimension of the latent representation output by the model. A pre-trained language model outputs a latent semantic embedding vector. Then, a two-layer MLP will be used as a prediction decoder to map it, thereby obtaining the target future prediction data tensor.
[0087]
[0088] in For the future time step Traffic flow forecast results for each road segment and It is the first Weights and biases of a layer perceptron. It is an activation function.
[0089] (2) PLM fine-tuning and training optimization;
[0090] Before freezing the pre-trained language model during the fine-tuning phase The parameters of the layer only apply to the last one. The Transformer layer is updated, and the PLM is updated before training. Layer parameter freezing, only for the back Layer parameters are optimized, and PSLoss is used as an auxiliary optimization objective. PSLoss first adaptively partitions the predicted and true sequences based on dominant frequency features, forming several structural fragment patches. Then, for each patch, the following three local structure alignment indices are calculated and weighted to form the final local structured auxiliary loss:
[0091] (3) Outcome evaluation mechanism;
[0092] The three local structure alignment metrics are as follows:
[0093] (a) Correlation loss: measures the consistency between the predicted patch and the actual patch in terms of trend direction, and encourages the model to maintain structural changes in the same direction;
[0094]
[0095] in, This represents the Pearson correlation coefficient; and The first The actual value and the predicted value of each patch.
[0096] (b) Variance loss: The relative distribution difference of fluctuations within the patch is calculated by using Softmax mapping and KL divergence to guide the model to capture the intensity of local fluctuations;
[0097]
[0098] in For the Softmax function, This represents the Kullback-Leibler divergence.
[0099] (c) Mean loss: measures the degree of deviation between the predicted and the actual patch in terms of the mean, and is used to correct the overall positional deviation and improve the alignment with the prediction baseline.
[0100]
[0101] in, , They represent the first The true mean and the predicted mean of each patch.
[0102] A dynamic weighting mechanism is used for the above three structural losses, automatically adjusting the weights based on the gradient magnitude of each loss term:
[0103]
[0104] in and These are weights that are dynamically adjusted during training, specifically based on the gradient of each term. The norm ratio is set and fine-tuned by incorporating the statistical distribution covariance of the predicted and actual values to improve the model's robustness and accuracy in long-term trend prediction. The final total loss function is updated to a three-layer structure:
[0105]
[0106] in , and These are hyperparameters, determined through cross-validation. The autoencoder reconstruction loss is defined by formula (4). The predicted loss for the primary monitoring term is expressed as mean squared error. :
[0107]
[0108] in, Predict the true value for the target. This is the predicted value from the decoder.
[0109] The results evaluation mechanism adopts the following three-step process.
[0110] (a) Predicted sequence extraction; after the model inference is completed, future sequences are extracted from the output layer. Each time step road section Traffic state prediction tensor with 3D features .
[0111] (b) Error measurement;
[0112] The predicted values are compared with the actual observed data point by point, using... and As an evaluation metric to measure overall prediction accuracy:
[0113]
[0114]
[0115] in, This represents the model's predicted value. This represents the corresponding actual observed value. The focus is on penalizing larger deviations. This reflects the overall absolute deviation, and together they characterize the model's accuracy and robustness.
[0116] (c) Determination of the validity of the results;
[0117] Set an experience threshold and like
[0118]
[0119] If the prediction is valid, it is considered valid; otherwise, it is considered abnormal. Attached Figure Description
[0120] Figure 1 This is a flowchart illustrating the overall steps of the present invention.
[0121] Figure 2 This is a schematic diagram of the spatiotemporal knowledge graph encoder (STKGE) of the present invention.
[0122] Figure 3 This is the spatiotemporal knowledge graph semantic skeleton of the present invention.
[0123] Figure 4 This is a schematic diagram of the specific spatiotemporal quintuple structure of the present invention.
[0124] Figure 5 This is a schematic diagram of the spatiotemporal convolutional autoencoder (STCAE) structure. Detailed Implementation
[0125] To address this, this invention proposes a traffic flow prediction method that combines unified spatiotemporal representation, anchored soft cueing engineering, and a structure-assisted PLM fine-tuning strategy. This method is based on multi-source heterogeneous spatiotemporal data, combines graph neural networks and autoencoders to extract unified spatiotemporal semantic embeddings, and aligns these embeddings with natural language input through a soft cueing mechanism to guide a pre-trained language model in the traffic prediction task. Simultaneously, a structure-aware auxiliary loss function is introduced to improve the model's structural expressiveness and prediction accuracy. The technical approach of this invention is detailed below:
[0126] Unified Spatiotemporal Representation Module
[0127] This invention designs a unified spatio-temporal representation module that combines a Spatio-Temporal Knowledge Graph Encoder (STKGE) and a Spatio-Temporal Convolutional Autoencoder (STCAE) to achieve unified modeling of multi-source data. Specifically, STKGE utilizes spatio-temporal index information (such as time slots and road segments / sensors), weather, holidays, traffic accidents, and POI data to construct a spatio-temporal knowledge graph, encoding it as external feature embeddings. STCAE, composed of multi-layer graph convolution and temporal convolution layers, extracts a unified spatio-temporal representation that combines spatio-temporal dependence with semantic generalization capabilities by combining the aforementioned external feature embeddings and historical traffic data. This representation not only preserves the dynamic structural features of the urban road network but also possesses semantic consistency aligned with the PLM input space, laying a semantic foundation for subsequent anchoring soft cue construction and fine-tuning tasks.
[0128] Anchoring soft prompt engineering mechanism
[0129] This invention proposes an anchored soft cue mechanism to integrate the low-dimensional spatiotemporal representation output by the unified spatiotemporal representation module with natural language cueing from the traffic domain. Specifically, a structured natural language cue template is first used to explicitly embed external spatiotemporal information such as weather, holidays, and traffic accidents as semantic anchors, supplemented by a learnable unified spatiotemporal representation. The two parts are then concatenated into a unified anchored soft cue, which is input into the PLM (Public Traffic Modeling) to achieve precise alignment between structured data and the PLM input paradigm. This mechanism ensures that the model accurately understands and generalizes the spatiotemporal dynamics of traffic data while fully leveraging the contextual modeling capabilities of the PLM, and achieves a balance between prediction accuracy and semantic interpretability through end-to-end training.
[0130] Structured Assisted PLM Fine-Tuning Strategy
[0131] This invention, based on a Transformer architecture-based PLM, encodes structured anchor soft cue words into semantic embedding vectors to characterize the spatiotemporal evolution trend of future traffic conditions; subsequently, a lightweight decoder (such as an MLP) maps these vectors to continuous traffic flow predictions. During fine-tuning, before freezing the PLM... Layer, only for the back The parameters are updated at each layer to enhance adaptability to the distribution of traffic data in the target city while preserving general semantics. To strengthen the perception of the internal structure of the sequence, a structured auxiliary loss function (Patch-wise Structural Loss, PSLoss) is introduced during the training phase: First, based on the dominant frequency feature, the predicted and real time-series data are adaptively divided into several structural segments (patch). In each patch, mean offset, variance distribution, and correlation indicators are comprehensively considered and weighted to form an error metric for local structural alignment. This compensates for the sluggishness of point-to-point errors on overall structural misalignment, enhances the model's ability to model long-range dependencies and local dynamic features, and achieves high-precision and high-stability long-range traffic flow prediction.
[0132] 2. Specific measures
[0133] like Figure 1 As shown, the main contents of this invention include a unified spatiotemporal representation module, an anchor-guided soft prompting engineering mechanism, a structured auxiliary PLM fine-tuning strategy, and result evaluation, forming an end-to-end traffic state perception and prediction method. The modules are connected through semantic information flow, enabling high-precision modeling and prediction of future traffic states from raw multi-source heterogeneous spatiotemporal information.
[0134] 2.1 Unified Spatiotemporal Representation Module
[0135] This module aims to integrate multi-source heterogeneous spatiotemporal information with historical traffic flow sequences to learn a unified spatiotemporal representation of traffic conditions. External feature embeddings are extracted using a spatiotemporal knowledge graph encoder (STKGE), concatenated with historical traffic flow data, and then input into a spatiotemporal convolutional autoencoder (STCAE) to extract the unified spatiotemporal representation. This combination preserves local spatiotemporal relevance and aligns with the PLM semantic space, laying the semantic input foundation for subsequent anchor soft cue construction and fine-tuning.
[0136] 2.1.1 Spatiotemporal Knowledge Graph Encoder
[0137] In intelligent transportation systems, external factors such as sudden weather changes, holiday travel peaks, unexpected accidents, and surrounding Points of Interest (POIs) often significantly impact road traffic conditions. To effectively integrate this multi-source, heterogeneous external spatiotemporal information, the Spatiotemporal Knowledge Graph Encoder (STKGE) integrates seemingly fragmented multi-source, heterogeneous spatiotemporal information into a spatiotemporal knowledge graph, ultimately refining it into low-dimensional vector representations of external feature embeddings, which serve as auxiliary inputs for traffic flow prediction. Using this graph structure, traffic flow prediction can be performed in any... The STKGE encoding process quickly extracts all facts related to its spatiotemporal neighborhood, then uses an attention mechanism for weighted aggregation to generate a concise yet information-rich external feature embedding. The STKGE encoding process consists of three levels, with the overall structure as follows: Figure 2 As shown: (1) GraphConstructionLayer: First, through entity-relation modeling, external information such as weather, holidays, POI, accidents, and spatiotemporal index information (such as time slots and road segments / sensors) is uniformly encoded into nodes and edges in the graph, forming a structured spatiotemporal quintuple set; (2) EmbeddingLearningLayer: Based on the TransE structure, spatial and temporal context information is fused to learn unified entity and relation embeddings; (3) FeatureAggregationLayer: At a specific sensor-time slot location, the attention mechanism is used to weight and aggregate relevant graph facts in its neighborhood to generate semantic external feature vectors, which are used as auxiliary inputs for traffic prediction. The specific implementation steps are as follows:
[0138] (1) Map construction layer
[0139] In the STKGE graph construction layer, we first structure the multi-source, heterogeneous external spatiotemporal information into a unified knowledge graph. To do this, we need to define a set of heterogeneous entities. Relation sets And the basic spatiotemporal quintuple structure in the graph to support semantic reasoning across time and space.
[0140] Entity Collection External spatiotemporal information is divided into six major categories and seventeen subcategories of computable nodes, i.e., entities, such as... As shown, the set of all entities is denoted as ,
[0141]
[0142] surface Entity types (6 major categories and 17 subcategories with fine granularity)
[0143]
[0144] Relation set Relationships give "facts" direction and meaning. The seven types of relationships listed in the document connect entities into a reasonable network. For example, the "time-sensitive" and "space-sensitive" columns can be used to determine which edges need to be considered given a context. Spatiotemporal filtering is performed on the above. The set of all relations is denoted as .
[0145]
[0146] surface relation schema
[0147]
[0148] Figure 3 This paper presents the semantic skeleton of the spatiotemporal knowledge graph constructed in this study. Nodes in the graph represent six heterogeneous entity classes and their subclasses, including road segments / sensors, weather, holidays, POIs, traffic accidents, and time slots; edges represent the semantic relationships between them, such as hasWeather, happensAt, and effectsFlow. By fusing multi-source heterogeneous spatiotemporal information, this graph establishes reasonable connections between entities in both spatial and temporal dimensions, providing unified and structured external feature support for subsequent traffic flow prediction tasks.
[0149] Spacetime quintuple set A single fact record is a snapshot of spacetime, and each fact can be represented as a spacetime quintuple. ,in Represents the set of all facts. Indicates the head and tail entities. Indicates a relationship. This indicates a discrete time slot (e.g., 5-min or 1-h particle size). Indicates the sensor / road segment number. The example shows some spatiotemporal quintuples, such as: (sensor_12, hasWeather, Rain_heavy, 2023-07-30T08:00, link_12) which means "Heavy rain occurred on the link_12 section between 8:00 and 8:05 on July 30, 2023." Figure 4 This demonstrates the structured representation of the specific spatiotemporal quintuple in the graph. Similarly, accidents, holidays, and POIs are stored in the same format for easy unified querying.
[0150] surface Example of a spacetime quintuple
[0151]
[0152] (2) Embedded learning layer
[0153] To achieve unified modeling of heterogeneous spatiotemporal entities, STKGE, in its graph embedding learning layer, proposes a spatiotemporal embedding scheme suitable for traffic scenarios by combining temporal and spatial embedding mechanisms, building upon the traditional knowledge graph embedding method TransE. This scheme targets the constructed quintuple fact set. This method embeds and expresses multidimensional information between entities, enhancing the modeling capabilities of traditional graph embedding in the spatiotemporal dimension and making it more consistent with the actual semantic structure of traffic flow scenarios.
[0154] First, all entities and relations are discrete information types, represented using a lookup table embedding method, with each head and tail entity... and each relationship The corresponding learnable embeddings are respectively , and ,in and These represent the head entities in the spatiotemporal knowledge graph. Tail-end entity Embedded vector, The dimension representing entity embedding (all entities) , (Dimension of the embedding vector); Representing entity relationship Embedded vector, This is entity relationship embedding Dimensions (all relationships) (Dimension of the embedding vector).
[0155] Secondly, regarding the time slots in the quintuple. ,in Represents the set of all discrete time slots, using The algorithm performs sinusoidal position encoding, thereby mapping discrete time to a continuous vector while preserving periodic patterns and sequence information. Specifically, it is expressed as follows:
[0156]
[0157] in, Indicates time slot of Temporal embedding vector, This indicates the dimension of time embedding.
[0158] For spatial information, i.e., sensor or road segment number ,in Represents the set of all sensor / segment numbers, using Algorithm generates spatial embedding This is done to preserve the topological adjacency characteristics of the road network. Specifically, it is expressed as:
[0159]
[0160] in, Is it a sensor or road segment number? of Spatial embedding vector, Indicates the dimension of spatial embedding.
[0161] A random walk strategy is performed on the road network graph to sample the set of context neighbors for each node. Based on the skip-gram principle, its goal is to maximize the prediction probability of a node in the context, that is:
[0162]
[0163] in Indicates at a given central node Embedded Next, predict the context node. The probability can be approximated using softmax or negative sampling. After training, the resulting spatial embedding matrix is: ∈ ,in This indicates the number of spatial nodes for road network sensors or road segments. This embedding can compress the structural information of the original spatial nodes into a low-dimensional semantic space, serving as a spatial representation of nodes in the graph.
[0164] To further enhance the modeling capabilities of spatiotemporal embedding, considering the heterogeneity of different information dimensions in traffic flow prediction, a learnable weighting factor can be introduced into the scoring function to dynamically adjust the contributions of entity, relation, temporal, and spatial embeddings. In summary, for any quintuple... The scoring function (i.e., the confidence level that the fact is true in the graph) is defined as:
[0165]
[0166] in, · The L2 norm (Euclidean distance) , , and These represent four types of learnable weight factors for embedding, which are automatically adjusted through training to increase the contribution of each dimension of information to the prediction task. , , These are the head entities in the corresponding quintuples. ,relation Tail entity Time slot and sensor / road segment number The embedding vector.
[0167] The scoring function follows TransE's "vector translation" concept, modeling each real fact in the spatiotemporal graph as a vector translation structure of "head entity + relation ≈ tail entity," and introducing temporal and spatial embeddings to jointly construct the semantic translation path. The training objective is to maximize the score of valid quintuples and minimize the score of negatively sampled quadruples to enhance the discriminative power of the embeddings. The loss function is defined as:
[0168] (6)
[0169] in, It is achieved by randomly replacing the head entity. or tail entity Constructed negative samples, It is a preset margin hyperparameter used in the loss function. In order to enhance the discriminative ability of the embedded part; (·) indicates that for any quintuple The scoring function measures the confidence level that the fact is true.
[0170] (3) Feature aggregation layer
[0171] In the STKGE feature aggregation layer, the model constructs a local correlation subgraph at each spatial node-temporal slot location, extracts relevant quintuple facts from its spatiotemporal neighborhood graph, and aggregates its semantic embeddings through an attention mechanism to form the final external feature vector representation, which serves as the semantic auxiliary input for the downstream prediction module. Specifically, for a given sensor... and time slot ,in Represents the set of all discrete time slots. Represents the set of all sensor / segment numbers, from the set of quintuples. The relevant subset of facts is selected from the data to form a subgraph of its association:
[0172]
[0173] in, This is the allowed temporal neighborhood window size, used for filtering within the feature aggregation layer relative to the current time slot. The relevant facts, It is a fact of the map The time slot in the graph represents the time when a certain graph fact occurs or exists, and is used to determine whether the fact is close enough to the time when the fact to be predicted occurs. , Must be in the current time slot Temporal neighborhood window Within ( ); For the associated subgraph, it represents the relationship between nodes. In the time slot A subset of all graph facts that are related in the vicinity.
[0174] For each map fact We extract its graph embeddings, including: head entity embeddings. Relational embedding Time embedding Next, to measure the impact of different facts on the current node state, an attention mechanism is introduced to assign weights. For each fact... Its attention weight Calculated using the following formula:
[0175]
[0176] in For activation function, This is a learnable attention parameter vector used by the attention mechanism to calculate the weights for each graph fact. Indicates the relationship with the node In the time slot A subset of all graph facts that are related in the vicinity The pictorial facts in the text, This represents the vector concatenation operation. Finally, the tail entity embeddings are performed on all facts corresponding to the facts in the subgraph. Perform a weighted summation to obtain the nodes. In the time slot external feature embedding :
[0177]
[0178] in The dimension representing the external feature embedding, and the dimension representing the entity embedding. Maintain consistency Represent each fact Attention weights.
[0179] The external feature vectors of all nodes are integrated across all time slots to form a global external feature embedding tensor:
[0180] ,
[0181] in It is the number of time slots. This represents the number of spatial nodes, i.e., the number of road segments or sensors. This tensor represents all... Each spatial node The external feature embedding matrix in each time slot serves as an auxiliary input in downstream models (such as STCAE) and participates in multi-source information fusion and future traffic state prediction tasks.
[0182] 2.1.2 Spatiotemporal Convolutional Autoencoder
[0183] To effectively extract deep spatiotemporal features from traffic flow data, this invention introduces a spatiotemporal convolutional autoencoder (STCAE) and integrates it with an external spatiotemporal feature embedding matrix extracted by a spatiotemporal knowledge graph encoder. By mining the spatiotemporal dependencies in traffic sequences, the overall structure of STCAE is as follows: Figure 5 As shown. The specific implementation process is as follows:
[0184] (1) The given input data is a sequence of traffic flow data for multiple road segments over several consecutive time steps, for example, the dimension is: ,in This indicates the length of the input historical time step (e.g., 15 steps). The number of road segments (e.g., 80 road segments), This represents the number of features for each road segment at each time step, such as traffic speed, flow rate, and density.
[0185] (2) To enhance the model's generalization ability in real-world scenarios such as sensor failure and data loss, a random spatiotemporal masking mechanism is introduced during training. This involves generating a masking matrix by randomly masking several road segments or time slices of the input data using a random Bernoulli mask, and then masking the original input.
[0186]
[0187] in Represents element-wise multiplication. It is a masking matrix, each element Following a Bernoulli distribution, the masking probability Commonly used (i.e., random occlusion) (data), input after masking With external feature embedding To splice,
[0188]
[0189] Then The data is fed into the encoder to extract its deep spatiotemporal feature representation, providing a more robust semantic foundation for subsequent predictions.
[0190] (3) The encoder consists of m-level spatiotemporal convolutional blocks Stacked together, each Each consists of a spatial graph convolutional network (GCN) and a temporal convolutional network (TCN):
[0191]
[0192] in It is a unified spatiotemporal representation with latent semantics after compression, providing a semantic foundation for subsequent predictions. This indicates the length of the input historical time step. For the number of road segments, express Unified spatiotemporal representation of encoder output The feature dimensions.
[0193] Specifically, firstly, regarding the first Input data of layer GCN Every time slice Perform graph convolution processing:
[0194]
[0195] in It is an adjacency matrix of the road network map, representing the connection relationships between sensors or road segments. Let represent the adjacency matrix after adding self-loops, where It is the identity matrix; This represents the corresponding degree matrix. Indicates the first layer The weight matrix of the convolutional layer in the Chinese image. This indicates the layer index where the current GCN is located. ,express The A time slice, Indicates the upper level Output feature representation The A time slice, in which yes The feature dimension size set in the intermediate layer, Indicates the first The time slice has passed the first The node feature representation after GCN processing. Then, the graph convolution outputs of all time slices are concatenated along the time dimension to obtain the result. Next, one-dimensional causal convolution is performed along the time dimension, i.e., Temporal Convolutional Network (TCN). Each TCN module includes convolution operations, pooling, and non-linear activation function operations. To enhance training stability, LayerNorm and Dropout are introduced after the TCN modules, and input features are preserved through residual structures.
[0196] +
[0197] in, These are time-series features that have undergone regularization. For the present The input features are then superimposed through residual connections to form the current... Output This design effectively expresses the complex spatiotemporal dynamics of traffic scenarios while avoiding the degradation problem in deep models, thus improving the robustness of modeling in real-world environments (such as missing data or sensor failures).
[0198] (4) Decoder and reconstruction loss: The decoder uses a multilayer perceptron (MLP). ) on unified spatiotemporal representation Reconstruct the original input data.
[0199]
[0200] The decoder represents the unified spatiotemporal representation. The original input data obtained by reconstruction express The encoder outputs a unified spatiotemporal representation with latent semantics.
[0201] Reconstruction error uses mean square error (MSE) The loss function is defined as follows:
[0202]
[0203] in, This represents the reconstruction error of the autoencoder. The original input value, The result of the decoder reconstruction; , , These represent the length of the input historical time step, the total number of sensors or road segments in the traffic network, and the number of features for each sensor or road segment at each time step, respectively. These represent the corresponding time slot index, sensor or road segment index, and feature index, respectively.
[0204] 2.2 Anchoring Soft Hint Engineering Mechanism
[0205] To seamlessly drive pre-trained language models with traffic state representations extracted by the unified spatiotemporal representation module, this invention proposes an anchored soft cueing engineering mechanism. This mechanism combines learnable soft cues and structured template cues, using natural language template cues with traffic semantics as anchors and trainable soft cues as supplements to jointly guide the model in completing complex traffic flow predictions. The specific implementation steps are as follows:
[0206] (1) Unifying the spatiotemporal representation of traffic conditions As a trainable soft cue embedding:
[0207]
[0208] Used to guide language models to perform task specialization.
[0209] (2) At the same time, construct structured prompt words, that is, natural language template prompt words that contain traffic semantics, for example: "The traffic station uses meding for the past 30 minutes is: Considering current weather: [Weather features], events: [Event features], please predict the next 30-minute soft raffic speeds. This prompt word is segmented and encoded by the tokenizer. The word segmentation encoding is then mapped to a fixed anchor hint embedding:
[0210]
[0211] in, Indicates the length of the prompt word sequence. Represents the embedding dimension, which aligns to the dimension of the pre-trained language model (PLM) input.
[0212] (3) Embed soft prompts and anchor hint embedding Concatenate as an anchor soft prompt embedded in the input PLM :
[0213]
[0214] in This indicates the length of the constructed anchor soft prompt sequence, the length of the unified spatiotemporal representation containing multi-source heterogeneous information, and the length of the word segmentation sequence for natural language template prompts. This indicates the embedding dimension, which aligns with the dimension of the input to the pre-trained language model.
[0215] In the anchor-guided soft prompting engineering proposed in this invention, the structured template prompts acting as anchors ensure that the pre-trained language model understands the task format, while the soft prompts, while retaining the pre-trained knowledge, implicitly map multi-source heterogeneous spatiotemporal information to the semantic space of the pre-trained language model, guiding the model to accurately capture the spatiotemporal dynamic features of traffic data, and at the same time leveraging the contextual expressive ability of the language model to achieve a unified optimization of prediction accuracy and semantic interpretability.
[0216] 2.3 Structured Assisted PLM Fine-Tuning Strategy
[0217] 2.3.1 Predictive Decoder
[0218] By leveraging the long-range dependency capabilities of pre-trained language models, latent semantic embedding vectors are extracted to facilitate traffic flow prediction. Specifically, cue words are embedded... enter :
[0219]
[0220] in, The latent semantic embedding vectors output by the pre-trained language model. Represents the number of future time steps to be predicted. The implicit representation dimension of the model output. It is to embed soft prompts and anchor hint embedding Anchor soft prompts are embedded by splicing.
[0221] The Transformer structure of the pre-trained language model captures the spatiotemporal dynamics and future trend changes of the input sequence through an attention mechanism, possessing powerful sequence reasoning and generalization capabilities. The output of the pre-trained language model is then converted into predictions of traffic flow values for multiple road segments at multiple future time steps. Specifically, the pre-trained language model outputs a latent semantic embedding vector. Next, a two-layer MLP will be used as a prediction decoder to map it, resulting in the target future prediction data tensor:
[0222]
[0223] in For the future time step Traffic flow forecast results for each road segment The latent semantic embedding vectors output by the pre-trained language model. and It is the first Weights and biases of a layer perceptron. It is an activation function.
[0224] 2.3.2 PLM Fine-tuning and Training Optimization
[0225] To adapt to specific traffic data distributions and improve model performance in target city scenarios, this invention proposes a flexible and efficient fine-tuning-training strategy. Before freezing the pre-trained language model during the fine-tuning phase (…),… The parameters of the last layer are only applicable to the last layer. The Transformer layer is updated, thus fully utilizing the existing knowledge of the pre-trained speech model, improving the model's adaptability to specific downstream tasks, and reducing training costs. Specifically, during training, the PLM layer is updated (…). Layer parameters are frozen, only for the later layers. Layer parameters are optimized, and PSLoss is used as an auxiliary optimization objective to improve the model's ability to fit local dynamic structures in complex traffic scenarios. This loss function compares the predicted and true sequences at the local structural level, integrating statistical indicators such as correlation, variance distribution, and mean shift, aiming to alleviate the insensitivity of traditional point-to-point error functions to overall sequence structural misalignment. PSLoss first adaptively divides the predicted and true sequences based on dominant frequency features, forming several structural patches. Then, the following three local structural alignment indices are calculated on each patch and weighted and fused to form the final local structural auxiliary loss:
[0226] (1) Correlation loss: measures the consistency between the predicted patch and the actual patch in terms of trend direction, and encourages the model to maintain structural changes in the same direction;
[0227]
[0228] in, This represents the correlation loss, used to measure the consistency between the predicted patch and the actual patch in terms of trend direction. This represents the Pearson correlation coefficient; and The first The true and predicted values of each patch, where the index... The data represents segments that have been divided into local structural pieces (patches). This represents the total number of structural segments (patches) into which the predicted sequence is divided.
[0229] (2) Variance loss: The relative distribution difference of fluctuations within the patch is calculated by using Softmax mapping and KL divergence to guide the model to capture the intensity of local fluctuations;
[0230]
[0231] in, This represents variance loss, used to measure the relative distributional differences in fluctuations within a patch. For the Softmax function, Indicates the Kullback-Leibler divergence. and The first The true and predicted values of each patch, where the index... The data represents segments that have been divided into local structural pieces (patches). This represents the total number of structural segments (patches) into which the predicted sequence is divided.
[0232] (3) Mean loss: measures the degree of deviation between the predicted and the actual patch in order to correct the overall positional deviation and improve the alignment of the prediction benchmark.
[0233]
[0234] in, This represents the mean loss, used to measure the deviation of the predicted patch from the actual patch's mean. , They represent the first The true mean and the predicted mean of each patch This represents the total number of structural segments (patches) into which the predicted sequence is divided.
[0235] A dynamic weighting mechanism is used for the above three structural losses, automatically adjusting the weights based on the gradient magnitude of each loss term:
[0236]
[0237] in, and These are dynamically adjusted weights during training, used to weight and combine the three loss terms in PSLoss, specifically based on the gradient of each term. The norm ratio is set and fine-tuned by incorporating the statistical distribution covariance of the predicted and actual values to improve the model's robustness and accuracy in long-term trend prediction. The final total loss function is updated to a three-layer structure:
[0238]
[0239] in , and These are hyperparameters used to calculate the various loss terms in the weighted total loss, determined through cross-validation. The autoencoder reconstruction loss is defined by formula (4). The predicted loss of the main monitoring term, i.e., the mean squared error (MSE). ):
[0240]
[0241] in, Predict the true value for the target. To predict the decoder's predicted values, , , These represent the number of future time steps to be predicted, the total number of sensors or road segments in the traffic network, and the number of features for each sensor or road segment at each time step, respectively. These represent the corresponding time slot index, sensor or road segment index, and feature index, respectively.
[0242] The above design, while maintaining the original model structure, introduces a structural consistency metric mechanism, which effectively enhances the model's ability to model traffic flow sequence structure. Finally, PSLoss is used as an auxiliary loss and... The combined effect of loss and reconstruction loss enables precise fitting and efficient prediction of the local dynamic structure of complex traffic time series data.
[0243] 2.4 Results Evaluation
[0244] To comprehensively evaluate the effectiveness of traffic flow prediction, this invention employs the following three-step process.
[0245] After the prediction sequence extraction model completes inference, it extracts the future sequence from the output layer. Each time step road section Traffic state prediction tensor with 3D features .
[0246] Error Measurement
[0247] The predicted values are compared with the actual observed data point by point, using... and As an evaluation metric to measure overall prediction accuracy:
[0248]
[0249]
[0250] in, This represents the model's predicted value. This represents the corresponding actual observed value. The focus is on penalizing larger deviations. This reflects the overall absolute deviation, and together they characterize the model's accuracy and robustness.
[0251] Validity determination of results
[0252] Set an experience threshold and like
[0253]
[0254] If the prediction is valid, it is considered valid; otherwise, it is considered abnormal.
Claims
1. A traffic flow prediction method based on spatiotemporal knowledge graphs and anchor-guided soft-cue engineering, characterized in that, It includes the following three steps, Step 1: Construct a unified spatiotemporal representation module; Step 2, anchoring soft prompt engineering mechanism; Step 3: Structured Assistance PLM Fine-tuning Strategy; In step 1, the unified spatiotemporal representation module includes: (1) Spatiotemporal knowledge graph encoder; Sudden weather changes, holiday travel peaks, unexpected accidents, and external factors such as surrounding Points of Interest (POIs) significantly impact road traffic conditions in intelligent transportation systems. The spatiotemporal knowledge graph encoder STKGE integrates seemingly fragmented multi-source heterogeneous spatiotemporal information into a spatiotemporal knowledge graph, ultimately refining it into low-dimensional vector representations of external feature embeddings as auxiliary inputs for traffic flow prediction. The algorithm quickly extracts all facts related to its spatiotemporal neighborhood, and then uses an attention mechanism to weighted aggregate them to generate external feature embeddings. The STKGE encoding process is divided into three layers: (1) Graph construction layer: First, through entity-relation modeling, external information such as weather, holidays, POI, accidents, and spatiotemporal index information is uniformly encoded into nodes and edges in the graph, forming a structured spatiotemporal quintuple set; (2) Embedding learning layer: Based on the TransE structure, spatial and temporal context information is fused to learn unified entity and relation embedding; (3) Feature aggregation layer: At a specific sensor-time slot location, the attention mechanism is used to weight and aggregate relevant graph facts in its neighborhood to generate semantic external feature vectors, which are used as auxiliary inputs for traffic prediction. (2) Spatiotemporal convolutional autoencoder; To extract deep spatiotemporal features from traffic flow data, a spatiotemporal convolutional autoencoder (STCAE) is introduced, which is combined with the external spatiotemporal feature embedding matrix extracted by the spatiotemporal knowledge graph encoder. To explore the spatiotemporal dependencies in traffic sequences; In step 2, learnable soft prompts and structured template prompts are combined, with natural language template prompts with traffic semantics as anchors and trainable soft prompts as supplements, to jointly guide the model to complete complex traffic flow prediction. In step 3, a structured auxiliary loss function and a PFT strategy are used to jointly optimize the soft cue embedding and model prediction results, and the language model driven by the cue is fine-tuned to achieve multi-step prediction of traffic conditions.
2. The traffic flow prediction method based on spatiotemporal knowledge graph and anchoring soft prompting engineering as described in claim 1, characterized in that, The specific implementation steps of the spatiotemporal knowledge graph encoder are as follows: (a) Map construction layer In the graph construction layer of STKGE, the first step is to structure the multi-source heterogeneous external spatiotemporal information into a unified knowledge graph; this requires defining a set of heterogeneous entities. Relation sets And the basic spatiotemporal quintuple structure in the graph to support semantic reasoning across time and space; Entity Collection External spatiotemporal information is divided into six major categories and seventeen subcategories of computable nodes, i.e., entities. The set of all entities is denoted as . ; Relation set To give facts direction and meaning to relationships; The set of all relations is denoted as , ; Spacetime quintuple set A single fact record is a snapshot of spacetime, and each fact is represented as a spacetime quintuple. ,in Represents the set of all facts. Indicates the head and tail entities. Indicates a relationship. Represents a discrete time slot. Indicates the sensor / road segment number; (b) Embedded learning layer To achieve unified modeling of heterogeneous spatiotemporal entities, STKGE, based on the knowledge graph embedding method TransE, proposes a spatiotemporal embedding scheme suitable for traffic scenarios by combining temporal and spatial embedding mechanisms in the graph embedding learning layer. A set of facts for constructing quintuples This method embeds and expresses multidimensional information between entities, enhancing the modeling ability of traditional graph embedding in the spatiotemporal dimension and making it more consistent with the actual semantic structure of traffic flow scenarios. First, all entities and relations are discrete information types, represented using a lookup table embedding method, with each head and tail entity... and each relationship The corresponding learnable embeddings are respectively , and ; Secondly, regarding the time slots in the quintuple. ,use The algorithm performs sinusoidal position encoding, thereby mapping discrete time to a continuous vector while preserving periodic patterns and sequence information; specifically, it is expressed as follows: ; For spatial information, i.e., sensor or road segment number ,use Algorithm generates spatial embedding This is done to preserve the topological adjacency characteristics of the road network; specifically, it is expressed as: ; A random walk strategy is performed on the road network graph to sample the set of context neighbors for each node. Based on the skip-gram principle, its goal is to maximize the prediction probability of a node in the context, that is:
3. Among them Indicates at a given central node Predicting context nodes under the embedding The probability can be approximated using softmax or negative sampling; after training, the resulting spatial embedding matrix is: ∈ This embedding can compress the structural information of the original spatial nodes into a low-dimensional semantic space, serving as a spatial representation of nodes in the graph. By introducing learnable weighting factors into the scoring function, dynamic adjustment of the contributions of entities, relations, and temporal and spatial embeddings can be achieved. In summary, for any quintuple... The scoring function, i.e., the confidence level that the fact is true in the graph, is defined as: ; in, · It is the L2 norm. , , and These represent the learnable weight factors for the four types of embeddings; The scoring function follows the vector translation principle of TransE, modeling each real fact in the spatiotemporal graph as a vector translation structure of head entity + relation ≈ tail entity, and introducing temporal and spatial embeddings to jointly construct the semantic translation path; the training objective is to maximize the score of valid quintuples and minimize the score of negatively sampled quadruples to enhance the discriminative power of the embeddings, and the loss function is defined as: ; in, It is achieved by randomly replacing the head entity. or tail entity Constructed negative samples, It is a preset interval hyperparameter; (c) Feature aggregation layer; In the STKGE feature aggregation layer, the model constructs a local correlation subgraph at each spatial node-temporal slot location, extracts relevant quintuple facts from its spatiotemporal neighborhood graph, and aggregates its semantic embeddings through an attention mechanism to form the final external feature vector representation, which serves as the semantic auxiliary input for the downstream prediction module; for a given sensor and time slot From the set of quintuples The relevant subset of facts is selected from the data to form a subgraph of its association: ; in, It is the allowed temporal neighborhood window size. Represents nodes In the time slot All related geographic facts in the vicinity; For each map fact Extract its graph embedding, including: head entity embedding. Relational embedding Time embedding To measure the impact of different facts on the current node state, an attention mechanism is introduced to assign weights; for each fact... Its attention weight Calculated using the following formula: ; in For activation function, For learnable attention parameter vectors, This represents the vector concatenation operation; ultimately, it embeds the tail entities corresponding to all facts in the subgraph. Perform a weighted summation to obtain the nodes. In the time slot external feature embedding : ; in = This indicates consistency with the entity embedding dimension; The external feature vectors of all nodes are integrated across all time slots to form a global external feature embedding tensor. ,in It is the number of time slots. It is the number of spatial nodes.
4. The traffic flow prediction method based on spatiotemporal knowledge graph and anchoring soft prompting engineering as described in claim 1, characterized in that, The specific implementation process of the spatiotemporal convolutional autoencoder is as follows: (a) Given input data as a sequence of multi-segment traffic flow data across multiple consecutive time steps, with the following dimensions: ,in This indicates the length of the input historical time step. For the number of road segments, This represents the number of features for each road segment at each time step; (b) To enhance the model's generalization ability in real-world scenarios with sensor failures and missing data, a random spatiotemporal masking mechanism is introduced during training. This involves generating a masking matrix by randomly masking several road segments or time slices of the input data using a Bernoulli mask, and then masking the original input. ; in Represents element-wise multiplication. It is a masking matrix, each element Following a Bernoulli distribution, the masking probability Pick Input after masking With external feature embedding To splice, ; Will The data is fed into the encoder to extract its deep spatiotemporal feature representation, providing a more robust semantic foundation for subsequent predictions. (c) The encoder consists of m-level spatiotemporal convolutional blocks Stacked together, each Each consists of a spatial graph convolutional layer (GCN) and a temporal convolutional layer (TCN). ; in It is a unified spatiotemporal representation with latent semantics after compression; Specifically, firstly, regarding the first Input data of layer GCN Every time slice Perform graph convolution processing: ; in It is an adjacency matrix of the road network map, representing the connection relationships between sensors or road segments. Let represent the adjacency matrix after adding self-loops, where It is the identity matrix; This represents the corresponding degree matrix. Indicates the first layer The weight matrix of the convolutional layer in the Chinese image. ,express The A time slice, Indicates the upper level The output feature representation of the first A time slice, in which yes The feature dimension size set in the intermediate layer, Indicates the first The time slice has passed the first The node feature representation after GCN processing; then the graph convolution outputs of all time slices are concatenated along the time dimension to obtain the result. Next, one-dimensional causal convolution is performed along the time dimension, i.e., Temporal Convolutional Network (TCN). Each TCN module includes convolution operations, pooling, and non-linear activation function operations. To enhance training stability, LayerNorm and Dropout are introduced after the TCN modules, and input features are preserved through residual structures. ; + ; in, These are time-series features that have undergone regularization. For the present The input features are then superimposed through residual connections to form the current... Output ; (d) Decoder and reconstruction loss: The decoder uses a multilayer perceptron. Unified spatiotemporal representation Reconstruct the original input data.
5. ; Reconstruction error uses mean square error The loss function is defined as follows: ; in, The original input value, This is the result of the decoder reconstruction.
6. The traffic flow prediction method based on spatiotemporal knowledge graph and anchoring soft prompting engineering as described in claim 1, characterized in that, Step 2 includes: (1) Unifying the spatiotemporal representation of traffic conditions As a trainable soft cue embedding: ; Used to guide language models in task specialization; (2) At the same time, structured prompt words are constructed, that is, natural language template prompt words containing traffic semantics. The prompt words are processed by a word segmenter to obtain the corresponding word segmentation codes: The word segmentation encoding is then mapped to a fixed anchor hint embedding: ; (3) Embed soft prompts and anchor hint embedding Concatenate as an anchor soft prompt embedded in the input PLM : ; in This indicates the length of the constructed anchor soft prompt sequence, the length of the unified spatiotemporal representation containing multi-source heterogeneous information, and the length of the word segmentation sequence for natural language template prompts. This indicates the embedding dimension, which aligns with the dimension of the input to the pre-trained language model.
7. The traffic flow prediction method based on spatiotemporal knowledge graph and anchoring soft prompting engineering as described in claim 1, characterized in that, The specific implementation steps in step 3 are as follows: (1) Predictive decoder; By leveraging the long-range dependency capabilities of pre-trained language models, latent semantic embedding vectors are extracted to facilitate traffic flow prediction; specifically, cue words are embedded... enter : ; in, The latent semantic embedding vectors output by the pre-trained language model. Represents the number of future time steps to be predicted. The implicit representation dimension of the model output; the pre-trained language model outputs a latent semantic embedding vector. Next, two layers of MLP will be used as a prediction decoder to map it and obtain the target future prediction data tensor. ; (22); in For the future time step Traffic flow forecast results for each road segment and It is the first Weights and biases of a layer perceptron. It is an activation function; (2) PLM fine-tuning and training optimization; Before freezing the pre-trained language model during the fine-tuning phase The parameters of the layer only apply to the last one. The Transformer layer is updated, and the PLM is updated before training. Layer parameter freezing, only for the back Layer parameters are optimized, and PSLoss is used as an auxiliary optimization objective. PSLoss first adaptively divides the predicted sequence and the real sequence based on the dominant frequency feature, forming several structural fragment patches. Then, the following three local structure alignment indices are calculated on each patch and weighted and fused to form the final local structured auxiliary loss: (3) Result evaluation mechanism.
8. The traffic flow prediction method based on spatiotemporal knowledge graph and anchoring soft prompting engineering as described in claim 5, characterized in that, The three local structure alignment metrics are as follows: (a) Correlation loss: measures the consistency between the predicted patch and the actual patch in terms of trend direction, and encourages the model to maintain structural changes in the same direction; ; in, This represents the Pearson correlation coefficient; and The first The actual and predicted values of each patch; (b) Variance loss: The relative distribution difference of fluctuations within the patch is calculated by using Softmax mapping and KL divergence to guide the model to capture the intensity of local fluctuations; ; in For the Softmax function, Indicates the Kullback-Leibler divergence; (c) Mean loss: measures the deviation of the mean between the prediction and the actual patch, used to correct the overall positional deviation and improve the alignment with the prediction baseline; ; in, , They represent the first The true mean and the predicted mean of each patch; A dynamic weighting mechanism is used for the above three structural losses, automatically adjusting the weights based on the gradient magnitude of each loss term: ; in and These are weights that are dynamically adjusted during training, specifically based on the gradient of each term. The norm ratio is set and fine-tuned by incorporating the statistical distribution covariance of the predicted and actual values to improve the robustness and accuracy of the model in long-term trend prediction; finally, the total loss function is updated to a three-layer structure: ; in , and These are hyperparameters, determined through cross-validation. The autoencoder reconstruction loss is defined by formula (4). The predicted loss for the primary monitoring term is expressed as mean squared error. : ; in, Predict the true value for the target. This is the predicted value from the decoder.
9. The traffic flow prediction method based on spatiotemporal knowledge graph and anchoring soft prompting engineering as described in claim 5, characterized in that, The results evaluation mechanism adopts the following three-step process; (a) Predicted sequence extraction; after the model inference is completed, future sequences are extracted from the output layer. Each time step road section Traffic state prediction tensor with 3D features ; (b) Error measurement; The predicted values are compared with the actual observed data point by point, using... and As an evaluation metric to measure overall prediction accuracy: ; ; in, This represents the model's predicted value. This represents the corresponding actual observed value; The focus is on penalizing larger deviations. This reflects the overall absolute deviation, and the two together characterize the model's accuracy and robustness; (c) Determination of the validity of the results; Set an experience threshold and like ; If the prediction is valid, it is considered valid; otherwise, it is considered abnormal.