Road and utility tunnel standard knowledge graph fine-grained entity classification method based on prompt learning
By building a tag ontology tree structure in the knowledge graph and using hybrid prompt templates to dynamically aggregate hierarchical tag information, the accuracy problem of entity classification in complex professional fields is solved, and efficient entity classification in low resource scenarios is achieved, especially Remarkable results have been achieved in the application of road and comprehensive pipe corridor standards.
Patent Information
- Application Number
- CN202410698500.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-05-31
AI Technical Summary
In complex professional fields, existing entity classification methods based on hint learning fail to fully utilize the hierarchical relationship between labels, and it is difficult to obtain accurate results in low-resource scenarios, especially in vertical fields such as roads and comprehensive pipe corridor standards. In digitalization, there are difficulties in data annotation and model training.
This paper proposes a fine-grained entity classification method for road and comprehensive pipe gallery standard knowledge graphs based on prompt learning. By constructing a label ontology tree structure, using hybrid prompt templates and graph attention networks to dynamically aggregate hierarchical label information, combined with BERT encoder and cross Attention mechanism optimizes the loss function of the model to improve prediction accuracy.
Effective use of the label hierarchy improves the model's prediction accuracy and performance in low-resource scenarios, and significantly improves the performance of entity classification tasks, especially in vertical field applications.
Smart Images

Figure CN118733764A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a fine-grained entity classification method for standard knowledge graphs of roads and integrated pipe corridors based on prompt learning. Background Art
[0002] At present, the paradigm of pre-training language models and fine-tuning has been widely used in downstream tasks of natural language processing. This method often requires a large amount of labeled sample data to obtain good results. In vertical fields, especially professional and emerging fields such as digitalization of road and integrated pipeline corridor standards, obtaining a large amount of data and labeling it is undoubtedly time-consuming and labor-intensive.
[0003] With the emergence of prompt learning, it has shown powerful capabilities in low-resource scenarios. However, there are still some problems with the entity classification methods based on prompt learning. For example, in complex professional fields, there are often hierarchical relationships between ontologies, and most current models use flat inputs and do not fully utilize the relationship between labels. There are currently methods that use external data for enhancement and have achieved good results in general fields, but due to the lack of resources, such methods are difficult to implement in downstream vertical fields. Summary of the invention
[0004] The present invention aims to solve the technical problems existing in the prior art, and particularly innovatively proposes a fine-grained entity classification method for standard knowledge graphs of roads and integrated pipeline corridors based on prompt learning. In low-resource professional field scenarios, the present invention can fully utilize the hierarchical structure of the label ontology and the ability of prompt learning to solve the problem of few samples, making the prediction results of the model more accurate.
[0005] In order to achieve the above object, the present invention provides a method for fine-grained entity classification of standard knowledge graphs of roads and integrated pipe corridors based on prompt learning, comprising the following steps:
[0006] S1: Collect data, conduct knowledge modeling and data annotation;
[0007] S2: Train the model based on the training data and optimize the parameters;
[0008] S3: Decode sample labels according to the path in the label ontology structure.
[0009] In the above scheme: step S1 also includes:
[0010] Label the collected data, divide the labeled data, and construct label words
[0011] This task is a multi-label classification task and there is a tree-like hierarchical relationship between labels. After collecting relevant text data, the entities and categories in the data are annotated according to the results of ontology modeling, and the annotated data is divided to construct a small sample data set.
[0012] In the above scheme: step S2 also includes:
[0013] S2-1: Initialize or update the label representation;
[0014] S2-2: Construct a hybrid prompt template, dynamically aggregate hierarchical label information and inject it into the template;
[0015] S2-3: Encode the generated embedding through the BERT encoder;
[0016] h(T mix )=[h(x),...,h(m),...,h([SOFT1]),h 1 ([MASK]),...,h([SOFT l ]),h l ([MASK])]
[0017] Among them, h(·) represents the representation of the corresponding symbol after BERT encoding;
[0018] S2-4: Get the output of the model [MASK] position Calculate the probability of belonging to each label within the label range of each level
[0019] Calculate using the following formula:
[0020]
[0021] in, represents the probability that the output of the i-th layer is predicted to be the j-th label of the layer, and Sigmoid(·) is the Sigmoid activation function;
[0022] S2-5: Calculate the loss of the model.
[0023] In the above scheme: step S2-1 also includes:
[0024] S2-1-1: Calculate the average vector after embedding;
[0025] Calculate label words through BERT model The average vector after embedding;
[0026] The formula is as follows:
[0027]
[0028] Among them, v i represents the i-th label word, d i represents the average vector of the i-th label word after embedding, and e(·) represents the embedding operation, which converts the input text symbol into a dense vector representation;
[0029] S2-1-2: Initialize or update the tag representation D;
[0030] The d calculated in step S2-1 i Initialize or update the label representation D:
[0031]
[0032] in, Nd represents the total number of labels and dim represents the dimension of embedding.
[0033] In the above scheme: step S2-2 also includes:
[0034] S2-2-1: Randomly select a sample (x, m) from the collected data, where x and m represent the sample sentence and the given entity reference respectively;
[0035] S2-2-2: The selected sample (x, m) is passed through the pre-defined mixed prompt template T mix (x, m) is constructed into a sample as shown below:
[0036] T mix (x, m) = x In this sentence, m belongs to [SOFT1][MASK]...[SOFT l ][MASK]
[0037] The hybrid prompt template contains natural language and l soft prompt words [SOFT], l represents the level of the label ontology structure; each soft prompt word is followed by a [MASK] special tag to predict the label of that level;
[0038] S2-2-3: The sample constructed in step S2-2-2 is converted into a vector representation as shown below through the BERT embedding layer:
[0039] e(T mix )=[e(x),...,e(m),...,e([SOFT1]),e([MASK]),...,e([SOFT l ]), e([MASK])]
[0040] Among them, the representation of soft prompt words ([SOFT i]) is dynamically generated by the representation of labels and samples, representing the label information of each layer and inserted into the embedded sequence;
[0041] S2-2-4: Get soft prompt word representation;
[0042] First, the label representation D is encoded through the graph attention network, which can better learn and represent the relationship between labels. The encoding result is recorded as
[0043] D emc =GAT(D)
[0044] Among them, GAT(·) represents the graph attention network;
[0045] S2-2-5: Group the tags according to the hierarchical relationship. Then, cross attention is used to obtain the soft prompt word representations at each tag level:
[0046]
[0047] Among them, W cq , W ck and W cv are all learnable weight parameters.
[0048] In the above scheme: step S2-2-3 also includes:
[0049] S2-2-3-1: Generate representation of sample instance; respectively obtain the representation of context by using self-attention mechanism and average pooling for the left and right context of input sample;
[0050] S2-2-3-2: Characterization of sample instances generated from the left context:
[0051]
[0052] Among them, e left represents the left context representation, AvePool(·) represents the average pooling operation, Softmax(·) represents the Softmax activation function, and W sq , W sk , W sv are all learnable parameters; X left Indicates the left context;
[0053] S2-2-3-3: Generate a representation of the sample instance for the right context in the same way as step S2-2-3-2 right ;
[0054] S2-2-3-4: Obtain the referential representation e through the following formula men :
[0055]
[0056] Among them, m is the reference in the sample (x, m). Characters;
[0057] S2-2-3-5: The context representation and the reference representation are fused through a feedforward neural network. The formula is as follows:
[0058] e ins =Concat(e left , e mem , e right )W a +b a
[0059] Among them, the representation of the generated sample instance dim represents the dimension of embedding, W a and b a are learnable weights and biases, and Concat(·) represents the concatenation of vectors.
[0060] In the above scheme: step S2-5 also includes:
[0061] S2-5-1: Calculate the model loss through the binary cross entropy loss function
[0062]
[0063] in, Represents the true label. represents the jth label of the i-th layer, represents the probability that the output of the i-th layer is predicted to be the j-th label of the layer; n i Indicates the number of labels in the i-th layer;
[0064] S2-5-2: Calculate the mean square error loss of the model In order to make the output of the special symbol "[MASK]" in the model represent h i ([MASK]) Try to be as close to the representation of the true label as possible, and also increase the mean square error loss
[0065] The mean square error loss of the model is calculated by the following formula
[0066]
[0067] Among them, t i is the representation of the true label of the sample at layer i,
[0068] S2-5-3: Calculate the actual loss of the model
[0069]
[0070] Among them, λ is the weight.
[0071] In the above scheme: step S3 also includes:
[0072] S3-1: Tree structure of the tag body Where Y is the set of label nodes, E is the set of edges, and the true label of a sample is represented by one or more paths from the root node to the leaf node in the label ontology structure;
[0073] S3-2: Classify nodes according to paths. Where N p is the number of leaf nodes;
[0074] S3-3: Assume that the node set of a certain path is represents the jth label of the i-th layer, then the probability of selecting this path is calculated as:
[0075]
[0076] in, Indicates the probability that the output of the lth layer is the kth label of this layer;
[0077] S3-4: Select a path based on the probability that each path calculated in step S3-3 is a true path.
[0078] In the above scheme: step S3-4 also includes:
[0079] S3-4-1: If the data set marked in step S1 is a single-path data set, execute S3-4-3; if it is a multi-path data set, execute S3-4-2;
[0080] S3-4-2: If it is a multi-path data set, first set a threshold according to the effect of the verification set. If the probability of each path is less than the threshold, execute S3-4-3; otherwise, execute S3-4-4;
[0081] S3-4-3: Select a path with the highest probability, and output the node label on the highest probability path as the predicted label for final decoding, and execute S3-4-5;
[0082] S3-4-4: Output all labels on the path that exceed the threshold as the model's predicted labels and execute S3-4-5;
[0083] S3-4-5: Over.
[0084] In summary, the beneficial effects of the present invention are: proposing a hierarchical-aware hybrid prompt template suitable for entity classification tasks, reflecting the hierarchical structure of labels in the prompt template; proposing dynamic label information aggregation, dynamically aggregating label information of each level according to different samples and contexts, and injecting it into the input template; proposing a label word decoding strategy based on label path, comprehensively predicting labels at different levels, and improving model performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0085] Figure 1 It is a schematic diagram of the process of the present invention;
[0086] Figure 2 It is a schematic diagram of the overall structure of the model;
[0087] Figure 3 is a schematic diagram of dynamic tag aggregation;
[0088] Figure 4 It is the tag body structure. DETAILED DESCRIPTION
[0089] The present invention will be further described below by way of embodiments and in conjunction with the accompanying drawings:
[0090] like Figure 1 As shown, a method for fine-grained entity classification of standard knowledge graphs of roads and integrated pipe corridors based on prompt learning includes the following steps:
[0091] S1: Collect data, conduct knowledge modeling and data annotation;
[0092] Label the collected data, divide the labeled data, and construct label words
[0093] This task is a multi-label classification task and there is a tree-like hierarchical relationship between labels. After collecting relevant text data, the entities and categories in the data are annotated according to the results of ontology modeling, and the annotated data is divided to construct a small sample data set.
[0094] S2: Train the model based on the training data and optimize the parameters. Build a hierarchical perception fine-grained entity classification model based on prompt learning, train it with the constructed dataset, and complete the optimization and update of the model parameters, including the following steps:
[0095] S2-1: Initialize or update the label representation;
[0096] S2-1-1: Calculate the average vector after embedding;
[0097] Calculate label words through BERT model The average vector after embedding;
[0098] The formula is as follows:
[0099]
[0100] Among them, v i represents the i-th label word, d i represents the average vector of the i-th label word after embedding, and e(·) represents the embedding operation, which converts the input text symbol into a dense vector representation;
[0101] S2-1-2: Initialize or update the tag representation D;
[0102] The d calculated in step S2-1 i Initialize or update the label representation D:
[0103]
[0104] in, N d Represents the total number of labels, dim represents the embedding dimension;
[0105] S2-2: Construct a hybrid prompt template, dynamically aggregate hierarchical label information and inject it into the template;
[0106] S2-2-1: Randomly select a sample (x, m) from the collected data, where x and m represent the sample sentence and the given entity reference respectively;
[0107] S2-2-2: The selected sample (x, m) is passed through the pre-defined mixed prompt template T mix (x, m) is constructed into a sample as shown below:
[0108] T mix (x, m) = x In this sentence, m belongs to [SOFT1][MASK]...[SOFT l ][MASK]
[0109] The hybrid prompt template contains natural language and l soft prompt words [SOFT], where l represents the level of the label ontology structure; each soft prompt word is followed by a [MASK] special tag to predict the label of that level;
[0110] S2-2-3: The sample constructed in step S2-2-2 is converted into a vector representation as shown below through the BERT embedding layer:
[0111] e(T mix)=[e(x),...,e(m),...,e([SOFT1]),e([MASK]),...,e([SOFT l ]), e([MASK])]
[0112] Among them, the representation of soft prompt words ([SOFT i ]) is dynamically generated by the representation of labels and samples, representing the label information of each layer, and inserted into the embedded sequence; for the convenience of expression, hard prompt words and special tags (such as "[CLS]" and "[SEP]") are deleted;
[0113] The representation of soft prompt words ([SOFT i The generation of ]) includes the following steps:
[0114] S2-2-3-1: Generate representation of sample instance; respectively obtain the representation of context by using self-attention mechanism and average pooling for the left and right context of input sample;
[0115] S2-2-3-2: Characterization of sample instances generated from the left context:
[0116]
[0117] Among them, e left represents the left context representation, AvePool(·) represents the average pooling operation, Softmax(·) represents the Softmax activation function, and W sq , W sk , W sv are all learnable parameters; X left Indicates the left context;
[0118] S2-2-3-3: Generate a representation of the sample instance for the right context in the same way as step S2-2-3-2, namely:
[0119]
[0120] Among them, e right represents the right context representation, X right Indicates the right context;
[0121] S2-2-3-4: Obtain the referential representation e through the following formula men :
[0122]
[0123] Where m is the character that refers to m in the sample (x, m);
[0124] S2-2-3-5: The context representation and the reference representation are fused through a feedforward neural network. The formula is as follows:
[0125] e ins =Concat(e left , e mem , e right )W a +b a
[0126] Among them, the representation of the generated sample instance dim represents the dimension of embedding, W a and b a are learnable weights and biases, Concat(·) represents the concatenation of vectors;
[0127] S2-2-4: Get soft prompt word representation;
[0128] First, the label representation D is encoded through the graph attention network, which can better learn and represent the relationship between labels. The encoding result is recorded as
[0129] D enc =GAT(D)
[0130] Among them, GAT(·) represents the graph attention network;
[0131] S2-2-5: Group the tags according to the hierarchical relationship. Then, cross attention is used to obtain the soft prompt word representations at each tag level:
[0132]
[0133] Among them, W cq , W ck and W cv All are learnable weight parameters;
[0134] S2-3: Encode the generated embedding through the BERT encoder;
[0135] h(T mix )=[h(x),...,h(m),...,h([SOFT1]),h 1 ([MASK]),...,h([SOFT l ]),h l ([MASK])]
[0136] Among them, h(·) represents the representation of the corresponding symbol after BERT encoding;
[0137] S2-4: Get the output of the model [MASK] position Calculate the probability of belonging to each label within the label range of each level
[0138] Calculate using the following formula:
[0139]
[0140] in, represents the probability that the output of the i-th layer is predicted to be the j-th label of the layer, and Sigmoid(·) is the Sigmoid activation function;
[0141] S2-5: Calculate the loss of the model;
[0142] S2-5-1: Calculate the model loss through the binary cross entropy loss function
[0143]
[0144] in, Represents the true label. represents the jth label of the i-th layer, represents the probability that the output of the i-th layer is predicted to be the j-th label of the layer; n i Indicates the number of labels in the i-th layer;
[0145] S2-5-2: Calculate the mean square error loss of the model In order to make the output of the special symbol "[MASK]" in the model represent h i ([MASK]) Try to be as close to the representation of the true label as possible, and also increase the mean square error loss
[0146] The mean square error loss of the model is calculated by the following formula
[0147]
[0148] Among them, t i is the representation of the true label of the sample at layer i,
[0149] S2-5-3: Calculate the actual loss of the model
[0150]
[0151] Among them, λ is the weight.
[0152] S3: Decode sample labels according to the path in the label ontology structure;
[0153] Through the above steps, the probability of belonging to each layer label can be obtained If the label with the highest probability or exceeding the set threshold is directly selected as the output of the model, the relationship between labels at each level will be ignored;
[0154] S3-1: Tree structure of the tag body Where Y is the set of label nodes, E is the set of edges, and the true label of a sample is represented by one or more paths from the root node to the leaf node in the label ontology structure;
[0155] S3-2: Classify nodes according to paths. Where N p is the number of leaf nodes;
[0156] S3-3: Assume that the node set of a certain path is represents the jth label of the i-th layer, then the probability of selecting this path is calculated as:
[0157]
[0158] in, Indicates the probability that the output of the lth layer is the kth label of this layer;
[0159] S3-4: Select a path based on the probability that each path calculated in step S3-3 is a true path;
[0160] S3-4-1: If the data set marked in step S1 is a single-path data set, execute S3-4-3; if it is a multi-path data set, execute S3-4-2;
[0161] S3-4-2: If it is a multi-path data set, first set a threshold according to the effect of the verification set. If the probability of each path is less than the threshold, execute S3-4-3; otherwise, execute S3-4-4;
[0162] S3-4-3: Select a path with the highest probability, and output the node label on the highest probability path as the predicted label for final decoding, and execute S3-4-5;
[0163] S3-4-4: Output all labels on the path that exceed the threshold as the model's predicted labels and execute S3-4-5;
[0164] S3-4-5: Over.
[0165] The following describes the present embodiment by taking the standard digitalization of roads and utility tunnels as an example, which should not be construed as limiting the present invention.
[0166] (1) Collect data, conduct knowledge modeling and data labeling.
[0167] Collect standards related to roads and utility tunnels, and obtain standard texts through OCR conversion and manual adjustment. Refer to the "Classification and Coding Standard for Building Information Modeling" (GB / T 51269-2017) and the actual standard clause organization, and design 5 coarse-grained entity categories and 10 fine-grained entity categories, such as Figure 4 As shown in the figure, the standard data is then manually labeled. In order to simulate low-resource scenarios, 5 items of the labeled data are randomly sampled from each category to construct training sets and validation sets, and the remaining data is used as a test set.
[0168] (2) Train the model based on the training data and optimize the parameters.
[0169] 1) Initialize or update the tag representation.
[0170] The label words V designed in the previous step are 15}={construction achievements, construction attributes, ..., modifiers} After word segmentation and the embedding layer of the BERT model, the embedded vectors are averaged to obtain the label representation D, and the gradient can be calculated for parameter update.
[0171]
[0172] D=[d1;d2;...;d 15 ]
[0173] 2) Construct a hybrid prompt template, dynamically aggregate hierarchical label information and inject it into the template.
[0174] Given a sample, first wrap it with a mixed prompt template. For example, for sample x: "The maximum longitudinal slope of the road in the tunnel should not be greater than 3.0%." and reference m: "Maximum longitudinal slope", the following template T can be obtained mix : "The maximum longitudinal slope of the road in the tunnel should not be greater than 3.0%. In this sentence, the maximum longitudinal slope belongs to [SOFT1][MASK][SOFT2][MASK]".
[0175] Passing the above template through the BERT embedding layer, the symbol can be converted into a vector representation:
[0176] e(T mix )=[e(x),...,e(m),...,e([SOFT1]),e([MASK]),e([SOFT2]),e([MASK])]
[0177] In the above formula, for the convenience of expression, hard prompt words and special marks (such as "[CLS]" and "[SEP]") are deleted.
[0178] Among them, the representation of soft prompt words ([SOFT i ]) is dynamically generated from the representation of labels and samples, representing the label information of each layer, and inserted into the embedded sequence. The method for generating soft prompt word representation is as follows:
[0179] ① Generate representation of sample instances:
[0180] a) The left and right contexts of the input sample are respectively represented by the self-attention mechanism and average pooling to obtain the context representation. Take the left context as an example:
[0181]
[0182] Among them, W sq , W sk , W sv are all learnable parameters. The right context representation e right The way to obtain is similar to the above formula.
[0183] b) Acquire a representation of the reference men , which is obtained by averaging the embedding vectors obtained by passing through the embedding layer of the BERT model.
[0184]
[0185] c) The context representation and the reference representation are fused through a feedforward neural network to generate a representation of the sample instance dim represents the dimension of the embedding.
[0186] e ins =Concat(e left , e mem , e right )W a +b a
[0187] In the above formula, W a and b a are learnable weights and biases.
[0188] ② Get soft prompt word representation:
[0189] The label representation is Where N d Represents the total number of labels. First, the label representation D is encoded through the graph attention network, and the result is
[0190] D enc =GAT(D)
[0191] Group the tags according to the hierarchical relationship. Then, cross attention is used to obtain the soft prompt word representations at each tag level:
[0192]
[0193] In the above formula, W cq , W ck and W cv are all learnable weight parameters.
[0194] 3) Encode the generated embedding through the BERT encoder:
[0195] h(T mix )=[h(x),...,h(m),...,h([SOFT1]),h 1 ([MASK]),h([SOFT2]),h 2 ([MASK])]
[0196] 4) Get the output of the model [MASK] position Calculate the probability of belonging to each label within the label range of each level:
[0197]
[0198] 5) During the model training process, the loss functions used are binary cross entropy and mean square error loss:
[0199]
[0200] (3) Decode the sample labels according to the paths in the label ontology structure.
[0201] Through the above steps, the probability of belonging to each layer label can be obtained According to the ontology structure of the label, the node can be divided into multiple paths
[0202] Among them, P1 = {construction results, building}, P2 = {construction results, building space}, and so on. Next, calculate the probability of each path. For example, the probability of path P1 is:
[0203]
[0204] The remaining paths are calculated in the same way as above, and we get p = {p1, p2, ..., p 10}.
[0205] Since the labels of the samples in this dataset are all on a single path, the nodes on the path with the highest probability are selected as the decoded labels. For example, if the sample outputs max(p) = p4, the decoded label is P4 = {construction attribute, attribute index}.
[0206] Compared with the traditional fine-tuning method and the hint learning method (hard template, soft template), the experimental results are shown in the following table. The evaluation indicators include strict accuracy (ACC), macro F1 score (MaF) and micro F1 score (MiF):
[0207] Model ACC F MiF VanillaFT 48.96 53.67 53.67 Hard Prompt 45.54 61.35 61.35 Soft Prompt 46.93 62.87 62.87 Method of the present invention 61.29 67.94 67.94
[0208] It can be seen that, compared with the various values in the table, the method of the present invention has obvious improvements in various indicators.
Claims
1. A fine-grained entity classification method for standard knowledge graphs of roads and integrated pipe corridors based on prompt learning, characterized by: The following steps are involved: S1: Collect data, conduct knowledge modeling and data annotation; S2: Train the model based on the training data and optimize the parameters; S3: Decode and classify sample labels according to the paths in the label ontology structure.
2. According to the prompt learning-based fine-grained entity classification method of standard knowledge graph of roads and integrated pipe corridors according to claim 1, it is characterized by: Step S1 also includes: Label the collected data, divide the labeled data, and construct label words 3. According to the prompt learning-based fine-grained entity classification method of road and integrated pipe gallery standard knowledge graph according to claim 1, it is characterized by: Step S2 also includes: S2-1: Initialize or update the label representation; S2-2: Construct a hybrid prompt template, dynamically aggregate hierarchical label information and inject it into the template; S2-3: Encode the generated embedding through the BERT encoder; h(T mix )=[h(x),...,h(m),...,h([SOFT1]),h 1 ([MASK]),...,h([SOFT l ]),h l ([MASK])] Among them, h(·) represents the representation of the corresponding symbol after BERT encoding; S2-4: Get the output of the model [MASK] position Calculate the probability of belonging to each label within the label range of each level Calculate using the following formula: in, represents the probability that the output of the i-th layer is predicted to be the j-th label of the layer, and Sigmoid(·) is the Sigmoid activation function; S2-5: Calculate the loss of the model.
4. According to claim 3, a method for fine-grained entity classification of standard knowledge graphs of roads and integrated utility tunnels based on prompt learning is characterized by: Step S2-1 also includes: S2-1-1: Calculate the average vector after embedding; Calculate label words through BERT model The average vector after embedding; The formula is as follows: Among them, v i represents the i-th label word, d i represents the average vector of the i-th label word after embedding, and e(·) represents the embedding operation, which converts the input text symbol into a dense vector representation; S2-1-2: Initialize or update the tag representation D; The d calculated in step S2-1 i Initialize or update the label representation D: in, N d represents the total number of labels, and dim represents the dimension of embedding.
5. According to claim 3, a method for fine-grained entity classification of standard knowledge graphs of roads and integrated pipe corridors based on prompt learning is characterized in that: Step S2-2 also includes: S2-2-1: Randomly select a sample (x, m) from the collected data, where x and m represent the sample sentence and the given entity reference respectively; S2-2-2: The selected sample (x, m) is passed through the pre-defined mixed prompt template T mix (x, m) is constructed into a sample as shown below: T mix (x, m) = x In this sentence, m belongs to [SOFT1][MASK]...[SOFT l ][MASK] The hybrid prompt template contains natural language and l soft prompt words [SOFT], l represents the level of the label ontology structure; each soft prompt word is followed by a [MASK] special tag to predict the label of that level; S2-2-3: The sample constructed in step S2-2-2 is converted into a vector representation as shown below through the BERT embedding layer: e(T mix )=[e(x),...,e(m),...,e([SOFT1]),e([MASK]),...,e([SOFT l ]),e([MASK])] Among them, the representation of soft prompt words ([SOFT i )]) is dynamically generated by the representation of labels and samples, representing the label information of each layer and inserted into the embedded sequence; S2-2-4: Get soft prompt word representation; First, the label representation D is encoded through the graph attention network, which can better learn and represent the relationship between labels. The encoding result is recorded as <h2 style=";text-align:left;direction:ltr">D<h2 style=";text-align:left;direction:ltr"> enc <h2 style=";text-align:left;direction:ltr"> (GAT(D)) Among them, GAT(·) represents the graph attention network; S2-2-5: Group the tags according to the hierarchical relationship. Then, cross attention is used to obtain the soft prompt word representations at each tag level: Among them, W cq , W ck and W cv are all learnable weight parameters.
6. According to claim 5, a method for fine-grained entity classification of standard knowledge graphs of roads and integrated utility tunnels based on prompt learning is characterized by: Step S2-2-3 also includes: S2-2-3-1: Generate representation of sample instance; respectively obtain the representation of context by using self-attention mechanism and average pooling for the left and right context of input sample; S2-2-3-2: Characterization of sample instances generated from the left context: Among them, e left represents the left context representation, AvePool(·) represents the average pooling operation, Softmax(·) represents the Softmax activation function, and W sq , W sk , W sv are all learnable parameters; X left Indicates the left context; S2-2-3-3: Generate a representation of the sample instance for the right context in the same way as step S2-2-3-2 right ; S2-2-3-4: Obtain the referential representation e through the following formula men : Where m is the character that refers to m in the sample (x, m); S2-2-3-5: The context representation and the reference representation are fused through a feedforward neural network. The formula is as follows: e ins =Concat(e left ,e men ,e right )W a +b a Among them, the representation of the generated sample instance dim represents the dimension of embedding, W a and b a are learnable weights and biases, and Concat(·) represents the concatenation of vectors.
7. According to claim 3, a method for fine-grained entity classification of standard knowledge graphs of roads and utility tunnels based on prompt learning is characterized by: Step S2-5 also includes: S2-5-1: Calculate the model loss through the binary cross entropy loss function in, Indicates the true label; represents the jth label of the i-th layer, represents the probability that the output of the i-th layer is predicted to be the j-th label of the layer; n i Indicates the number of labels in the i-th layer; S2-5-2: Calculate the mean square error loss of the model In order to make the output of the special symbol "[MASK]" in the model represent h i ([MASK]) Try to be as close to the representation of the true label as possible, and also increase the mean square error loss The mean square error loss of the model is calculated by the following formula Among them, t i is the representation of the true label of the sample at layer i, S2-5-3: Calculate the actual loss of the model Among them, λ is the weight.
8. According to the prompt learning-based fine-grained entity classification method of standard knowledge graph of roads and integrated pipe corridors according to claim 1, it is characterized by: Step S3 also includes: S3-1: Tree structure of the tag body Where Y is the set of label nodes, E is the set of edges, and the true label of a sample is represented by one or more paths from the root node to the leaf node in the label ontology structure; S3-2: Classify nodes according to paths. Where N p is the number of leaf nodes; S3-3: Assume that the node set of a certain path is represents the jth label of the i-th layer, then the probability of selecting this path is calculated as: in, Indicates the probability that the output of the lth layer is the kth label of this layer; S3-4: Select a path based on the probability that each path calculated in step S3-3 is a true path.
9. According to claim 8, a method for fine-grained entity classification of standard knowledge graphs of roads and utility tunnels based on prompt learning is characterized by: Step S3-4 also includes: S3-4-1: If the data set marked in step S1 is a single-path data set, execute S3-4-3; if it is a multi-path data set, execute S3-4-2; S3-4-2: If it is a multi-path data set, first set a threshold according to the effect of the verification set. If the probability of each path is less than the threshold, execute S3-4-3; otherwise, execute S3-4-4; S3-4-3: Select a path with the highest probability, and output the node label on the highest probability path as the predicted label for final decoding, and execute S3-4-5; S3-4-4: Output all labels on the path that exceed the threshold as the model's predicted labels and execute S3-4-5; S3-4-5: Over.
Citation Information
Patent Citations
Small sample text classification method for prompting learning
CN115455181A
Knowledge perception prompt learning-based few-sample relation extraction method
CN117010392A
Text classification method, device and equipment and computer readable storage medium
CN117390192A
English art character recognition method for enhancing attention based on structure
CN117612151A
Sparse medical entity identification method based on attention mechanism
CN117952107A
