Few-sample relation classification device and classification method for text in the field of bridge inspection
By using context and entity feature extraction modules in the bridge detection field text's small sample relationship classification task, the relationship classification is solved, and the problem of long text, large entity span, and the need for reverse context information is solved, and the classification performance is improved, which is better than the mainstream methods in the public domain.
Patent Information
- Application Number
- CN202211034115.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-26
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2042-08-26
AI Technical Summary
The small sample relationship classification task of bridge detection field text faces the domain characteristics of long text, large entity span, and needing reverse context information, which leads to poor relationship classification performance of existing models.
The context feature extraction module is adopted, including a sample encoder and a bidirectional encoding network, to extract the context feature vectors of sentences; the entity feature extraction module obtains the entity feature vectors through entity location and encoding layer; and through the relation classification module, the context and entity features are fused for relational classification.
It effectively solves the domain characteristics of the bridge detection field text, improves the classification performance of neural network models in the small sample relationship classification task, can better distinguish different relationship types, and is better than the mainstream methods in the current public domain.
Smart Images

Figure CN115391535B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of relationship classification, and in particular to a few-sample relationship classification method for texts in the field of bridge detection. Background Art
[0002] Relation classification is an important task in the field of natural language processing. It aims to determine the predefined relationship between two target entities in a given sentence, which provides a basis for building structured knowledge (such as knowledge graphs). The mainstream deep learning model currently used for this task is driven by a large amount of supervised data. This approach results in the generalization ability of the model relying on the quantity and quality of supervised data. However, in specific fields, there is no such large amount of high-quality supervised data in the public domain.
[0003] In order to alleviate the problem of insufficient supervised data, one solution is the remote supervision method, which automatically generates a large amount of labeled training data by aligning a large amount of text corpus with an existing knowledge base. Remote supervision assumes that "if two entities have a certain relationship in the knowledge base, then the sentence containing these two entities can express this relationship to some extent", and heuristically aligns the target entity in the sentence with the entity in the knowledge base to achieve the purpose of automatically annotating the sentence. However, this assumption also brings the following problems: (1) The relationship represented by the same entity pair in different sentences may not be the same, and the remote supervision method will generate noisy data; (2) In many fields, there is no complete knowledge base yet (such as the field of bridge inspection), and most entity pairs and relationships are long-tailed, so the available data for training is still insufficient.
[0004] Another solution is to study how to make full use of a small number of labeled samples for training so that the model has better generalization ability. The goal of few-shot learning is to learn solutions to problems from a small number of samples. The concept of few-shot learning emerged from the field of computer vision, and research work has mainly focused on the task of few-shot image recognition. In recent years, few-shot learning methods have also developed rapidly in natural language processing. With the launch of the public domain few-shot relation classification dataset FewRel, researchers introduced few-shot learning into the relation classification task for the first time. On the FewRel dataset, a lot of excellent work has emerged, which has promoted the development of few-shot in the field of relation classification and enriched the research on few-shot learning. However, in the field of bridge detection, the models and methods on the public domain dataset FewRel cannot efficiently achieve accurate classification of entity relationships in texts in the field of bridge detection. This is because, in the texts in the field of bridge detection, the way sentences are written has strong domain characteristics:
[0005] (1) Text sentences are long and the span between entities is large: There are many long sentences. Current models and methods cannot fully obtain the semantic information of sentences and cannot accurately represent the contextual features of sentences. In addition, long text sentences may cause the span between entities to be too large. The model cannot accurately obtain the semantic dependency information between two entities, which brings challenges to relationship judgment.
[0006] (2) The inference of some relationship categories needs to rely on reverse context information: In the Chinese bridge detection domain text, some of the relationships have a head entity that appears at the end of the sentence, and a tail entity that appears before the head entity. When making a relationship judgment on such text (head entity, relationship, tail entity), it is necessary to obtain reverse context information dependency, so it is necessary to consider backward context information;
[0007] (3) The same text contains different relationships between multiple entities, and there is a problem of overlapping relationships: In the text data in the field of bridge inspection, there are a large number of texts with overlapping relationships, that is, the same text contains multiple different entity relationships. When performing few-shot relationship classification tasks, if the same text appears in the same training process, it will greatly interfere with the model's learning and understanding of the features of different relationship instances, affecting the model's classification performance.
[0008] This kind of text with domain characteristics brings great challenges to the few-shot relationship classification task. The current few-shot relationship classification models and methods focus more on the novelty of the model method. When dealing with the few-shot relationship classification task in the field of bridge inspection, the relationship classification performance is poor due to the influence of the text characteristics in the field of bridge inspection.
[0009] Therefore, in the study of few-sample relation classification based on text characteristics in the bridge inspection field, how to reduce the impact of domain characteristics on the neural network model has become a problem that needs to be solved urgently. Summary of the invention
[0010] In view of the above-mentioned domain characteristics and the shortcomings of the prior art, the present invention provides a few-sample relationship classification method for texts in the field of bridge detection. This method improves the classification performance of the neural network model in the few-sample relationship classification task in the field of bridge detection, and reduces the interference of domain characteristics to the neural network.
[0011] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0012] A few-sample relation classification device for text in the bridge detection field, including a context feature extraction module, an entity feature extraction module and a relation classification module;
[0013] The context feature extraction module includes a sample encoder and a bidirectional encoding network; the sample encoder is used to encode the sentences of bridge detection into a vector form to obtain the encoding vector of the sentence; the bidirectional encoding network is used to encode the sentence forward and backward to obtain the long-term dependency feature information of the context and the reverse modeling feature information of the text, and the encoding results of the two directions are spliced to obtain the context feature vector of the sentence; the entity feature extraction module is used to extract the encoding information of the entity from the sentence encoding vector, and obtain the feature vector of the entity through transformation; the relationship classification module is used to perform relationship classification based on the sentence information feature vector obtained by fusing the context feature vector and the entity feature vector.
[0014] Basic solution principle and effect:
[0015] In the present invention, through the context feature extraction module, the model can extract more sufficient feature information for longer texts, obtain long-distance dependency information in the text, thereby solving the interference caused by the longer characteristics of the text to the neural network model. Secondly, the reverse encoding function of BiLSTM obtains the reverse context dependency information of the text, supplements the context information of the text, and enables the model to better cope with the characteristics of needing reverse information for relationship judgment. Then, the entity encoding information is extracted by the entity feature extraction module to obtain the entity feature vector. The introduction of the entity feature vector can solve the characteristic problem of overlapping text relations, and helps the neural network model to learn different relationship differences according to the entity information when processing the same text, so as to correctly distinguish the relationship between different entities. Finally, the text context features and entity features are fused, and the relationship classification module performs relationship classification on the text vector that integrates the above two features, so that different relationship types can be better distinguished.
[0016] In summary, the present invention can effectively solve the domain characteristic problem of text in the field of bridge detection, enable the neural network model to achieve better classification performance in the few-sample relationship classification task in the field of bridge detection, and better distinguish different relationship categories in the field of bridge detection.
[0017] Preferably, the sample encoder is a pre-trained language model RoBERTa; the vector output by the last hidden layer of RoBERTa is used as the encoding vector representation of the sentence.
[0018] Beneficial effect: Using RoBERTa for sentence encoding can obtain a sentence vector representation that is more consistent with the meaning of Chinese sentences. This will help the model understand the meaning of relation classification instances and better distinguish different relation category instances.
[0019] Preferably, the bidirectional encoding network is a bidirectional long short-term memory network BiLSTM; the hidden layer vector of the last forward moment of the BiLSTM is concatenated with the hidden layer vector of the last backward moment of the BiLSTM to obtain a context feature vector of the sentence.
[0020] Beneficial effect: Due to the design characteristics of LSTM, it is very suitable for modeling time series data. For the problem of long instance texts of various relationships in the bridge detection field data set, the use of LSTM structure can obtain richer text features. The long text in the data set and the large span between entities are factors that affect the classification performance of the current few-sample relationship classification model structure. After adding the LSTM structure, the model can better capture the longer sentence information dependency relationship and avoid insufficient context feature extraction due to the long sentence. However, if only LSTM is used, the backward context dependency information cannot be encoded. For the characteristics of some relationship categories in the data set that require reverse context information, the model needs to be able to capture reverse semantic information for relationship classification. In the present invention, this problem is solved by introducing the BiLSTM structure, and the reverse encoding ability of BiLSTM is used to obtain the semantic dependency information of the latter text on the former text. Because the hidden state of the last moment of the forward direction and the hidden state of the last moment of the backward direction contain all the semantic information of the forward and backward directions, the two hidden vectors are spliced together as the context feature representation of the sentence. The introduction of BiLSTM solves the domain characteristics of long texts, large entity spans, and the need for reverse context information, enabling the neural network model to obtain the long-term dependency feature information of the sentence context and the reverse modeling feature information of the text, and obtain more comprehensive sentence context features.
[0021] Preferably, the entity feature extraction module specifically includes: finding the vector representation of the entity after passing through the encoding layer through the position of the entity in the sentence, and obtaining the final entity feature vector through the activation function and the fully connected layer for fusion with the context feature information.
[0022] Beneficial effects: The feature information of two entities in the text is obtained through the entity feature extraction module. The entity features are integrated with the context features, which can solve the relationship overlapping characteristics of the text in the bridge detection field and the misleading problem of the same instance text representing different relationship categories to the neural network model. The entity feature information enhances the model's ability to learn instance features of different relationships, greatly improving the performance of the model's relationship extraction.
[0023] Preferably, the relationship classification module is a prototype network Prototypical Network.
[0024] Beneficial effects: The role of the Prototypical Network is to calculate the relationship prototype based on the instance vectors contained in each relationship category in the support set in the few-shot relationship classification task, and then calculate the distance between the query instance vector and the relationship prototype to determine the relationship category to which the query instance belongs. When calculating the relationship category prototype, the prototype network uses the average method to represent the category prototype of this relationship by taking the mean of the feature vectors of all instances contained in each category in the support set.
[0025] Preferably, when training a few-sample relation classification method for text in the field of bridge detection, the loss function is a cross entropy loss function and an inter-class loss function; wherein the inter-class loss function is defined as the inverse of the distance between each category prototype; and the feature vector of the category prototype is the mean of the feature vectors of all relation instances of the category.
[0026] Beneficial effects: The inter-class loss function is introduced to increase the distance between different category prototype vectors in the high-dimensional vector space, so that the distance measurement function can more accurately measure the distance between the query instance vector and the relationship category prototype vector, and better judge the category of the query instance. The inter-class loss function is defined as the opposite of the distance between each category prototype. The direction in which the inter-class loss decreases is the direction in which the distance between the category prototypes increases; it is easy to understand the degree of training more intuitively through the loss function.
[0027] Based on the above-mentioned few-sample relationship classification device for bridge detection field text, the present invention also provides a few-sample relationship classification method for bridge detection field text, comprising the following steps:
[0028] S1. Use a sample encoder to encode the sentence of bridge detection into a vector form to obtain a sentence encoding vector;
[0029] S2, forward and backward encoding the sentence through a bidirectional encoding network to obtain the long-term dependency feature information of the context and the reverse modeling feature information of the text, and concatenate the encoding results of the two directions to obtain the context feature vector of the sentence;
[0030] S3, extracting the encoding information of the entity from the sentence encoding vector through the entity feature extraction module, and obtaining the feature vector of the entity through transformation; and fusing the entity feature vector with the context feature vector of the corresponding sentence to obtain the information feature vector used for classification of the sentence;
[0031] S4. Use the relationship classification module to perform relationship classification based on the information feature vector of the sentence.
[0032] Preferably, in S1, the sample encoder is a pre-trained language model RoBERTa; the hidden state output by the last hidden layer of RoBERTa is used as the encoding feature representation of the sentence encoding vector.
[0033] Preferably, in S2, the bidirectional encoding network is a bidirectional long short-term memory neural network BiLSTM; the hidden layer state of the BiLSTM at the last forward moment is concatenated with the hidden layer state of the BiLSTM at the last backward moment to obtain the encoding feature representation of the final vector of the sentence.
[0034] Preferably, in S4, the relationship classification module is a prototypical network. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to make the purpose, technical solution and advantages of the invention more clear, the present invention will be further described in detail below with reference to the accompanying drawings, in which:
[0036] Figure 1 It is a structural schematic diagram of a few-sample relation classification device for text in the field of bridge detection in an embodiment;
[0037] Figure 2 Schematic diagram of the use of the prototype network Prototypical Network in the embodiment. DETAILED DESCRIPTION
[0038] The following is a further detailed description through specific implementation methods:
[0039] Example:
[0040] like Figure 1 As shown, this embodiment discloses a small sample relationship classification device for text in the field of bridge detection, including a context feature extraction module, an entity feature extraction module and a relationship classification module;
[0041] The context feature extraction module includes a sample encoder and a bidirectional encoding network; the sample encoder is used to encode the sentence of bridge detection into a vector form to obtain the encoding vector of the sentence.
[0042] In the specific implementation, the sample encoder is the pre-trained language model RoBERTa; the hidden state output by the last hidden layer of RoBERTa is used as the encoding feature representation of the sentence encoding vector. BERT is a new language model proposed by Google in 2018. The RoBERTa model is an improved version of BERT and a major improvement of BERT on multiple levels. The Chinese RoBERTa improves the data generation method and tasks in the same way as the English RoBERTa; it uses larger and more diverse data: news, community discussions, multiple encyclopedias, covering hundreds of thousands of topics; it trains longer; it uses larger batches; it adjusts the optimizer parameters; and it uses a full-word masking strategy. Using Chinese RoBERTa for sentence feature extraction can obtain a sentence feature representation that is more in line with the meaning of Chinese sentences. This will help the model understand the meaning of the relationship classification instance and better distinguish different relationship category instances. The hidden state output by the last hidden layer of the RoBERTa model is selected as the encoding feature representation of the sentence, and it is used as the input of the bidirectional encoding network.
[0043] The bidirectional encoding network is used to encode the sentence forward and backward to obtain the long-term dependency feature information of the context and the reverse modeling feature information of the text, and the encoding results of the two directions are spliced to obtain the context feature vector of the sentence. In specific implementation, the bidirectional encoding network is a bidirectional long short-term memory network BiLSTM; the hidden layer vector of the last moment of the BiLSTM forward is spliced with the hidden layer vector of the last moment of the BiLSTM backward to obtain the context feature vector of the sentence.
[0044] Due to the design characteristics of LSTM, it is very suitable for modeling time series data. For the problem of long instance texts of various relationships in the bridge detection field data set, the use of LSTM structure can obtain richer text features. The field characteristics of long texts and large spans between entities in the data set are factors that affect the classification performance of the current few-sample relationship classification model structure. After adding the LSTM structure, the model can better capture the longer sentence information dependency relationship and avoid insufficient context feature extraction caused by too long sentences. However, if only LSTM is used, the backward context dependency information cannot be encoded. For the characteristics of some relationship categories in the data set that require reverse context information, the model needs to be able to capture reverse semantic information for relationship classification. In the present invention, this problem is solved by introducing the BiLSTM structure, and the reverse encoding ability of BiLSTM is used to obtain the semantic dependency information of the latter text on the former text. Because the hidden state of the last moment of the forward direction and the hidden state of the last moment of the backward direction contain all the semantic information of the forward and backward directions, the two hidden vectors are spliced together as the context feature representation of the sentence. The introduction of BiLSTM solves the domain characteristics of long texts, large entity spans, and the need for reverse context information, enabling the neural network model to obtain the long-term dependency feature information of the sentence context and the reverse modeling feature information of the text, and obtain more comprehensive sentence context features.
[0045] The entity feature extraction module is used to extract the encoding information of the entity from the sentence encoding vector and obtain the entity's feature vector through transformation. Specifically, the vector representation of the entity after the encoding layer is found through the position of the entity in the sentence, and the vector is passed through the activation function and the fully connected layer to obtain the final entity feature vector for fusion with the context feature information. Among them, extracting the entity feature vector from the sentence encoding vector specifically includes: finding the position of the entity in the sentence encoding vector to obtain the entity encoding vector, and obtaining the entity feature vector through the activation function and the fully connected layer.
[0046] The process of obtaining the information feature vector is as follows:
[0047] instance r =Bilstm(e roberta );
[0048]
[0049]
[0050] Entity r =contact(e h , e t );
[0051] V=contact(instancer , Entity r );
[0052] Among them, instance r is the sentence context feature information, e roberta Encode the sentence vector, e h is the feature vector of the head entity, W is the fully connected weight parameter, activation() represents the activation function tanh(), O is the number of tokens contained in the head entity, P represents the number of tokens completed by the tail entity, e 1i is the encoding information of the i-th token of the header entity, b is the bias parameter of the fully connected layer, and e t is the tail entity feature vector, e 2i The encoding information of the i-th token of the tail entity, Entity r is the feature vector representation after the head and tail entities are concatenated, contact() represents the concatenation function, and V is the feature vector representation of the sentence information finally used for relationship classification.
[0053] The relationship classification module is used to classify relationships based on the sentence information feature vector obtained by fusing the context feature vector and the entity feature vector. In specific implementation, the relationship classification module is the prototype network Prototypical Network. The role of the prototype network Prototypical Network is to calculate the relationship prototype based on the instance vector contained in each relationship category in the support set in the few-shot relationship classification task, and then calculate the distance between the query instance vector and the relationship prototype to determine the relationship category to which the query instance belongs. When calculating the relationship category prototype, the prototype network uses the average method to represent the category prototype of this relationship by taking the mean of the feature vectors of all instances contained in each category in the support set. The overall flow chart of few-shot relationship classification is as follows: Figure 2 As shown, Figure 2 It is a 3-way-K-shot few-shot relation classification task, where K represents the number of relation instances contained in each relation.
[0054] It should be noted that in the study of few-shot relationship classification, there are many ways to represent relationship category prototypes, all of which can better represent support instances as relationship category prototypes. For example, in specific implementation, the prototype network PrototypicalNetwork can be replaced by a variant of the prototype network, ProtoNetwork_hatt. This model optimizes the method of calculating relationship categories in the prototype network and proposes an attention mechanism. First, the instances with high similarity to the query instance in each relationship category in the support set are calculated and assigned high weights. Then, the weighted sum of all instances in the relationship category is used as the category prototype representation of the relationship. This method replaces the simple mean calculation method in the prototype network and can better represent the relationship category prototype. When calculating the distance between the distance support instance and the relationship category prototype, the original simple Euclidean distance is also replaced by a dynamic distance, that is, each distance is multiplied by the relevant weight, and the simple distance formula is improved to complete the classification of the relationship. After testing, if the prototype network structure is replaced by its variant ProtoNetwork_hatt, it does not have much impact on the overall effect of the model, and can only be used when the number of instances in the relationship category is greater than 1, and does not have much impact on the classification task with only one instance (such as 5-way-1-shot). In the study of few-shot relation classification based on text characteristics in the bridge inspection field, the main challenge of data with domain characteristics to the model lies in the method of obtaining text features.
[0055] When the present invention is trained, the loss function is a cross entropy loss function and an inter-class loss function; wherein the inter-class loss function is defined as the inverse of the distance between each category prototype; the feature vector of the category prototype is the mean of the instance feature vector of the category. The inter-class loss function is introduced to increase the distance between prototypes of different categories in the high-dimensional vector space, so that the distance between the query instance and the category prototype vector can be better calculated to better determine the category of the query instance. The inter-class loss function is defined as the inverse of the distance between each category prototype, and the direction in which the inter-class loss decreases is the direction in which the distance between the category prototypes increases; it is convenient to understand the degree of training more intuitively through the loss function.
[0056] Specifically, the loss function is as follows:
[0057] LOSS=LOss crossEntropy +0.3*LOss class ;
[0058]
[0059] Among them, LOSS is the total loss function during training, that is, the total loss value when the model outputs the relationship category, Loss crossEntropy is the cross entropy loss function, Loss classis the inter-class loss function, class i is the prototype vector of the i-th relation category in the support set, class j is the prototype vector of the jth relation category in the support set, and N is the total number of relation categories.
[0060] The present invention also provides a method for classifying a few-sample relationship of text in the field of bridge detection, using the above-mentioned device for classifying a few-sample relationship of text in the field of bridge detection, comprising the following steps:
[0061] S1. Use a sample encoder to encode the sentence of bridge detection into a vector form to obtain a sentence encoding vector; the sample encoder is a pre-trained language model RoBERTa; the hidden state output by the last hidden layer of RoBERTa is used as the encoding feature representation of the sentence encoding vector;
[0062] S2. The sentence is encoded forward and backward through a bidirectional encoding network to obtain long-term dependency feature information of the context and reverse modeling feature information of the text, and the encoding results of the two directions are spliced to obtain a context feature vector of the sentence; the bidirectional encoding network is a bidirectional long short-term memory neural network BiLSTM; the hidden state of the BiLSTM at the last forward moment is spliced with the hidden state of the BiLSTM at the last backward moment to obtain the encoding feature representation of the final vector of the sentence;
[0063] S3, extracting the encoding information of the entity from the sentence encoding vector through the entity feature extraction module, and obtaining the feature vector of the entity through transformation; and fusing the entity feature vector with the context feature vector of the corresponding sentence to obtain the information feature vector used for classification of the sentence;
[0064] S4. Use a relationship classification module to perform relationship classification according to the information feature vector of the sentence; the relationship classification module is a prototype network Prototypical Network.
[0065] In the present invention, by encoding sentences through the sample encoder and bidirectional encoding network of the context feature extraction module, the model can extract the long-term dependent feature information of longer texts in the field of bridge detection, process the dependency relationship of texts over a longer distance, and obtain the reverse context dependency information through reverse encoding to obtain a more sufficient text context feature vector, thereby solving the field characteristic problem that the text in the field of bridge detection is longer, the entity span is large, and the reverse context information is needed to support relationship judgment. Afterwards, the entity feature extraction module extracts the entity feature information as the key information to solve the overlapping of text relationships in the field of bridge detection. By fusing the context feature information and the entity feature information as the information feature vector representation of the relationship instance text for relationship classification, and performing relationship classification according to the information feature vector through the relationship prediction module, the influence of the text characteristics in the field of bridge detection on the model performance can be reduced, so that the classification performance of the present invention on the few-sample relationship classification data set constructed by the text in the field of bridge detection is better than the mainstream methods in other general fields.
[0066] As shown in Table 1, experiments have proved that in the study of few-sample relationship classification of text characteristics in the field of bridge detection, the present invention is compared with the mainstream methods in the current common field, and the best effect is achieved on the few-sample relationship classification dataset in the field of bridge detection.
[0067] Table 1 Classification accuracy of each model on the bridge detection dataset (%)
[0068]
[0069] The present invention can effectively solve the domain characteristic problem of text entity relationship classification in the field of bridge detection, and can achieve better classification performance in the few-sample relationship classification task in the field of bridge detection, so that the neural network model can better distinguish different relationship types in the field of bridge detection, which is superior to the mainstream methods and models in the current public domain.
[0070] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit the technical solution. Those skilled in the art should understand that those modifications or equivalent substitutions of the technical solution of the present invention that do not depart from the purpose and scope of the technical solution should be included in the scope of the claims of the present invention.
Claims
1. A few-sample relation classification device for text in the bridge inspection field, Features: It includes context feature extraction module, entity feature extraction module and relationship classification module; The context feature extraction module includes a sample encoder and a bidirectional encoding network; the sample encoder is used to encode the sentence of bridge detection into a vector form to obtain the encoding vector of the sentence; the bidirectional encoding network is used to encode the sentence forward and backward to obtain the long-term dependency feature information of the context and the reverse modeling feature information of the text, and the encoding results of the two directions are spliced to obtain the context feature vector of the sentence; the entity feature extraction module is used to extract the encoding information of the entity from the sentence encoding vector, and obtain the feature vector of the entity through transformation; the relationship classification module is used to perform relationship classification based on the sentence information feature vector obtained by fusing the context feature vector and the entity feature vector; The sample encoder is the pre-trained language model RoBERTa. The vector output by the last hidden layer of RoBERTa is used as the encoding vector representation of the sentence. The bidirectional encoding network is a bidirectional long short-term memory network BiLSTM; the hidden layer vector of the last moment of the BiLSTM forward transmission is concatenated with the hidden layer vector of the last moment of the BiLSTM backward transmission to obtain the context feature vector of the sentence; The main structure of the relationship classification module is the Prototypical Networks; Extracting the entity feature vector from the sentence encoding vector specifically includes: finding the position of the entity in the sentence to obtain the entity encoding vector, and obtaining the entity feature vector through an activation function and a fully connected layer.
2. The apparatus for classifying small sample relationships of texts in the field of bridge detection as claimed in claim 1, Features: When training the few-shot relation classification method for text in the field of bridge detection, the loss functions are the cross entropy loss function and the inter-class loss function; the inter-class loss function is defined as the inverse of the distance between each category prototype; the feature vector of the category prototype is the mean of the feature vectors of all relation instances of the category.
3. A few-sample relation classification method for text in the bridge inspection field. It is characterized in that Using the few-sample relationship classification device for text in the field of bridge detection as described in any one of claims 1-2, the method comprises the following steps: S1. Use a sample encoder to encode the sentence of bridge detection into a vector form to obtain a sentence encoding vector; S2, forward and backward encoding the sentence through a bidirectional encoding network to obtain the long-term dependency feature information of the context and the reverse modeling feature information of the text, and concatenate the encoding results of the two directions to obtain the context feature vector of the sentence; S3, extracting the encoding information of the entity from the sentence encoding vector through the entity feature extraction module, and obtaining the feature vector of the entity through transformation; and fusing the entity feature vector with the context feature vector of the corresponding sentence to obtain the information feature vector used for classification of the sentence; S4, using the relationship classification module to classify the relationship according to the information feature vector of the sentence; In S1, the sample encoder is a pre-trained language model RoBERTa; the hidden state output by the last hidden layer of RoBERTa is used as the encoding feature representation of the sentence encoding vector; In S2, the bidirectional encoding network is a bidirectional long short-term memory network BiLSTM; the hidden layer vector of the last moment of the BiLSTM forward transmission is concatenated with the hidden layer state vector of the last moment of the BiLSTM backward transmission to obtain the final context feature vector representation of the sentence; In S4, the relationship classification module is a prototype network Prototypical Networks; Extracting the entity feature vector from the sentence encoding vector specifically includes: finding the position of the entity in the sentence encoding vector to obtain the entity encoding vector, and obtaining the entity feature vector through an activation function and a fully connected layer.