+

CN115563297A - A food safety knowledge map construction and completion method based on graph neural network - Google Patents

A food safety knowledge map construction and completion method based on graph neural network Download PDF

Info

Publication number
CN115563297A
CN115563297A CN202211134812.6A CN202211134812A CN115563297A CN 115563297 A CN115563297 A CN 115563297A CN 202211134812 A CN202211134812 A CN 202211134812A CN 115563297 A CN115563297 A CN 115563297A
Authority
CN
China
Prior art keywords
graph
entity
food safety
representation
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211134812.6A
Other languages
Chinese (zh)
Inventor
向金海
翁永琳
倪福川
李国亮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huazhong Agricultural University
Original Assignee
Huazhong Agricultural University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huazhong Agricultural University filed Critical Huazhong Agricultural University
Priority to CN202211134812.6A priority Critical patent/CN115563297A/en
Publication of CN115563297A publication Critical patent/CN115563297A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/36Creation of semantic tools, e.g. ontology or thesauri
    • G06F16/367Ontology
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00Computing arrangements using knowledge-based models
    • G06N5/02Knowledge representation; Symbolic representation
    • G06N5/022Knowledge engineering; Knowledge acquisition

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • General Physics & Mathematics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Artificial Intelligence (AREA)
  • Evolutionary Computation (AREA)
  • Computing Systems (AREA)
  • Databases & Information Systems (AREA)
  • Animal Behavior & Ethology (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • General Health & Medical Sciences (AREA)
  • Molecular Biology (AREA)
  • Machine Translation (AREA)

Abstract

The invention provides a food safety knowledge graph building and complementing method based on a graph neural network, which comprises the steps of acquiring national food safety standard files related to food types, food additives and pesticide residues in food, processing the national food safety standard files into triples capable of being applied to the knowledge graph through operations such as data cleaning, formatting and the like, and building a body layer mode framework of the food safety knowledge graph; designing a food safety knowledge map query system capable of realizing entity query and visual display; generating a word vector of an entity name in the food safety knowledge graph according to a pre-training language model BERT; and performing feature fusion on text information and graph structure information in the food safety knowledge graph by using a graph neural network architecture, and respectively applying the feature fusion to two downstream tasks of entity classification and link prediction so as to fulfill the aim of knowledge graph completion. The invention improves the integrity and the practicability of the food safety knowledge map and realizes the intelligent application of food safety standard information.

Description

一种基于图神经网络的食品安全知识图谱构建与补全方法A food safety knowledge map construction and completion method based on graph neural network

技术领域technical field

本发明属于知识图谱和图神经网络技术领域,具体涉及一种基于图神经网络的食品安全知识图谱构建与补全方法。The invention belongs to the technical field of knowledge graph and graph neural network, and in particular relates to a method for constructing and completing a food safety knowledge graph based on graph neural network.

背景技术Background technique

随着人们生活水平的不断提高,人们对食品安全的重视程度也越来越高。无论是监管部门还是普通民众,都需要一套切实有效的标准指导。但是目前来说,食品安全国家标准仍然是以文件的形式存储,并且文件的种类和数目繁多,格式不够统一,彼此间还有引用关系。虽然我国对食品质量规范化和信息化管理的工作一直在推进,但是在结构化整合这些标准、系统化分析关联上仍有欠缺。With the continuous improvement of people's living standards, people pay more and more attention to food safety. Both regulators and ordinary people need a set of practical and effective standard guidance. But at present, the national food safety standards are still stored in the form of documents, and there are many types and numbers of documents, the format is not uniform enough, and there are references to each other. Although my country has been promoting the standardization and information management of food quality, there are still deficiencies in the structural integration of these standards and systematic analysis of the relationship.

伴随着科学技术的发展,知识图谱这一形式可以把客观世界的概念和关系以图结构的形式描述为节点和边,更有利于查询食品标准的内容和它们之间的关系。目前国内外大部分食品安全知识图谱都集中于子领域的构建,没有一个权威的食品安全标准的知识库作为指导。With the development of science and technology, the form of knowledge graph can describe the concepts and relationships of the objective world as nodes and edges in the form of a graph structure, which is more conducive to querying the content of food standards and the relationship between them. At present, most of the food safety knowledge maps at home and abroad are focused on the construction of sub-fields, and there is no authoritative food safety standard knowledge base as a guide.

如果仅仅依靠人工抽取标准内容作为数据来构建知识图谱,对于食品这么庞大的领域来说无疑是低效的,且信息往往会不够完整。而图神经网络在处理图结构数据上具有优势性,可以尝试应用于知识图谱补全的实体分类和链接预测任务中。但由于图神经网络自身结构的原因,当获取深层图信息时会出现过平滑的现象,影响模型的效果,并且如果仅仅考虑图结构信息的话,知识图谱自身的信息并没有得到充分的利用,这也是如今需要考虑的问题之一。If only relying on manual extraction of standard content as data to construct a knowledge map, it is undoubtedly inefficient for such a huge field of food, and the information is often incomplete. The graph neural network has advantages in processing graph-structured data, and can try to be applied to entity classification and link prediction tasks of knowledge graph completion. However, due to the structure of the graph neural network itself, when the deep graph information is obtained, there will be over-smoothing, which will affect the effect of the model, and if only the graph structure information is considered, the information of the knowledge graph itself has not been fully utilized. It is also one of the issues that need to be considered now.

发明内容Contents of the invention

本发明要解决的技术问题是:提供一种基于图神经网络的食品安全知识图谱构建与补全方法,用于提高食品安全知识图谱的完整性。The technical problem to be solved by the present invention is to provide a method for constructing and completing a food safety knowledge map based on a graph neural network, which is used to improve the integrity of the food safety knowledge map.

本发明为解决上述技术问题所采取的技术方案为:一种基于图神经网络的食品安全知识图谱构建与补全方法,包括以下步骤:The technical solution adopted by the present invention to solve the above technical problems is: a method for constructing and completing a food safety knowledge map based on a graph neural network, including the following steps:

(此处与权利要求一致,待权利要求确认后填充)(Here is consistent with the claim, to be filled after the claim is confirmed)

本发明的有益效果为:The beneficial effects of the present invention are:

1.本发明的一种基于图神经网络的食品安全知识图谱构建与补全方法,通过提取食品安全标准信息构建知识图谱,根据预训练语言模型BERT生成食品安全知识图谱中实体名称的词向量;利用图神经网络架构将食品安全知识图谱中的文本信息和图结构信息进行特征融合,并分别应用到实体分类和链接预测两项下游任务中对食品安全知识图谱进行补全,实现了提高食品安全知识图谱的完整性的功能;本发明通过在图神经网络中引入文本表示,丰富了节点信息的同时,缓解了多层数图神经网络本身结构导致的过平滑现象,有利于模型学习到更多的知识图谱信息;本发明通过改进R-GCN链接预测模型中的打分函数,引入分段式分块点积的思想构建的打分函数,以图结构特征向量和文本特征向量分别各自计算的形式提高了链接预测的效果。1. A method for constructing and completing a food safety knowledge map based on a graph neural network of the present invention, constructing a knowledge map by extracting food safety standard information, and generating word vectors of entity names in the food safety knowledge map according to the pre-trained language model BERT; Using the graph neural network architecture to fuse the text information and graph structure information in the food safety knowledge map, and apply them to the two downstream tasks of entity classification and link prediction to complete the food safety knowledge map, and realize the improvement of food safety. The function of the integrity of the knowledge map; the invention introduces text representations into the graph neural network, enriches the node information, and alleviates the over-smoothing phenomenon caused by the structure of the multi-layer digital graph neural network itself, which is conducive to the model to learn more knowledge map information; the present invention improves the scoring function in the R-GCN link prediction model, and introduces the scoring function constructed by the idea of segmented block dot product, which is improved in the form of calculating the graph structure feature vector and the text feature vector respectively. effect on link prediction.

2.本发明获取与食品品类、食品添加剂、食品中农药残留相关的国家食品安全标准文件,通过数据清洗和格式化等操作将不同食品类别、食品添加剂、食品中农药残留的最大限量等食品安全国家标准信息处理为可以应用到知识图谱中的三元组形式,并构建食品安全知识图谱的本体层模式架构,弥补了食品安全领域知识图谱数据的空缺。2. The present invention obtains national food safety standard documents related to food categories, food additives, and pesticide residues in food, and through operations such as data cleaning and formatting, the food safety standards for different food categories, food additives, and maximum limits of pesticide residues in food, etc. The national standard information is processed into a triplet form that can be applied to the knowledge map, and the ontology layer model structure of the food safety knowledge map is constructed, which makes up for the vacancy of the knowledge map data in the field of food safety.

3.本发明搭建了一个基于Python的Flask框架和Echarts.js的网页端可视化系统,以图的形式存储食品安全国家标准内容的数据并应用到下游任务中,实现了实体查询和可视化展示的食品安全知识图谱查询系统。3. The present invention builds a Python-based Flask framework and a web-side visualization system of Echarts.js, stores the data of the national food safety standard content in the form of a graph and applies it to downstream tasks, and realizes entity query and visual display of food Security knowledge graph query system.

4.本发明弥补了当前技术的不足,提高了食品安全知识图谱的完整性和实用性,实现了食品安全标准信息的智能化应用。4. The invention makes up for the shortcomings of the current technology, improves the integrity and practicability of the food safety knowledge map, and realizes the intelligent application of food safety standard information.

附图说明Description of drawings

图1是本发明实施例的初步构建食品安全知识图谱的流程图。Fig. 1 is a flowchart of the preliminary construction of a food safety knowledge map according to an embodiment of the present invention.

图2是本发明实施例的食品安全知识图谱的本体结构图。Fig. 2 is an ontology structure diagram of the food safety knowledge map of the embodiment of the present invention.

图3是本发明实施例的数据抽取和处理的流程图。Fig. 3 is a flowchart of data extraction and processing in an embodiment of the present invention.

图4是本发明实施例的实体分类模型的结构示意图。Fig. 4 is a schematic structural diagram of an entity classification model according to an embodiment of the present invention.

图5是本发明实施例的链接预测模型的结构示意图。Fig. 5 is a schematic structural diagram of a link prediction model according to an embodiment of the present invention.

具体实施方式detailed description

下面结合附图和具体实施方式对本发明作进一步详细的说明。The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.

参见图1,本发明的实施例包括食品安全知识图谱的初步构建模块、基于图神经网络和文本预训练模型的知识图谱实体分类模型、基于编码器-解码器的知识图谱链接预测模型。Referring to Fig. 1, the embodiment of the present invention includes a preliminary building block of a food safety knowledge graph, a knowledge graph entity classification model based on a graph neural network and a text pre-training model, and an encoder-decoder-based knowledge graph link prediction model.

本发明的一种基于图神经网络的食品安全知识图谱构建与补全方法,包括以下步骤:A method for constructing and completing a food safety knowledge map based on a graph neural network of the present invention comprises the following steps:

S1:收集数据;采用包括网络爬虫和表格解析的手段提取食品安全国家标准信息,包括标准文件中的半结构化信息和非结构化信息;数据抽取的工作流程图如图3所示;S1: Collect data; extract national food safety standard information by means including web crawler and table analysis, including semi-structured information and unstructured information in standard documents; the work flow chart of data extraction is shown in Figure 3;

S11:通过网络爬虫方法从网站上获取食品安全国家标准的信息、下载食品安全国家标准文件;S11: Obtain information on national food safety standards from websites and download national food safety standard documents through web crawlers;

S12:OCR识别下载的食品安全国家标准文件,解析文件中的表格信息;S12: OCR identifies the downloaded national food safety standard file, and parses the table information in the file;

S13:基于规则匹配和网页、表格解析,得到半结构化数据和非结构化数据。S13: Obtain semi-structured data and unstructured data based on rule matching and web page and table analysis.

S2:构建本体;基于得到的半结构化信息和人工辅助标注,构建食品安全知识图谱的本体框架,并利用得到的本体框架进一步完善数据的提取方式,得到的本体框架图如图2所示,其中包括了与食品品类、食品标准、食品添加剂和农药残留相关的实体类型和关系类型;S2: Construct ontology; based on the obtained semi-structured information and manual assisted annotation, construct the ontology framework of the food safety knowledge map, and use the obtained ontology framework to further improve the data extraction method. The resulting ontology framework diagram is shown in Figure 2. These include entity types and relationship types related to food categories, food standards, food additives, and pesticide residues;

S3:处理数据;根据构建的本体框架和知识图谱的存储需要,对半结构化和非结构化数据进行格式化处理和数据清洗,得到csv格式的三元组形式数据;数据处理的工作流程图如图3所示;S3: Data processing; according to the storage requirements of the constructed ontology framework and knowledge graph, format and clean semi-structured and unstructured data to obtain triplet form data in csv format; work flow chart of data processing As shown in Figure 3;

S4:存储知识图谱,并构建可视化查询系统;S4: Store the knowledge map and build a visual query system;

S41:将csv格式的知识图谱三元组数据存储到Neo4J图数据库中;S41: storing the knowledge graph triplet data in csv format into the Neo4J graph database;

S42:基于Python的Flask框架,调用Neo4j图数据库,以Echarts.js的力导向图展示知识图谱;S42: Based on the Python Flask framework, call the Neo4j graph database, and display the knowledge graph with the force-directed graph of Echarts.js;

S43:通过Python调用Neo4J的cypher语句实现知识图谱实体的查询,并显示到网页端页面上。S43: Call the cypher statement of Neo4J through Python to realize the query of the knowledge map entity, and display it on the web page.

S5:利用图神经网络和文本预训练模型BERT完成知识图谱实体分类任务;图4展示了本发明中结合文本表示的关系图卷积网络示意图,包括BERT文本表示部分和R-GCN图结构信息部分;S5: Use the graph neural network and the text pre-training model BERT to complete the knowledge map entity classification task; Figure 4 shows a schematic diagram of the relational graph convolution network combined with text representation in the present invention, including the BERT text representation part and the R-GCN graph structure information part ;

S51:基于食品安全知识图谱的三元组构建数据集,划分训练集、验证集和测试集,将食品安全相关的实体类型为对应的类型编号,将实体本身抽象为实体编号,基于实体类型表和三元组表构建DGLDataset数据集;S51: Construct a data set based on the triplet of the food safety knowledge map, divide the training set, verification set and test set, assign the food safety-related entity type to the corresponding type number, and abstract the entity itself into the entity number, based on the entity type table Construct the DGLDataset dataset with the triple table;

S52:采用BERT预训练模型作为实体分类模型(参见图4),提取知识图谱实体名称的文本词向量表示,对预训练得到的词向量进行降维处理;S52: Use the BERT pre-training model as the entity classification model (see Figure 4), extract the text word vector representation of the entity name of the knowledge graph, and perform dimensionality reduction processing on the word vector obtained from the pre-training;

实体分类模型用于结合图的结构信息和实体的文本描述,将知识图谱表示从单一的网络结构表示拓展到结构和文本的共同表示,构建融合多源知识图谱信息的模型;通过文本预训练模型BERT得到实体描述的词向量表示,将词向量表示添加到实体表示中与原有的实体关系结构信息融合后,共同通过关系图卷积网络模型学习知识图谱表示;The entity classification model is used to combine the structural information of the graph and the textual description of the entity, expand the knowledge graph representation from a single network structure representation to the common representation of structure and text, and build a model that integrates multi-source knowledge graph information; through the text pre-training model BERT obtains the word vector representation of the entity description, adds the word vector representation to the entity representation and fuses the original entity relationship structure information, and jointly learns the knowledge graph representation through the relational graph convolutional network model;

采用BERT服务bert-as-service,基于C/S架构封装预训练的BERT模型,将其作为一种服务提供给客户端,更方便地为工程类项目提供支持。因为食品安全知识图谱中的实体名称大部分为中文词汇,所以选取中文BERT预训练模型chinese_L-12_H-768_A-12,得到所有实体名称的768维词向量。由于通过预训练模型得到的词向量维度较高,如果直接使用会大大增加模型的计算量,通过主成分分析(Principal Component Analysis,PCA)的方法对维数较高的768维词向量进行降维。后续实验证明,维数的降低对实验结果的影响不大,考虑到计算复杂度和文本信息表示的完整性,实体分类模型统一使用的文本表示维数为5维并将浮点数保留了4位小数,便于后续的使用。The BERT service bert-as-service is used to encapsulate the pre-trained BERT model based on the C/S architecture, and provide it to the client as a service, so as to provide support for engineering projects more conveniently. Because most of the entity names in the food safety knowledge map are Chinese words, the Chinese BERT pre-training model chinese_L-12_H-768_A-12 is selected to obtain the 768-dimensional word vectors of all entity names. Due to the high dimension of the word vector obtained through the pre-training model, if it is used directly, the calculation amount of the model will be greatly increased, and the dimensionality of the 768-dimensional word vector with a high dimension is reduced by the method of Principal Component Analysis (PCA). . Subsequent experiments proved that the reduction of dimensionality has little effect on the experimental results. Considering the computational complexity and the integrity of text information representation, the text representation dimension used uniformly by the entity classification model is 5-dimensional and the floating-point number is reserved for 4 bits. Decimals are convenient for subsequent use.

S53:利用R-GCN聚合信息,更新节点表示,获取图结构信息;S53: Use R-GCN to aggregate information, update node representation, and obtain graph structure information;

S54:将实体名称的文本词向量嵌入到R-GCN的输出层之前;S54: Embedding the text word vector of the entity name before the output layer of R-GCN;

S55:经过输出层学习后,使用softmax对实体进行分类,对样本中每个实体预测可能的类别,在所有有标签的节点上最小化交叉熵损失函数进行优化。S55: After learning the output layer, use softmax to classify entities, predict possible categories for each entity in the sample, and optimize by minimizing the cross-entropy loss function on all labeled nodes.

经过实验证实,本发明结合文本信息的R-GCN模型在对比是否使用文本表示时取得了更高的实体分类准确率。Experiments have proved that the R-GCN model combined with text information in the present invention achieves a higher entity classification accuracy rate when compared with whether text representation is used.

S6:基于编码器-解码器的图神经网络模型完成知识图谱链接预测任务;图5展示了基于编码器-解码器的链接预测模型的结构图,包括BERT文本表示部分和R-GCN图结构信息部分;将R-GCN模型作为编码器得到三元组的表示,将打分函数作为解码器;S6: The encoder-decoder-based graph neural network model completes the knowledge map link prediction task; Figure 5 shows the structure diagram of the encoder-decoder-based link prediction model, including the BERT text representation part and R-GCN graph structure information Part; the R-GCN model is used as the encoder to obtain the representation of the triplet, and the scoring function is used as the decoder;

通过三元组构建的知识图谱,以及基于图神经网络和文本表示实现实体分类,提高了食品安全知识图谱在实体类型上的完整性,但是食品安全知识图谱还存在部分关系缺失的问题。通过预测知识图谱中缺失的三元组,基于打分函数来判断三元组是否符合要求,从而实现链接预测。对于形如(头实体,关系,尾实体)类型的三元组,依据其中一个实体和对应关系预测另一个实体,从而解决头尾实体预测问题。The knowledge map constructed by triples and the entity classification based on graph neural network and text representation have improved the integrity of the food safety knowledge map in terms of entity types, but there are still some missing relationships in the food safety knowledge map. By predicting the missing triples in the knowledge graph and judging whether the triples meet the requirements based on the scoring function, link prediction is realized. For a triple of the type (head entity, relationship, tail entity), predict another entity based on one of the entities and the corresponding relationship, so as to solve the problem of head and tail entity prediction.

通过这种方式得到的链接预测模型同样可以应用到知识图谱的推理当中,根据一个实体和它的关系结构预测可能与之具有某种特定关联的其他实体。就食品安全问题而言,可以通过上述方法,根据某个食品类别推断出与其具有一定关系的其他食品或可能超标的其他物质,从而精准把握食品全链条(生产、运输、储存等)中可能存在的安全隐患,及时发现问题,防患于未然。The link prediction model obtained in this way can also be applied to the reasoning of knowledge graphs, predicting other entities that may have a specific relationship with it according to an entity and its relationship structure. As far as food safety issues are concerned, the above methods can be used to infer other foods that have a certain relationship with it or other substances that may exceed the standard according to a certain food category, so as to accurately grasp the possible existence of food in the whole food chain (production, transportation, storage, etc.). potential safety hazards, discover problems in time, and prevent problems before they happen.

在链接预测任务中,主要包括两方面的工作。一方面,为了让模型学习到知识图谱的信息,需要获取知识图谱的表示。相较于实体分类模型,需要更多地考虑结构图中边的类型和表示。另一方面,需要选择一个适用于当前问题的三元组打分函数,此函数直接影响模型的训练和结果。In the link prediction task, it mainly includes two aspects of work. On the one hand, in order for the model to learn the information of the knowledge graph, it is necessary to obtain the representation of the knowledge graph. Compared with entity classification models, more consideration needs to be given to the type and representation of edges in structural graphs. On the other hand, it is necessary to choose a triplet scoring function suitable for the current problem, which directly affects the training and results of the model.

S61:划分食品安全知识图谱数据集,为了避免类型不均衡影响预测效果,抽取数据时尽可能保证训练集和验证集、测试集的关系类型比例基本一致,将食品安全相关的实体类型和关系类型抽象为对应的类型编号;S61: Divide the food safety knowledge map data set. In order to avoid the impact of type imbalance on the prediction effect, when extracting data, try to ensure that the relationship type ratios of the training set, verification set, and test set are basically the same. Food safety-related entity types and relationship types Abstract to the corresponding type number;

S62:利用BERT预训练模型对知识图谱中每个节点的描述信息做文本特征提取并得到词向量表示;S62: Use the BERT pre-training model to perform text feature extraction on the description information of each node in the knowledge graph and obtain word vector representation;

S63:链接预测模型的编码器部分:基于R-GCN的隐藏层更新节点的表示,包括节点的描述作为文本信息通过BERT预训练模型得到词向量表示,将文本表示词向量嵌入到最后一个R-GCN隐藏层之前,而知识图谱本身的图结构信息则通过初始化嵌入后输入R-GCN隐藏层得到知识图谱的表示;两种特征在进入最后一层隐藏层之前先进行融合和表示学习,再通过最后一层R-GCN隐藏层;S63: The encoder part of the link prediction model: update the representation of the node based on the hidden layer of R-GCN, including the description of the node as text information, obtain the word vector representation through the BERT pre-training model, and embed the text representation word vector into the last R- Before the GCN hidden layer, the graph structure information of the knowledge map itself is input into the R-GCN hidden layer after initialization and embedding to obtain the representation of the knowledge map; the two features are fused and represented before entering the last hidden layer, and then passed The last layer of R-GCN hidden layer;

S64:链接预测模型的解码器部分:通过打分函数实现对三元组的评价,得到正样本在所有样本分数中的排名。将打分函数定义为f(s,r,o),其中s,r,o分别表示头实体、关系和尾实体。S64: the decoder part of the link prediction model: realize the evaluation of triplets through the scoring function, and obtain the ranking of positive samples among all sample scores. Define the scoring function as f(s, r, o), where s, r, o denote head entity, relation and tail entity, respectively.

S641:打分函数基于分段式的分块点积思想,结合节点表示中包含的图结构信息和文本信息,分为fgraph(s,r,o)和fword(s,r,o)两部分来进行计算,即f(s,r,o)=fgraph(s,r,o)+fword(s,r,o),将图结构特征和文本特征各分为2部分,fgraph(s,r,o)=∑0≤x,y<2sx,y·<rx,sy,oz>,fword(s,r,o)=∑2≤x,y<4<rx,sy,oz>;其中x,y,z分别代表关系表示、头实体表示和尾实体表示分段的段编号。S641: The scoring function is based on the segmented block dot product idea, combined with the graph structure information and text information contained in the node representation, and is divided into f graph (s, r, o) and f word (s, r, o) part to calculate, that is, f(s, r, o) = f graph (s, r, o) + f word (s, r, o), divide the graph structure features and text features into two parts, f graph (s, r, o) = ∑ 0≤x, y<2 s x, y <r x , s y , o z >, f word (s, r, o) = ∑ 2≤x, y<4 <r x , s y , o z >; where x, y, and z represent the segment numbers of the relationship representation, head entity representation, and tail entity representation segments, respectively.

S642:图结构信息部分需要考虑对称性,使用奇数表示非对称关系,偶数表示对称关系,引入参数sx,y,在词向量部分的计算中则不添加关系约束。当x为奇数且x+y≥2时,sx,y为-1,其余为1。S642: The graph structure information part needs to consider the symmetry, use an odd number to indicate an asymmetric relationship, and an even number to indicate a symmetric relationship, introduce parameters s x, y , and do not add relationship constraints in the calculation of the word vector part. When x is an odd number and x+y≥2, s x, y is -1, and the rest are 1.

S643:为了简化计算,引入尾实体的索引wx,y,降低复杂度。S643: In order to simplify the calculation, the index w x, y of the tail entity is introduced to reduce the complexity.

S65:前期构造的数据集中并不包含负例数据,因此采用随机破坏正例数据的方法进行负采样,即以数据集中其他的随机实体替换头实体或尾实体的方式生成一定比例的负样本,并通过交叉熵损失进行优化。S65: The data set constructed in the previous stage does not contain negative data, so the method of randomly destroying positive data is used for negative sampling, that is, a certain proportion of negative samples are generated by replacing the head entity or tail entity with other random entities in the data set, And optimized by cross-entropy loss.

以上实施例仅用于说明本发明的设计思想和特点,其目的在于使本领域内的技术人员能够了解本发明的内容并据以实施,本发明的保护范围不限于上述实施例。所以,凡依据本发明所揭示的原理、设计思路所作的等同变化或修饰,均在本发明的保护范围之内。The above embodiments are only used to illustrate the design concept and characteristics of the present invention, and its purpose is to enable those skilled in the art to understand the content of the present invention and implement it accordingly. The protection scope of the present invention is not limited to the above embodiments. Therefore, all equivalent changes or modifications based on the principles and design ideas disclosed in the present invention are within the protection scope of the present invention.

Claims (9)

1.一种基于图神经网络的食品安全知识图谱构建与补全方法,其特征在于:包括以下步骤:1. A method for constructing and completing a food safety knowledge map based on a graph neural network, characterized in that: comprising the following steps: S1:采用包括网络爬虫和表格解析的手段提取食品安全国家标准信息,食品安全国家标准信息包括标准文件中的半结构化数据和非结构化数据;S1: Use methods including web crawlers and table analysis to extract national food safety standard information. National food safety standard information includes semi-structured data and unstructured data in standard documents; S2:基于半结构化数据并进行人工辅助标注,构建食品安全知识图谱的本体框架,利用本体框架进一步完善数据的提取方式;S2: Based on semi-structured data and artificially assisted labeling, construct the ontology framework of the food safety knowledge map, and use the ontology framework to further improve the data extraction method; S3:根据本体框架和知识图谱的存储需要,对半结构化数据和非结构化数据进行格式化处理和数据清洗,得到csv格式的食品安全知识图谱三元组数据;S3: According to the storage requirements of the ontology framework and knowledge graph, format and clean semi-structured and unstructured data to obtain triple data of food safety knowledge graph in csv format; S4:存储食品安全知识图谱三元组数据并构建可视化查询系统;S4: Store food safety knowledge map triplet data and build a visual query system; S5:结合文本表示关系图卷积网络,包括BERT文本表示部分和R-GCN图结构信息部分;采用图神经网络和文本预训练模型BERT搭建实体分类模型,完成知识图谱实体分类任务;实体分类模型用于结合图的结构信息和实体的文本描述,将知识图谱表示从单一的网络结构表示拓展到结构和文本的共同表示,构建融合多源知识图谱信息的模型;通过文本预训练模型BERT得到实体描述的词向量表示,将词向量表示添加到实体表示中与原有的实体关系结构信息融合后,共同通过关系图卷积网络模型学习知识图谱表示;S5: Combining text representation relational graph convolutional network, including BERT text representation part and R-GCN graph structure information part; using graph neural network and text pre-training model BERT to build an entity classification model to complete the knowledge map entity classification task; entity classification model It is used to combine the structural information of the graph and the text description of the entity, expand the knowledge graph representation from a single network structure representation to the common representation of structure and text, and build a model that integrates multi-source knowledge graph information; the entity is obtained through the text pre-training model BERT The word vector representation of the description, after adding the word vector representation to the entity representation and merging with the original entity relationship structure information, jointly learn the knowledge graph representation through the relational graph convolutional network model; S6:将R-GCN模型作为编码器得到三元组的表示,将打分函数作为解码器;构造基于编码器-解码器的链接预测模型的结构,包括BERT文本表示部分和R-GCN图结构信息部分;基于编码器-解码器的链接预测模型用于根据一个实体和它的关系结构预测可能与之具有某种特定关联的其他实体,通过预测知识图谱中缺失的三元组,基于打分函数判断三元组是否符合要求,从而完成知识图谱链接预测任务。S6: Use the R-GCN model as the encoder to obtain the representation of the triplet, and use the scoring function as the decoder; construct the structure of the link prediction model based on the encoder-decoder, including the BERT text representation part and the R-GCN graph structure information Part; the encoder-decoder-based link prediction model is used to predict other entities that may have a certain relationship with it according to an entity and its relationship structure, by predicting missing triples in the knowledge graph, based on the scoring function judgment Whether the triplet meets the requirements, so as to complete the knowledge graph link prediction task. 2.根据权利要求1所述的一种基于图神经网络的食品安全知识图谱构建与补全方法,其特征在于:所述的步骤S1中,具体步骤为:2. A method for constructing and completing a food safety knowledge map based on a graph neural network according to claim 1, characterized in that: in the step S1, the specific steps are: S11:通过爬虫程序从网络上获取食品安全国家标准的信息、下载食品安全国家标准文件;S11: Obtain information on national food safety standards from the Internet through a crawler program, and download national food safety standard documents; S12:OCR识别下载的食品安全国家标准文件,解析文件中的表格信息;S12: OCR identifies the downloaded national food safety standard file, and parses the table information in the file; S13:基于规则匹配和网页、表格解析,得到半结构化数据和非结构化数据。S13: Obtain semi-structured data and unstructured data based on rule matching and web page and table analysis. 3.根据权利要求1所述的一种基于图神经网络的食品安全知识图谱构建与补全方法,其特征在于:所述的步骤S2中,本体框架包括与食品品类、食品标准、食品添加剂和农药残留相关的实体类型和关系类型。3. A graph neural network-based food safety knowledge map construction and completion method according to claim 1, characterized in that: in the step S2, the ontology framework includes food categories, food standards, food additives and Entity types and relationship types related to pesticide residues. 4.根据权利要求3所述的一种基于图神经网络的食品安全知识图谱构建与补全方法,其特征在于:所述的步骤S4中,具体步骤为:4. A food safety knowledge map construction and completion method based on graph neural network according to claim 3, characterized in that: in the step S4, the specific steps are: S41:将csv格式的知识图谱三元组数据存储到Neo4J图数据库中;S41: storing the knowledge graph triplet data in csv format into the Neo4J graph database; S42:基于Python的Flask框架,调用Neo4j图数据库,以Echarts.js的力导向图展示知识图谱;S42: Based on the Python Flask framework, call the Neo4j graph database, and display the knowledge graph with the force-directed graph of Echarts.js; S43:通过Python调用Neo4J的cypher语句实现知识图谱实体的查询,并显示到网页端页面上。S43: Call the cypher statement of Neo4J through Python to realize the query of the knowledge map entity, and display it on the web page. 5.根据权利要求4所述的一种基于图神经网络的食品安全知识图谱构建与补全方法,其特征在于:所述的步骤S5中,具体步骤为:5. A method for constructing and completing a food safety knowledge map based on a graph neural network according to claim 4, characterized in that: in the step S5, the specific steps are: S51:基于食品安全知识图谱三元组数据构建数据集,划分训练集、验证集和测试集,将食品安全相关的实体类型作为对应的类型编号,将实体本身抽象为实体编号,基于实体类型表和三元组表构建DGLDataset数据集;S51: Construct a data set based on the triplet data of the food safety knowledge map, divide the training set, verification set and test set, use the entity type related to food safety as the corresponding type number, and abstract the entity itself into an entity number, based on the entity type table Construct the DGLDataset dataset with the triple table; S52:采用BERT预训练模型作为实体分类模型,提取知识图谱实体名称的文本词向量表示,对预训练得到的词向量进行降维处理;S52: Using the BERT pre-training model as the entity classification model, extracting the text word vector representation of the entity name of the knowledge graph, and performing dimensionality reduction processing on the word vector obtained through pre-training; S53:利用R-GCN聚合信息更新节点表示,获取图结构信息;S53: Utilizing the R-GCN aggregation information to update the node representation, and obtain graph structure information; S54:将实体名称的文本词向量嵌入到R-GCN的输出层之前;S54: Embedding the text word vector of the entity name before the output layer of R-GCN; S55:经过输出层学习后,使用softmax对实体进行分类,对样本中的每个实体预测可能的类别,通过在所有有标签的节点上最小化交叉熵损失函数进行优化。S55: After learning the output layer, use softmax to classify entities, predict possible categories for each entity in the sample, and optimize by minimizing the cross-entropy loss function on all labeled nodes. 6.根据权利要求5所述的一种基于图神经网络的食品安全知识图谱构建与补全方法,其特征在于:所述的步骤S6中,实体分类模型包括一个输入层、若干个隐藏层和一个输出层;6. A food safety knowledge map construction and completion method based on graph neural network according to claim 5, characterized in that: in the step S6, the entity classification model includes an input layer, several hidden layers and an output layer; 实体分类模型的每一层都包含关系图卷积网络层R-GCN,关系图卷积网络层R-GCN用于对于训练集上的每一个节点分别根据节点表示和边的类型通过消息函数计算输出信息,以及聚合信息获得新的节点表示;Each layer of the entity classification model includes a relational graph convolutional network layer R-GCN, which is used to calculate each node on the training set according to the node representation and edge type through the message function Output information, and aggregate information to obtain new node representations; 模型的输入层使用实体的类型和编号作为特征;输入层和隐藏层采用ReLU作为激活函数;最后一层的输出使用softmax用于分类;The input layer of the model uses the type and number of entities as features; the input layer and hidden layer use ReLU as the activation function; the output of the last layer uses softmax for classification; 在隐藏层中,输入层得到的节点表示分别经过多个关系图卷积网络层R-GCN和激活函数ReLU的计算;设Y是节点的索引集合,K为类别总数,
Figure FDA0003851102740000031
表示第l层有标签的第i个节点的第k个类别的预测值,tik表示真实标签,则输出层得到的表示在所有有标签的节点上最小化交叉熵损失函数Loss为:
In the hidden layer, the node representation obtained by the input layer is calculated by multiple relational graph convolutional network layers R-GCN and activation function ReLU respectively; let Y be the index set of nodes, K be the total number of categories,
Figure FDA0003851102740000031
Represents the predicted value of the k-th category of the i-th node with a label in the l-th layer, and t ik represents the real label, then the output layer obtains the minimum cross-entropy loss function Loss on all labeled nodes:
Figure FDA0003851102740000032
Figure FDA0003851102740000032
在实体分类任务中,通过基函数分解的方式来降低模型的计算量;将BERT预训练模型得到的词向量嵌入到R-GCN模型的输出层用于得到最好的效果。In the entity classification task, the calculation amount of the model is reduced by means of basis function decomposition; the word vector obtained by the BERT pre-training model is embedded into the output layer of the R-GCN model to obtain the best effect.
7.根据权利要求5所述的一种基于图神经网络的食品安全知识图谱构建与补全方法,其特征在于:所述的步骤S6中,具体步骤为:7. A food safety knowledge map construction and completion method based on graph neural network according to claim 5, characterized in that: in the step S6, the specific steps are: S61:划分食品安全知识图谱数据集,抽取数据时使训练集和验证集、测试集的关系类型比例一致用于避免类型不均衡影响预测效果;将食品安全相关的实体类型和关系类型抽象为对应的类型编号;S61: Divide the food safety knowledge map data set, and make the relationship type ratios of the training set, verification set, and test set consistent when extracting data to avoid type imbalance from affecting the prediction effect; abstract food safety-related entity types and relationship types into correspondence type number of S62:利用BERT预训练模型对知识图谱中每个节点的描述信息做文本特征提取,并得到词向量表示;S62: Use the BERT pre-training model to perform text feature extraction on the description information of each node in the knowledge graph, and obtain word vector representation; S63:链接预测模型的编码器部分基于R-GCN的隐藏层更新节点的表示,将包括节点的描述作为文本信息通过BERT预训练模型得到词向量表示,将文本表示词向量嵌入到最后一个R-GCN隐藏层之前,而知识图谱本身的图结构信息则通过初始化嵌入后输入R-GCN隐藏层得到知识图谱的表示;两种特征在进入最后一层隐藏层之前先进行融合和表示学习,再通过最后一层R-GCN隐藏层;S63: The encoder part of the link prediction model updates the representation of the node based on the hidden layer of R-GCN, uses the description of the node as text information to obtain the word vector representation through the BERT pre-training model, and embeds the text representation word vector into the last R-GCN Before the GCN hidden layer, the graph structure information of the knowledge map itself is input into the R-GCN hidden layer after initialization and embedding to obtain the representation of the knowledge map; the two features are fused and represented before entering the last hidden layer, and then passed The last layer of R-GCN hidden layer; S64:设s、r、o分别表示头实体、关系和尾实体,定义打分函数为f(s,r,o);链接预测模型的解码器部分通过打分函数实现对三元组的评价,得到正样本在所有样本分数中的排名;S64: Let s, r, and o denote the head entity, relation, and tail entity respectively, and define the scoring function as f(s, r, o); the decoder part of the link prediction model realizes the evaluation of triples through the scoring function, and obtains The rank of positive samples among all sample scores; S65:前期构造的数据集不包含负例数据,采用随机破坏正例数据的方法进行负采样,以数据集中其他的随机实体替换头实体或尾实体的方式生成一定比例的负样本,并通过交叉熵损失进行优化。S65: The data set constructed in the previous stage does not contain negative example data, and the method of randomly destroying positive example data is used for negative sampling, and a certain proportion of negative samples is generated by replacing the head entity or tail entity with other random entities in the data set, and through crossover Entropy loss is optimized. 8.根据权利要求7所述的一种基于图神经网络的食品安全知识图谱构建与补全方法,其特征在于:所述的步骤S64中,具体步骤为:8. A graph neural network-based food safety knowledge map construction and completion method according to claim 7, characterized in that: in the step S64, the specific steps are: S641:设打分函数的图结构特征为fgraph(s,r,o),文本特征为fword(s,r,o),则:S641: Let the graph structure feature of the scoring function be f graph (s, r, o), and the text feature be f word (s, r, o), then: f(s,r,o)=fgraph(s,r,o)+fword(s,r,o);f(s, r, o) = f graph (s, r, o) + f word (s, r, o); 设x、y、z分别为关系表示、头实体表示和尾实体表示分段的段编号,将图结构特征和文本特征各分为2部分,为:Let x, y, and z be the segment numbers of the relationship representation, head entity representation, and tail entity representation segments respectively, and divide the graph structure features and text features into two parts, as follows: fgraph(s,r,o)=∑0≤x,y<2sx,y·<rx,sy,oz>,f graph (s, r, o) = ∑ 0≤x, y<2 s x, y <r x , s y , o z >, fword(s,r,o)=∑2≤x,y<4<rx,sy,oz>;f word (s, r, o) = ∑ 2≤x, y<4 <r x , s y , o z >; S642:图结构信息部分考虑对称性,使用奇数表示非对称关系,偶数表示对称关系,引入参数sx,y;在词向量部分的计算中不添加关系约束;当x为奇数且x+y≥2时,sx,y为-1,其余为1;S642: Consider symmetry in the graph structure information part, use odd numbers to indicate asymmetric relationships, and even numbers to indicate symmetric relationships, and introduce parameters s x, y ; do not add relationship constraints in the calculation of the word vector part; when x is an odd number and x+y≥ 2, s x, y is -1, and the rest are 1; S643:引入尾实体的索引wx,y用于简化计算、降低复杂度。S643: Introduce the index w x, y of the tail entity to simplify calculation and reduce complexity. 9.一种计算机存储介质,其特征在于:其内存储有可被计算机处理器执行的计算机程序,该计算机程序执行如权利要求1至权利要求8中任意一项所述的一种基于图神经网络的食品安全知识图谱构建与补全方法。9. A computer storage medium, characterized in that: a computer program that can be executed by a computer processor is stored therein, and the computer program executes a graph-based neural network as described in any one of claims 1 to 8. Construction and completion method of food safety knowledge graph in network.
CN202211134812.6A 2022-09-19 2022-09-19 A food safety knowledge map construction and completion method based on graph neural network Pending CN115563297A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211134812.6A CN115563297A (en) 2022-09-19 2022-09-19 A food safety knowledge map construction and completion method based on graph neural network

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211134812.6A CN115563297A (en) 2022-09-19 2022-09-19 A food safety knowledge map construction and completion method based on graph neural network

Publications (1)

Publication Number Publication Date
CN115563297A true CN115563297A (en) 2023-01-03

Family

ID=84740135

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211134812.6A Pending CN115563297A (en) 2022-09-19 2022-09-19 A food safety knowledge map construction and completion method based on graph neural network

Country Status (1)

Country Link
CN (1) CN115563297A (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116186295A (en) * 2023-04-28 2023-05-30 湖南工商大学 Attention-based knowledge map link prediction method, device, equipment and medium
CN116955648A (en) * 2023-07-19 2023-10-27 上海企卓元科技合伙企业(有限合伙) Knowledge graph analysis method based on non-privacy data association
CN116992959A (en) * 2023-06-02 2023-11-03 广州数说故事信息科技有限公司 Knowledge graph-based food product creative concept generation and verification method
CN117009553A (en) * 2023-09-08 2023-11-07 清华苏州环境创新研究院 Polluted site portrait construction method and system based on knowledge graph reasoning
CN117151217A (en) * 2023-08-29 2023-12-01 中国电子科技南湖研究院 Entity chain indicating method based on fusion of language model and chart sign
CN117669718A (en) * 2023-12-05 2024-03-08 广州鸿蒙信息科技有限公司 Fire control knowledge training model and training method based on artificial intelligence
CN117932089A (en) * 2024-03-25 2024-04-26 南京中医药大学 Knowledge graph-based data analysis method
WO2024226848A3 (en) * 2023-04-25 2025-01-23 Strong Force Ee Portfolio 2022, Llc Ai-based energy edge platform, systems, and methods

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024226848A3 (en) * 2023-04-25 2025-01-23 Strong Force Ee Portfolio 2022, Llc Ai-based energy edge platform, systems, and methods
CN116186295A (en) * 2023-04-28 2023-05-30 湖南工商大学 Attention-based knowledge map link prediction method, device, equipment and medium
CN116992959A (en) * 2023-06-02 2023-11-03 广州数说故事信息科技有限公司 Knowledge graph-based food product creative concept generation and verification method
CN116992959B (en) * 2023-06-02 2024-03-15 广州数说故事信息科技有限公司 Knowledge graph-based food product creative concept generation and verification method
CN116955648A (en) * 2023-07-19 2023-10-27 上海企卓元科技合伙企业(有限合伙) Knowledge graph analysis method based on non-privacy data association
CN116955648B (en) * 2023-07-19 2024-01-26 上海企卓元科技合伙企业(有限合伙) Knowledge graph analysis method based on non-privacy data association
CN117151217A (en) * 2023-08-29 2023-12-01 中国电子科技南湖研究院 Entity chain indicating method based on fusion of language model and chart sign
CN117009553A (en) * 2023-09-08 2023-11-07 清华苏州环境创新研究院 Polluted site portrait construction method and system based on knowledge graph reasoning
CN117669718A (en) * 2023-12-05 2024-03-08 广州鸿蒙信息科技有限公司 Fire control knowledge training model and training method based on artificial intelligence
CN117932089A (en) * 2024-03-25 2024-04-26 南京中医药大学 Knowledge graph-based data analysis method

Similar Documents

Publication Publication Date Title
CN115563297A (en) A food safety knowledge map construction and completion method based on graph neural network
CN113505244B (en) Knowledge graph construction method, system, equipment and medium based on deep learning
CN111026842B (en) Natural language processing method, natural language processing device and intelligent question-answering system
WO2023065545A1 (en) Risk prediction method and apparatus, and device and storage medium
CN112989761B (en) Text classification method and device
CN113254675A (en) Knowledge graph construction method based on self-adaptive few-sample relation extraction
CN118585658B (en) AI-based safety declaration training knowledge graph and data management method and system
CN116383399A (en) A method and system for predicting event public opinion risk
CN112100398A (en) Patent blank prediction method and system
WO2023137918A1 (en) Text data analysis method and apparatus, model training method, and computer device
CN113901224B (en) Confidential text recognition model training method, system and device based on knowledge distillation
CN115526236A (en) A Text Network Graph Classification Method Based on Multimodal Contrastive Learning
CN114942981A (en) Question-answer query method and device, electronic equipment and computer readable storage medium
Zhang et al. Modeling and prediction of stock price with convolutional neural network based on blockchain interactive information
CN117235280A (en) Operation ticket generation method, device, equipment and medium
CN120317286A (en) A large model training method and system based on electric power smart engineering
Bai Variable incremental adaptive learning model based on knowledge graph and its application in online learning system
CN115936119A (en) A Knowledge Representation Learning Method Based on Graph Attention Network
Han et al. Entity relation joint extraction method for manufacturing industry knowledge data based on improved BERT algorithm
Subbarao et al. Automated Dialogue-Based Response and Resolution of Conversational IT Tickets Using Deep Neural Networks
CN116628222A (en) Beidou user behavior analysis method based on knowledge graph
CN116961969A (en) Methods and apparatus for determining the security of network links
CN114580955A (en) A policy recommendation method, system, device and storage medium
Fu et al. A study on recursive neural network based sentiment classification of Sina Weibo
Chen et al. Towards accurate search for e-commerce in steel industry: a knowledge-graph-based approach

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载