You are on page 1of 8

How Does Akinator

Work Using Python?


Welcome to the world of Akinator! This presentation will guide you through the
fascinating algorithm behind Akinator and show you how to implement it using
Python.
Introduction
What is Akinator?

Akinator is an artificial intelligence program that can guess any real or fictional
character you're thinking of through a series of questions.

Purpose of the Presentation:

To provide an in-depth understanding of how Akinator works and showcase the


Python code for its implementation.
How Akinator Works
Algorithm Overview:

Akinator uses a decision tree algorithm to narrow down the possibilities based on
the user's responses to a series of questions.

Question-Response System:

Akinator asks a series of yes or no questions to gather information and eliminate


characters based on the user's answers.

Data Storage and Retrieval:

Akinator stores character information in a structured database and retrieves it


based on user interactions.
Implementing Akinator in Python
import akinator

aki = akinator.Akinator()

q = aki.start_game()

while aki.progression <= 80:


a = input(q + "\n\t")
if a == "b":
try:
q = aki.back()
except akinator.CantGoBackAnyFurther:
pass
else:
q = aki.answer(a)
aki.win()

correct = input(f"It's {aki.first_guess['name']}


({aki.first_guess['description']})! Was I correct?\
n{aki.first_guess['absolute_picture_path']}\n\t")
sample code:
database = [ {"name":"Iron man", "human":True, "youtuber":False, "movie":True , "original":False,
"inventor":True, "indian":False},

{"name": "Einstein", "human": True, "youtuber": False, "movie": False,


"original": True, "inventor": True,"indian": False},

{"name": "Carry Minati", "human": True, "youtuber": True, "movie": False,


"original": True, "inventor": False,"indian": True},

{"name": "PewDiePie", "human": True, "youtuber": True, "movie": False,


"original": True, "inventor": False,"indian": False},

{"name": "Nemo", "human": False, "youtuber": False, "movie": True, "original":


False, "inventor": False,"indian": False},

{"name": "Narendra Modi", "human": True, "youtuber": False, "movie": False,


"original": True, "inventor": False,"indian": True},

{"name": "Mukesh Ambani", "human": True, "youtuber": False, "movie": False,


"original": True, "inventor": True,"indian": True},

def take_chance(answer, property): if answer == "y": ans = True else: ans = False

to_remove=[]
for d in database:
Logic behind the guessing game ?
• Root Node: Is the topmost in a tree data structure.
• Internal Nodes : Test for the value of a certain attribute or feature.
• Branch : Correspond to the outcome of a test and connect to the next Internal Node or Leaf Node (black
straight line in the figure).
• Leaf Nodes : Terminal nodes that predict the outcome (represent class labels or class distribution).

Now the question that arises is:

how to choose the best attribute to replace in the Root Node of the previous figure?

Suppose that we have a set of instances data set called S. We split this set into S_1 and S_2 and also assume that we
have two classes denoted by C+ and C-. For instances, the best situation is when S_1(+)= C+ and S_1(-)=∅ or
S_1(+)= ∅ and S_1(-)=C-. In this case, the two children of the division are said to be Pure.

To know the impurity or purity of a data set, We can measure the impurity of a set of n+ labelled positives and n−
labelled negatives and then compute the Empirical Probability:
Conclusion: Unveiling the Python Magic in
Akinator
In conclusion, the impact of Python in the creation of Akinator is nothing short of magical. Python's versatility and
adaptability have shaped Akinator into the enchanting guessing game millions around the world have come to love.

Python as the Architect of Logic: At the heart of Akinator's intelligence lies Python, orchestrating the intricate
dance of algorithms that captivate users. Python's readability and expressive syntax make it not just a programming
language but the architect of Akinator's logical prowess.

The Backbone of Backend Brilliance: Python's role in the backend development of Akinator cannot be
overstated. From managing user sessions to processing the guessing algorithm, Python ensures the seamless
orchestration of the game's mechanics. Its scalability features contribute to the robustness that allows Akinator to
gracefully handle the ebb and flow of user traffic.

The Canvas for Web Masterpieces: In crafting the user interface and ensuring an interactive web experience,
Python, in tandem with frameworks like Flask or Django, acts as the canvas for web masterpieces. Akinator's
frontend, shaped by Python's web development capabilities, provides users with an immersive and delightful
journey.
Citations
1. https://pypi.org/project/akinator.py/
2. https://en.akinator.com/
3. akinator.py — akinator.py 1.1.1 documentation
4. https://medium.com/analytics-vidhya/building-akinator-with-python-usin
g-bayes-theorem-216253c98daa

You might also like