The power of Knowledge Graph to enhance Financial Industry

Tirth Patel
18 min readNov 25, 2021

Outside of financial services, an increasing number of companies are learning the capacity to combine and use data, allowing them to make better decisions based on deep insights. Nevertheless, the advantages do not stop there: they can also provide customization on a large scale, allowing them to form deeper bonds with their customers; they can comply faster, compete harder, and thrive. As a result, many individuals are entering what has been dubbed “the knowledge age.”

Table of Content

Abstract

In financial services, on the other hand, many companies are still caught in the past, utilizing decades-old technology to compete on an entirely new data-driven playing field. They cannot deal with and use legacy, siloed data; their clients and business users are dissatisfied by slow responses to simple requests; those in charge of change are drowning in complexity. These
firms face growing challenges from regulators, and as part-fossilized data dinosaurs, they are threatened with extinction.

There is a powerful technology that most of us use every day,
often unknowingly. It uses data — just a bit differently — to create shared knowledge at an incredible scale, from fragments of facts.
This technology is at the heart (or brain) of tools we have come
to depend upon, tools that help us to search (Google), navigate
(SatNav), Alternatively, turn on lights or music with our voices (Alexa/Siri).
This sounds high-tech, but it was born back in 1736. It sounds complex, but its building blocks could not be simpler. It sounds expensive, but you could start using it today — with a small, intuitive change to the way you work. You can create new value within minutes.

What is this mysteriously potent, standard, hidden technology?

Semantic and graph thinking and technology, precisely,
knowledge graphs.

What is a knowledge graph?

A knowledge graph is a data structure (usually held in a graph database) that represents things and how they relate. It is data that describes a network, where the relationships between things (or business objects) are at least as important as the things themselves. A Knowledge Graph is an Ontological Structure filled with data.

In knowledge graphs, the simple, atomic facts (known as triples) – state how things are related. These things (sometimes called entities, nodes or vertices) and their relationships (sometimes called edges) self–assemble into chains or paths that can infer new, often unexpected, valuable connections. Inference and reasoning are just two examples of analytics capabilities that graphs enable. Graph data can be created by extracting or virtualization of existing information, expert or crowdsourcing, and also machine learning — increasingly a combination of all three.

Why knowledge graph in Financial Services?

A Knowledge Graph brings together Machine Learning and Graph technologies to give AI the context it needs. Knowledge Graphs represent a complex network of information in a meaningful way (similar way to human intelligence) by integrating data from a wide range of data silos and incorporating learning and reasoning. It’s use-cases in Financial Industry includes but are not limited to

  • 360° view of Risk & Value
  • Compliance Management
  • Data Lineage & Metadata Management
  • Fraud Detection & Financial Crime Analysis
  • Recommender Systems and Conversational AI

Build an Enriched Knowledge Graph for Financial Documents

Knowledge Graphs (KG) offer a widely used format for representing information in the computer-processable form. Natural Language Processing (NLP) is therefore needed for mining (or lifting) knowledge graphs from Natural Language(NL) texts. A central part of the problem is to extract the named entities in the text. However, financial documents have a tabular structure, and most of the essential entities like Revenue, Net Income are present in the tables of financial records. The paper can be divided into two parts for information retrieval, and the text in the documents can be sent to the Azure Language Studio Custom NER model. While the tabular content is processed by Form Recognizer API, it detects and returns the tabular content that can be processed and tagged as entities for building Knowledge Graph. We will discuss an overview of retrieving Named Entities and relations as a tuple using highly efficient pre-trained custom NER models on Language Studio and Form Recognizer on Azure.

Relation Extraction Methods

The next crucial part is Relation Extraction. Relation Extraction is the task of predicting attributes and relations for entities in a sentence. For example, given the sentence “Barack Obama was born in Honolulu, Hawaii.”, a relation classifier aims at predicting the relation of “bornInCity.” Relation Extraction is the critical component for building relation knowledge graphs, and it is crucial to natural language processing applications such as structured search, sentiment analysis, question answering, and summarization. There are numerous way to perform relation extraction using methods such as Rule Based RE, Supervised and Weakly Supervised RE, Distant Supervised RE, Unsupervised RE etc. In this article, we shall discuss the methods and methodologies of Relation Extraction using various techniques, including

  1. Supervised RE
  2. Weakly Supervised RE
  3. AmpliGraph

We will go through each of them in detail and discuss building efficient RE models and Knowledge graphs.

How to build dataset?

We will be using Microsoft’s quarterly earnings document as our Dataset, which can be fetched from here. As these are financial statements, the required details are present in the Tabular structure.

Sample Document(Microsoft Earnings)

The above table shows that Revenue in 2019 as reported was $36,906. Here, we can generate a tuple of entities and relations as
Head Entity → Relates → Tail Entity
To extract the tabular content, we used Azure Form Recognizer. We need to send a post request to the Form Recognizer API, and it returns a JSON comprising the text and table content. We need to process and filter the JSON file to get accurate data.

Below is the sample code to filter and retrieve tabular content.

import json
f = open('./source_json/2018_Q1_page3.json')
data = json.load(f)
f.close()
import ast
import pandas as pd
mystr = str(data)
#print(mystr)
val = ast.literal_eval(mystr)
val1 = json.loads(json.dumps(val))
relation={}
#print(type(relation))
relationlist=[]
#print(type(relationlist))
entity={}
#print(type(entity))
entitylist=[]
#print(type(entitylist))
table=val1['analyzeResult']['pageResults'][0]['tables'][0]['cells']
no_of_cell=len(table)
#for i in range(0,no_of_cell):
#if table[i]['columnIndex']==0:
#print(table[i]['text'])
for i in range(0,no_of_cell):
if table[i]['columnIndex']==0:
relationlist.append(table[i]['text'])
else:
entitylist.append(table[i]['text'])
entitylist.pop(0)
relationlist.pop(0)
count=0
Entity=[]
i=0
for i in range(0,18):
for j in range(3,24,1):
if(count==15):
break
if(i>2):
i=0
#print(entitylist[i]+" and "+entitylist[j])
Entity.append([entitylist[i],entitylist[j]])
count=count+1
i=i+1
Relation=[]
for i in range(0,len(relationlist)):
for j in range(0,3):
#print(relationlist[i])
Relation.append(relationlist[i])
Tuple=[]
count=0
for item in Entity:
item.insert(1,Relation[count])
count=count+1
#print(item)
import csv
rows = Entity
with open('DP.csv', 'a') as f:
write = csv.writer(f)
write.writerows(rows)
f.close()
df=pd.read_csv('DP.csv')
df

Below is the image of dataset for relation classification.

Final Dataset for Relation Classification

Supervised Technique for Relation Classification using Traditional ML Models

We need to preprocess the data such that the textual information is encoded and the relation is labelled encoded. After preprocessing, we trained the model using SVM, KNN, Naive Bayes and Random Forest.

Classifiers for Supervised Methods

  1. SVM
# importing necessary libraries
from sklearn import datasets
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
X = data_array
y = target_array
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 0)# training a linear SVM classifier
from sklearn.svm import SVC
svm_model_linear = SVC(kernel = 'linear', C = 1).fit(X, y)
svm_predictions = svm_model_linear.predict(X_test)
# model accuracy for X_test
accuracy_test = svm_model_linear.score(X_test, y_test)
# creating a confusion matrix
cm = confusion_matrix(y_test, svm_predictions)

2. KNN

# training a KNN classifier
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors = 7).fit(X_train, y_train)
# accuracy on X_test
accuracy = knn.score(X_test, y_test)
print (accuracy)
# creating a confusion matrix
knn_predictions = knn.predict(X_test)
cm = confusion_matrix(y_test, knn_predictions)

3. Naive Bayes

# training a Gaussian Naive Bayes Model
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB().fit(X_train, y_train)
gnb_predictions = gnb.predict(X_test)
# accuracy on X_test
accuracy = gnb.score(X_test, y_test)
print (accuracy)
# creating a confusion matrix
cm = confusion_matrix(y_test, gnb_predictions)

4. Random Forest

import numpy
from sklearn.model_selection import cross_val_scorefrom sklearn.model_selection import RepeatedStratifiedKFold
from sklearn.ensemble import RandomForestClassifier
from sklearn.utils import class_weight
from sklearn.model_selection import validation_curve
from sklearn.model_selection import KFold
from sklearn import preprocessing
import sklearn.model_selection
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(X, y, test_size=0.4, random_state=1,stratify=y)def evaluate_model(X, y, model):
# define evaluation procedure
cv = RepeatedStratifiedKFold(n_splits=5, n_repeats=3, random_state=1
# evaluate model
scores = cross_val_score(model, X, y, scoring='accuracy', cv=cv, n_jobs=-1)
return scores
# define the reference model
model = RandomForestClassifier()
# evaluate the model
scores = evaluate_model(X_train, y_train, model)
# summarize performance
print('Mean Accuracy: %.3f (%.3f)' % (numpy.mean(scores), numpy.std(scores)))

Below is the bar graph depicting their performance in terms of accuracy.

Training a stacked binary classifier (or a standard binary classifier) to identify a specific relationship between two things is a common approach to accomplish Supervised Relation Extraction. These classifiers use text features as input, which means other NLP modules must first tag the text. Context words, part-of-speech tags, dependency paths between entities, NER tags, tokens, proximity distance between words, and other attributes are common.

We could train and extract relations through the Supervised Method by:

  1. Manually label the text data to indicate whether or not a sentence is related to a particular relation type.
    For example, “Satya Nadella is the CEO of Microsoft.” is appropriate for the “CEO” relationship.
    “Steve Jobs is the CEO of Meta.” is meaningless.
  2. Manually label the relevant sentences as positive/negative if they are expressing the relation. E.g. “Apple CEO Steve Jobs said to Bill Gates.”:
    (Satya Nadella, CEO, Microsoft) is positive
    (Steve Jobs, CEO, Meta) is negative
  3. To decide if the statement is appropriate for the relation type, learn a binary classifier.
  4. Learn a binary classifier to assess if the relevant sentences represent the relationship or not.
  5. Use the classifiers to detect relations in new text data.

Why the extra step?
* Faster classification training by eliminating most pairs
* Can use distinct feature sets appropriate for each task.

Pros of Supervised RE

  1. Supervision of exceptional quality (ensuring that the relations that are extracted are relevant)
  2. We can train the classifier to have a perfect decision boundary to distinguish different relations accurately.

Cons of Supervised RE

  1. Labelling an extensive training set is expensive.
  2. Difficult to add new relations as we would have to train a new classifier.
  3. Supervised models are brittle, do not generalize well to different genres for relation extraction. For example: if we introduce a supervised model to detect relations in Financial Documents, it will not work for Medical Documents. Models are biased towards a particular text-domain.
  4. Supervision is only feasible for a small set of relation types for a specific genre. In our case, the Microsoft Earnings document can be well trained on Supervised RE. However, our supervised model fails to detect relevant relations if we introduce Facebook’s earnings with different text structures.
  5. Computation time is vast for supervised learning.

Weakly Supervised Relation Extraction

The idea is to start with a set of hand-crafted rules and automatically find new ones from the unlabeled text data through an iterative process (bootstrapping). Alternatively, one can begin with sed of seed tuples, describing entities with a specific relation. E.g. seed={(ORG: Microsoft, LOC: Redmond)} states entities having the connection “based in.”

There are various ways to perform weak supervision, and each methodology has a specific use case to solve and extract relations.

  1. PSPP(process-structure-property-performance) reciprocity

This approach is used for knowledge graph population and graph search concerning material design. The task is decomposed into three subtasks: Factor collection, relation identification & branching.

  • Collect factors for nodes in PSPP Knowledge Graph, and classify elements into each PSPP class. A factor is an important scientific concept for material design and is classified into ‘process’, ‘structure’, or ‘property’. For example, process factors include ‘tempering’; structural factors include ‘grain refining’; property factor include ‘strength.
  • For given two nodes and sentences mentioning factors represented by these nodes, their relation is identified. The relation is labelled in binary manner i.e positive or negative. A positive relation between A and B indicates that factor A affects factor B and a negative relation between A and C represents that factor A occurs independently of factor C. In chart, two nodes are connected if they have a positive relation.
  • Branching the nodes and relation will create a PSPP Knowledge Graph.

Use case: Material Designing, Commercial Product Manufacturing, Scientist developing new materials. For example, a scientist developing new materials with specific desired properties can look for factors in a PSPP Knowledge Graph and query accordingly.

2. Pattern enhanced Embedding learning

The distributional and pattern-based methods in a weakly-supervised setting can provide complementary supervision for each other to build a practical, unified model. During training, the distributional module helps the pattern module discriminate between the informative patterns and the other patterns. The pattern module generates some highly-confident instances to improve the distributional module.

  • The pattern module aims at learning a set of reliable textual patterns for relation extraction.
  • While the distributional module tries to learn a relation classifier on entity representations for prediction.

Use case: Knowledge Graph completion. For corpus-level RE, it aims at predicting the relationship of a pair of entities from several sentences mentioning both of them.

3. Multi-task transfer learning

The framework naturally transfers the knowledge learned from the old relation types to the new relation type and helps improve the recall of the relation extractor. Multi-task learning is another learning paradigm in which multiple related tasks are learned simultaneously to achieve better performance for each job.

The Syntactic similarity between relation types

Instances of different relation types can share specific common syntactic structures. For example, the syntactic pattern “arg-1 of arg-2” strongly indicates some relation between the two arguments. However, the nature of the relationship may be well dependent on the semantic meanings of the two arguments. In a feature-based linear classifier, a proper syntactic pattern is translated into large weights for features related to the Syntactic pattern. If “arg-1 of arg-2” is a valuable pattern, in the learned linear classifier, we should have relatively large weights for features such as “the word of occurs before arg-2” or “a preposition occurs before arg-2,” or even more complex features such as “there is a prepositional phrase containing arg-2 attached to arg-1.” The weights of these generally useful features are transferable from the auxiliary relation types to the target relation type.

The Statistical learning model tries to force the linear classifiers for different relation types to share their model weights for those features related to the common syntactic patterns.

Use case: Biomedical relation extraction

In case of the Microsoft Earnings document, we have prepared data for relation classification. As the amount of labelled data is meagre, we can use weak Supervision to label the data at the first stage and then build a relation classifier. In weak Supervision, we can use a Support Vector Classifier, which classifies the unlabelled data based on the model trained on the available labelled data. We choose SVM for this purpose because it represents state of the art in machine learning research, and there are exemplary implementations of the algorithm available. It also supports multi-class classification and provides probability estimates as well. In terms of a specific SVM model, the RBF(Radial Basis Function) kernel is used. It is used as it can handle non-linear relations between class labels and attributes. Furthermore, it has fewer hyperparameters than a polynomial kernel.

To kick-off building the clustering model, we first need to do text pre-processing and the entities have to TF-IDF vectorized. We know that are 14 classes of relation so, we create a KMeans model with appropriate clusters.

Check the comparison graph of accuracies of different models.

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cluster import KMeans
# Extract TFIDF features
TFIDF_PARAMS = {
'max_features':80,
'strip_accents': 'ascii',
'stop_words': 'english',
'sublinear_tf': True,
'min_df': 0.003,
}
vectorizer = TfidfVectorizer(**TFIDF_PARAMS)
tfidf_model_relation = vectorizer.fit(df['Entity'])
train_features_relation = tfidf_model_relation.transform(df['Entity'])
# Identify clusters on the model
cluster_model_relation = KMeans(n_clusters=14).fit(train_features_relation)
df['cluster_label_Entity'] = cluster_model_relation.labels_

Now, we introduce the unlabelled data, preprocess the entities, and create a tf-idf vectorized entities as input to the clustering model. The relations predicted from the clustering model is used for labelling the data. Once we have enough labelled data, we can train a classification model.

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cluster import KMeans
# Extract TFIDF features with 1-2 gramsTFIDF_PARAMS = {
'max_features':80,
'strip_accents': 'ascii',
'stop_words': 'english',
'sublinear_tf': True,
'min_df': 0.003,
}
vectorizer = TfidfVectorizer(**TFIDF_PARAMS)
tfidf_entity_model = vectorizer.fit(inpt['Entities'])
tfidf_entity_features = tfidf_entity_model.transform(inpt['Entities'])
data_array= tfidf_entity_features.toarray()
target_array=cluster_model_relation.predict(data_array)
frame_1 = { 'Entities': sec_stage_inpt, 'Relation' : target_array }
dataframe = pd.DataFrame(frame_1)

We have sufficient labelled data stored in dataframe variable. Further, we will create classification models and check their accuracies.

Random Forest

def evaluate_model(X, y, model):
# define evaluation procedure
cv = RepeatedStratifiedKFold(n_splits=5, n_repeats=3,random_state=1)
# evaluate model
scores = cross_val_score(model, X, y, scoring='accuracy', cv=cv, n_jobs=-1)
return scores
# define the reference model
model_rf = RandomForestClassifier()
# evaluate the model
scores = evaluate_model(X_train, y_train, model_rf)
rf_acc = numpy.mean(scores)
# summarize performance
print('Mean Accuracy: %.3f (%.3f)' % (numpy.mean(scores), numpy.std(scores)))

KNN Model

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors = 7).fit(X_train, y_train)
# accuracy on X_test
accuracy_knn = knn.score(X_test, y_test)
acc_train_knn = knn.score(X_train, y_train)
print("Training Accuracy : ", acc_train_knn)
print ("Testing Accuracy : ", accuracy_knn)
# creating a confusion matrix
knn_predictions = knn.predict(X_test)
cm = confusion_matrix(y_test, knn_predictions)

Naive Bayes

from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB().fit(X_train, y_train)
gnb_predictions = gnb.predict(X_test)
# accuracy on X_test
accuracy_nb = gnb.score(X_test, y_test)
accuracy_train_nb = gnb.score(X_train, y_train)
print ("Training Accuracy : ", accuracy_train_nb)
print ("Testing Accuracy : ", accuracy_nb)
# creating a confusion matrix
cm = confusion_matrix(y_test, gnb_predictions)

SVM - Linear Kernel

from sklearn.svm import SVC
svm_model_linear = SVC(kernel = 'linear', C = 1).fit(X, y)
svm_predictions = svm_model_linear.predict(X_test)
# model accuracy for X_test
accuracy_train_svm_lin = svm_model_linear.score(X_train,y_train)
accuracy_test_svm_lin = svm_model_linear.score(X_test, y_test)
print("Training Score : ", accuracy_train_svm_lin)
print("Testing Score : ", accuracy_test_svm_lin)
# creating a confusion matrix
cm = confusion_matrix(y_test, svm_predictions)

SVM Model with RBF kernel performs the best when working with textual data. Below is the implementation of SVM(RBF kernel) which got accuracy of 96%.

def fitting(X, y, C, gamma):
# Create training and testing samples
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0, stratify=y)
# Fit the model
# Note, available kernels: {‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’}, default=’rbf’
model = SVC(kernel='rbf', probability=True, C=C, gamma=gamma)
clf = model.fit(X_train, y_train)
# Predict class labels on training data
pred_labels_tr = model.predict(X_train)
# Predict class labels on a test data
pred_labels_te = model.predict(X_test)
# Use score method to get accuracy of the model
print('----- Evaluation on Test Data -----')
score_te = model.score(X_test, y_test)
print('Accuracy Score: ', score_te)
# Look at classification report to evaluate the model
print(classification_report(y_test, pred_labels_te))
print('--------------------------------------------------------')
print('----- Evaluation on Training Data -----')
score_tr = model.score(X_train, y_train)
print('Accuracy Score: ', score_tr)
# Look at classification report to evaluate the model
print(classification_report(y_train, pred_labels_tr))
print('--------------------------------------------------------')
# Return relevant data for chart plotting
return X_train, X_test, y_train, y_test, clf
X = entity_features
y = target_array
X_train, X_test, y_train, y_test, clf = fitting(X, y, 1, 'scale')

Accuracy Comparison Bar Graph for different Models

Advantages of Weakly Supervised RE

  1. Minimal number of annotations for relation identification
  2. More relations can be identified, hence higher recall.
  3. It can be used when labelled data is noisy or obtained from an imprecise source.
  4. Weakly Supervision works best when we do not have Domain Expertise, or getting them is very costly.
  5. Weak Supervision can enhance Knowledge Graph by semanticizing short texts using Weakly Supervised Short Text Classification. (Knowledge Graph enrichment)

Disadvantages of Weakly Supervised RE

  1. The set of patterns become more error-prone with each iteration.
  2. New relation types require new seeds (which have to be manually provided)
  3. Must be careful when generating new patterns through occurrences of tuples, e.g. “Microsoft shut down an office in Redmond” could easily be caught by mistake when generating patterns for the “based in” relation.

AmpliGraph

The problem of graph is related to two traditional research problems, i.e., graph analytics and representation learning. Graph embedding, in particular, seeks to represent a graph as low-dimensional vectors while preserving the graph’s structure. On the one hand, while developing classifiers or other predictors, graph analytics seeks to extract relevant information from graph data.

Graph embedding is the process of converting a graph into a low-dimensional space while preserving the graph’s information. It is not easy to embed graphs in low-dimensional spaces. The difficulties of graph embedding are determined by the problem context, which includes embedding input and output.

Let’s use a TensorFlow-based open source framework — AmpliGraph to predict relationships between entities in a knowledge graph.

AmpliGraph’s machine learning models generate knowledge graph embeddings, vector representations of concepts in a metric space.

https://docs.ampligraph.org/en/latest/index.html

AmpliGraph is a collection of neural machine learning models for relational learning, a type of machine learning that involves supervised learning on knowledge graphs. It is a TensorFlow-based open-source library developed by Accenture Labs for predicting links between concepts in knowledge graphs. It is a collection of neural ML models for statistical relational learning (SRL) (also called Relational Machine Learning) — a subdiscipline of AI/ML which deals with supervised learning on knowledge graphs.

AmpliGraph includes the following sub-modules:

  • Datasets: helper functions to load datasets (knowledge graphs).
  • Models: knowledge graph embedding models. AmpliGraph contains TransE, DistMult, ComplEx, HolE, ConvE, ConvKB (More to come!)
  • Evaluation: metrics and evaluation protocols to assess the predictive power of the models.
  • Discovery: High-level convenience APIs for knowledge discovery (discover new facts, cluster entities, predict near duplicates).

Highlights of AmpliGraph

  • It can run on CPUs as well as GPUs to speed-up the training process
  • Its APIs reduce the amount of code required for code predictions in knowledge graphs
  • AmpliGraph base estimators are extensible

The code here has been implemented using AzureML. We have used ComplEx (Complex Embeddings) model for KGE. Step-wise explanation of the code is as follows:

  1. Installation of AmpliGraph
!pip install ampligraph==1.0.3

2. Import required libraries

import ampligraph
import numpy as np
import pandas as pd
import requests #module for making HTTP requests
from ampligraph.datasets import load_from_csv
from ampligraph.evaluation import train_test_split_no_unseen
from ampligraph.latent_features import ComplEx
from ampligraph.evaluation import evaluate_performance
from ampligraph.utils import create_tensorboard_visualizations

3. Import the dataset and create entities as input variables and relations as target variable.

X = load_from_csv('.', 'dataset.csv', sep=',')
entities = np.unique(np.concatenate([X[:, 0], X[:, 2]])
relations = np.unique(X[:, 1])

4. Perform train-test split to create training and test sets from the dataset

from ampligraph.evaluation import train_test_split_no_unseen
X_train, X_test = train_test_split_no_unseen(X, test_size=10)
print('Train set size: ', X_train.shape)
print('Test set size: ', X_test.shape)

5. Instantiate the ComplEx model

model = ComplEx(batches_count=100,
seed=0,
epochs=200,
k=150,
eta=5,
optimizer='adam',
optimizer_params={'lr':1e-3},
loss='multiclass_nll',
regularizer='LP',
regularizer_params={'p':3, 'lambda':1e-5},
verbose=True)

6. Fit the model to training data

tf.logging.set_verbosity(tf.logging.ERROR)
model.fit(X_train, early_stopping = False)0

Finally, we evaluate and make predictions. The sample output is shown below. Given entities and relations as a statement, our model predicts how accurate the relation holds for the entities. For example: Office 365 commercial(Entity1), 0%(Entity2), the relation Constant Currency Impact is true with 0.998104 probability.

Use AmpliGraph in the following cases:

  • Discover new knowledge from an existing knowledge graph.
  • Complete large knowledge graphs with missing statements.
  • Generate stand-alone knowledge graph embeddings.
  • Develop and evaluate a new relational model.

Further, we can use the AmpliGraph model that we trained to build a Knowledge Graph. To visualize, we can use the Networkx library in python. Below is the implementation of networkx to build and view knowledge graph on Microsoft Earnings document.

# create a directed-graph from a dataframe
G=nx.from_pandas_edgelist(kg_df, "source", "target", edge_attr=True, create_using=nx.MultiDiGraph())
plt.figure(figsize=(12,12))
pos = nx.spring_layout(G)
nx.draw(G, with_labels=True, node_color='skyblue', edge_cmap=plt.cm.Blues, pos = pos)
plt.show()
Knowledge Graph

If we want to draw a knowledge graph on a particular relation, say Constant Currency Impact, we can define it in the code.

G=nx.from_pandas_edgelist(kg_df[kg_df['edge']=="Constant Currency Impact"], "source", "target",
edge_attr=True, create_using=nx.MultiDiGraph())
plt.figure(figsize=(18,18))
pos = nx.spring_layout(G, k = 0.5) # k regulates the distance between nodes
nx.draw(G, with_labels=True, node_color='skyblue', node_size=1500, edge_cmap=plt.cm.Blues, pos = pos)
plt.show()
Knowledge Graph on Constant Currency Impact

Conclusion

In summary, Knowledge Graphs are at the crossroads of Data Base and Artificial intelligence to provide intelligent insights (or Knowledge) from very different data types. Decision-makers can store all business knowledge as connected vectors and use artificial neural networks to reason using this information. The financial sector competes on data. Unless companies can quickly find the information they need to make decisions, they jeopardize their future. Knowledge graphs help companies extract more value from their data by making it easier to retrieve and analyze. They mimic the way humans think, linking concepts via relationships. This model results in a store of information that is both machine and human-readable. It layers context and meaning on top of the data itself. With a knowledge graph in its back pocket, a financial services company can see its data more effectively and use it more efficiently.

--

--