Teaching Machines to Read Our Scribbles: A Journey Through Machine Learning and Neural Networks
Tazkera Sharifi
AI/ML Engineer @ Booz Allen Hamilton | LLM | Generative AI | Deep Learning | AWS certified | Snowflake Builder DevOps | DataBricks| Innovation | Astrophysicist | Travel
We've all been there - writing a quick note or scribbling down a number in a hurry. It's easy for us to read our own writing (well, most of the time!). But how does a machine, like a computer or a smartphone, make sense of it? Did you ever stop to think how machines manage to decipher our varied, and sometimes untidy, penmanship? If not, then you've already encountered the incredible world of handwritten digit recognition
In this case study, we'll embark on a fascinating journey, starting with the basics. We'll explore how a neural network is trained to recognize just two handwritten digits: '0' and '1'. This task, known as binary classification, is where our adventure begins.
But we won't stop there.
Once we unravel the mystery behind recognizing these two digits, we'll scale up to a more complex and intriguing challenge: recognizing all 10 digits (0-9). This next step, known as multiclass classification, opens up a whole new world of understanding Machine Learning and role of Neural networks
The Challenge: Utilizing neural network methods to recognize handwritten digits.
Data Insight:
Let's dive into the visualization:
We loaded the dataset containing images of these digits and their corresponding labels. Then, it randomly selects 64 images, reshapes them to their original 20x20 pixel size, and arranges them in an 8x8 grid for display. The resulting visual shows the variety in how people write the numbers 0 and 1. It's a neat way to see how machine learning can interact with something as personal and unique as handwriting!
Why we need Neural Network in this case:
For handwriting recognition, neural networks act as a complex pattern recognizer
A data scientist's role is essential in weaving these complex decisions together to create a model that can recognize handwritten digits accurately and effectively.
Here we will deploy and test performances for 3 prominent activation functions for NN: ReLU, Sigmoid and Linear
the code snippet defines a simple neural network architecture using TensorFlow Keras
A dense (fully connected) layer with 128 neurons and the provided activation function.
2nd dense layer with 64 neurons and the provided activation function.
A final 3rd dense layer with 1 neuron and the 'sigmoid' activation function to output a probability that the image is a 1 (or 0).
The model is compiled using the Adam optimizer
Finally, the model is trained on the training data for 50 epochs and also evaluates its performance on the test data at the end of each epoch.
领英推荐
These three models are like the "reaction" a neuron gives to the information it receives.
Now, why is the model struggling with Sigmoid in recognizing handwritten images?
So when it comes to recognizing letters from squiggly handwriting. ReLU and Linear are like detectives that can jump on strong clues, while Sigmoid is more cautious and might miss those clues, thus performing less accurately.
These activation functions are like tuning how our model thinks, and in this case, ReLU and Linear seem to think in a way better suited for recognizing handwriting.
Next stage: Multi-Layer Perceptron (MLP)
Let's elevate our game! We're constructing a mighty Multi-Layer Perceptron (MLP) to decode the intricate art of handwritten digits, ranging from 0 all the way to 9.
By designing this sophisticated neural architecture, we're essentially crafting a digital maestro, adept at distinguishing the nuanced curves and strokes of every single handwritten number. So, whether it's a hastily scribbled '3' or a meticulously crafted '9', our neural maestro is on the task, ready to recognize and classify!
Here our final activation function is softmax, because for multiple class neural network for classification tasks, it is the most useful function.
We're again using the Adam optimizer, with the curated loss function categorical_crossentropy which measures how well the predicted probabilities match the actual labels. Our aim during training is to maximize the accuracy!
After rigorously training for 120 epochs, our MLP model demonstrates robust performance. The accuracy on both training and validation datasets converges at an impressive approximate rate of 95%. This showcases the model's capability to reliably recognize a wide array of handwriting styles and nuances.
Let's take a closer look at some images that even our meticulously trained model misclassified. To be fair, some of these handwritten digits are so intricate that they might stump even the keenest human eye. It's a gentle reminder that while our neural network is powerful, deciphering tricky handwriting remains a challenging task for any entity.
Truth be told, a few of these handwritten samples are so intricate they'd leave many of us scratching our heads. While our neural network has achieved a commendable feat, it highlights the intriguing challenge that intricate handwriting poses, even in the age of AI.
In conclusion, the realm of neural networks and machine learning stands as a testament to the advancements we've made in technology. Yet, the nuances of human behavior, like our unique handwriting styles, remind us of the delightful intricacies that make us human. As data scientists, every misclassified image isn't just an error; it's an opportunity, a puzzle waiting to be solved. The journey in machine learning isn't just about perfection; it's about the chase, the learning, and the endless possibilities that lie ahead.
Connect with me on LinkedIn as we continue to traverse this captivating world of AI together. Tazkera Haque | LinkedIn
Data Analyst | Power BI Consultant | Transforming Data into Strategic Business Decisions | SQL | Excel
1 年Great project Tazkera! Lots to learn from you ??
Data-Driven Mainframe developer| Data Analyst
1 年You always come up with interesting projects! Great job on this one as well Tazkera!
Data Analyst || Lab informatics || MS 2023
1 年This is such a cool topic. Thanks for sharing this.
Board Chair at United Way of Southeast MN | Fostering Lasting Community Impact | Passionate advocate | Career Coach | Writer | Servant Leader | Accredited Media Manager | Photographer/Videographer
1 年Awesome!
Computational Chemist | Data Scientist | Artificial Intelligence | Multidisciplinary Collaborator | Machine Learning | Mentor | Outdoor Enthusiast
1 年Great work and write-up, very interesting!