1. Learning Objectives
By the end of this lesson, you will be able to:
-
Understand the theoretical foundations of knowledge graphs (KGs) and their role in organising financial information.
-
Design a financial ontology using description logics and formalise it in OWL/RDF.
-
Formulate the construction pipeline: entity extraction, entity linking (disambiguation), relation extraction, and knowledge fusion as a probabilistic graphical model.
-
Apply graph embedding techniques (TransE, DistMult, ComplEx) and derive their optimisation objectives for link prediction.
-
Implement graph neural networks (GCN, GAT, R-GCN) for node classification and link prediction on financial KGs.
-
Evaluate KGs using link prediction metrics (MRR, Hits@N) and entity resolution metrics.
2. Knowledge Graphs in Finance: Theoretical Foundations
2.1 Definition and Representation
A knowledge graph is a directed labelled graph G = (V, E, L) where:
-
V is a set of nodes (entities: companies, persons, financial instruments, events).
-
E ⊆ V × V is a set of directed edges (relations:
acquires,subsidiary_of,employs,reports_earnings). -
L is a set of labels (types for nodes and relations).
Formally, a KG is a set of triples (h, r, t) where h ∈ V (head), t ∈ V (tail), and r ∈ R (relation type). Additionally, nodes may have attributes (key-value pairs) attached.
2.2 Ontology and Schema
An ontology defines the vocabulary and constraints: node types (e.g., Company, Person, Instrument), relation types, domains and ranges, cardinalities, and inheritance. In description logic (DL), we can express axioms such as:
-
Company ⊑ Organization -
acquires ⊑ (Company × Company) -
∃employs.Person ⊑ Company(every company employs some person)
The ontology ensures semantic consistency and enables reasoning (e.g., inferring that a subsidiary is also an organization).
Standard financial ontologies:
-
FIBO (Financial Industry Business Ontology): OMG standard covering corporate structures, financial instruments, and markets.
-
EDGAR schema: used by the SEC for structured filings.
-
Schema.org with extensions for financial products.
Formalisation in OWL: Classes, properties, and individuals are defined using RDF/XML or Turtle syntax. Reasoning engines (e.g., HermiT, Pellet) can check consistency and infer new triples.
3. Knowledge Graph Construction Pipeline
Building a KG from unstructured and structured sources involves several stages, each of which can be modelled as a probabilistic inference problem.
3.1 Named Entity Recognition (NER) – Sequence Labelling Revisited
Given a token sequence x = (x₁, …, x_T), we assign labels y_t ∈ 𝒴 (BIO scheme). This is a structured prediction problem; we use a CRF or BiLSTM‑CRF as covered in Lesson 6.3. The output is a set of entity mentions with their spans and types.
3.2 Entity Linking (Disambiguation)
Entity linking maps a mention m (e.g., “Apple”) to a unique KG node e ∈ V. This is a classification problem over candidate entities C(m) (obtained from a dictionary or via search). The probability of entity e given mention m and context c is:
P(e∣m,c)=exp(score(e,m,c))∑e′∈C(m)exp(score(e′,m,c))
The score can be based on:
-
Prior probability: P(e | m) from Wikipedia hyperlinks.
-
Context similarity: cosine similarity between the mention context embedding and the entity description embedding (e.g., using BERT).
-
Popularity: e.g., PageRank of the entity.
Training is typically done with a max‑margin or cross‑entropy loss over positive and negative entity candidates.
Example: The mention “Apple” in “Apple reported record earnings” should link to dbpedia:Apple_Inc., not to the fruit.
3.3 Relation Extraction – As a Classifier
Given a sentence s and two entity mentions e₁ and e₂, we predict a relation r from ℛ (or NA). This is a multi‑class classification problem:
P(r∣s,e1,e2)=softmax(W⋅ψ(s,e1,e2)+b)
where ψ is a feature vector. In neural models, ψ is derived from the contextualised representations of the entity spans (e.g., using BERT and pooling).
Distant supervision: We generate training data by aligning entities from a KG with text. If a sentence mentions both h and t and the KG contains (h, r, t), we label the sentence with r. This is noisy (the sentence may not express that relation). We can use multi‑instance learning: for a bag of sentences mentioning the same entity pair, we predict the relation if at least one sentence is positive.
3.4 Knowledge Fusion and Conflict Resolution
When integrating multiple sources (e.g., news, SEC filings, Wikipedia), we may encounter conflicts (e.g., different revenue numbers). We can model fusion as a probabilistic graphical model where each source has a reliability weight. For each triple (h, r, t), we aggregate evidence from all sources using a weighted vote or a Bayesian approach:
P(true(h,r,t)∣evidence)∝∏source iP(evidencei∣true(h,r,t))λi
where λ_i are source reliability parameters estimated from data.
4. Graph Embeddings for Link Prediction
Once we have a KG, we want to learn vector representations for nodes and relations that enable link prediction (predicting missing triples). The key idea is to define a scoring function f_r(h, t) that measures the plausibility of a triple.
4.1 Translational Models: TransE
TransE models relations as translations in the embedding space. For a triple (h, r, t), we want:
h+r≈t
where h, r, t ∈ ℝᵈ. The scoring function is:
fr(h,t)=∥h+r−t∥22
Training: We minimise a margin‑based ranking loss:
L=∑(h,r,t)∈T∑(h′,r,t′)∈T′max(0,γ+fr(h,t)−fr(h′,t′))
where:
-
𝒯 is the set of positive triples.
-
𝒯’ is a set of negative triples (corrupted by replacing h or t with a random entity).
-
γ > 0 is the margin.
Limitation: TransE cannot model 1‑N, N‑1, and N‑N relations well (e.g., a company has many subsidiaries). The translation assumption forces a single embedding for each relation.
4.2 Semantic Matching Models: DistMult and ComplEx
DistMult uses a bilinear scoring function:
fr(h,t)=h⊤diag(r)t=∑i=1dhi⋅ri⋅ti
This is symmetric (f_r(h,t) = f_r(t,h)), so it cannot model asymmetric relations (e.g., acquires is not symmetric). ComplEx extends DistMult to complex embeddings to handle asymmetry:
fr(h,t)=Re(h⊤diag(r)t‾)
where h, r, t ∈ ℂᵈ, and \overline{\mathbf{t}} is the complex conjugate. This allows the model to capture both symmetric and antisymmetric relations.
Training: Similar to TransE, using a logistic loss or cross‑entropy with negative sampling.
4.3 Evaluation Metrics for Link Prediction
We evaluate on a test set of triples. For each test triple (h, r, t), we corrupt the tail (or head) with all other entities and rank the correct one among the corruptions. We report:
-
Mean Reciprocal Rank (MRR): average of 1/rank over all test triples.
-
Hits@N: percentage of test triples where the correct entity is ranked in the top N (often N=1, 3, 10).
Mathematically, for a set of test triples T_test:
MRR=1∣Ttest∣∑(h,r,t)∈Ttest1rank(t∣h,r)
Hits@N=1∣Ttest∣∑(h,r,t)∈TtestI[rank(t∣h,r)≤N]
5. Graph Neural Networks (GNNs) for Financial KGs
GNNs learn node representations by aggregating information from neighbours. This is powerful for propagating risk signals, predicting creditworthiness, or recommending investments.
5.1 Graph Convolutional Network (GCN)
For a graph with adjacency matrix A (size N × N) and node feature matrix X (N × F), a GCN layer computes:
H(l+1)=σ(D~−1/2A~D~−1/2H(l)W(l))
where:
-
\tilde{A} = A + I_N (self‑loops).
-
\tilde{D} is the diagonal degree matrix of \tilde{A}: \tilde{D}{ii} = Σ_j \tilde{A}{ij}.
-
H^(l) is the node feature matrix at layer l (H^(0) = X).
-
W^(l) is a learnable weight matrix (size F^(l) × F^(l+1)).
-
σ is a non‑linearity (e.g., ReLU).
Interpretation: The term \tilde{D}^{-1/2} \tilde{A} \tilde{D}^{-1/2} normalises the adjacency matrix so that the aggregation is a weighted average of neighbour features. This avoids numerical instability and allows stacking multiple layers.
Application: Predict the credit risk of a company based on the features of its suppliers and customers.
5.2 Graph Attention Network (GAT)
GAT introduces an attention mechanism to weight neighbours differently:
hi(l+1)=σ(∑j∈N(i)αijWhj(l))
where the attention coefficient α_{ij} is computed as:
αij=exp(LeakyReLU(a⊤[Whi(l)∥Whj(l)]))∑k∈N(i)exp(LeakyReLU(a⊤[Whi(l)∥Whk(l)]))
Here, a is a learnable weight vector, and || denotes concatenation. The attention allows the model to focus on the most relevant neighbours, which is useful in financial networks where different relations have different importance.
5.3 Relational Graph Convolutional Networks (R‑GCN)
R‑GCN extends GCN to multi‑relational graphs. It uses relation‑specific weight matrices:
hi(l+1)=σ(∑r∈R∑j∈Nr(i)1∣Nr(i)∣Wr(l)hj(l)+W0(l)hi(l))
where:
-
𝒩ᵣ(i) is the set of neighbours of i under relation r.
-
Wᵣ^(l) is a relation‑specific weight matrix.
-
W₀^(l) is a self‑loop transformation.
This is ideal for financial KGs with many relation types (e.g., acquires, competes_with, supplies). However, the number of parameters grows with |ℛ|, so we often use basis decomposition or block‑diagonal matrices to regularise.
6. Reasoning and Querying Over Financial KGs
Once the KG is constructed, we can perform logical reasoning and complex queries.
Logical inference: Using the ontology, we can infer new triples. For example, if Company A is a Subsidiary of Company B, and Company B is a Subsidiary of Company C, then Company A is a Subsidiary of Company C (transitivity).
Query answering: Use SPARQL or graph traversal to answer questions like “Find all companies that are suppliers of Apple and have revenue > $1B.”
Path‑based reasoning: In a KG, paths can be used to infer relations. For example, if we have a path (Company A) --produces--> (Product X) --competes_with--> (Product Y) --produced_by--> (Company B), we might infer that Company A and Company B are competitors. This can be modelled using Path‑Ranking Algorithms or Compositional Embeddings (e.g., using TransE composition: r_comp = r₁ + r₂).
7. Evaluation of KG Quality
-
Link prediction: MRR, Hits@N on held‑out triples.
-
Entity resolution: F1 score for entity linking against a gold standard.
-
Completeness: Compare the KG against a manually curated subset; measure recall of known facts.
-
Consistency: Check for logical contradictions using an OWL reasoner.
-
Downstream task performance: Use the KG as input to a predictive model and measure performance improvement.
8. Applications in Finance
-
Risk propagation: Traverse the KG to identify indirect exposures (e.g., if a supplier fails, which companies are affected?).
-
Fraud detection: Detect cycles or unusual degree patterns indicating circular ownership.
-
Portfolio construction: Identify companies connected via supply chains or partnerships to diversify risk.
-
Explainable AI: Use paths in the KG to explain predictions (e.g., “This stock is recommended because its main supplier has strong earnings”).
-
Event impact analysis: When news mentions a company, traverse the KG to find affected peers.
9. Summary for the AI Practitioner
-
KGs are powerful for organising financial data; they are defined as sets of triples (h, r, t) with an ontological schema.
-
Construction involves NER, entity linking, and relation extraction – each can be formulated as a probabilistic inference problem.
-
Graph embeddings (TransE, DistMult, ComplEx) are used for link prediction; they map entities and relations to vectors.
-
GNNs (GCN, GAT, R‑GCN) enable node‑level and edge‑level predictions by propagating information across the graph.
-
Evaluation uses link prediction metrics (MRR, Hits@N) and entity resolution metrics.
-
KGs enable reasoning, query answering, and explainability in financial AI systems.
10. References
-
Bordes, A., et al. (2013). Translating embeddings for modeling multi‑relational data. NIPS.
-
Trouillon, T., et al. (2016). Complex embeddings for simple link prediction. ICML.
-
Kipf, T. N., & Welling, M. (2017). Semi‑supervised classification with graph convolutional networks. ICLR.
-
Veličković, P., et al. (2018). Graph attention networks. ICLR.
-
Schlichtkrull, M., et al. (2018). Modeling relational data with graph convolutional networks. ESWC.
-
Nickel, M., et al. (2016). A review of relational machine learning for knowledge graphs. Proceedings of the IEEE.
-
FIBO (Financial Industry Business Ontology) – OMG standard.
-
Noy, N., et al. (2019). Industry‑scale knowledge graphs: Lessons and challenges. Communications of the ACM.