Understanding Ontologies and Knowledge Graphs

Anjaneya Tripathi
CodeX
Published in
5 min readMar 27, 2021

Knowledge graphs have taken many by storm. Its ability to represent data and derive inferences have proved to be a game changer for information representation and retrieval. In this article, we shall go through ontologies, discuss a few examples. We then dive into knowledge graphs and discuss an interesting application as well.

What is an Ontology?

An ontology models generalized data, that is, we take into consideration general objects that have common properties and not specified individuals. A ‘building’ would be a generalized model while the ‘Taj Mahal’ is a specific entity. Using these models, we create a conceptualisation which is a simplified and abstract view of the data we have with us. You may be wondering, why ontologies in the first place right? The reason is that is provides a way in which humans and machines can easily interpret the data and perform actions on them.

Components of an Ontology

  1. Individuals: Things that can be named in the data (eg. Jack, How to Train Your Dragon etc.)
  2. Classes: A collection of individuals
  3. Properties: These form a connection between an individual and a value (eg. humans have a property of 2 legs, Jack has a salary of one million dollars etc.)
  4. Relationships: Defines how two individuals are related to each other (Jack is the father of Tom ie. Jack → isFather → Tom)
  5. Axioms: An integral part of ontologies, they help us to derive assumptions from the data and make inferences.

Understanding Ontologies with an Example

Using the tables given below, we will identify the classes, relationships, properties and then form the ontology. Using this ontology, we will construct a knowledge graph!

Table 1
Table 2
Table 3

The classes that have been observed in our dataset are — Player, Owner, Team and Country. After identifying the classes, we can proceed to draw relationships between them.

  1. Team → hasCaptain → Player
  2. Player → homeCountry → Country
  3. Team → ownedBy → Owner

We will also list some properties of the classes.

  1. Team → hasWon → Wins
  2. Owner → is → Type of Owner (business or individual)

With that done, let us proceed to create our knowledge graph! However, let us first understand what a knowledge graph is.

Knowledge Graphs, what are they?

A knowledge graph is the representation of entities that are linked to each other. It gives a representation that is easy for humans as well as for machines to understand. In addition to this, a knowledge graph is dynamic, that is, it can provide new inferences and remodel itself with the addition of new data over time. As a result, unlike traditional approaches, a knowledge graph is neither dormant nor does it require to be updated manually.

Source: Pinterest

Continuing from where we left off, after we have defined the ontology, we identify the entities in the data with us and find the relationships, properties and then link them to each other.

Using the classes and relationships defined earlier, we have constructed a knowledge graph of the same data, cool isn’t it?

Knowledge graph constructed on the IPL dataset

The code for the above can be found at this link. You can star and fork the repository and tinker around with it.

Apart from what we have done above, we can construct a knowledge graph on large chunks of text. The knowledge graph below was done on the plot of movie called Drishyam 2.

A knowledge graph constructed on the plot of Drishyam 2

The code for the construction of the graph can be found at this link.

Using Knowledge Graphs to Answer Questions

An interesting application of knowledge graphs are answering questions. How does this work? Well, you can visualise it as a typical graph with the entities and relationships as edges. In addition to this, each edge also has an association score. This association score tells us the likelihood that the node connected to our subject node has the correct answer. The association score can be understood as the confidence. So every time a question is asked, we go to the concerned node and select the linked node with the highest association score or some other parameter.

Source: Go Fish Digital

Conclusion

I hope that you all have understood the basics of ontologies and knowledge graphs and how they are way forward for information representation and retrieval.

You can check out a project I have done on knowledge graphs and ontologies on the Litigation Releases provided by the US Security and Exchange Commission.

Feel free to connect with me on LinkedIn! 😃

--

--