ELOC CYBER

AI CLASS / BEGINNER LAB NO ACCOUNT NEEDED HERE

Teach a computer
to read movie reviews.

Build something that works. Then change one setting and see what happens.
Our main project: decide whether a review is positive or negative.

These browser exercises need no login or installation. The optional Colab notebook needs a Google account. Your text and uploaded pictures stay in this browser.

  1. Read examples
  2. Turn text into numbers
  3. Train & check
  4. Change one setting

TikTok and photo activities are optional. You can finish the movie-review project and stop there.

BUILD / START WITH THE EXAMPLES

1. What is a text classifier?

A classifier is a program that chooses a category. Ours reads a movie review and predicts positive or negative. We give it examples with known answers so it can learn patterns.

“I loved the movie.”

POSITIVE · 1

“I was bored the whole time.”

NEGATIVE · 0

“The actors were great, but the plot was weak.”

WHAT WOULD YOU CHOOSE?
X = input

The review text: “The movie was too long.”

y = answer

Its known label: negative (0).

Why keep separate groups of reviews?

We want to check whether the model handles reviews it did not learn from.

Train

Examples the model learns from.

Here: 32 short teaching reviews.

Validation

Separate examples used to compare settings.

Here: 12 reviews that stay the same.

Test

Examples saved for one final check.

The Colab notebook adds this group.

This page uses a small set written for practice. The Colab project uses thousands of real movie reviews. A high score here does not tell us how well the model handles all real reviews.

BUILD / TURN TEXT INTO NUMBERS

2. What is an n-gram?

First we break a sentence into words. An n-gram is a group of n neighboring words. One word is a unigram, two are a bigram, and three are a trigram.

In (1, 2), 1 is the shortest group and 2 is the longest. The pairs overlap: after “this movie,” we move forward one word to “movie is.”

Try this: Remove “not” from the sentence above. Which groups disappear? Why might “not good” be more useful than “good” by itself?

3. What does TF-IDF do?

The model needs numbers instead of words. TF-IDF turns each review into a row of numbers for selected words and phrases. A column is a feature: one piece of information the model can use.

TF: frequency in this review

How often does this word or phrase appear here?

IDF: rarity across training reviews

Words found in nearly every review usually get less weight.

See a small table of text turned into numbers

Each row is a review. Each column is a word. Larger numbers give that word more weight in the row. The table is made from these three examples only.

TF-IDF does not understand a sentence the way a person does. It gives the classifier numerical patterns to learn from.

Which classifier are we using?

Logistic regression learns a weight for each text feature and combines them to estimate the chance that a review is positive. Despite its name, this is classification. Ordinary linear regression usually predicts an amount, such as the price of a bike.

  1. Review text
  2. TF-IDF numbers
  3. Logistic regression
  4. Positive or negative

A pipeline keeps these steps in order. In Python, fit() trains the model and predict() uses what it learned on new text.

BUILD / TRAIN AND CHECK

4. Train a model and try your own reviews

A first model is ready below. Try positive, negative, mixed, or sarcastic sentences. Then change one setting, train again, and compare the results.

Settings you can change

Start with word groups. Keep the other settings the same for a fair comparison.

More training controls

These control how the browser model learns its weights. The notebook uses its own Python fitting steps, so its numbers may differ.

Read & edit the training examples

There are 16 positive and 16 negative reviews to start with. Add a review with a known label, then see how it affects the model.

Write a new review

X = YOUR INPUT
NegativePositive

The percentage is the model’s estimated chance of positive sentiment. It is a prediction, not a guarantee.

Which words helped it decide?

A plus sign pushes the guess toward positive. A minus sign pushes it toward negative. These are patterns learned from our training examples.

Change the cutoff for a positive guess

At 50%, a score of at least 50% gets the positive label. A higher cutoff makes that label harder to get. This changes decisions without training again.

5. How do we know if it is working?

Accuracy counts the fraction of reviews with correct predictions. Correct on 8 of 10 reviews means 80% accuracy.

—Validation accuracy
—Reviews correct
—Simple baseline accuracy

The baseline always chooses the most common training label without reading the review. Can our model do better? We compare both on the same 12 validation reviews.

Correct and incorrect guesses by category (confusion matrix)
Known answer ↓ / Guess →NegativePositive
Negative——
Positive——
Look at each validation review
ReviewKnown answerModel’s guess
More detail: features, F1, and training progress

Learned text features: —. Positive-class F1: — (a score that balances finding positive reviews with avoiding incorrect positive guesses).

How closely did the model fit the training examples?

We use validation to choose settings. If we keep choosing settings using the same reviews, they become less useful as a fresh check. The notebook saves a separate test group until the end.

EXPERIMENT / CHANGE ONE THING

6. Which setting would you try next?

Write down your first score. Change one setting above, click Train with these settings, and compare the new validation accuracy.

Word groups (n-grams)

Compare single words, words + pairs, and words + pairs + triples. Longer groups give more context but may repeat less often.

Vocabulary choices

A larger word-group limit lets more terms in. A higher minimum number of reviews removes rare terms. Try these separately.

Weights and examples

Try C = 0.1, 1, and 10, then compare smaller and larger training groups. More freedom or more data does not always win.

Your comparison table

Each successful training run is added here. The cutoff is saved with the run. Keep it the same while comparing training settings. This table stays only while this page is open.

RunSettingsReviewsAccuracy
Your class investigation:
  1. Which setting did you change?
  2. What was the score before and after?
  3. Which example did the model get wrong?
  4. What would you like to try next?

You can stop here. To use the full movie-review dataset, choose a final model, and build a Python app, continue in the beginner notebook.

Open the beginner notebook ↗

OPTIONAL / A DIFFERENT QUESTION

Could captions help predict TikTok views?

The notebook’s TikTok chapter reuses text classification with a different question.

X = caption text

Use the caption alone, or add on-screen text.

y = a popularity label

Did the video reach the top 20% by observed views in the selected sample?

Try top 20% versus top 10%, or compare text choices. The notebook downloads one small historical monthly file. These labels describe views already observed in that sample; they do not guarantee a new video’s future reach.

Try the optional TikTok chapter ↗

OPTIONAL / A MODEL THAT SEES IMAGES

What’s in the photo?

ALREADY TRAINED

Image classification takes a photo and predicts a category, such as “mug.” Here we use a pretrained model: someone already trained its weights before this lab. Changing the picture does not teach it new weights.

1. Choose a photo

Use a JPG, PNG, or WebP, or try our sample.

2. Change what it sees

The first run may take a little longer while the model downloads. No account needed.

The picture the model receives

Crop keeps the middle of the image. Brightness makes it lighter or darker. Try one change at a time.

3. Compare its guesses

Choose a photo and click Recognize the photo.

The labels come from categories the model already knows. Scores compare its guesses; they do not guarantee the answer. Showing fewer labels or hiding low scores changes the display, not the model.

Try this: Recognize the sample. Then crop it, darken it, or remove its color and recognize it again. Does the top guess change? Look at the other guesses too.
Image classification

Photo → category.
“Mug.” This is what the browser exercise does.

Visual question answering (VQA)

Photo + question → written answer.
“What am I holding?” → “A mug.” Try this in Colab.

Ask questions about photos in Colab ↗
About the image model

This exercise uses MobileNetV4, trained to choose among 1,000 ImageNet categories, with Transformers.js. The first run downloads about 15 MB of weights and 22 MB of browser tools. Everything runs on this device.

CLASS MATERIALS / BEGINNER EDITION

Keep building in Google Colab.

The student slides and notebook follow the same route: examples → n-grams → numbers → train → check → change settings → build an app. The TikTok and photo chapters are optional.

Read & copy the student notebook ↗Download beginner notebookDownload student slides