ZyVOP Logo
Content That Connects
SeriesAI NewsLeaderboardWrite for Us
ZyVOP Logo
Content That Connects

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

Content

  • Categories
  • Tags
  • Badges
  • Leaderboard
  • Write Article
  • Newsletter

Company

  • About Us
  • API Documentation
  • Write for 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

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.

ZyVOP
ZyVOPSenior Developer
June 23, 2026
4 min read
I Thought AI Was Magic Until I Built My Own Model
#AI#beginners#Python#machinelearning
๐Ÿ‘1

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.

ZyVOP

ZyVOP

Founder of Zyvop ๐Ÿš€ | Building AI-driven tools & premium insights for software engineers, CTOs, and tech leaders. Obsessed with automating workflows and exploring the frontier of AI.

Comments (0)

Login to post a comment.

I Thought AI Was Magic Until I Built My Own Model

Related Posts

Why I score contractor websites for after-hours leak risk before I sell anything

I score HVAC and plumbing public sites for after-hours leak risk before any paid offer. Free radar first; fixed 149 USD audit only if they want the write-up.

Read article

OpenRouter: One API Key to Rule Them All ๐Ÿ”‘

Overview Hey everyone ๐Ÿ‘‹ Managing AI models in 2026 has gotten ridiculous. Anthropic key here, OpenAI key there, a separate billing account for Google, another ...

Read article

Massing: The Open-Source AEC Platform That Covers the Entire Building Lifecycle

For most of the industry's history, AEC software has worked in silos โ€” one tool for feasibility, another for BIM modeling, yet another for construction manageme...

Read article

Why I built my own local-first job-search tool (and how it works)

A free, open-source, local-first job-search command center: it aggregates 78 sources, AI-scores every posting against your CV, tracks applications and generates ATS resumes โ€” all on 127.0.0.1, with no cloud, telemetry or auto-submit.

Read article

Developers now install the author, not the skill: 'matt pocock skills' searches are up 160%

The fastest-rising Claude Code skill search is an author's name. Setup skills with 540k installs, lockstep family installs, and 97 of 100 trending slots held by six authors: the adoption unit is now the author.

Read article