Disclosure of Invention
The invention aims to provide an intelligent searching system based on a knowledge graph, provides a solution of natural language searching, and aims to design and develop the intelligent searching system for realizing natural language searching based on the knowledge graph aiming at data in a specific enterprise field.
The invention develops an intelligent search system by applying natural language processing technologies such as triplet extraction, named entity recognition, semantic matching and the like and combining a search engine sol and a graph database nebula-graph adopted by the invention and using Java, python, springboot frames and the like.
In order to achieve the above purpose, the technical scheme adopted by the invention is an intelligent searching system based on a knowledge graph, which is divided into five sub-modules from the functional perspective, namely a data management module, a data processing module, a natural language processing service module, a knowledge graph construction module and an information retrieval module, wherein the data management module, the data processing module, the natural language processing service module, the knowledge graph construction module and the information retrieval module are connected in parallel as shown in figure 1. In a natural language processing module, the invention realizes the following three NLP services based on the BERT pre-training model, including triplet extraction (used for constructing a knowledge graph), named entity recognition and semantic matching. And providing service for the system in the form of a web service interface through a python-based flash frame, packaging a returned result, and calling a corresponding interface by the system in a part needing natural language processing to analyze and process the result. In the knowledge graph construction part, a knowledge graph construction method based on data in a specific field is developed, a method for secondarily training a triplet extraction model is provided, the workload of manually marking training data is reduced, the aim of manually marking as few as possible for an original specific data set is achieved, and the triplet extraction model for the data set is trained. In the natural language searching part, semantic searching based on named entity recognition and template matching is realized, and on the basis of the semantic searching, the semantic matching mode between sentences and relational words is put forward, so that an enterprise-level search engine can understand a natural language searching request of a user.
The architecture of the entire system is shown in fig. 2, and five important modules designed in the entire system are labeled. The sol is a search engine, which can be broadly considered as a database in the invention, collection is created through a Java client provided by the sol, each colleciton stores enterprise data in a specific field, the invention stores enterprise data collection called collection to be queried, the data stored in the sol is displayed in json format at an admin interface of the sol, a plurality of documents (doc) are stored in one collection, each document is a piece of data, each piece of data is a document with a plurality of fields (field), and the id field is used as a unique identifier of the data in the collection.
Nebula-graph is a graph database product adopted by the subject, one nebula-graph instance consists of one or more graph spaces (spaces), each graph space is physically isolated, a user can use different graph spaces to store different data sets in the same instance, SPACENAME uniquely identifies one data set, each space corresponds to one collection, stores one kind of entity-relation data, namely stores triad information extracted from data corresponding to the collection, namely knowledge information, and forms a semantic knowledge base corresponding to the collection. For each space, a schema configuration needs to be defined for that space, and the schema for nebula-graph is shown in Table 1.
TABLE 1nebula map space configuration
The invention discloses a data management module, which comprises a software and nebula-graph, wherein some data and basic configuration need to be managed, and in the invention, the creation and deletion of the collection of the software, the addition, deletion and modification of fields of the collection of the software, the creation and deletion of space of the nebula-graph and the like are realized by the data management module. The data management module is used for managing data and basic configuration in the whole system, and mainly realizes the following four functions of software data management, nebula-graph data management, triplet ontology schema configuration management and natural language question template configuration management, and is shown in fig. 3.
The sor data management module is responsible for creating, configuring and deleting the collection of the data set, and configuring, adding and deleting the collection field. The collection is created and deleted, namely, a space creating and deleting method is called in the collection creating and deleting method, the space name and the collection are the same, a data set for a user to search is formed together, the collection is an original data set to be queried, and data stored in the space is an extracted knowledge base corresponding to collection data.
Nebula-graph data management is responsible for realizing space creation and deletion of the graph database nebula-graph, and is responsible for managing schema configuration information of space of nebula-graph, namely creating and deleting labels or point types (tags), creating and deleting edge types (edge types), creating and deleting tag indexes and creating and deleting edge indexes.
The triplet schema configures the management module that the triplet is a subject, a predicate, a head entity, a relation and a tail entity, and the triplet schema is a type of the subject, a predicate and a type of the object. The module is used for constructing a knowledge graph. The invention needs to perform triplet extraction on the collection data to construct the corresponding knowledge graph, and the triplet extraction is realized by calling a web interface provided by a natural language processing service module. The invention is based on bert pre-training language model, the parameters of the model are correspondingly modified through the downstream task, then the training of the triplet extraction character is carried out, and the training needs schema configuration and the training data marked according to the schema configuration. The schema configuration is stored in a data set with a suffix name of "_schema" corresponding to the data set to be searched, and is used for managing the schema, the module is used for adding, modifying and deleting the schema, auditing and remarking the data to be searched and collected according to the schema, and writing the configuration into training data to train a triplet extraction model. Triplet body configuration management is shown in fig. 3.
And (3) natural language question template management, namely, aiming at the well configured schemes of the collection to be queried, acquiring a relation, namely, predicte from each scheme, and according to all the relations (predicte) in the knowledge graph, matching the templates by questions, wherein the template management part is responsible for adding, deleting and modifying the matched templates, and the question templates are stored in the corresponding collection with the suffix of 'template'.
And the data processing module is used for storing data of two parts in total, namely a search engine sol and a graph database nebula-graph.
The module is responsible for storing the data of the two parts, adding, deleting and modifying the data in the collection of the sor, and inserting, deleting and updating the triple entity and the relation in nebula-graph.
The original data needs to be processed to a certain extent before being stored into solrcollection, the module realizes three processing modules of short text filtering, text replacement and segmentation clauses of the data, and finally the processed data is indexed into the collection of the solr. And this part of data processing has the property of being expandable, and the corresponding requirement can be realized by adding a processing module, as shown in fig. 4. The data of the triples corresponding to the collection to be queried is stored in the collection with the suffix of "_extraction", the data of the triples in the collection, namely, the relation and the entity are stored in nebula-graph, and the relation is established between the nodes to form a knowledge graph.
The natural language processing service module is written by python, realizes four functions of triple extraction, named entity identification, semantic matching between sentences and relation words and semantic matching between two sentences, packages the four functions into interfaces respectively, and provides a web service form for springboot items to call through a flash framework. As shown in fig. 5.
The triple extraction module realizes the triple extraction function, firstly trains a triple extraction model, stores the trained model on a server, writes codes, provides web services to the outside through a flash framework, inputs the web services as a short text set List < Stringtext >, outputs the triple corresponding to each short text, including extracted text and triple information corresponding to text, namely subject, subjectType, object, objectType, predicate, and packages the returned result into json format.
The named entity recognition module realizes the named entity recognition function, firstly trains a named entity recognition model, stores the trained model on a server, writes codes, provides a web service interface through a flash framework for springboot items to call, inputs a short text set, returns a named entity, and encapsulates the result into json format.
The semantic matching is divided into two parts, namely semantic matching between sentences and relation words and semantic matching between two sentences, respectively training a model, storing the trained model on a server, writing codes, providing web services through a flash frame, and calling in the natural language searching process. Semantic matching between sentences and relational words aims to obtain an entity with the closest relation to a certain entity from a graph database, and semantic matching between two sentences aims to find a question template which is most relevant to a sentence input by a user so as to perform subsequent searching and detailed description in a natural language searching section. And inputting a List < Stringtext > set, dividing each text into two parts by using a "#", outputting a parameter "prob" to represent a fraction, reflecting the matching degree of the left part and the right part of the "#", setting a threshold in a program, and considering the left part and the right part of the "#", namely the left part and the right part of the "#", as matching if the fraction exceeds the threshold.
Knowledge graph construction module:
the purpose of this module is to triage the solrcollection data and store the extracted entity and relationship data into nebula-graph as a knowledge graph to support natural language searches.
The knowledge graph construction process comprises the following steps:
and 1, performing triplet data annotation on the data in the collection to be queried by the solr.
And 2, training a triplet extraction model.
And 3, calling a triplet extraction interface of the natural language processing service module to extract, and storing the extracted result into a collection corresponding to the solr.
And 4, auditing the extracted triples, namely, the triples stored in the corresponding collection of the sol.
And 5, storing the data after the auditing into a space corresponding to the graph database, and taking the space as a knowledge base corresponding to the collection data.
The information retrieval module is used for retrieving data in a database (solr, nebula-graph) and comprises a common retrieval module and a natural language search module.
The common retrieval module is realized based on keyword matching and a query resolver packaged by a solr.
The natural language search module is a scene of inputting natural language by a user, and needs to convert unstructured natural language query sentences input by the user into structured query sentences (for query sentences of a graph database, nebula-graph is adopted in the invention, unstructured query sentences need to be converted into structured NGQL), query is performed in a corresponding knowledge base (space), the returned query results are entity information, the entity information is used as a part of the results of the user query, and meanwhile, the entity information is searched in a corresponding collection to return a final search result which is used as another part of the user query results, and the two search results jointly form the query results of the user.
Detailed Description
In order to further clean the objects, technical solutions and advantages of the embodiments of the present invention, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. It will be apparent that the described embodiments are only some, but not all, embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The intelligent search system comprises a plurality of modules, namely a data management module, a data processing module, a natural language processing service module, a knowledge graph construction module and an information retrieval module. The overall architecture of the system is shown in figure 2.
In the present invention, the entire system architecture is described by the following steps, according to fig. 2.
Step 1 data management
The data management module and its sub-module diagram are shown in fig. 6.
Firstly, creating collections of a software through a software data management module, wherein each collection represents enterprise data in a specific field;
after creating the collection, configuring fields of the collection;
Creating a graph database space corresponding to the collection, and configuring a point type (tag) and an edge type (edge type) corresponding to the space;
configuring a plurality of attributes of tag and edgetype;
establishing a single index and a joint index of the attributes for the tag and the edgetype;
The method comprises the steps of configuring a triplet body ontology (the type, the relation and the type of the object) used by a knowledge graph constructed by the data of the collection to be queried, and storing the triplet body ontologies as a data set with a suffix of "_schema" corresponding to the data set to be queried after the schema is configured;
step 2, data processing
Enterprise data is unstructured data, and before the data is indexed into the collection of the solr, some processing needs to be performed on the data to be indexed according to actual requirements, and then the collection of the solr is indexed. The module realizes three processing modules of short text filtering, text replacement and segmentation clause of the data, and the data processing part can realize corresponding requirements by adding the processing modules aiming at different types of data.
Step 3, knowledge graph construction
The knowledge graph construction process of the system is shown in figure 7. The method comprises the following steps:
1. aiming at collection to be extracted, configuring a triplet schema;
2. training a triplet extraction model through an open source training set;
3. sentence dividing is carried out on the data to be extracted from collection;
4. extracting by calling a triplet of the natural language processing service module, and storing the result into a collection with a suffix of "_extraction";
5. Extracting, cleaning and re-labeling the audit triples, and writing the re-labeled training data aiming at the collection into a training file (the purpose of the audit is to re-label the triples training data aiming at the collection to be queried);
6. training the triplet extraction model again aiming at the collection to be queried, and storing the triplet extraction model to the corresponding collection;
7. audit data (the purpose of this audit is to store in the graph database space);
8. stored in a graph database nebula-graph.
Because the knowledge graph is constructed aiming at the data of a collection to be queried, the data of the collection is often from enterprise clients or the data of a specific field, a model trained by an open-source triplet extraction training data set does not necessarily have a good extraction effect aiming at the data of the specific field, generally, special personnel are required to manually mark the specific data set according to configured triplet schema, the system writes the marked training data into a training set file, invokes extraction service of a natural language processing service module to extract triples, and then checks and stores. Aiming at the situation, the invention adopts a small improvement scheme, namely, two times of training are carried out, the operation of manually marking data is reduced, the efficiency of the whole process is improved, namely, the collection is firstly extracted through an open source data set, the extracted data is not stored in a graph database, is checked and modified, the modified data is written into a training set as training data for carrying out a second time of training, the purpose of the checking and the modification is to re-mark the data of the collection to be checked and to train a model for the data of the collection, the modified data of the triples and corresponding texts are used as re-marked data, the re-marked data is written into a training set file, and a training interface of a natural language processing module is called for training again, so as to obtain the triples extraction model which accords with the data set to be checked.
At this time, the data of the data set to be queried can be extracted again through the model and is audited again, and the aim of the audit is to store the audited data into a space of nebula-graph for the storage of the final triplet data.
Step 4, searching natural language
A natural language search flow chart is shown in fig. 8.
Through the previous description, a knowledge graph for the collection to be queried has been constructed, and natural language search needs to be performed based on the knowledge graph. The query sentence input by the user is unstructured natural language, and the knowledge graph is realized through the graph database nebula-graph, so that the query is required to be performed through the structured query sentence, and the result is returned. In the system, the nature of realizing natural language search is to convert unstructured natural language query sentences of users into structured query sentences based on knowledge maps for query. The conversion of unstructured statements into structured query statements is performed by the following steps.
1. Identifying and acquiring a subject of the text through the named entity;
named entity recognition is the first step in converting unstructured query terms into structured query terms, requiring the acquisition of key entity information, i.e., subjects, of the user input terms.
2. Acquiring a relation prediction through semantic matching;
firstly, constructing a query statement NGQL (NGQL does not specify an edgetype or a relationship) aiming at nebula-graph through the subject obtained in the step 1, wherein the purpose is to obtain all related words (predictes) corresponding to the subject in a graph database;
Combining each relation word with the input sentence of the user to obtain a List < Stringtext > set;
The set is used as a relation semantic matching structure of a parameter call natural language processing service module, each group of relation and query sentences returns a matching score, when the matching score reaches a certain threshold value, the relation is considered to be a relation word capable of reflecting the query sentences input by a user, and the relation word with the highest score is taken as a prediction;
The resulting subjects and predictes are built into a structured query statement NGQL for nebula-grams, which queries the object as a tail entity in the space of nebula-grams, which is part of the returned results.
3. And querying the obtained tail entity in a collection to be queried, which is taken as a query keyword desolr, and taking the tail entity as the other part of the returned result.
In summary, the invention realizes NLP downstream tasks such as triplet extraction, named entity recognition and the like through research and application of bert models, and enables a search engine to understand the intention of a user to a certain extent through application of NLP technology and knowledge graph constructed through enterprise data, namely data in a specific field, thereby realizing natural language search of the user and enabling the enterprise-level search engine to be more intelligent.