Ontology library automatic construction method based on priori knowledge and data driving
Through prior knowledge and data-driven methods, machine learning models are used to extract entities and relationships in the ontology library, which solves the problems of time-consuming and labor-intensive and inaccurate automated construction of existing ontology library construction methods, and achieves efficient and accurate ontology. Library construction and knowledge graph construction.
Patent Information
- Application Number
- CN202410699381.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-09-24
AI Technical Summary
Existing ontology library construction methods rely on manual operations, which are time-consuming and labor-intensive, and automated construction methods lack in-depth understanding of domain expertise, resulting in inaccurate or incomplete construction.
Using a method based on prior knowledge and data-driven, the machine learning model is used to extract entities and association rules, and the BERT model is fine-tuned with P-tuningv2 to build a knowledge graph to improve the accuracy of entity extraction and the efficiency of relationship extraction.
It achieves more accurate and faster ontology library construction, improves the practicality and effect of knowledge graphs in application fields, and reduces manual annotation and hardware requirements.
Smart Images

Figure CN118690119A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of natural language processing and relates to a method for automatically constructing an ontology library based on prior knowledge and data-driven. Background Art
[0002] With the explosive growth of information, building semantically informed knowledge graphs and ontologies has become increasingly important. A knowledge graph is a structured knowledge network consisting of entities, relationships, and attributes. Ontologies, on the other hand, form the foundation of knowledge graphs, providing formal definitions and semantic information for entities and relationships. They play a key role in search engines, natural language processing, intelligent question answering, and other fields.
[0003] Traditional ontology construction typically relies on domain experts, requiring significant time and labor. Traditional manual ontology construction methods are cumbersome and time-consuming when faced with such complexity. Furthermore, when faced with large-scale, multi-source, and heterogeneous data, manual ontology construction is limited in efficiency and accuracy. Therefore, research on how to automate the construction of ontology libraries has become a current research hotspot. However, existing research on automated construction is limited, and the accuracy of extracted entities is low, making them less representative of the domain.
[0004] Prior knowledge provides deep insight and understanding from domain experts, ensuring the comprehensiveness of the ontology in terms of entities, relationships, and attributes within the domain. Data-driven approaches, by mining large amounts of real-world data, increase the depth and richness of the ontology, covering more practical scenarios and contexts. Incorporating prior knowledge and data-driven techniques into ontology construction can create more complete, accurate, flexible, and efficient ontology libraries, enhancing the practicality and effectiveness of knowledge graphs in various application domains. Summary of the Invention
[0005] The purpose of the present invention is to provide an automatic construction method of an ontology library based on prior knowledge and data-driven, which introduces prior knowledge and data-driven technology into the construction of the ontology library and improves the accuracy of entity extraction during the construction of the ontology library.
[0006] The technical solution adopted in the present invention is an automatic ontology library construction method based on prior knowledge and data-driven. First, the data is preprocessed, and then based on prior knowledge, entities and association rules are extracted with the help of a machine learning model. Based on the extracted association rules, the BERT model is fine-tuned with the help of P-tuningv2 to obtain relationship extraction results. Finally, the extracted relationships and entities are merged to construct an ontology library, and a knowledge graph is constructed based on the ontology library.
[0007] The present invention is also characterized in that:
[0008] The specific steps include:
[0009] Step 1: Collect encyclopedia data and combine it with domain-specific knowledge documents as a domain-specific dataset, use an open-source Chinese open domain dataset as a non-domain-specific dataset, and preprocess these two datasets separately;
[0010] Step 2: Based on prior knowledge and question templates, a machine learning model is used to automatically extract entities from the preprocessed dataset text;
[0011] Step 3: Obtain association rules based on the frequency mining algorithm, fine-tune the BERT model with the help of the P-tuningv2 fine-tuning method, and use the trained model to extract the relationship between entity pairs;
[0012] In step 4, based on the constructed ontology library, a pipeline approach is used to perform entity relationship extraction tasks, BERT-BILSTM-CRF is used for named entity recognition tasks, and then the RoBERTa model is used to extract relationships, and finally the data layer of the knowledge graph is constructed.
[0013] The specific process of step 1 is:
[0014] Step 1.1: For domain-specific expertise documents, use crawler technology to crawl movie information from Baidu Encyclopedia and add it to domain-specific document A. For non-domain-specific document B, add the open-source MSRA-NER entity dataset to document B.
[0015] Step 1.2: For the domain-specific dataset containing document-type data and image-type data, write Python code to extract the file names of image-type files and the contents of document-type files, and store them in the domain-specific text document A.
[0016] Step 1.3: Use Python code to remove special characters, punctuation marks, HTML tags, and other interference items from document B in the non-domain-specific dataset and the domain-specific dataset processed in step 1.2. Furthermore, convert all English letters in the domain-specific text documents processed in step 1.2 to lowercase.
[0017] Step 1.4: Build a custom stop word list based on the stop word list of Harbin Institute of Technology and Baidu, and use the NTLK library to delete stop words in the document based on the custom stop word list;
[0018] Step 1.5: For the specific domain text document A obtained in step 1.3, which contains proper nouns in both Chinese and English, a dictionary is created for the English proper nouns. The segmentation results are stored in document A' using the CSW Chinese professional word segmentation tool. The data in document A' is used as the specific domain dataset D. s, the data in the non-specific domain document B is used as the non-specific domain dataset D n .
[0019] The specific process of step 2 is:
[0020] Step 2.1, manually define question template 1 and question template 2;
[0021] Step 2.2: Calculate the domain-specific dataset D using the following formula (1): s The frequency of each word in TF(t,D s ), filter the words with TF value greater than 0.005 to form the high-frequency word set W o :
[0022]
[0023] Among them, count(t,D s ) represents the vocabulary t in the dataset D s The number of times it appears in total(D s ) represents the dataset D s The total number of all words in TF(t,D s ) represents the word frequency of vocabulary t;
[0024] Step 2.3: Use the search engine to obtain the initial entity category candidate set W for a specific field p ;
[0025] Step 2.4, calculate W by the following formula (2) o With W p The intersection of is used as the domain-specific partial entity category dataset E1;
[0026] E1=W o ∩W p (2)
[0027] Step 2.5, calculate W o The TF-IDF value T of all words in i , the calculation formula is as follows:
[0028]
[0029] Among them, tf ij is the frequency of word i appearing in document j, and sa is the domain-specific dataset D s The total frequency of all words in the dataset D s With the non-specific dataset D n The total number of documents in df i is the number of documents in which word i appears;
[0030] Step 2.6, the dataset D s Input into the LDA topic model to obtain a specific domain dataset D s The subject word set WI and the probability P(w h |D m ), the calculation formula is as follows:
[0031]
[0032] Among them, w h Represents any word in the subject word set WI; T k represents any topic in the topic set; P(w h |T k ) means that when the topic is k, the word w h Probability of occurrence; C hk Represents word w h The number of times it is assigned to topic k; N is the size of the vocabulary; β is a hyperparameter; D m Represents a domain-specific dataset D s Any document in the document collection; T k represents any topic in the topic set; P(T k |D m ) means that when the document is m, the topic T k Probability of occurrence; C km Represents a domain-specific dataset D s The words in document m in the document collection are assigned to topic T k The number of times; P(w h |D m ) represents the probability of the topic word; K represents the number of topics; α represents the hyperparameter;
[0033] Step 2.7, use W o All the words in WI are matched to the words in WI. If they exist, the P(w h |D m ) as W o The probability P of the word in s If no match is found, it is set to 0;
[0034] Step 2.8: The domain-specific dataset D s With the non-specific domain dataset D n Merge into background corpus, divide the documents in background corpus into independent classes {C1, C2..., C n}, the total number of categories is n, W o The information entropy calculation formula for each word i in is as follows:
[0035]
[0036] H(i)=-P(i)logP(i) (8)
[0037] in, is the total number of documents in the background document set where word i appears, d n Category C n The number of documents in which word i appears in , H(i) is the information entropy of word i;
[0038] Step 2.9, calculate W o The ontology relevance O of each word i in i :
[0039]
[0040] Among them, otn is the total number of domain ontology categories that already exist in E1, totn j W o The number of times each word i appears with the j-th domain ontology category, W o The average number of words that appear together with each word i and the domain ontology category in , totn is the number of domain ontology categories that appear together with each word i;
[0041] Step 2.10: Use the random forest model as the entity classification model and train the entity classification model;
[0042] Step 2.11, traverse all entity categories in the entity category set E2, embed question template 1 into the search engine to get "yes" or "no", delete all entity categories corresponding to the answer "no", and finally obtain the entity category set E2 required to construct the ontology f .
[0043] The specific process of step 2.10 is:
[0044] Step 2.10.1, the entity category in E1 obtained in step 2.4 is used as a positive example; then manually select W o Words that cannot be used as entity categories are used as counterexamples;
[0045] Step 2.10.2: All the words obtained in step 2.10.1 as positive examples and negative examples are combined into a vocabulary list W e , calculated according to the definition in steps 2.5-2.9 to obtain W e T(i), P for all words in s , H(i) and O i and labels constitute the training set T r , the label column is manually annotated, if it is a positive example, the label is 1, if it is a negative example, the label is 0;
[0046] Step 2.10.3, the training set T r The data is input into the random forest model for training. When the four indicators of F1-score, recall rate, precision rate, and area under the ROC curve reach the highest value, the trained model TL-FR is obtained.
[0047] In step 2.10.4, all W obtained in steps 2.5-2.9 are converted to o T(i), P for all words in s , H(w) and O i The input is input into the model TL-FR to obtain the output prediction value 0 or 1, and all words with output value 1 are selected to form the entity category set E2.
[0048] The specific process of step 3 is:
[0049] Step 3.1, taking a movie as a transaction, based on the obtained entity category set E f , use the apriori algorithm to get the association rule set R f , when calculating the support, the weight is introduced; finally, the interest degree is introduced to filter the association rules, and the calculation formula is as follows:
[0050]
[0051] Where Transactions containing A represents the number of transactions containing the item set A, Total transactions represents the total number of transactions; Support(A) represents the minimum support of the item set A, and γ is defined as: if the item set A∈E f , then γ=0; if the item set Then γ = 1; Support(A∪B) is the number of transactions that include itemsets A and B; Support(B) represents the minimum support of itemset B; Confidence(A→B) refers to the probability that a transaction set also includes itemset B under the premise of including itemset A, also known as confidence; max{} is the maximum value; Intrerest(A→B) represents interest;
[0052] Step 3.2: Based on association rules, a set of sentences SEN representing entities and relationships is obtained with the help of a search engine;
[0053] Step 3.3, divide SEN into training set T s and test set C s ;
[0054] Step 3.4, extract T sThe relationship between all sentences in is converted into vectors to obtain the training set T of the BERT model b ;
[0055] Step 3.5, the training set T b The data is input into the BERT model for training, and the model is fine-tuned through P-tuningv2 to maximize the F1-score, resulting in the trained model PTBERT.
[0056] Step 3.6, use the test set C s Test the performance of the PTBERT model;
[0057] Step 3.7: Input all the data in SEN into PTBERT, and get all the relation sets and compare them with the set R. f The entity pairs in the table correspond to each other, and the entity relationship triples required to build the ontology library are stored in the form of entity relationship triples. R ;
[0058] Step 3.8, E R The triples in E f The entity categories in the dataset are imported into the Neo4j graph database to build the ontology library of the knowledge graph.
[0059] The specific process of step 3.4 is:
[0060] Step 3.4.1, T s The sentence SE1 obtained in the sentence matches the regular expression and obtains the relationship S between the entity pairs in the sentence r ;
[0061] Step 3.4.2, use the Doc2vec model to convert SE1 into vector S v , S v With S r Stored together in the MySQL database;
[0062] Step 3.4.3, loop steps 3.4.1-3.4.2 until all sentences in SEN are processed to obtain the training set T b .
[0063] The specific process of step 4 is:
[0064] Step 4.1: Divide the domain-specific dataset D s The training set D T , test set D C ;
[0065] Step 4.2, use the training set D T Train the BiLSTM-CRF model on named entity recognition tasks;
[0066] Step 4.3, use the test set D C Verify the performance of the BERT-BILSTM-CRF model and use the trained BERT-BILSTM-CRF model to perform named entity recognition tasks. The extracted entity set is E S ;
[0067] Step 4.4: Based on the manually defined template and cosine similarity, link the entities extracted in step 4.3 to the existing entity categories in the ontology library, and match the entity and entity category embedding template in the ontology library with the full text of document A to obtain the matching score t m ; Then use the Doc2vec model to convert the entities extracted in step 4.3 into word vectors, use the word vectors to calculate the residual similarity, define the weight and the residual similarity, and the calculation formula is as follows:
[0068]
[0069] Where A and B are the word vectors of two entity categories, ||A|| and ||B|| are the modulo lengths of the word vectors of entity categories A and B, and t m represents the template matching score, which is defined as 1 if the match is successful and 0 if the match fails, and δ is the weight;
[0070] Step 4.5: For the entity category pairs that have relationships in the ontology library, map the entity category pairs to E by the method of step 4.4. s The entities in the dataset are obtained, and the entity pairs and their relationships are used as the training set T r , for E s The remaining entities in are used as the test set T e ;
[0071] Step 4.6, use the training set T r Train the relation extraction model RoBERTa to achieve the highest F1-score;
[0072] Step 4.7, use the test set T e Test the trained relation extraction model RoBERTa to obtain the relations of the remaining entities;
[0073] In step 4.8, the entities extracted in steps 4.2-4.3 and the relationships extracted in steps 4.4-4.7 are manually converted into entity-relationship triples, stored in the graph database Neo4j, and the final knowledge graph is obtained.
[0074] The specific process of step 4.2 is:
[0075] Step 4.2.1, use BERT as the embedding layer model of the BiLSTM-CRF model and input the training set D T The sentences in are converted into word vectors;
[0076] In step 4.2.2, the converted word vectors are input into the BILSTM model, which outputs a bidirectional context representation sequence for each word.
[0077] In step 4.2.3, after receiving the output of the BILSTM model, the CRF model outputs the final label sequence, which represents the entity category of each word.
[0078] The beneficial effect of the present invention is that most of the existing methods for constructing ontology libraries are based on pure manual and semi-automatic construction, which is time-consuming and labor-intensive, and the existing automated ontology library construction methods still lack a deep understanding of domain expertise, resulting in the ontology library constructed in a specific field being inaccurate or incomplete. In order to ensure the high quality of the ontology library construction in the film field, the present invention introduces prior knowledge in the film field to assist in the automatic extraction of entities. Compared with the existing automatic ontology library construction methods, this paper adopts a method combining information entropy, ontology relevance, TF-IDF and LDA model with random forest model to improve the accuracy of entity recognition, which is more convenient and quick and has low requirements for hardware equipment; for the relationship extraction method in the ontology library, this paper introduces association rules and question templates. With the help of the search engine, the relationship candidate set of some entities can be directly obtained without manual labeling of relationship labels, which facilitates the subsequent relationship extraction model training. BRIEF DESCRIPTION OF THE DRAWINGS
[0079] Figure 1 This is the overall flow chart of the method for automatically constructing an ontology library based on prior knowledge and data-driven implementation of the present invention;
[0080] Figure 2 This is a flow chart of constructing an ontology library in the method for automatically constructing an ontology library based on prior knowledge and data-driven according to the present invention;
[0081] Figure 3(a) to Figure 3(d) It is a comparison chart of ROC curves of the model used in the method for automatically constructing an ontology library based on prior knowledge and data-driven in the present invention and three other existing models. DETAILED DESCRIPTION
[0082] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0083] Example 1
[0084] The present invention is based on a priori knowledge and data driven ontology library automatic construction method, the process is as follows Figure 1 As shown, the specific steps include:
[0085] Step 1: Collect encyclopedia data and combine it with knowledge documents in a specific field (taking the film field as an example) (the document contains: movie name, director, producer, screenwriter, male lead, and female lead) as the specific field dataset, and use the open source Chinese open domain dataset MSRA-NER entity dataset as the non-specific field dataset, and preprocess these two datasets separately.
[0086] In step 1.1, the data comes from two sources. For specialized knowledge documents in a specific field (for example, the film field), this paper uses crawler technology to crawl movie information from Baidu Encyclopedia and add it to the specific field (for example, the film field) document A. For non-specific field document B, the currently open-source general domain dataset MSRA-NER entity dataset is used.
[0087] Step 1.2: For a specific field (taking the film field as an example), the dataset contains document type data and image type data. Write Python code to extract the file name of the image type file and the content of the document type file, and store them in the specific field text document A.
[0088] In step 1.3, for the non-domain-specific dataset and the domain-specific dataset (taking the movie field as an example) processed in step 1.2, use Python code to remove interference items such as special characters, punctuation marks, and HTML tags in the document, and convert the English letters in document A to lowercase.
[0089] In step 1.4, based on the stop word list of Harbin Institute of Technology and the stop word list of Baidu, the present invention summarizes these two word lists to establish a custom stop word list, and uses the NTLK library (natural speech processing library) to delete the stop words in the document based on the custom stop word list.
[0090] Step 1.5: For proper nouns in Chinese and English in document A, a dictionary is created for English proper nouns, and the segmentation results are stored in document A' using the CSW Chinese professional word segmentation tool. The data in document A' is used as a dataset D for a specific field (for example, the film field). s , the data in the text document B is used as the non-specific domain dataset D n .
[0091] Step 2: Based on prior knowledge and question templates, a machine learning model is used to automatically extract entities from the preprocessed dataset text. The process is as follows: Figure 2 As shown, the specific steps include:
[0092] Step 2.1: The question template used in this method is manually defined in advance as follows:
[0093] Template 1 Can x be used as an entity category in the movie domain? Template 2 <![CDATA[What possible entity relationships exist between x1 and x2]]>
[0094] Among them, x, x1 and x2 represent a certain entity category.
[0095] Step 2.2, calculate D s The word frequency TF of each word in the word list is filtered, and the words with TF values greater than 0.005 are formed into a high-frequency word set W. o ;
[0096]
[0097] Among them, count(t,D s ) is represented as vocabulary t in the dataset D s The number of times it appears in total(D s ) represents the dataset D s The total number of all words in TF(t,D s ) represents the word frequency of vocabulary t.
[0098] Step 2.3: Use a search engine (e.g., chatGPT) to obtain entity category words (director, editor, movie title, award) in a specific field (taking the film field as an example), and put these entity category words into a set to form the initial entity category candidate set W. p ;
[0099] Step 2.4, calculate W o With W p The intersection of is used as the entity category dataset E1 in a specific field (taking the film field as an example);
[0100] E1=W o ∩W p (2)
[0101] Step 2.5, calculate W o The TF-IDF (term frequency - inverse document frequency) value of all words in is calculated as follows:
[0102]
[0103] Among them, tf ij is the frequency of word i appearing in document j, and sa is the dataset D in a specific field (taking the film field as an example). s The total frequency of all words in the dataset D s With the non-specific dataset D n The total number of documents in df i is the number of documents in which word i appears, T i is the TF-IDF value of the vocabulary.
[0104] Step 2.6, the dataset D sInput the LDA (Latent Dirichlet Allocation) topic model to obtain a specific domain dataset D s The subject word set WI and the probability P(w h |D m ), the calculation formula is as follows:
[0105]
[0106] Among them, w h Represents any word in the subject word set WI; T k represents any topic in the topic set; P(w h |T k ) means that when the topic is k, the word w h Probability of occurrence; C hk Represents word w h The number of times it is assigned to topic k; N is the size of the vocabulary; β is a hyperparameter, set to 10; D m Represents a domain-specific dataset D s Any document in the document collection; T k represents any topic in the topic set; P(T k |D m ) means that when the document is m, the topic T k Probability of occurrence; C km Represents a domain-specific dataset D s The words in document m in the document collection are assigned to topic T k The number of times; P(w h |D m ) represents the probability of the topic word; K represents the number of topics; α represents the hyperparameter, which is set to 10;
[0107] Step 2.7, W o All the words in WI are matched to the words in WI. If they exist, the P(w h |D m ) as W o The probability P of the word in s If no match is found, it is set to 0. For example, W o The vocabulary in includes: director, lighting, photography, while the vocabulary in WI includes: director, Xi'an, editing and the corresponding probability P(w h |D m ) are: 0.075, 0.055, 0.072, then W o The probability P of the director in s The probability is 0.075, while if “lighting” and “photography” are not matched, the probability is 0.
[0108] Step 2.8, domain-specific (taking the movie domain as an example) dataset D s With the non-specific domain dataset D n Merge into background corpus, divide the documents in background corpus into independent classes (C1, C2..., C n ), the total number of categories is n, W o The information entropy calculation formula for each word i in is as follows:
[0109]
[0110] H(i)=-P(i)logP(i) (8)
[0111] in, is the total number of documents in the background document set where word i appears, d n Category C n The number of documents in which word i appears in , H(i) is the information entropy of word i.
[0112] Step 2.9, calculate W o The OCD (OCD is the ontology relevance) of each word i in i , the concept is: the mean square error of the frequency of the candidate entity category and the entity category in a specific field (taking the film field as an example) appearing together multiplied by the frequency, O i The calculation formula is as follows:
[0113]
[0114] Among them, otn is the total number of domain ontology categories that already exist in E1, totn j W o The number of times each word i appears with the j-th domain ontology category, W o The average number of words that appear together with each word i and the domain ontology category in totn is the number of domain ontology categories that appear together with each word i.
[0115] In step 2.10, the random forest model is used as the entity classification model to train the entity classification model.
[0116] Step 2.10.1, the entity category in E1 obtained in step 2.4 is used as a positive example; then manually select W o Words that cannot be used as entity categories are used as counterexamples (counterexamples include Xi'an Film Studio and nomination, which are instances but not entity categories);
[0117] Step 2.10.2: All the words obtained in step 2.10.1 as positive examples and negative examples are combined into a vocabulary list W e, calculated according to the definition in steps 2.5-2.9 to obtain W e T(i), P for all words in s , H(i) and O i and labels constitute the training set T r , the label column is manually annotated, if it is a positive example, the label is 1, if it is a negative example, the label is 0;
[0118] Step 2.10.3, the training set T r The data is input into the random forest model for training. When the four indicators of F1-score, recall rate, precision rate, and area under the ROC curve reach the highest value, the trained model TL-FR is obtained.
[0119] In step 2.10.4, all W obtained in steps 2.5-2.9 are converted to o T(i), P for all words in s , H(w) and O i Input into the model TL-FR to get the output prediction value 0 or 1, and select all words with output value 1 to form the entity category set E2;
[0120] Step 2.11, traverse all entity categories in the entity category set E2, embed the question template 1 into the search engine (ChatGPT) to get "yes" or "no", and delete all entity categories corresponding to the answer "no". For example, embed the word "director" into the question template to get: Can director be used as an entity category in the film field? The answer is: yes, then keep it, and embed the word "Xi'an" into the question template to get: Can Xi'an be used as an entity category in the film field? The answer is: no, then delete the word "Xi'an" from E2. Finally, the entity category set E required to construct the ontology is obtained. f .
[0121] Step 3: Obtain association rules based on the frequency mining algorithm, fine-tune the BERT model with the help of the P-tuningv2 fine-tuning method, and use the trained model to extract the relationship between entity pairs.
[0122] Step 3.1, taking a movie as a transaction, based on the obtained entity category set E f , use the apriori algorithm to get the association rule set R f (R f is a set of entity pairs), weights are introduced when calculating support; finally, interest-based association rules are introduced, and the calculation formula is as follows:
[0123]
[0124] Where Transactions containing A represents the number of transactions containing item set A, and Total transactions represents the total number of transactions. Support(A) represents the minimum support of item set A, and γ is defined as: if item set A∈E f , then γ=0; if the item set Then γ=1; Support(A∪B) contains the number of transactions of item sets A and B (the probability of two item sets appearing at the same time). Support(B) represents the minimum support of item set B. Confidence(A→B) refers to the probability that a transaction set also contains item set B under the premise of containing item set A, also known as confidence. Max{} is the maximum value. Intrerest(A→B) means that the interest is greater than 0, and the greater the actual utilization value. Then the present invention selects association rules with interest greater than 0 to form a set R f .
[0125] In step 3.2, based on association rules, a search engine (e.g., ChatGPT) is used to obtain a set of sentences SEN representing entities and relationships.
[0126] Step 3.2.1, extract the set R obtained in step 3.1 f The entity pairs in , such as (movie, director), are embedded in question template 2 to obtain the complete question. For example, if the entity pair is {movie, director}, then after embedding question template 2, the question is "What is the possible entity relationship between movie and director?"
[0127] In step 3.2.2, the complete question is input into a search engine (e.g., Baidu) to obtain multiple sentences containing corresponding entity pairs, and the sentences with the longest character strings are captured to form a set SEN.
[0128] Step 3.3, divide SEN into training set T s and test set C s ;
[0129] Step 3.4, extract T s The relationship between all sentences in is converted into vectors to obtain the training set T of the BERT model b .
[0130] Step 3.4.1, T s The sentence SE1 obtained in the above example matches the regular expression (this expression is customized and depends on the actual situation) and obtains the relationship S between the entity pairs in the sentence. r(For example, the regular expression is: the relationship between (.+?) and (.+?) is (.+?), which matches the sentence "the relationship between director and movie is guidance", and the relationship between the entity pairs "director" and "movie" is "guidance");
[0131] Step 3.4.2, use the Doc2vec model to convert SE1 into vector S v , S v With S r Stored together in the MySQL database;
[0132] Step 3.4.3, loop steps 3.4.1-3.4.2 until all sentences in SEN are processed to obtain the training set T b .
[0133] Step 3.5, the training set T b The data is input into the BERT model for training, and the model is fine-tuned through P-tuningv2 to maximize the F1-score, resulting in the trained model PTBERT.
[0134] Step 3.6, use the test set C s Test the performance of the PTBERT model;
[0135] Step 3.7: Input all the data in SEN into PTBERT, and get all the relation sets and compare them with the set R. f In the form of entity relationship triples, such as "(director, guidance, movie name)", the entity relationship triples dataset E required to build the ontology library is stored. R .
[0136] Step 3.8, E R The triples in E f The entity categories in the dataset are imported into the Neo4j graph database to build the ontology library of the knowledge graph.
[0137] In step 4, based on the constructed ontology library, a pipeline approach is used to perform entity relationship extraction tasks, BERT-BILSTM-CRF is used for named entity recognition tasks, and then the RoBERTa model is used to extract relationships, and finally the data layer of the knowledge graph is constructed.
[0138] Step 4.1: Divide the dataset D into a specific field (taking the film field as an example) s The training set D T , test set D C ;
[0139] Step 4.2, use the training set D TThe BiLSTM-CRF model is trained for named entity recognition tasks. Taking a sentence as an example, the model processing flow is as follows:
[0140] Step 4.2.1, use BERT as the embedding layer model of the BiLSTM-CRF model and input the training set D T The sentences in are converted into word vectors;
[0141] In step 4.2.2, the converted word vectors are input into the BILSTM model, which outputs a bidirectional context representation sequence for each word.
[0142] In step 4.2.3, after the CRF (conditional random field) model receives the output of the BILSTM model (the bidirectional context representation sequence of each word), it outputs the final label sequence, which represents the entity category of each word.
[0143] Step 4.3, use the test set D C Verify the performance of the BERT-BILSTM-CRF model and use the trained BERT-BILSTM-CRF model to perform named entity recognition tasks. The extracted entity set is E S .
[0144] Step 4.4: Based on the manually defined template and cosine similarity, link the entities extracted in step 4.3 to the existing entity categories in the ontology library, and match the entity and entity category embedding template in the ontology library with the full text of document A to obtain the matching score t m For example, the manually defined template is: {entity 1}: {entity 2}, the entity is "Zhang Yimou", and the entity category is "Director". If the sentence "Director: Zhang Yimou" exists, the match is successful; if the full text is matched and the sentence "Director: Zhang Yimou" does not exist, the match fails; then use the Doc2vec model to convert the entities extracted in step 4.3 into word vectors, use the word vectors to calculate the residual similarity, and define the weight combined with the residual similarity. The calculation formula is as follows:
[0145]
[0146] Among them, A and B are the word vectors of two entity categories, ||A|| and ||B|| are the modulo lengths of the word vectors of entity categories A and B, and t m Represents the template matching score, which is defined as 1 if the match is successful and 0 if the match fails. δ is the weight, which ranges from [0, 0.5].
[0147] Step 4.5: For entity category pairs that have existing relationships in the ontology library, map them to E by using the method of step 4.4. s In this way, the entity pairs and their relationships are obtained as the training set Tr For example, if the relationship between "director" and "movie" in the ontology library is "direction", then "Zhang Yimou" is linked to "director" and "Red Sorghum" is linked to "movie", then the relationship between "Zhang Yimou" and "Red Sorghum" can be obtained as "direction". s The remaining entities in are used as the test set T e .
[0148] Step 4.6, use the training set T r Train the relation extraction model RoBERTa and maximize the F1-score by increasing or decreasing the hyperparameters: learning rate, number of iterations, and batch size.
[0149] Step 4.7, use the test set T e Test the trained relation extraction model RoBERTa to obtain the relations of the remaining entities.
[0150] In step 4.8, the entities extracted in steps 4.2-4.3 and the relationships extracted in steps 4.4-4.7 are manually converted into entity-relationship triples, such as "(Zhang Yimou, guidance, Red Sorghum)", and stored in the graph database Neo4j to obtain the final knowledge graph.
[0151] Example 2
[0152] Experimental Configuration
[0153] 1. Python 3.8.
[0154] 2.Sklearn1.3.2: Load random forest models and other machine learning models.
[0155] 3. Dataset path: the directory containing the source documents, training set, and test set.
[0156] Entity extraction experiment part:
[0157] 1) The source document is segmented and stop words are removed. The results of some data after processing are shown in Table 1 below:
[0158] Table 1
[0159] Snow Sea and Silver Mountain Film title: Snow Sea and Silver Mountain, produced by Xi'an Film Studio, released in November 1959 Song of Tianshan Film title: Song of Tianshan, produced by Xi'an Film Studio, released in July 1959 Flowers are blooming Movie title: Flowers in Bloom, filmed at Xi'an Film Studio, released in 1959
[0160] 2) After filtering high-frequency words, we get a high-frequency vocabulary set, and some high-frequency vocabulary sets W o : {Movie name, production, Xi'an Film Studio, release year, film type, film reel number, film length, screenwriter}
[0161] 3) TF-IDF, LDA, OCD, and information entropy were used to calculate the feature value of each word and divide it into training and test sets. Some of the results are shown in Table 2 below:
[0162] Table 2
[0163] Word TF-IDF Freq importance Ocd y Movie Title 1.066839154 0.005829 0.52366672 0.967858091 1 Produced 0.81856694 0.004233067 0.518272444 0.676894552 1 Year of release 1.066442334 0.005806811 0.523593463 0.923669575 1 Movie Type 1.064455762 0.005694392 0.523226116 0.888228316 1 Film roll number 1.052046225 0.00499731 0.520907032 0.763713721 1
[0164] 4) Use the training set to train the random forest model. The optimal model is obtained when the F1-score, recall rate, accuracy rate, and area under the ROC curve reach the highest. Finally, use the test set for testing.
[0165] Example 3
[0166] The TL-FR model of the present invention is compared with the traditional method. The F1-score, recall rate, accuracy and ROC curve are used to evaluate the performance of the TL-FR model. It is proved that the model proposed in the present invention achieves better performance in entity extraction. The ROC curve comparison is shown in the figure below. Figure 3(a) to Figure 3(d) As shown in Figure 3(a), the ROC curve of the BP neural network model; Figure 3(b) is the ROC curve of the decision tree model; Figure 3(c) is the ROC curve of the KNN model; and Figure 3(d) is the ROC curve of the TL-FR model.
[0167] The model performance comparison results are shown in Table 3 below:
[0168] Table 3
[0169] Model F1-score Recall Accuracy Area under the ROC curve BP 0.73 0.75 0.72 0.78 Decision Tree 0.79 0.75 0.79 0.78 KNN 0.71 0.75 0.68 0.72 TL-FR 0.79 0.75 0.83 0.81
Claims
1. The automatic construction method of ontology library based on prior knowledge and data-driven is characterized by: First, the data is preprocessed, and then based on prior knowledge, entities and association rules are extracted with the help of machine learning models. Based on the extracted association rules, the BERT model is fine-tuned with the help of P-tuningv2 to obtain the relationship extraction results. Finally, the extracted relationships and entities are merged to build an ontology library, and a knowledge graph is built based on the ontology library.
2. The method for automatically constructing an ontology library based on prior knowledge and data-driven according to claim 1, characterized in that: The specific steps include: Step 1: Collect encyclopedia data and combine them with knowledge documents in specific fields as specific field datasets, use open source Chinese open domain datasets as non-specific field datasets, and pre-process these two datasets respectively; Step 2: Based on prior knowledge and question templates, a machine learning model is used to automatically extract entities from the preprocessed dataset text; Step 3: Obtain association rules based on the frequency mining algorithm, fine-tune the BERT model with the help of the P-tuningv2 fine-tuning method, and use the trained model to extract the relationship between entity pairs; Step 4: Based on the constructed ontology library, a pipeline approach is used to perform entity relationship extraction tasks, BERT-BILSTM-CRF is used for named entity recognition tasks, and then the RoBERTa model is used to extract relationships, and finally the data layer of the knowledge graph is constructed.
3. The method for automatically constructing an ontology library based on prior knowledge and data-driven according to claim 2, characterized in that: The specific process of step 1 is as follows: Step 1.1: For professional knowledge documents in a specific field, use crawler technology to crawl movie information from Baidu Encyclopedia and add it to the specific field document A; for document B in a non-specific field, put the open source dataset MSRA-NER entity dataset into document B; Step 1.2: For the document type data and image type data in the specific domain data set, write Python code to extract the file name of the image type file and the content of the document type file, and store them in the specific domain text document A; Step 1.3: For document B of the non-domain-specific dataset and the domain-specific dataset processed in step 1.2, use Python code to remove interference items such as special characters, punctuation marks, and HTML tags in the document, and convert the English letters in the domain-specific text document processed in step 1.2 to lowercase; Step 1.4, build a custom stop word list based on the stop word list of Harbin Institute of Technology and Baidu, and use the NTLK library to delete stop words in the document based on the custom stop word list; Step 1.5: For the specific domain text document A obtained in step 1.3, which contains proper nouns in Chinese and English, a dictionary is established for the English proper nouns, and the segmentation results are stored in the document A' using the CSW Chinese professional word segmentation tool. The data in the document A' is used as the specific domain dataset D. s , the data in the non-specific domain document B is used as the non-specific domain dataset D n .
4. The method for automatically constructing an ontology library based on prior knowledge and data-driven according to claim 3, characterized in that: The specific process of step 2 is: Step 2.1, manually define question template 1 and question template 2; Step 2.2: Calculate the domain-specific dataset D using the following formula (1): s The frequency of each word in TF(t,D s ), filter the words with TF value greater than 0.005 to form a high-frequency word set W o : Among them, count(t,D s ) represents the vocabulary t in the dataset D s The number of occurrences in total(D s ) represents the data set D s The total number of all words in TF(t,D s ) represents the word frequency of vocabulary t; Step 2.3: Use the search engine to obtain the initial entity category candidate set W in a specific field p ; Step 2.4, calculate W by the following formula (2): o With W p The intersection of is used as the domain-specific partial entity category dataset E1; E1=W o ∩In p (2) Step 2.5, calculate W o The TF-IDF value of all words in the vocabulary T i , the calculation formula is as follows: Among them, tf ij is the frequency of word i appearing in document j, and sa is a domain-specific dataset D s The total frequency of all words in the dataset D s With the non-specific dataset D n The total number of documents in df i is the number of documents in which word i appears; Step 2.6: Dataset D s Input into the LDA topic model to obtain a domain-specific dataset D s The subject word set WI and the probability P(w h |D m ), the calculation formula is as follows: Among them, w h represents any word in the subject word set WI; T k represents any topic in the topic set; P(w h |T k ) means that when the topic is k, the word w h Probability of occurrence; C hk Represents word w h The number of times topic k is assigned; N is the size of the vocabulary; β is a hyperparameter; D m Denotes a domain-specific dataset D s Any document in the document collection; T k represents any topic in the topic set; P(T k |D m ) means that when the document is m, the topic T k Probability of occurrence; C km Denotes a domain-specific dataset D s The words in document m in the document collection are assigned to topic T k The number of times; P(w h |D m ) represents the probability of the topic word; K represents the number of topics; α represents the hyperparameter; Step 2.7, use W o All the words in WI are matched to the words in WI. If they exist, P(w h |D m ) as W o The probability P of the word s If no match is found, it is set to 0; Step 2.8: The domain-specific dataset D s With the non-domain-specific dataset D n Merge into the background corpus, and divide the documents in the background corpus into independent classes {C1, C2..., C n }, the total number of categories is n, W o The information entropy calculation formula for each word i in is as follows: in, is the total number of documents in the background document set where word i appears, d n Category C n The number of documents in which word i appears, H(i) is the information entropy of word i; Step 2.9, calculate W o The ontology relevance O of each word i in i : Among them, otn is the total number of domain ontology categories that already exist in E1, totn j W o The number of times each word i appears with the jth domain ontology category in , W o The average number of words that appear together with each word i and the domain ontology category in , totn is the number of domain ontology categories that appear together with each word i; Step 2.10, using the random forest model as an entity classification model, and training the entity classification model; Step 2.11, traverse all entity categories in the entity category set E2, embed question template 1 into the search engine to get "yes" or "no", delete all entity categories corresponding to the answer "no", and finally obtain the entity category set E2 required to construct the ontology f .
5. The method for automatically constructing an ontology library based on prior knowledge and data-driven according to claim 4, characterized in that: The specific process of step 2.10 is as follows: Step 2.10.1, the entity category in E1 obtained in step 2.4 is taken as a positive example; then manually select W o Words that cannot be used as entity categories are used as counterexamples; Step 2.10.2: All the words obtained in step 2.10.1 as positive examples and negative examples are combined into a word list W e , calculated according to the definition in steps 2.5-2.9 e T(i), P of all words in s , H(i) and O i and labels form the training set T r , the label column is manually annotated, if it is a positive example, the label is 1, if it is a negative example, the label is 0; Step 2.10.3, the training set T r Input into the random forest model for training. When the four indicators of F1-score, recall rate, accuracy, and area under the ROC curve reach the highest value, the trained model TL-FR is obtained. Step 2.10.4: Substitute all W obtained in steps 2.5-2.9 into o T(i), P of all words in s , H(w) and O i The input is sent to the model TL-FR to obtain the output prediction value 0 or 1, and all words with output value 1 are selected to form the entity category set E2.
6. The method for automatically constructing an ontology library based on prior knowledge and data-driven according to claim 5, characterized in that: The specific process of step 3 is as follows: Step 3.1: Take a movie as a transaction and based on the entity category set E f , using the apriori algorithm to obtain the association rule set R f , when calculating the support, weights are introduced; Finally, the interest degree filtering association rule is introduced, and the calculation formula is as follows: Where Transactions containing A represents the number of transactions containing item set A, Total transactions represents the total number of transactions; Support(A) represents the minimum support of item set A, and γ is defined as: if item set A∈E f , then γ=0; if the item set Then γ=1; Support(A∪B) is the number of transactions that contain item sets A and B; Support(B) indicates the minimum support of item set B; Confidence(A→B) refers to the probability that a transaction set also contains item set B under the premise of containing item set A, also known as confidence; max{} is the maximum value; Intrerest(A→B) indicates interest; Step 3.2, based on association rules, using a search engine to obtain a set of sentences SEN representing entities and relationships; Step 3.3, divide SEN into training set T s and test set C s ; Step 3.4, extract T s The relationship between all the sentences in is converted into vectors to obtain the training set T of the BERT model. b ; Step 3.5: Set the training set T b The data is input into the BERT model for training, and the model is fine-tuned through P-tuningv2 to achieve the highest F1-score, thus obtaining the trained model PTBERT. Step 3.6, use the test set C s Test the performance of the PTBERT model; Step 3.7: Input all the data in SEN into PTBERT, and obtain all the relation sets and then compare them with the set R. f The entity pairs in the table correspond to each other, and the entity relationship triples required to build the ontology library are stored in the form of entity relationship triples. R ; Step 3.8, E R The triples in E f The entity categories in the data are imported into the Neo4j graph database to build the ontology library of the knowledge graph.
7. The method for automatically constructing an ontology library based on prior knowledge and data-driven according to claim 6, characterized in that: The specific process of step 3.4 is as follows: Step 3.4.1, T s The sentence SE1 obtained in the above example matches the regular expression and obtains the relationship S between the entity pairs in the sentence. r ; Step 3.4.2, use the Doc2vec model to convert SE1 into vector S v , S v With S r Stored together in the MySQL database; Step 3.4.3, loop through steps 3.4.1-3.4.2 until all sentences in SEN are processed, and the training set T is obtained. b .
8. The method for automatically constructing an ontology library based on prior knowledge and data-driven according to claim 7, characterized in that: The specific process of step 4 is as follows: Step 4.1: Divide the domain-specific dataset D s The training set D T , test set D C ; Step 4.2, use the training set D T Train the BiLSTM-CRF model on named entity recognition tasks; Step 4.3, use the test set D C Verify the performance of the BERT-BILSTM-CRF model and use the trained BERT-BILSTM-CRF model to perform named entity recognition tasks. The extracted entity set is E S ; Step 4.4: Based on the manually defined template and cosine similarity, link the entities extracted in step 4.3 to the existing entity categories in the ontology library, and match the entity and the entity category embedding template in the ontology library with the full text of document A to obtain the matching score t m ; Then use the Doc2vec model to convert the entities extracted in step 4.3 into word vectors, use the word vectors to calculate the residual similarity, define the weight combined with the residual similarity, and the calculation formula is as follows: Among them, A and B are word vectors of two entity categories, ||A|| and ||B|| are the modulus lengths of word vectors of entity categories A and B, and t m represents the template matching score, which is defined as 1 if the match is successful and 0 if the match fails, and δ is the weight; Step 4.5: For the entity category pairs that have existing relationships in the ontology library, map the entity category pairs to E by using the method in step 4.
4. s The entities in the dataset are obtained by taking the entity pairs and their relationships as the training set T r , for E s The remaining entities in are used as the test set T e ; Step 4.6, use the training set T r Train the relation extraction model RoBERTa to achieve the highest F1-score; Step 4.7, use the test set T e Test the trained relation extraction model RoBERTa to obtain the relations of the remaining entities; In step 4.8, the entities extracted in steps 4.2-4.3 and the relationships extracted in steps 4.4-4.7 are manually converted into entity-relationship triples, stored in the graph database Neo4j, and the final knowledge graph is obtained.
9. The method for automatically constructing an ontology library based on prior knowledge and data-driven according to claim 8, characterized in that: The specific process of step 4.2 is as follows: Step 4.2.1, use BERT as the embedding layer model of the BiLSTM-CRF model and input the training set D T The sentences in are converted into word vectors; Step 4.2.2: The converted word vector is input into the BILSTM model, and the BILSTM model outputs a bidirectional context representation sequence for each word. In step 4.2.3, after receiving the output of the BILSTM model, the CRF model outputs the final label sequence, indicating the entity category of each word.
Citation Information
Patent Citations
Bert-based entity relationship pipeline extraction method and system
CN112199519A
Character representation-oriented news text occurrence place extraction method
CN112307364A
Legal knowledge graph construction system
CN112559766A
Method and system for constructing service knowledge graph based on LDA cross-domain to realize service combination optimization
CN113342988A
Short text classification and intelligent analysis system for multi-granularity demand
CN114840677A
