The Great Bat-Name Debate: Can NLP and KR Solve Sheldon's Riddle?
Even the brilliant Dr. Sheldon Cooper can get stumped by a good riddle. In a classic episode of "The Big Bang Theory," Sheldon presents a seemingly simple question to his friends Leonard and Penny, but it quickly spirals into a hilarious exploration of language, logic, and the complexities of superhero identities.
# Bazinga! Can we solve the Great Bat-Identity Crisis?
Let's see the scene first and then a small transcript of it :
https://www.youtube.com/watch?v=1ZzFFkYdjWA
Transcript :
Series 09 Episode 21 - The Viewing Party Combustion
Scene 1: The comic book store.
Sheldon: I have a question about Batman. Batman is a man who dresses up like a bat. Man-bat is a part man, part bat hybrid. Now, if Man-Bat dressed up as a man to fight crime, would he be Man-Batman?
Leonard: No, he’d be Bat-Man-Bat.
Raj: But wouldn’t Man-Batman just be a Batman that was bitten by a radioactive man?
Howard: But Batman is a man. You’re talking about a man who would have the powers of a man. That’s just Man-Man.
Sheldon: Well, isn’t Man-Man just Man?
Leonard: But what if Man-Man dressed as a bat?
Raj: Well, that’s just Batman.
Leonard: No, if a man dresses as a bat, that’s Batman, but if Man-Man dresses as a bat, that’s Batman-Man.
Howard: So does that answer your question?
Sheldon: Oh, I haven’t asked it yet.
Scene 2: Leonard’s bedroom.
Sheldon: (Knock, knock, knock) Leonard. (Knock, knock, knock) Leonard. (Knock, knock, knock) Leonard.
Leonard: What?
Sheldon: I never got to ask my question about Batman.
Leonard: What is it?
Sheldon: If Batman were bitten by a radioactive Man-Bat, and then fought crime disguised as Man-Bat, would he be Man-Bat-Man-Bat-Man or simply Man-Bat-Man-Bat-Batman?
Penny: Is he still wearing the Batman suit under the Man-Bat suit?
Sheldon: I’ll be back.
And the question stands for itself. Let's see if we can figure this out using KR and NLP, respectively :D
Method 1 (Definitive) : KR in AI
Let's first figure this out using the traditional and reliable Knowledge Representation (KR) in AI :
The main question is :
If Batman were bitten by a radioactive Man-Bat, and then fought crime disguised as Man-Bat, would he be Man-Bat-Man-Bat-Man or simply Man-Bat-Man-Bat-Batman?
We will try to solve with a vague overview of KR in AI so as not to overwhelm the new readers, students, etc.
-
Define Entities and Relationships:
-
Entities: Batman, Man-Bat, Radioactive Man-Bat
-
Properties: IsBatman, IsManBat, IsRadioactive
-
-
Formalize Relationships:
-
Batman can become a Man-Bat if bitten by a radioactive Man-Bat.
-
Batman fights crime.
-
-
Reasoning with Logical Rules:
-
If Batman is bitten by a radioactive Man-Bat, then he becomes a Man-Bat.
-
If Batman, as Man-Bat, fights crime, he is still Batman in essence.
-
# Diagrammatic Representation of the question :
Batman --(bitten by radioactive Man-Bat)--> Man-Bat --(fights crime)--> Man-Bat-Man-Bat-Man OR Man-Bat-Man-Bat-Batman
# Mathematical and Logical Notation
-
Define Variables:
-
Let
BMbe Batman. -
Let
MBbe Man-Bat. -
Let
RMBMbe Radioactive Man-Bat.
-
-
Define Predicates:
-
IsBatman(BM): B is Batman. -
IsManBat(X): X is a Man-Bat. -
Bitten(X, Y): X is bitten by Y. -
FightsCrime(X): X fights crime.
-
-
Logical Rules:
-
Rule 1:
Bitten(BM, RMBM) → IsManBat(BM) -
Rule 2:
IsManBat(BM) ∧ FightsCrime(BM) → (IsBatman(BM) ∨ IsManBat(BM))
-
# Reasoning Process
-
Initial State:
-
IsBatman(BM) -
RMBMexists.
-
-
Transition:
-
Batman (BM) is bitten by a radioactive Man-Bat (RMBM):
Bitten(BM, RMBM) → IsManBat(BM)
-
-
Result:
-
Now, Batman (BM) is a Man-Bat (MB) and fights crime:
-
IsManBat(BM) ∧ FightsCrime(BM) → IsBatman(BM) ∨ IsManBat(BM)
-
Initial State
+------+
| |
v |
+----+ |
| B | |
+----+ |
| |
v |
Bitten by RMB
+------+
| |
v |
+---------+
| MBBM |
+---------+
|
v
Fights Crime as Man-Bat
|
v
+----------+
| MBMBBM |
+----------+
|
v
Man-Bat-Man-Bat-Batman (MBMBBM)
# Logical Breakdown
-
Initial Batman is represented as
BM. -
Man-Bat is represented as
MB.
# Transformations
-
First Transformation:
-
Batman (
BM) bitten by Man-Bat (MB). -
Result:
B→MBBM.
-
-
Second Transformation:
-
Man-Bat (
MBBM) fights crime disguised as Man-Bat (MB). -
Result:
MBBM→MBMBBM.
-
Now let us see how modern advancements in natural language processing (NLP) can tackle the same conundrum.
As Sheldon Cooper once quipped, "What's life without whimsy?"

This approach not only backs up our earlier findings but does so with the kind of computational skill that brings to mind Leonard's experiments and Howard's engineering talents. Below, I'll showcase the practical application of NLP using PyTorch to solve the Batman conundrum, transitioning from our KR model to a sophisticated NLP model.
Method 2 (Data dependent) : NLP

Let's first figure this out using NLP :
The main question is :
If Batman were bitten by a radioactive Man-Bat, and then fought crime disguised as Man-Bat, would he be Man-Bat-Man-Bat-Man or simply Man-Bat-Man-Bat-Batman?
We will try to solve with a vague overview of NLP so as not to overwhelm the new readers, students, etc. That's why I used Google's t5 model in it. :D
First things first, GitHub link : https://github.com/AdityaSeth777/nlp-sheldon
So, there are two things that needs to be said here :
-
What did I do in there ?
-
How can anyone run it and find the answer ?
# What did I do in there ?

Great, let me tell you this by first introducing the file structure of the NLP project.
│ .gitattributes
│ LICENSE
│ README.md
│ requirements.txt
├───data
│ dialogues.json
├───image
│ └───1717607383577.png
├───scripts
│ infer.py
│ train.py
└───utils/
├── │ data_preprocessing.py
├── └── __init__.py
-
Data Preprocessing (data_preprocessing.py)
-
Cleaning: Removing unnecessary characters or formatting issues.
-
Tokenization: Breaking down the input text into smaller parts (tokens) that the model can understand.
-
Padding: Ensuring all sequences are of the same length by adding padding tokens where necessary.
-
Encoding: Converting text into numerical format that the model can process.
-
Data preprocessing ensures that the data is in the right format for training and inference, making the model more effective.
-
Training the Model (train.py)
-
Loading and Configuring the Model: Using a pre-trained transformer model (like Google's T5) and adapting it for the specific task.
-
Preparing the Data: Creating training and validation datasets using preprocessed data.
-
Training Loop:
-
Forward Pass: Feeding input data to the model to get predictions.
-
Loss Calculation: Comparing predictions with the actual labels to calculate the error.
-
Backward Pass and Optimization: Adjusting the model’s parameters to reduce the error in subsequent iterations.
-
-
Training equips the model to generate accurate and meaningful responses to queries about Batman.
-
Inference (infer.py)
-
Loading the Trained Model and Tokenizer: Ensuring the model and tokenizer are ready for inference.
-
Encoding Input Text: Converting new input text into a format suitable for the model.
-
Generating Output: The model processes the input and generates a response.
-
Decoding the Response: Converting the model’s numerical output back into human-readable text.
-
And after doing all of these things, what's the output after around 20-30 errors, sleepless nights, and training countlessly ?
# Output :

I mean this is definitely not the traditional and best method to solve it, but I had free time, so why not ? :D
Coming to the next question,
# How can anyone run it and find the answer ?

# Project Overview
This project consists of two main scripts:
-
train.py: For training the model on custom dialogue datasets. -
infer.py: For generating responses using the trained model.
# Setup Instructions
# Prerequisites
-
Python 3.7 or later
-
PyTorch
-
Transformers library by Hugging Face
-
Git
# Installation
-
Clone the repository.
-
Create a virtual environment and activate it.
-
Install the required packages, by using
pip install -r requirements.txt
# Model and Tokenizer
Ensure you have the pre-trained Google's t5 model and tokenizer saved in the models directory:
-
models/t5_model -
models/t5_tokenizer
If not, use the train command to train and save the models.
# Usage
# Training
To train the model, use the train.py script. Ensure your training data is properly preprocessed and available.
# Inference
To generate responses using the trained model, use the infer.py script.
# Conclusion ƪ(˘⌣˘)ʃ
So, before concluding, I want to say that there were two phases of me before starting this project and after completing this project.
-
Before starting, I was this :

-
After this project, I was this :
So, yes now if you meet someone who matches your taste in old sitcoms and romcoms, then you can say confidently that you know the answer to the riddle asked in The Big Bang Theory S9E21. Although, the odds of having this conversation is like 1 in 18M (Got the reference ? :D)
Reason to do this : I was relaxing after completing my freelancing projects and thought to do delve into ML. Also, this particular episode was on so I though to myself, why not ? :D
Happy reading, y'all.
Aditya.

If you want to contact me, feel free to drop an e-mail at [email protected] or check out my website at adityaseth.in :)
Also, here’s my LinkedIn.
Thank you everyone for reading,
Over and out,
Aditya Seth.
Comments