ZyVOP Logo
Content That Connects
SeriesAI NewsCategoriesTags
ZyVOP Logo
Content That Connects

Empowering developers and creators with cutting-edge insights, comprehensive tutorials, and innovative solutions for the digital future.

Content

  • Tags
  • Write Article
  • Newsletter

Company

  • About Us
  • Contact

Connect

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • DMCA Policy
  • Code of Conduct

© 2026 ZyVOP. Crafted with care for the developer community.

Made with ❤️ by the ZyVOP team
All systems operational
HomeTutorialI Thought AI Was Magic Until I Built My Own Model
Tutorial
👍1

I Thought AI Was Magic Until I Built My Own Model

A developer's journey from simple text classification to understanding the core ideas behind machine learning, one prediction at a time.

#AI#machinelearning#Python#beginners
Z
ZyVOP

Senior Developer

June 23, 2026
4 min read
22 views
I Thought AI Was Magic Until I Built My Own Model

When people start learning AI today, they usually jump straight into ChatGPT, Gemini, Claude, or other AI tools.

I almost did the same.

But I kept wondering:

How does an AI model actually learn?

Not how to call an API.

Not how to use an AI service.

How does a machine learn that "hello" is a greeting and "bye" means goodbye?

To answer that question, I decided to build the simplest AI model I could think of.

No APIs.

No GPUs.

No large language models.

Just Python and a small machine learning model.

By the end of this project, I understood:

  • What training data is

  • How text becomes numbers

  • How models make predictions

  • Why AI sometimes makes mistakes

  • Why data is often more important than code

Let's build it together.


Step 1: Create a Project Folder

Create a new directory for the project:

mkdir ai-learning
cd ai-learning

Step 2: Create a Virtual Environment

A virtual environment keeps project dependencies isolated.

Create one:

python3 -m venv venv

Activate it:

macOS / Linux

source venv/bin/activate

Windows

venv\Scripts\activate

If successful, you'll see:

(venv)

at the beginning of your terminal prompt.


Step 3: Install Required Libraries

We'll use a library called scikit-learn.

Install it:

pip install scikit-learn

Verify installation:

pip list

You should see:

scikit-learn
numpy
scipy
joblib
threadpoolctl

Step 4: Create Your First AI Program

Create a file called:

chatbot.py

Add the following code:

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression

texts = [
    "hello",
    "hi",
    "hey",
    "hey there",
    "greetings",
    "good morning",
    "good evening",
    "good afternoon",
    "bye",
    "see you later",
    "what is the price",
    "how much does it cost",
    "pricing information",
]

labels = [
    "greeting",
    "greeting",
    "greeting",
    "greeting",
    "greeting",
    "greeting",
    "greeting",
    "greeting",
    "goodbye",
    "goodbye",
    "pricing",
    "pricing",
    "pricing",
]

At first glance, this looks like a simple list.

But this is actually your training data.


Understanding Training Data

Each message has a matching label.

For example:

Message

Label

hello

greeting

hi

greeting

bye

goodbye

pricing information

pricing

This is how we teach the model.

We're essentially saying:

If you see "hello", the correct answer is "greeting".

If you see "bye", the correct answer is "goodbye".

Machine learning starts with examples.

Lots of examples.


Step 5: Convert Text into Numbers

This was the moment AI stopped feeling like magic.

Add:

vectorizer = CountVectorizer()
X = vectorizer.fit_transform(texts)

print(X.toarray())
print(vectorizer.get_feature_names_out())

Run:

python chatbot.py

You'll see output similar to:

['bye' 'cost' 'good' 'hello' 'hi' 'price' ...]

Why?

Because computers don't understand words.

They understand numbers.

The vectorizer creates a vocabulary and converts every sentence into a numerical representation.

For example:

hello

might become:

[0 0 0 1 0 0 ...]

The computer isn't reading the word.

It's reading numbers.

That realization completely changed how I thought about AI.


Step 6: Train the Model

Now let's teach the machine.

Add:

model = LogisticRegression()

model.fit(X, labels)

This line trains the model.

During training, the model tries to find patterns.

It learns relationships such as:

hello -> greeting
hi -> greeting
bye -> goodbye
price -> pricing

Not because we programmed those rules.

Because it discovered them from the examples.


Step 7: Make Predictions

Let's test it.

Add:

while True:
    user_input = input("\nYou: ")

    if user_input.lower() == "exit":
        break

    user_vector = vectorizer.transform([user_input])

    prediction = model.predict(user_vector)[0]

    print("Intent:", prediction)

Run:

python chatbot.py

Example:

You: hello
Intent: greeting

You: bye
Intent: goodbye

You: pricing information
Intent: pricing

Congratulations.

You just built your first AI model.


When My Model Got It Wrong

Then something interesting happened.

I typed:

pricing

The model replied:

greeting

That didn't make sense.

I thought my code was broken.

It wasn't.

The problem was my data.

I had trained the model using:

pricing information

but never:

pricing

by itself.

The model wasn't making a coding mistake.

It simply hadn't seen enough examples.

This taught me one of the most important lessons in machine learning:

Bad predictions are often caused by bad or incomplete data.


Looking at Probabilities

I wanted to understand how the model was making decisions.

So I added:

print(model.predict_proba(user_vector))

Example:

[[0.20 0.22 0.56]]

The classes were:

['goodbye', 'greeting', 'pricing']

Meaning:

goodbye = 20%
greeting = 22%
pricing = 56%

The model isn't certain.

It's making educated guesses based on probabilities.

The highest probability wins.


Improving the Dataset

To improve the model, I added more pricing examples:

texts.extend([
    "pricing",
    "price",
    "cost",
    "subscription",
    "plan"
])

labels.extend([
    "pricing",
    "pricing",
    "pricing",
    "pricing",
    "pricing"
])

After retraining, the predictions became much more accurate.

The code didn't change.

The algorithm didn't change.

Only the data improved.


The Biggest Lesson

Before building this project, AI felt mysterious.

After building it, I realized the core idea is surprisingly simple:

Training Data
        ↓
Text to Numbers
        ↓
Pattern Recognition
        ↓
Prediction

The models used by modern AI systems are far more advanced.

But the basic idea is still the same.

The most surprising lesson wasn't learning how to train a model.

It was discovering that when the model made a bad prediction, the problem was usually my data—not my code.


What I'm Learning Next

Now that I understand the basics, my next goals are:

  • Save and load trained models

  • Learn TF-IDF vectorization

  • Build a sentiment analysis model

  • Explore embeddings

  • Create a document search assistant

  • Learn PyTorch

  • Build a tiny GPT model from scratch

Every AI journey starts somewhere.

For me, it started with teaching a computer that "hello" is a greeting.

And that small project taught me more about machine learning than I expected.

Z

ZyVOP

Passionate developer sharing knowledge about modern web technologies and best practices.

Comments (0)

Login to post a comment.

Table of Contents

Step 1: Create a Project FolderStep 2: Create a Virtual EnvironmentmacOS / LinuxWindowsStep 3: Install Required LibrariesStep 4: Create Your First AI ProgramUnderstanding Training DataStep 5: Convert Text into NumbersStep 6: Train the ModelStep 7: Make PredictionsWhen My Model Got It WrongLooking at ProbabilitiesImproving the DatasetThe Biggest LessonWhat I'm Learning Next

Stay Updated

Get the latest articles delivered to your inbox.

We respect your privacy. Unsubscribe anytime.

Related Posts

Types of Machine Learning Explained: Supervised vs. Unsupervised vs. Reinforcement Learning

Supervised, unsupervised, and reinforcement learning solve different problems entirely. Learn to tell them apart fast, with three real, tested code demos." excerpt: "Same dataset, three different lenses. Here's how to tell which kind of machine learning problem you're actually solving, before you write any code.

Read article

What Is Machine Learning? A Beginner-to-Pro Guide for 2026

Most explanations of machine learning are wrong. Here's what it actually is, why it beats hardcoded rules, and the one runnable example that makes it click.

Read article

Apple Just Confirmed Claude Is Coming to Your iPhone — Here's What WWDC 2026 Actually Changes

Last week’s WWDC was Apple’s most AI-focused event in years: a rebuilt Siri, a standalone chat interface, deeper on-screen awareness, and smarter app actions were officially announced. But claims that iOS 27 will let Siri hand requests to Claude, ChatGPT, or Gemini remain reports and rumors, not Apple-confirmed features.

Read article

I Built a Tiny AI Agent From Scratch — Every Line Tested Before It Touched a Real API

AI agents are often overcomplicated. At their core, they’re just models that can call tools, use the results, and continue working. This tutorial builds that loop from scratch in about 80 lines of Python and includes a complete test run that proves the agent works before making a single real API call.

Read article

Best AI Tools for Developers in India (2026) — Tried, Tested & Ranked

85% of developers use AI tools daily in 2026. But most "best tools" lists are written for US developers with dollar budgets. This guide covers what actually works for Indian developers — with real 2026 pricing in rupees.

Read article

Popular Tags

#.env.example Node.js#0x profiling#10x faster python scraper tutorial#12-factor#2026#AI#AI Backend#AI Comparison#AI Cost Optimization#AI Engineering