A prompt-based building entity recognition and classification method and system

By adding pre-training data from the architectural domain and designing initial prompt templates to the BERT model, and transforming it into a mask language task, the problem of entity recognition accuracy under small sample datasets in the architectural domain was solved, achieving high-precision entity recognition and classification.

CN115859164BActive Publication Date: 2026-04-14THIRD DIMENSION (HENAN) SOFTWARE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
THIRD DIMENSION (HENAN) SOFTWARE TECH CO LTD
Filing Date
2022-09-09
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing entity recognition methods have low accuracy on small sample datasets in the construction field, and traditional sequence labeling tasks are prone to underfitting.

Method used

We adopted a prompt-based approach to pre-train the BERT model by collecting data from the architectural domain and designing initial prompt templates. We then used automatic template search to add semantic information during the pre-training stage, transforming it into a masked language task and reducing the sample dependence of downstream tasks.

Benefits of technology

It improves the accuracy of entity recognition in the construction field, ensuring high recognition accuracy even on small sample datasets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115859164B_ABST
    Figure CN115859164B_ABST
Patent Text Reader

Abstract

The application provides a prompt-based building entity recognition and classification method and system. The method is as follows: collecting building field specifications, rules and public data sets, and preprocessing to obtain a sample data set, selecting a part of data samples to label entities to obtain a labeled sample set; selecting unlabeled data samples to pretrain a BERT pretraining model to obtain a pretraining completed BERT model; designing an initial prompt template according to the BERT model; setting a target prediction space and an answer space according to the task of recognizing entities and entity categories; extracting words from the labeled sample set according to the given span; putting the extracted words into the initial prompt template to form a complete prompt template, and putting the complete prompt template into the BERT model after vectorization, recognizing entities in the input data and classifying the entities into five categories in the building field. The application increases prompt template prompt word information, reduces the dependence of the downstream building field entity recognition task on samples, and improves the accuracy of the task.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of building entity recognition, and in particular to a method and system for recognizing and classifying building entities based on prompts. Background Technology

[0002] The building entity recognition and classification method aims to identify building entity information in architectural texts. It categorizes entities into five main types: architecture, structure, water supply and drainage, HVAC, and electrical, establishing an entity database that provides semantic information. This is crucial for relation extraction and building a node graph of relationships. Furthermore, during corpus collection, an integrated architectural information corpus can be established, providing a basic database for subsequent tasks. Secondly, semantic information can be added to the automatic generation of building structure designs using generative networks, accelerating the learning process of drawings and effectively assisting in constructing reasonable, efficient, accurate, and batch-producible structural and equipment location diagrams, thus improving the accuracy of model generation. In the field of building information systems (BIS), enriching the corpus and information database can increase model accuracy and improve efficiency in tasks such as collision checking and effective time-based control of construction schedules.

[0003] The currently widely used approach for entity recognition is sequence labeling, which employs a BERT (Bidirectional Encoder Representation from Transformer) pre-trained model to better vectorize the data. This is followed by a bidirectional Long Short-Term Memory (LSTM) network to learn the temporal information of words within a sentence, and finally, a traditional Conditional Random Field (CRF) is used to determine the label of the current word based on the context of the sentence. This approach achieves high accuracy, but in the construction industry where data is scarce (i.e., small sample sizes), adjusting model parameters during training can easily lead to underfitting, resulting in lower accuracy on small datasets. Therefore, for entity recognition in the construction industry, we are abandoning traditional sequence labeling and instead considering adding prompts during training, transforming it into a prompt-based masking language task.

[0004] Prompt-based masked language tasks involve adding template prompts to the model to enhance semantic information. Traditional entity recognition tasks use the third paradigm of natural language processing, the "pre-training-fine-tuning" paradigm. In the pre-training phase, a large amount of unlabeled data is used to train the pre-trained model, allowing it to learn semantic features. When performing downstream tasks, the model is fine-tuned based on the pre-trained model to better suit the downstream task. However, due to the limited data available for this task, we consider adding semantic prompts to the model, transforming the downstream task into the task performed by the pre-trained model during the pre-training phase. This is the fourth paradigm—prompt learning.

[0005] However, because the BERT pre-trained model is only trained using a general language, it is unfamiliar with the semantic features of terms in the architecture field. Therefore, it is necessary to collect a suitable dataset to pre-train the BERT model, enabling it to have some understanding of specialized terms in the architecture industry. This allows for a reduction in the training load during the actual training phase. Summary of the Invention

[0006] To address the technical problem of low accuracy in existing entity recognition methods applied to small sample datasets in the construction field, this invention proposes a prompt-based method and system for building entity recognition and classification. This method solves the problem of low accuracy in small sample datasets by adding prompt template hint words, thereby reducing the dependence of downstream building entity recognition tasks on samples, and thus better recognizing building entities and improving the accuracy of entity recognition tasks.

[0007] To achieve the above objectives, the technical solution of the present invention is implemented as follows: a method for identifying and classifying building entities based on prompts, comprising the following steps:

[0008] S1. Collect the standards, general rules and public datasets of the five major fields of architecture as a unified dataset and preprocess the data to obtain a sample dataset. Select a part of the data samples in the sample dataset and label the entities in them to obtain a labeled sample set.

[0009] S2. Select a BERT pre-trained model and select unlabeled data samples from the sample dataset to pre-train the BERT pre-trained model to obtain a pre-trained BERT model.

[0010] S3. Design an initial prompt template based on the BERT model, determine the shape of the initial prompt template, and set the information of the prompt words and predicted words in the initial prompt template;

[0011] S4. Set the target prediction space for the predicted word position based on the task of recognizing entities and entity categories, and set the answer space based on the target prediction space;

[0012] S5. Extract words from the sample data in the labeled sample set according to the given span 1-5;

[0013] S6. The extracted words are put into the initial prompt template to form a complete prompt template. The complete prompt template is then vectorized and put into the BERT model. The BERT model's masking task identifies the architectural entities in the input data and classifies the entities into five major categories of the architectural domain.

[0014] In step S3, the shape of the initial prompt template is Cloze Prompt, meaning that the predicted word appears in the middle of the prompt word in the initial prompt template, and the number of predicted words is fixed.

[0015] The initial prompt template is an automatically searched template. In the initial state, the prompt words of the automatically searched template are randomly generated. Based on the error feedback of the BERT model during training, the prompt template is continuously updated to finally obtain a high-precision prompt template.

[0016] The automatic search template includes the prompt word [unused], the prediction word [MASK], and the word x′ extracted from the input data x. The design method for the format and initial state of the automatic search template is as follows: determine the number and position of the prompt word [unused] in the template, determine the number and position of the prediction word [MASK] in the template, and simultaneously determine the position of the word x′ extracted from the input data x. The position of the word x′ is denoted as the position of [X]. Then, the initial format of the automatic search template is:

[0017] x prompt =<unused> loc [X]<unused> loc [MASK] loc <unused> loc

[0018] Among them, <unused> loc Indicates the position of the prompt word [unused], [MASK] loc The position of the prediction word [MASK].

[0019] The method for setting the target prediction space in step S4 is as follows:

[0020] Based on the task of identifying entities in the data text and categorizing them into five major categories: architecture, structure, water supply and drainage, HVAC, and electrical, the target prediction space mapped to the prediction word [MASK] is obtained as follows:

[0021] T type= {"Not a major", "Architecture", "Structural Engineering", "Water Supply and Drainage", "Heating, Ventilation and Air Conditioning", "Electrical Engineering"};

[0022] The method for setting the answer space based on the target prediction space in step S4 is as follows: Determine the target prediction space T. type For each type of initial answer space, the initial answer space of each type is manually expanded according to the paraphrasing method. The word length in the answer space is set to not exceed 4, forming a reasonable answer space I(X).

[0023] The method for extracting words in step S5 is as follows:

[0024] Based on the given range of 1-5, words are extracted from the sentences of the sample data. The words in the i-th sentence are extracted as follows:

[0025]

[0026] Among them, S i N(x) = {1, 2, 3, ..., m}, where m is the length of the i-th sentence, and N(x) is the given span of extracted words, where N(x) = {1, 2, 3, 4, 5}; l ranges from 1 to m, meaning words are extracted starting from the l-th character in the sentence; n ranges from 1 to 5, representing n characters extracted starting from the l-th character; x i Let x represent the i-th sentence in the original input. i ′ represents the word extracted from the i-th sentence, and span represents the function that extracts the word.

[0027] The implementation method of step S6 is as follows:

[0028] S6.1 Extract the word x i Place it in the [X] position of the automatic search template to form a complete suggestion template;

[0029] S6.2 vectorizes the complete prompt template and the words in the target prediction space;

[0030] S6.3 transforms the prompt words into vectors and passes them through a bidirectional long short-term memory network to obtain information about the prompt words before and after the vector; then, it passes them through a ReLU activation function to obtain a new word vector h for the prompt word. q ′;

[0031] S6.4 The obtained word vector h q The vectors of the extracted words from the ′ and [X] parts, the predicted word [MASK] part, and the sentence start symbol [CLS] and sentence end symbol [SEP] are concatenated to obtain x. prompt The vector form of the input BERT model is denoted as x. prompt ";

[0032] S6.5 transforms the words in the answer space into vector matrix form using word vectors and word matrices from the vocabulary of the BERT model;

[0033] S6.6 uses the BERT model's masking task to predict architectural entities in the input data and categorizes the entities into five major architectural categories. It then calculates the similarity score between the predicted words and the vectors in the answer space from step S6.5.

[0034] S6.7 uses the softmax function to activate the similarity score into a probability distribution. The word with the highest probability value is the information of the answer to the extracted word x′. Based on the information of the answer, the words in the target prediction space are determined, which is the output of the predicted word [MASK].

[0035] The implementation method of S6.2 is as follows:

[0036] In the complete prompt template x prompt Add a sentence start symbol [CLS] before the sentence and a sentence end symbol [SEP] at the end of the sentence to get sentence x. prompt ′;

[0037] Sentence x prompt Vectorize the sentence x by character, converting each character into a vector. prompt The algorithm is divided into two parts, where the prompt word "unused" is vectorized differently from the information in the rest of the automatic search template.

[0038] Based on the different vectorization methods for cue word positions and non-cue word positions, the encoding forms are divided into two types: Encoding I and Encoding II. Encoding I represents the vectorization of information at the [unused] position of the cue word, using an initialized matrix that has not been pre-trained; Encoding II represents the vectorization of information at the non-cue word position, using a matrix pre-trained by the BERT model.

[0039] Each character's vector is divided into three parts: character vector, segment vector, and position vector. The character vector is a vector form that incorporates contextual semantic information. The character vector is represented as follows:

[0040] Where j represents the position in the initial prompt template;

[0041] in, This indicates that encoding I is used for word vector encoding. This indicates that encoding of the word vectors is performed using Encoding II.

[0042] The segment vector is represented as follows:

[0043] Where j represents the position in the initial prompt template;

[0044] in, This indicates that segment vectors are encoded using code I. This indicates that segment vectors are encoded using Encoding II.

[0045] The position vector is represented by the following formula:

[0046] Where j represents the position in the template;

[0047] in, This indicates that the position vector is encoded using code I. This indicates that the position vector is encoded using Code II.

[0048] The three vector parts of each character are added together at their corresponding positions to obtain sentence x. prompt Vectorized form of ′:

[0049] The word vectors in step S6.3

[0050]

[0051] Where q represents the q-th cue word, u represents the total number of cue words; LSTM represents a bidirectional long short-term memory network function, and the cue word vector h obtained through LSTM is... q The encoding of ' contains semantic information about the preceding and following prompts;

[0052] In step S6.6, the similarity between the predicted word [MASK] position matrix A and the matrix B∈I(X) of words in the answer space I(X) is calculated to obtain the similarity score:

[0053]

[0054] Where w represents the row vector of matrix A and the row vector of matrix B. T Column vectors;

[0055] The softmax function in step S6.7 is:

[0056] During training, the predicted vector of the predicted word [MASK] and the one-hot encoded vector of the label word are processed by the cross-entropy loss function. Calculate the loss and backpropagate to update the parameters of the initial prompt template prompt words; where y represents the tag word; This represents the predicted value.

[0057] A prompt-based building entity recognition and classification system includes:

[0058] The data collection module is used to collect data in the construction field and perform preprocessing and annotation.

[0059] The pre-training module is used to train the BERT pre-trained model on specialized data to obtain the BERT model;

[0060] Build the prompt module, which contains information for designing the initial prompt template;

[0061] The answer setting module is used to set the answers for predicted words;

[0062] The word extraction module is used to extract words from the input data;

[0063] The prediction module is used to extract words from the input data and place them into the initial prompt template. It uses the BERT model to predict whether a word is an entity and at the same time predicts which type of entity the word is.

[0064] The data collection module is connected to the pre-training module, which in turn is connected to the prompt building module, the answer setting module, and the word extraction module. The prompt building module, the answer setting module, and the word extraction module are all connected to the prediction module.

[0065] A computer storage medium for storing a computer program, which, when executed, can implement any step of the prompt-based building entity recognition and classification method.

[0066] Compared with existing technologies, the beneficial effects of this invention are as follows: This invention first collects and preprocesses data related to the construction industry, pre-trains the BERT model, then sets the format and initial state of the prompt template, extracts words from the input data and puts them into the prompt template, predicts whether the words are entities, and categorizes entities into five major professions in the construction field. This invention transforms the traditional sequence labeling task of extracting construction entities into a masking language task in the BERT pre-training stage, reducing the gap between the downstream construction industry entity recognition task and the pre-trained model, ensuring consistency in training methods. Simultaneously, the designed prompt template can also provide some linguistic information to the BERT model, thereby enabling construction entity recognition to maintain high accuracy even on small sample sets. Attached Figure Description

[0067] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0068] Figure 1 This is a schematic diagram of the process of the present invention.

[0069] Figure 2 This is a framework diagram for identifying and classifying building entities according to the present invention.

[0070] Figure 3 This is a schematic diagram of the system of the present invention. Detailed Implementation

[0071] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0072] like Figure 1 As shown, a method for identifying and classifying building entities based on prompts includes the following steps:

[0073] S1. Collect the standards, general rules and public datasets of the five major fields of architecture as a unified dataset and preprocess the data to obtain a sample dataset. Select a part of the data samples in the sample dataset and label the entities in them to obtain a labeled sample set.

[0074] Furthermore, the data preprocessing in step S1 mainly includes deleting images, tables, and redundant blank lines of the selected specifications and general rules.

[0075] Selecting a portion of the data from the sample dataset and labeling the entities within it mainly involves dividing the data in the sample dataset into two parts: one part is used to pre-train the BERT pre-trained model, and the other part is used for data labeling, labeling the correct entity categories.

[0076] The method for labeling entities is as follows: Entities from the five major architectural domains are represented as dictionaries, where the keys are the entities and the values ​​are the entity categories. For example: {“The compressive strength of masonry can be directly found in design specifications.”, “Masonry”: “Structural Engineering”}. The first quotation mark represents a sentence from the data; “Masonry” represents the extracted term, which is the key in the dictionary; and “Structural Engineering” is the label for “Masonry”, representing the correct category of the entity and its value in the dictionary.

[0077] S2. Select a BERT pre-trained model and select unlabeled data samples from the sample dataset to pre-train the BERT pre-trained model to obtain a pre-trained BERT model.

[0078] Every industry's language has its own semantic features. The traditional BERT model is pre-trained on a general language dataset. Therefore, the BERT model does not have the semantic features and grammatical representations of architectural words. In order to improve the accuracy of the task, it is necessary to pre-train the BERT pre-trained model on the basis of the architectural industry dataset before the entity recognition task.

[0079] S3. Design an initial prompt template based on the BERT model, determine the shape of the initial prompt template, and set the information of the prompt words and prediction words in the initial prompt template.

[0080] Traditional entity recognition tasks are sequence labeling tasks, which have an inherent gap with the tasks in the pre-training stage of the BERT model. Meanwhile, to reduce the impact of small sample sizes on the accuracy of entity recognition tasks, prompt words can be added to the downstream entity recognition task, making it essentially a task performed during the pre-training stage of the BERT model. This reduces the gap between the pre-training stage and the downstream task stage, and the prompt words also add semantic information to the BERT model, potentially improving its accuracy.

[0081] Furthermore, the method for designing the initial prompt template based on the BERT model, determining the shape of the initial prompt template, and setting the prompt words and predicted word information in the initial prompt template in step S3 mainly refers to:

[0082] To make downstream entity recognition and classification tasks more similar to the BERT model, template prompt words need to be added, turning the sequence labeling task of entity recognition into a BERT masking task.

[0083] Since the predicted word [MASK] in the BERT model (BERT masked language model) cloze test is located in the middle of the sentence, the shape of the initial prompt template is determined to be Cloze Prompt. That is, the predicted word appears in the middle of the prompt word in the initial prompt template, and the number of predicted words is fixed.

[0084] The initial prompt templates were selected from manually designed templates and automatically searched templates. Since manually designed templates require a lot of experiments, experience, and language expertise, the experimental results showed that even with only minor differences in individual words, the final results varied greatly. Therefore, in order to avoid the problem of language information from manually designed templates affecting the accuracy of the model, the template type was determined to be an automatically searched template.

[0085] In the initial state, the prompt words for the automatic search template are randomly generated, no longer determined based on human understanding. Based on error feedback during model training, the prompt template is continuously updated in each training iteration, ultimately resulting in a high-precision prompt template. The automatic search template includes the prompt word [unused], the predicted word [MASK], and the word x′ extracted from the original input data x.

[0086] Design the format and initial state of the automatic search template, including determining the number of prompt words [unused] and their positions in the template, determining the number of predicted words [MASK] and their positions in the template, and determining the position of the word x′ extracted from the original input data x, with the position of word x′ denoted as the position of [X].

[0087] The initial format of the automatically searched template can be obtained as follows:

[0088] x prompt =<unused> loc [X]<unused> loc [MASK] loc <unused> loc

[0089] Among them, <unused> loc This indicates the position of the auto-search template suggestion word "[unused]", or "[MASK]". loc The position of the prediction word [MASK].

[0090] like Figure 2 As shown, due to <unused> loc and [MASK] locThis only indicates location information, not the number of items. The number of items is determined by the user. Therefore, the number of [unused] and [MASK] used subsequently in this application is as follows: First, the number of [unused] prompts in the automatic search template is determined to be 6, and the position of the [unused] prompts is determined to be 4. Second, the number of [MASK] predictions in the template is determined to be 4, and the position of the [MASK] predictions is determined to be 4. At the same time, the position of the word x′ extracted from the original data can be determined, and its position is denoted as the position of [X].

[0091] The initial form of the obtained automatic search template:

[0092] x prompt =[u1][u2][u3][X][u4][MASK][MASK][MASK][MASK][u5][u6];

[0093] Among them, [u1]~[u6] represent 6 prompt words [unused1]~[unused6].

[0094] S4. Set the target prediction space for the predicted word position based on the task of recognizing entities and entity categories, and set the answer space based on the target prediction space.

[0095] In order to correctly identify and classify entities, the BERT model first extracts words from the input data during the training phase, then predicts whether the word is an entity based on the prompt words and classifies the entity. Subsequently, the prompt words of the prompt template are updated based on the difference between the predicted value and the true label value, thereby making the prompt words of the prompt template more accurate in predicting entities and entity categories.

[0096] Furthermore, setting the final target prediction space in step S4 mainly includes:

[0097] Based on the task of identifying entities in the data text and classifying them into five categories: architecture, structure, water supply and drainage, HVAC, and electrical, the task of identifying and classifying entities is achieved by automatically searching the initial form x of the template. prompt The BERT model is used to predict the word at the position of the predicted word [MASK] and to determine the final recognition result. Therefore, the final target mapping to the target prediction space of the predicted word [MASK] is as follows:

[0098] T type = {"Not a major", "Architecture", "Structural Engineering", "Water Supply and Drainage", "Heating, Ventilation and Air Conditioning", "Electrical Engineering"}.

[0099] Since different categories can be represented by different words, and slight differences in word expression may result in different final precision, the answer space should be expanded as much as possible.

[0100] Determine the target prediction space T type For each initial answer space, subsequently, manually expand each initial answer space by means of paraphrasing, that is, first translate it into another language and then translate it back into Chinese. At the same time, according to the number of prediction words [MASK] and to ensure the feasibility of subsequent calculations, set the number of words in the answer space not to exceed 4. For example, some answers in the building category are "{\"building type\", \"building category\"}", etc. Finally, form a reasonable answer space I(X). Ensure that the words in the target prediction space are four Chinese characters.

[0101] S5. Extract words from the sample data in the labeled sample set according to the given span of 1 - 5.

[0102] Furthermore, in step S5, when extracting words from the data, according to the length of conventional building type words and to minimize the word calculation amount as much as possible, after inputting the data, extract words from the sentence according to the given span of 1 - 5.

[0103] The formula for extracting words from the i-th sentence is as follows:

[0104]

[0105] where S i (x) = {1, 2, 3,..., m}, m is the length of the i-th sentence, N(x) is the given span for extracting words, that is, N(x) = {1, 2, 3, 4, 5}; the range of l is from 1 to m, that is, start extracting words from the l-th character in the sentence, and the range of n is from 1 to 5, indicating extracting n characters starting from the l-th character. x i represents the i-th sentence in the original input, x i ′ represents the words extracted from the i-th sentence, and span represents the process of extracting words, which can be implemented through code.

[0106] For example Figure 2 As shown, first perform encoding and finally obtain the framework diagram of the predicted category. For example, in the case of "The thickness of the insulation layer should be determined by calculation according to the current building energy efficiency design standard in the region where it is located", starting from the first character of the sentence and when the span span ranges from 1 to 5, the extracted words are "bao", "baowen", "baowenceng", "baowencenghou", "baowencenghoudutu". Subsequently, move one character backward successively from the first character, and repeat the above process of extracting words from the current position respectively. According to the length of the sentence, obtain the corresponding number of extracted words.

[0107] S6. The extracted words are put into the initial prompt template to form a complete prompt template. The complete prompt template is then vectorized and put into the BERT model. The BERT model's masking task identifies the architectural entities in the input data and classifies the entities into five major categories of the architectural domain.

[0108] Furthermore, step S6 mainly includes:

[0109] S6.1 First, the extracted words x should be... i Place it in the [X] position of the automatic search template to form a complete prompt template.

[0110] For example, placing "insulation layer" in the [X] position of the automatic search template will give you the complete suggestion template:

[0111] x prompt =[u1][u2][u3]Insulation layer[u4][MASK][MASK][u5][u6].

[0112] S6.2 vectorizes the complete prompt template and the words in the target prediction space.

[0113] According to the format of the BERT model, first in the complete template x prompt Adding the sentence start symbol [CLS] before the sentence and the sentence end symbol [SEP] at the end of the sentence gives the sentence x. prompt As shown below:

[0114] x prompt = [CLS][u1][u2][u3]Insulation layer[u4][u5][MASK][MASK][MASK][MASK][u6][SEP];

[0115] Secondly, sentence x prompt Vectorize the sentence x by character, converting each character into a vector. promptThe algorithm is divided into two parts. The information from the prompt word "[unused]" and other positions in the automatic search template is vectorized differently. Therefore, based on the different vectorization methods for prompt and non-prompt word positions, the encoding forms are divided into two types: Encoding I and Encoding II. Encoding I represents the vectorization of information from the prompt word "[unused]" position, using an initial matrix that has not been pre-trained and is subsequently optimized based on training. Encoding II represents the vectorization of information from non-prompt word positions, using a matrix pre-trained by the BERT model, and is not optimized further in downstream tasks. Furthermore, the vector for each character is mainly divided into three parts: token embeddings, segment embeddings, and positional embeddings. The token embeddings are vector forms that incorporate contextual semantic information, and their representation is shown in the following formula:

[0116] Where j represents the position in the initial prompt template;

[0117] in, This indicates that encoding I is used for word vector encoding. This indicates that encoding II is used for encoding word vectors.

[0118] Because the BERT model includes a pre-training task to predict the next sentence, two sentences may be concatenated in some cases, separated by a [SEP] delimiter. The segment vector is used to distinguish between the two sentences, and its representation is shown in the following formula:

[0119] Where j represents the position in the initial prompt template;

[0120] in, This indicates that segment vectors are encoded using code I. This indicates that segment vectors are encoded using Encoding II.

[0121] To enable the model to distinguish that the same word has different meanings in different positions, a position vector is added to represent the position. The position vector is represented by the following formula:

[0122] Where j represents the position in the template;

[0123] in, This indicates that the position vector is encoded using code I. This indicates that the position vector is encoded using Encoding II.

[0124] Finally, the three vector parts of each character are added together at their corresponding positions to obtain the sentence x. promptThe vectorized form of ′ is:

[0125]

[0126] In other words, the [unused] part uses encoding I, and the non-[unused] part uses encoding II. For the [unused1] to [unused6] parts, after vectorization, we get h1 to h6. Later, we can optimize the random initialization matrix used for the part encoded by encoding I according to the loss function. The initialization matrix is ​​randomly initialized.

[0127] S6.3 To increase the relevance between prompt words, the prompt words h1 to h6, converted into vectors, are passed through a bidirectional Long Short-Term Memory (LSTM) network, allowing the vectors to obtain information from the preceding and following prompt words. Then, a ReLU activation function is applied to reduce the vanishing gradient problem, resulting in a new prompt word vector h. q ′.

[0128] i.e., word vectors

[0129]

[0130] Where q represents the q-th cue word, and u represents the total number of cue words (6). LSTM stands for Bidirectional Long Short-Term Memory Network. The Bidirectional Long Short-Term Memory Network recognizes the encoded information of words from both the preceding and following directions, allowing the cue word vector h obtained through LSTM to be more efficient. q The encoding of ' contains semantic information about the preceding and following prompts.

[0131] S6.4 Since the prompt word part and the non-prompt word part use different encodings, it is necessary to convert the obtained word vector h q The vectors of the extracted words from the ′ and [X] parts, the predicted word [MASK] part, and the sentence start symbol [CLS] and sentence end symbol [SEP] are concatenated to obtain x. prompt The final vector form input into the BERT model is denoted as x. prompt ″.

[0132] S6.5 further transforms the words in the answer space into vector matrix form using word vectors and word matrices from the vocabulary in the BERT model. If the word length in the answer space I(X) is less than 4, it is padded to 4 using PAD vectors.

[0133] The vectorization of the answer space only involves word vectors, because the number of columns in the matrix is ​​not uniform, so PAD vectors are used to fill in the gaps.

[0134] S6.6 further identifies architectural entities in text through the masking task of the BERT model and categorizes the entities into five major architectural categories.

[0135] First, the input vector is fed into the BERT model, which outputs a new vector. At the same time, a vector containing contextual semantic information at the predicted word [MASK] position can also be obtained.

[0136] The similarity score is calculated by combining the vectors of the words at the predicted [MASK] position in the BERT model to form matrix A, and the vectors of the words in the answer space I(X) B∈I(X).

[0137]

[0138] Where w represents the row vector of matrix A and the row vector of matrix B. T Column vectors.

[0139] S6.7 Subsequently, the similarity score is activated into a probability distribution using the softmax function, where the softmax function is... The word with the highest probability value is the information of the extracted word x′. Since the words in the answer space are all secondary words of the words in the target prediction space, the vocabulary in the target prediction space is determined based on the information of the answer, which is the final output of the prediction word [MASK].

[0140] If words starting with the same character but with different spans are predicted as entities, they are considered embedded words. Therefore, only words with larger spans are retained as entities. Generally, embedded words with larger spans are complete entities. This ensures the accuracy of training.

[0141] S6.8 In the training phase, the predicted vector of the predicted word [MASK] and the one-hot encoding of the labeled word are processed using the cross-entropy loss function. The loss is calculated, and then the parameters in the initialization matrix of the prompt word encoding are differentiated. The parameters in the initialization matrix of the prompt word encoding of the prompt template are updated through backpropagation. In the subsequent forward propagation process, the prompt words can be represented by a more suitable vector.

[0142] Where y represents the actual labeled value, that is, whether the extracted word is an entity and what type of entity it is; This represents the predicted value, that is, the predicted entity type of the extracted words.

[0143] Since the template vector is obtained by randomly initializing the parameter matrix, the initial prompts cannot play a full role. Therefore, a small amount of data is needed to update the template parameters during the training phase. Finally, a higher result can be obtained in recognizing and classifying building entities. After the training phase is completed, the parameter updates are stopped.

[0144] During the testing phase, the input data was vectorized into words as described above and then directly fed into the BERT model to identify entities and predict their categories.

[0145] As a preferred implementation, the present invention also provides a prompt-based entity recognition and classification system for the architectural field, comprising:

[0146] The data collection module is used to collect data in the construction field and perform preprocessing and annotation.

[0147] The pre-training module is used to train the BERT pre-trained model on specialized data to obtain the BERT model;

[0148] Build the prompt module, which contains information for designing the initial prompt template;

[0149] The answer setting module is used to set the answers for predicted words;

[0150] The word extraction module is used to extract words from the input data;

[0151] The prediction module is used to extract words from the input data and place them into the initial prompt template. It uses the BERT model to predict whether a word is an entity and at the same time, it can predict which type of entity the word is.

[0152] The data collection module is connected to the pre-training module, which in turn is connected to the prompt building module, the answer setting module, and the word extraction module. All three of these modules are connected to the prediction module.

[0153] As a preferred embodiment, the present invention also provides a computer storage medium that can store a computer program, which, when executed, can implement any step of the prompt-based building entity recognition and classification method.

[0154] It should be noted that the examples given in this invention are only for illustrating the implementation method of a certain step and are not intended to limit this patent; those skilled in the art can modify the previously implemented solutions, and such modifications should not cause the technical solutions to deviate from the scope of this invention.

[0155] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for identifying and classifying building entities based on prompts, characterized in that, The steps are as follows: S1. Collect the standards, general rules and public datasets of the five major fields of architecture as a unified dataset and preprocess the data to obtain a sample dataset. Select a part of the data samples in the sample dataset and label the entities in them to obtain a labeled sample set. S2. Select a BERT pre-trained model and select unlabeled data samples from the sample dataset to pre-train the BERT pre-trained model to obtain a pre-trained BERT model. S3. Design an initial prompt template based on the BERT model, determine the shape of the initial prompt template, and set the information of the prompt words and predicted words in the initial prompt template; In step S3, the shape of the initial prompt template is Cloze Prompt, meaning that the predicted word appears in the middle of the prompt word in the initial prompt template, and the number of predicted words is fixed. The initial prompt template is an automatically searched template. In the initial state, the prompt words of the automatically searched template are randomly generated. Based on the error feedback of the BERT model during training, the prompt template is continuously updated to finally obtain a high-precision prompt template. S4. Set the target prediction space for the predicted word position based on the task of recognizing entities and entity categories, and set the answer space based on the target prediction space; S5. Extract words from the sample data in the labeled sample set according to the given span 1-5; the span 1-5 means that the span value is {1, 2, 3, 4, 5}. S6. The extracted words are put into the initial prompt template to form a complete prompt template. The complete prompt template is then vectorized and put into the BERT model. The BERT model's masking task identifies the architectural entities in the input data and classifies the entities into five major categories of the architectural domain.

2. The method for identifying and classifying building entities based on prompt according to claim 1, characterized in that, The automatic search template includes prompts. and prediction words And from input data Words extracted The design method for the format and initial state of the automatic search template is as follows: determine the prompt words in the template. The number and position of the predicted words in the template are determined. The number and position of, and also determine the input data. Words extracted Location, words The position is recorded as If the position is specified, the initial format of the automatically searched template will be: ; in, Indicator words Location, Representative prediction words The location.

3. The method for identifying and classifying building entities based on prompt according to claim 2, characterized in that, The method for setting the target prediction space in step S4 is as follows: Based on the task of identifying entities in the data text and categorizing them into five major categories—architecture, structure, water supply and drainage, HVAC, and electrical—the target is mapped to predicted words. The target prediction space is: {"Not a major", "Architecture", "Structural Engineering", "Water Supply and Drainage", "Heating, Ventilation and Air Conditioning", "Electrical Engineering"}; The method for setting the answer space based on the target prediction space in step S4 is as follows: Determine the target prediction space. For each type of initial answer space, the initial answer space for each type is manually expanded according to the paraphrasing method. The word length in the answer space is set to no more than 4, thus forming a reasonable answer space. .

4. The method for identifying and classifying building entities based on prompt according to any one of claims 1-3, characterized in that, The method for extracting words in step S5 is as follows: Based on the words in the sentences from which sample data is extracted across a given span of 1-5, extract the words from the first sentence. The words in the sentence are shown below: ; in, , For the first The length of each sentence Given the span of the extracted words, and ; The range is from 1 to That is, from the first sentence Words are extracted starting from each character; The range is from 1 to 5, indicating from the th Starting with the character extraction Each character; Indicates the first element in the original input. One sentence. Indicates from the first Words extracted from a sentence This function represents the process of extracting words.

5. The method for identifying and classifying building entities based on prompt according to claim 2 or 3, characterized in that, The implementation method of step S6 is as follows: S6.1 will extract the words Add to automatic search template Location, forming a complete prompt template; S6.2 vectorizes the complete prompt template and the words in the target prediction space; S6.3 transforms the prompt words into vectors and passes them through a bidirectional long short-term memory network to obtain information about the prompt words before and after the vector; then, it passes them through a ReLU activation function to obtain a new word vector for the prompt word. ; S6.4 will obtain the word vectors and Partial word extraction and prediction The vectors of the sentence, along with the sentence start symbol [CLS] and sentence end symbol [SEP], are concatenated to obtain the sentence. The vector form of the input BERT model is denoted as: ; S6.5 transforms the words in the answer space into vector matrix form using word vectors and word matrices from the vocabulary of the BERT model; S6.6 uses the BERT model's masking task to predict architectural entities in the input data and categorizes the entities into five major architectural categories. It then calculates the similarity score between the predicted words and the vectors in the answer space from step S6.

5. S6.7 usage The function converts the similarity scores into a probability distribution, and the word with the highest probability value is the extracted word. The information from the answer is used to determine the words in the target prediction space, which are the predicted words. The output.

6. The method for identifying and classifying building entities based on prompt according to claim 5, characterized in that, The implementation method of S6.2 is as follows: In the complete prompt template Add a sentence start character [CLS] before the sentence and a sentence end character [SEP] at the end of the sentence to get the sentence. ; Sentence Vectorize the text character by character, converting each character into a vector. During vectorization, the sentence... Divided into two parts, including the prompt words The information in the remaining positions of the automatically searched template is vectorized differently; Based on the different vectorization methods used for prompt and non-prompt word positions, the encoding formats are divided into two types: Encoding I and Encoding II. Encoding I represents the prompt word. The location information is vectorized using an initialized matrix that has not been pre-trained; Encoding II represents the vectorization of non-comment word location information using a matrix pre-trained with the BERT model. Each character's vector is divided into three parts: character vector, segment vector, and position vector. The character vector is a vector form that incorporates contextual semantic information. The character vector is represented as follows: ,in, Indicates the position within the initial prompt template; in, This indicates that encoding I is used for word vector encoding. This indicates that encoding of the word vectors is performed using Encoding II. The segment vector is represented as follows: ,in, Indicates the position within the initial prompt template; in, This indicates that segment vectors are encoded using code I. This indicates that segment vectors are encoded using Encoding II. The position vector is represented by the following formula: ,in, Indicates the position within the initial prompt template; in, This indicates that the position vector is encoded using code I. This indicates that the position vector is encoded using Code II. The three vector parts of each character are added together at their corresponding positions to obtain the sentence. Vectorized form: .

7. The method for identifying and classifying building entities based on prompt according to claim 6, characterized in that, The word vectors in step S6.3 ; in, Indicates the first One prompt word, Indicates the total number of prompt words; This represents a bidirectional long short-term memory network function, through... The obtained prompt word vectors The encoding contains semantic information from the preceding and following prompts; In step S6.6, the predicted words will be... Position matrix and answer space The matrix of words in The similarity score is calculated as follows: ; in, Representation matrix row vectors and matrices Column vectors; In step S6.7 The function is ; During training, predict words The predicted vector and the one-hot encoded vector of the tag word are obtained through the cross-entropy loss function. Calculate the loss and backpropagate to update the parameters of the initial prompt template prompt words; where, Indicates tag words; This represents the predicted value.

8. A prompt-based building entity recognition and classification system, utilizing the prompt-based building entity recognition and classification method according to any one of claims 1-7, characterized in that, include: The data collection module is used to collect data in the construction field and perform preprocessing and annotation. The pre-training module is used to train the BERT pre-trained model on specialized data to obtain the BERT model; Build the prompt module, which contains information for designing the initial prompt template; The answer setting module is used to set the answers for predicted words; The word extraction module is used to extract words from the input data; The prediction module is used to extract words from the input data and place them into the initial prompt template. It uses the BERT model to predict whether a word is an entity and at the same time predicts which type of entity the word is. The data collection module is connected to the pre-training module, which in turn is connected to the prompt building module, the answer setting module, and the word extraction module. The prompt building module, the answer setting module, and the word extraction module are all connected to the prediction module.

9. A computer storage medium for storing computer programs, characterized in that, When the computer program is executed, it can implement any step of the prompt-based building entity identification and classification method described in any one of claims 1-7.