OkayStudy
EN English 한국어 日本語 中文 हिन्दी বাংলা اردو Español Português Français Deutsch Русский العربية Bahasa Indonesia Tiếng Việt ไทย Türkçe

How to enable notifications

Notifications are unavailable in this browser or on this address. Try a supported browser on the secure BaeumNova site.

If notifications are blocked, allow them in your browser settings.

  1. Open the site controls beside the address bar, or your browser’s site settings. Set Notifications for this site to Allow.
  2. In your device settings, allow notifications for your browser and check Do Not Disturb or Focus.
  3. Return to BaeumNova and reload the page. Once notifications are on, the bell disappears.

On iPhone or iPad, add BaeumNova to your Home Screen, open it there, then allow notifications.

Guest

Sign in to see your lesson schedule.

Getting started

Start English lessons step by step

Tap a step to go there.

Free trial

  1. Pick a free trial teacher

    Tap a teacher with [Free trial] on the photo.

  2. Tap a time with a gift

    Tap a free time with a gift picture in the timetable.

  3. Sign in and book

    Sign in and it is booked right away. No payment.

  4. Camera & Mic Check

    Check your camera and mic before class.

  5. Check your booked lessons

    See the time and tutor of your booked lesson.

  6. Enter the lesson

    Join the video classroom when it’s time.

  7. Check your past lessons

    Look back at the lessons you finished.

  8. Rate your tutor

    Rate your tutor after the lesson.

About me

  1. Add your profile photo

    A photo helps your tutor recognize you.

  2. Introduce yourself

    Write a hello on the introductions board.

Take lessons

  1. Book a lesson

    Pick a time on a tutor’s timetable.

  2. Pay the lesson fee with PayPal

    Pay on PayPal — your lesson is booked as soon as PayPal confirms it.

  3. Check your booked lessons

    See the time and tutor of your booked lesson.

  4. Enter the lesson

    Join the video classroom when it’s time.

  5. Check your past lessons

    Look back at the lessons you finished.

  6. Rate your tutor

    Rate your tutor after the lesson.

Build an AI that learns from examples and corrects itself

Build a small in one file that fixes its own every time it gets an example wrong. Run it right here and watch w change from 0 to 2.

The data to learn

This is the our will learn from.

InputAnswer
12
24
36
48

We can see the rule at a glance: "twice the input". Let's have the learn that relationship from the data too. When training is finished, we check its predictions with 5 and 7 — inputs it never saw while learning.

The shape of the calculation — the model

First we give the program the shape of its calculation — in other words, the model.

prediction = input × w

w is the number the program changes while it learns. A value like this is called a , and one that multiplies an input, like this one, is called a .

We start with w = 0.

input 3 → prediction 0 → the answer is 6 → a big difference!

As training repeats and w gets close to 2, it looks like this:

input 3 → prediction about 6 → almost the same as the answer!

People prepare the shape of the calculation and the example data; the program finds the w that fits the data.

The code — mini_ai.py

Save the below as mini_ai.py. On this page, press [Run] and the inside your runs it straight away. You can change the code and run it again.

Press [Run] to get the browser Python ready. The first time, it downloads about 12 MB.

# 1. Training data: (input, answer)
data = [(1, 2), (2, 4), (3, 6), (4, 8)]

# 2. Start without knowing the rule.
weight = 0.0
learning_rate = 0.01

# 3. Look at all the data and train 100 times.
for step in range(100):
    gradient = 0.0

    for x, answer in data:
        prediction = weight * x       # predict with the current weight
        error = prediction - answer   # how far from the answer
        gradient += 2 * error * x     # direction and size of the fix

    # Gather the results of all the data and change the weight a little.
    weight -= learning_rate * gradient / len(data)

    if step + 1 in [1, 10, 50, 100]:
        print(f"Training {step + 1}: w = {weight:.4f}")

# 4. Predict inputs that were not used for training.
print(f"Prediction for input 5: {weight * 5:.4f}")
print(f"Prediction for input 7: {weight * 7:.4f}")

Output

Press [Run] and the result will appear here.

Run it on your own computer

In the folder where you saved the file, run it with this command:

python3 mini_ai.py

The result

This is the result we got by actually running it. Numbers are shown to four decimal places.

Training 1: w = 0.3000
Training 10: w = 1.6063
Training 50: w = 1.9994
Training 100: w = 2.0000
Prediction for input 5: 10.0000
Prediction for input 7: 14.0000

The weight started at 0 and became about 2 through . Using this weight to calculate the answer for a new input is called prediction, or .

Three key ideas in the code

error How wrong was it?
The prediction minus the answer. During training, the weight is adjusted so that the average of these errors squared gets smaller.
gradient Which way should the weight change?
It calculates the direction and size of the change needed to reduce the error. This method is called . 2 * error * x is what you get by differentiating this model's . You can experiment before you fully understand differentiation.
learning_rate How much to change at a time
Here it is 0.01. Too small and learning is slow; too large and the weight can swing wildly or learning can fail.
A hiker walks down a misty grassy hill step by step along a dotted trail toward a flag in the valley; a small chart in the corner shows a curve going down.
Gradient descent is like walking down a foggy hill by feeling only the slope under your feet. The slope is the gradient and the size of each step is the . Just like the curve in the corner, the error gets smaller step by step.

Experiment for yourself

Change one thing at a time and run it again. Press [Load and run] to put the changed code into the editor above and run it right away.

  1. Change the data to "three times"

    data = [(1, 3), (2, 6), (3, 9), (4, 12)]

    Leave the rest of the code as it is and run it. This time, check that the weight is learned as about 3.

    Show the result we got
    Training 1: w = 0.4500
    Training 10: w = 2.4094
    Training 50: w = 2.9991
    Training 100: w = 3.0000
    Prediction for input 5: 15.0000
    Prediction for input 7: 21.0000
  2. Train fewer times

    for step in range(10):

    Compare how much less accurate the predictions are than after 100 rounds of training.

    Show the result we got
    Training 1: w = 0.3000
    Training 10: w = 1.6063
    Prediction for input 5: 8.0313
    Prediction for input 7: 11.2438
  3. Take away the perfect rule

    data = [(1, 2.1), (2, 3.9), (3, 6.2), (4, 7.8)]

    Even when the data is a little off, see whether it finds a weight that fits well overall.

    Show the result we got
    Training 1: w = 0.2985
    Training 10: w = 1.5982
    Training 50: w = 1.9894
    Training 100: w = 1.9900
    Prediction for input 5: 9.9500
    Prediction for input 7: 13.9300

Next challenge — input × w + b

This model can only express a proportional relationship of the form input × w. To learn input × 2 + 3, for example, you extend the model to input × w + b and learn two numbers, w and b. b is called the bias.

Once you understand the experiments above, try changing the code yourself first. If you get stuck, open the solution below.

Show the solution

The is (1, 5), (2, 7), (3, 9), (4, 11), made with input × 2 + 3. Because it learns two numbers, we raise the learning rate to 0.05 and train 1000 times.

# 1. Training data: (input, answer) made with input × 2 + 3
data = [(1, 5), (2, 7), (3, 9), (4, 11)]

# 2. Start both the weight w and the bias b at 0.
weight = 0.0
bias = 0.0
learning_rate = 0.05

# 3. Look at all the data and train 1000 times.
for step in range(1000):
    grad_w = 0.0
    grad_b = 0.0

    for x, answer in data:
        prediction = weight * x + bias    # predict with the current w and b
        error = prediction - answer       # how far from the answer
        grad_w += 2 * error * x           # direction and size to change w
        grad_b += 2 * error               # direction and size to change b

    # Change w and b a little, together.
    weight -= learning_rate * grad_w / len(data)
    bias -= learning_rate * grad_b / len(data)

    if step + 1 in [1, 10, 100, 500, 1000]:
        print(f"Training {step + 1}: w = {weight:.4f}, b = {bias:.4f}")

# 4. Predict inputs that were not used for training.
print(f"Prediction for input 5: {weight * 5 + bias:.4f}")
print(f"Prediction for input 7: {weight * 7 + bias:.4f}")
Training 1: w = 2.2500, b = 0.8000
Training 10: w = 2.6082, b = 1.2119
Training 100: w = 2.1565, b = 2.5399
Training 500: w = 2.0004, b = 2.9989
Training 1000: w = 2.0000, b = 3.0000
Prediction for input 5: 13.0000
Prediction for input 7: 17.0000

w first goes past 2, then comes back to 2 as b grows, ending at w = 2 and b = 3.

Booking time has passed

Voice chat with Lyen Pick a language and a topic, then talk with Lyen by voice

Lyen speaks aloud in English · 한국어 · 日本語 · हिन्दी. In other languages she answers in text.

Voice chat with Lyen is for members. Sign up first, then start talking.