What Is Artificial Intelligence?

Generative AI & LLM Fundamentals · AI and machine learning basics · 15 min read · Updated

AI, machine learning and deep learning

  1. Artificial intelligence is the big idea: computers doing tasks that normally need human thinking.
  2. Machine learning sits inside it. Instead of writing every rule, we let the computer learn patterns from examples.
  3. Deep learning is a kind of machine learning that uses neural networks with many layers.
  4. Generative AI uses deep learning to create new text, images or code. Chat assistants belong here.
  5. Today every system you meet is narrow AI: very good at some tasks, and not a general thinking mind.

Artificial intelligence, or AI, is software that does tasks we normally think need human judgement. Recognising a face in a photo, translating a sentence, recommending a job, spotting a fake message, or writing a paragraph are all examples. AI is not one single technology. It is a broad label that covers many different techniques, some very old and some very new. In this first lesson you will learn what the main words mean, see the difference between a program that follows rules and a program that learns, and build a small example of both so that you can see the difference with your own eyes.

You do not need any maths or programming knowledge to follow the ideas. If you can read a short piece of TypeScript code you will get more from the exercise, but the explanations are written in easy English, and every idea comes with an example from everyday life or from job hunting.

AI, machine learning and deep learning

You will see three terms again and again: AI, machine learning and deep learning. They are nested, like a set of boxes. AI is the biggest box: any software that appears to show intelligent behaviour. Machine learning, often shortened to ML, is a smaller box inside it. In machine learning the program is not given the rules. Instead it is shown many examples, and it works out a pattern by itself. Deep learning is a still smaller box inside machine learning. It uses neural networks with many layers, and it is the technology behind most of the AI news you read today, including chat assistants such as Claude.

A simple way to remember the difference is to think about how you would teach a new person to spot a fake job message. You could write a list of rules on a card: “If the message asks for money before the job starts, it is fake.” That is the rule-based way. Or you could show the person two hundred real messages and two hundred fake ones, and let them develop a feeling for the difference without writing any rules down. That is the learning way. Both can work. They fail in different ways, and a good engineer knows when to use each.

Rule-based systems

A rule-based system is a program where a human writes the logic. A resume checker that says “this resume has no email address” is a rule-based system. A rule is easy to read, easy to explain and easy to fix. If a user asks, “Why was my message flagged?”, you can point to the exact rule. Rule-based systems are also very predictable. The same input always gives the same output.

The weakness is that rules only cover what the writer thought of. Scammers change their words every week. If your rule looks for the phrase “registration fee”, a scammer will write “processing charge” instead, and your rule sees nothing. To keep up you must keep adding rules by hand, and the list gets long and hard to manage.

Learning systems

A learning system works in the opposite way. You give it examples that are already labelled, such as “this message is a scam” and “this message is normal”. The program counts and measures things in those examples and builds a small mathematical model. When a new message arrives, the model uses what it learned to guess. Nobody wrote a rule about “processing charge”. But if the word “charge” appeared often in scam examples and rarely in normal ones, the model will lean towards “scam” whenever it sees that word.

This is powerful because the model can notice patterns that a person did not think of. It is also risky, for three reasons. First, the model is only as good as its examples. If your examples are few, old or one-sided, the model will be poor or unfair. Second, it is harder to explain: the answer comes from many small numbers rather than one clear rule. Third, it can be wrong with confidence. A learning system will happily give an answer even for a message that looks nothing like its examples.

Narrow AI and general AI

Every AI product you can use today is narrow AI. It is very good at a limited set of tasks and useless outside them. A resume parser does not drive a car, and a chess engine cannot write a cover letter. Even large language models, which can do many different language tasks, are still narrow in an important way: they work with text and patterns in text, and they have no goals of their own. General AI, a system that can do any intellectual task a person can do, is a research goal. It is not a product you can buy or a thing you need to worry about when you build today’s apps.

Where you already meet AI

  • Spam filters decide which emails go to the junk folder. Most use a learning method.
  • Search and recommendations decide which jobs, videos or products you see first.
  • Speech to text on your phone turns your voice into words.
  • Applicant tracking systems (ATS) read resumes, pull out skills and rank candidates. Some use rules, some use learning, and many use both.
  • Chat assistants such as Claude write, summarise and explain in plain language.

What AI cannot do well

Knowing the limits is as useful as knowing the strengths. AI systems learn from data, so poor data gives poor results. If a hiring model learned from past decisions that were unfair, it will copy the unfairness. AI can be confidently wrong. It does not understand the world the way people do. And for decisions that matter, such as hiring, health or money, a person should check the result. Keep one habit from this lesson for the whole course: whenever you read about an AI feature, ask two questions. What data did it learn from? And what happens when it is wrong?

Your task: rules against learning

In this task you will build the first page of the lab. It lets you type a job message and see two verdicts side by side: one from a few hand-written rules, and one from a small model that learns from labelled examples.

What you will build

  • A list of 14 example messages, each marked as a scam or as normal.
  • Four hand-written rules, for example “asks you to pay first” and “pushes you to hurry”.
  • A small learning model called naive Bayes. It counts how often each word appears in scam and in normal examples, and turns those counts into a score.
  • An Angular page with a text box, two result cards, and buttons to add your own examples.

Steps

  1. Create src/app/lib/spam.ts. Define the type Example with a text and a spam flag, and write the 14 starting examples (7 scam, 7 normal). Use realistic messages: scam ones mention fees, OTP codes or guaranteed income, and normal ones mention interviews and documents.
  2. Write the rules as a list of objects, each with a name and a test function that checks the text with a regular expression. Write ruleVerdict, which runs all rules and returns the names of the rules that fired.
  3. Write the NaiveBayes class. In the constructor, count for every word how many scam and how many normal examples contain it. Write weight(word) so that a positive number pushes towards scam and a negative number pushes towards normal. Add one to every count so that a word never seen in one group does not give a zero.
  4. Write classify(text). Add the weights of the known words in the message to a starting value (the prior) and turn the total into a probability between 0 and 1 with the formula 1 / (1 + e^-x).
  5. Create the page in src/app/pages/spam.ts. Show the message box, both verdicts, the rules that fired, and the words that pushed the learned verdict the most. Add buttons to add the current message as a scam example or as a normal example, and rebuild the model each time.
  6. Add the route spam and a menu link in app.routes.ts and the menu.

Hints

  • Make the words lower case and count each word once per message. Otherwise a long message with a repeated word gets too much influence.
  • Use Set to remove repeated words from a message.
  • Keep the logic in lib/spam.ts, with no Angular code, so that you can test it on its own.
  • Try a clever scam sentence that uses none of your rule words. Then add it as an example and see what changes.

You know it works when the rules flag “Pay a registration fee today” but miss “Send a processing charge today”, the learned model gives a high scam probability to a sentence it never saw but which uses scam-like words, and adding your own example changes the learned verdict but not the rules.

Try to build it yourself first. Struggling with the first version is where the understanding grows. Then compare with the solution below.

Solution

The solution zip contains the whole lab after this lesson. These are the new files. First the logic, with the examples, the rules and the learning model:

// Two ways to catch scam job messages.
//  1. Rules: a person writes the rules. Clear and predictable, but only catches what the writer thought of.
//  2. Learning: the computer counts which words appear in scam and normal messages in the examples,
//     then uses those counts to judge a new message. It can notice patterns nobody wrote down.

export type Example = { text: string; spam: boolean };

export const startExamples: Example[] = [
  { text: 'Pay a registration fee of 2000 rupees to confirm your job offer today', spam: true },
  { text: 'Earn 5000 per day from home, guaranteed income, no experience needed', spam: true },
  { text: 'Urgent! Last chance, limited seats, send your bank account details now', spam: true },
  { text: 'You are selected. Share your OTP and Aadhaar number to receive the joining letter', spam: true },
  { text: 'Congratulations winner, claim your free laptop and job, pay the courier charge', spam: true },
  { text: 'Work from home and earn lakhs weekly, just pay a small security deposit first', spam: true },
  { text: 'Hurry, earn money fast with this simple task, guaranteed payment, join now', spam: true },
  { text: 'We would like to invite you for an interview on Monday at 10 am at our Pune office', spam: false },
  { text: 'Thank you for applying for the accountant role. Our team will review your resume', spam: false },
  { text: 'Please bring your certificates and one photo ID for the walk-in drive on Friday', spam: false },
  { text: 'Your application for warehouse supervisor has been shortlisted. Please confirm a time', spam: false },
  { text: 'The salary range for this role is 25000 to 30000 per month plus provident fund', spam: false },
  { text: 'Reminder: your video interview with the hiring manager starts tomorrow at 3 pm', spam: false },
  { text: 'We have received your resume and will contact you if your profile matches', spam: false },
];

const words = (text: string) => text.toLowerCase().match(/[a-z0-9]+/g) ?? [];

// ---------- 1. Rules ----------
export type Rule = { name: string; test: (text: string) => boolean };

export const RULES: Rule[] = [
  { name: 'asks you to pay first', test: (t) => /(registration|security|training|courier)\s+(fee|deposit|charge)|pay\s.*\b(fee|deposit)\b/i.test(t) },
  { name: 'promises easy money', test: (t) => /earn\s+\d+.*(per day|a day|daily|weekly)|guaranteed\s+(job|income|payment)/i.test(t) },
  { name: 'asks for private details', test: (t) => /\b(otp|aadhaar|bank account|card number|password)\b/i.test(t) },
  { name: 'pushes you to hurry', test: (t) => /\b(urgent|hurry|last chance|limited seats|act now)\b/i.test(t) },
];

export function ruleVerdict(text: string) {
  const hits = RULES.filter((r) => r.test(text)).map((r) => r.name);
  return { spam: hits.length > 0, hits };
}

// ---------- 2. Learning (naive Bayes) ----------
export class NaiveBayes {
  private counts = { spam: new Map<string, number>(), ham: new Map<string, number>() };
  private docs = { spam: 0, ham: 0 };
  private total = { spam: 0, ham: 0 };
  private vocab = new Set<string>();

  constructor(examples: Example[]) {
    for (const ex of examples) {
      const c = ex.spam ? 'spam' : 'ham';
      this.docs[c]++;
      for (const w of new Set(words(ex.text))) {
        this.counts[c].set(w, (this.counts[c].get(w) ?? 0) + 1);
        this.total[c]++;
        this.vocab.add(w);
      }
    }
  }

  // How much one word pushes towards spam (positive) or normal (negative), as a log ratio.
  weight(word: string) {
    const v = this.vocab.size || 1;
    const pSpam = ((this.counts.spam.get(word) ?? 0) + 1) / (this.total.spam + v); // +1 so unseen words never give zero
    const pHam = ((this.counts.ham.get(word) ?? 0) + 1) / (this.total.ham + v);
    return Math.log(pSpam / pHam);
  }

  classify(text: string) {
    const n = this.docs.spam + this.docs.ham;
    if (!n || !this.docs.spam || !this.docs.ham) return { spam: false, probSpam: 0.5, top: [] as { word: string; weight: number }[] };
    const uniq = [...new Set(words(text))].filter((w) => this.vocab.has(w));
    const prior = Math.log((this.docs.spam + 1) / (this.docs.ham + 1));
    const parts = uniq.map((word) => ({ word, weight: this.weight(word) }));
    const logOdds = prior + parts.reduce((s, p) => s + p.weight, 0);
    const probSpam = 1 / (1 + Math.exp(-logOdds)); // turn log-odds into a probability between 0 and 1
    const top = parts.filter((p) => Math.abs(p.weight) > 0.2).sort((a, b) => Math.abs(b.weight) - Math.abs(a.weight)).slice(0, 6);
    return { spam: probSpam >= 0.5, probSpam, top };
  }
}

Then the page that shows both verdicts:

import { Component, computed, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NaiveBayes, ruleVerdict, startExamples, type Example } from '../lib/spam';

@Component({
  selector: 'app-spam',
  imports: [FormsModule],
  template: `
    <h1>Rules or learning?</h1>
    <p class="hint">Paste a job message. One checker uses rules a person wrote. The other learned from the examples below. Add your own examples and watch the learner change.</p>

    <div class="card">
      <label for="m">Message</label>
      <textarea id="m" [ngModel]="message()" (ngModelChange)="message.set($event)" style="min-height:90px"></textarea>
      <div class="grid2">
        <div>
          <h2>Rule-based</h2>
          <p [class]="rules().spam ? 'bad' : 'ok'"><strong>{{ rules().spam ? 'Looks like a scam' : 'No rule fired' }}</strong></p>
          @for (h of rules().hits; track h) { <p class="muted">Rule: {{ h }}</p> }
        </div>
        <div>
          <h2>Learned from examples</h2>
          <p [class]="learned().spam ? 'bad' : 'ok'"><strong>{{ learned().spam ? 'Looks like a scam' : 'Looks normal' }}</strong> ({{ percent() }}% scam)</p>
          @for (t of learned().top; track t.word) { <p class="muted">"{{ t.word }}" pushes towards {{ t.weight > 0 ? 'scam' : 'normal' }} ({{ t.weight.toFixed(1) }})</p> }
        </div>
      </div>
    </div>

    <div class="card">
      <h2>Training examples ({{ examples().length }})</h2>
      <label for="n">Add an example</label>
      <input id="n" [(ngModel)]="newText" placeholder="Type a message..." />
      <button (click)="add(true)" [disabled]="!newText.trim()">Add as scam</button>
      <button class="secondary" (click)="add(false)" [disabled]="!newText.trim()">Add as normal</button>
      <table>
        <tbody>
          @for (e of examples(); track $index) {
            <tr><td [class]="e.spam ? 'bad' : 'ok'">{{ e.spam ? 'scam' : 'normal' }}</td><td>{{ e.text }}</td><td><button class="danger" (click)="remove($index)">x</button></td></tr>
          }
        </tbody>
      </table>
    </div>
  `,
})
export class SpamPage {
  message = signal('Hurry! Pay a registration fee today and earn 3000 per day from home');
  examples = signal<Example[]>([...startExamples]);
  newText = '';

  rules = computed(() => ruleVerdict(this.message()));
  model = computed(() => new NaiveBayes(this.examples()));
  learned = computed(() => this.model().classify(this.message()));
  percent = computed(() => Math.round(this.learned().probSpam * 100));

  add(spam: boolean) {
    this.examples.update((list) => [{ text: this.newText.trim(), spam }, ...list]);
    this.newText = '';
  }

  remove(i: number) {
    this.examples.update((list) => list.filter((_, j) => j !== i));
  }
}

What you learned

  • AI is a broad label. Machine learning is the part where programs learn patterns from examples. Deep learning is machine learning with many-layered neural networks.
  • A rule-based system is predictable and easy to explain, but it only covers what a person thought of.
  • A learning system can notice patterns nobody wrote down, but it depends on its examples and is harder to explain.
  • Today’s AI is narrow. It does limited tasks well and needs human checking when the stakes are high.

In the next lesson you will meet the small set of maths ideas that sit behind almost everything in AI: vectors, similarity, averages, probabilities and learning by small steps.

Download the solution (genai-basics-lesson-01.zip)

Frequently asked questions

Is machine learning the same as AI?

No. Machine learning is one approach inside AI, where programs learn patterns from data. AI also includes older rule-based methods.

Do I need advanced maths to start learning AI?

Not to use and build with AI tools. A few basic ideas, such as averages and similarity, help you understand how models work. The next lesson covers them with simple examples.

Should I use rules or learning for my own project?

Use rules when the logic is clear, must be explained, or must never change, for example a legal check. Use learning when the patterns are too many or too fuzzy to write down. Many real systems combine both.

Is the naive Bayes model in this lesson a real AI?

Yes, it is a real and still widely used machine learning method, especially for spam filtering. It is simple, which makes it a good first example. Large language models are far bigger and work differently.