בינה מלאכותית RB108-6 : בינה מלאכותית – איך נוירון לומד ?

בינה מלאכותית RB108-6 : בינה מלאכותית – איך נוירון לומד

חלק א :

שימו לב !!!

בהסבר זה לפעמים אני מראה חישוב על ערך X אחד בלבד  – זה עלמנת  שהכל יהיה ברור וקל במציאות יש לחשב את כל הערכים עבור פונקציה LOST  MSE


x = [-3, -2, -1, 0, 1, 2, 3]

y = [-5, -3, -1, 1, 3, 5, 7]


those are the true values  :y = [-5, -3, -1, 1, 3, 5, 7]

1) The Neuron Model

The neuron predicts:

y_predict = w * x + b

Starting values:

w = 1
b = 0
learning_rate = 0.05

2) Forward Pass (Prediction)

For each x:

y_predict = w * x + b
x y_true y_predict
-3 -5 -3
-2 -3 -2
-1 -1 -1
0 1 0
1 3 1
2 5 2
3 7 3

3).Error , lost Function 

we start w=1,b=0

y_true    = w * x + b

y_predict = w * x + b

x y_true y_predict = 1·x + 0 error = y_predict – y_true loss = (y_true – y_predict)²
-3 -5 -3 +2 4
-2 -3 -2 +1 1
-1 -1 -1 0 0
0 1 0 -1 1
1 3 1 -2 4
2 5 2 -3 9
3 7 3 -4 16

Totals for Step 3

Sum of errors:


2 + 1 + 0 – 1 – 2 – 3 – 4 = -7

Sum of loss values:


4 + 1 + 0 + 1 + 4 + 9 + 16 = 35

Mean Loss (The Value Used for Learning)

The Mean Loss is:

mean loss=sum of all lossesnumber of samples\text{mean loss} = \frac{\text{sum of all losses}}{\text{number of samples}}

In our case:

  • Total loss = 35

  • Number of samples = 7

So:

mean loss=357=5

MSE (mean squared error) = cost function =  Error loss

 


3.1 Why we use the Loss and not the Error

Example:

error = +3
error = -3

Loss converts both to:

loss = 9
loss = 9

So the neuron learns how big the mistake is, not just the sign.

Raw error cancels out:

(+3) + (-3) = 0 → looks perfect, but actually very wrong.

Loss does NOT cancel out → always correct for learning.


4.Gradients for a Single Neuron 

 

 

We will calculate the gradients for  w , b


Step 1 — Start With the Loss Function

For one training sample:

L = (y_true – y_predict)²

This is the loss the neuron wants to minimize.


Step 2 — Substitute the Neuron Output

The neuron predicts:

y_predict = w*x + b

Substitute into the loss:

L = (y_true – (w*x + b))²

Derivative With Respect to w

 

dL/dw = 2x (y_predict – y_true)

We use the chain rule.

A) Define inner function

u = y_true – (w*x + b)

Then:

L = u²

B) Outer derivative

dL/du = 2u

C) Inner derivative

u = y_true – w*x – b

Derivative with respect to w:

du/dw = –x

D) Combine (Chain Rule)

dL/dw = (dL/du) * (du/dw)
dL/dw = 2 * (y_true – (w*x + b)) * (–x)

Rewrite using y_predict = w*x + b:

dL/dw = 2x (y_predict – y_true)

4) Gradients are computed from the loss – Gradients for a Single Neuron

dL/dw = 2x (y_predict – y_true)
dL/db = 2 (y_predict – y_true)

Derivative With Respect to w

We use the chain rule.

A) Define inner function

u = y_true – (w*x + b)

Then:

L = u²

B) Outer derivative

dL/du = 2u

C) Inner derivative

u = y_true – w*x – b

Derivative with respect to w:

du/dw = –x

D) Combine (Chain Rule)

dL/dw = (dL/du) * (du/dw)
dL/dw = 2 * (y_true – (w*x + b)) * (–x)

Rewrite using y_predict = w*x + b:

dL/dw = 2x (y_predict – y_true)

Derivative With Respect to b (Step-by-Step)

We again use the chain rule.


A) Define the inner function

We define:

u = y_true – (w*x + b)

The loss is:

L = u²

B) Outer derivative

Derivative of L = u² with respect to u:

dL/du = 2u

C) Inner derivative (with respect to b)

Write u again:

u = y_true – w*x – b

Derivative of u with respect to b:

du/db = –1

Because only “–b” depends on b.


D) Combine (Chain Rule)

Now multiply the inner and outer derivatives:

dL/db = (dL/du) * (du/db)

Substitute:

dL/db = 2 * (y_true – (w*x + b)) * (–1)

Rewrite Using y_predict

Since:

y_predict = w*x + b

Then:

(y_true – (w*x + b)) = –(y_predict – y_true)

Substitute into the formula:

dL/db = 2 * (y_predict – y_true)

Why We Don’t Solve With Derivative = 0 (Except for One Neuron)

1) For a single neuron (like your example):

y=wx+b    

This is a simple line.

We can take the derivative of the loss, set it to 0, and solve for the exact best:

w=2,b=1

This works because the loss surface is a perfect parabola (a simple bowl shape).


2) But for many neurons (real neural networks):

When you add:

  • more neurons

  • more layers

  • activation functions (ReLU, sigmoid)

  • millions of parameters

The loss surface becomes:

  • twisted

  • curved

  • full of valleys and hills

  • impossible to solve with algebra

You cannot write equations like:

∂L∂w=0

for millions of nonlinear parameters.

There is no formula that gives all w and b directly.

 

 


Gradient Descent (Step-by-Step With Example)

שימו לב !!!

בהסבר זה  אני מראה חישוב על ערך X אחד בלבד  – זה עלמנת  שהכל יהיה ברור וקל במציאות יש לחשב את כל הערכים עבור פונקציה LOST MSE

 

Gradient Descent is the action step where the neuron actually updates
the weight w and the bias b to reduce the loss.

We use:

w_new = w_old – η * (dL/dw)
b_new = b_old – η * (dL/db)

Where:

  • η (eta) = learning rate

  • dL/dw, dL/db = gradients

  • w_old, b_old = values before update

  • w_new, b_new = values after update


Example Setup (single x , not all dataset for keep it simple )

We use this data point for simplicity:

x = 1
y_true = 3
w = 1
b = 0
η = 0.05

Prediction:

y_predict = w*x + b = 1*1 + 0 = 1

Error:

error = y_predict – y_true = 13 = –2

Gradients:

dL/dw = 2 * x * (y_predict – y_true)
dL/dw = 2 * 1 * (1 – 3) = –4
dL/db = 2 * (y_predict – y_true)
dL/db = 2 * (1 – 3) = –4

Now we perform Gradient Descent.


Epoch 1 — Update w and b

Update weight

w_new = w_old – η * (dL/dw)
w_new = 10.05 * (–4)
w_new = 1 + 0.2
w_new = 1.2

Update bias

b_new = b_old – η * (dL/db)
b_new = 00.05 * (–4)
b_new = 0 + 0.2
b_new = 0.2

End of Epoch 1:

w = 1.2
b = 0.2

The neuron has learned a little.


Epoch 2 — Repeat With New w and b

1) Forward Pass

y_predict = w*x + b
y_predict = 1.2*1 + 0.2 = 1.4

2) Error

error = 1.43 = –1.6

3) Gradients

dL/dw = 2 * 1 * (1.4 – 3)
dL/dw = 2 * (–1.6)
dL/dw = –3.2
dL/db = 2 * (1.4 – 3)
dL/db = –3.2

4) Update Step

w_new = 1.20.05 * (–3.2)
w_new = 1.2 + 0.16
w_new = 1.36
b_new = 0.20.05 * (–3.2)
b_new = 0.2 + 0.16
b_new = 0.36

End of Epoch 2:

w = 1.36
b = 0.36

The neuron is now closer to the true pattern.


Final Summary (Easy to Understand)

Epoch w b
Start 1.00 0.00
1 1.20 0.20
2 1.36 0.36

Gradient Descent is the step that actually updates w and b.
The gradient tells the direction.
Gradient Descent moves the weights in that direction.


Gradients Also Require ALL Data (Full Batch Training)

Before we use the full dataset, let’s start with the basic gradient formulas for a single sample:

dL/dw = 2 * x * (y_predict – y_true)
dL/db = 2 * (y_predict – y_true)

These formulas work when you use one training example at a time.

But real training uses all samples together to compute one global update.


Using ALL Data: Full Batch Gradients

If you have N samples:

x₁, x₂, …, xₙ
y_true₁, y_true₂, …, y_truen

Then the total loss is:

Total Loss = Σ (y_trueᵢ – y_predictᵢ)²

And the Mean Squared Error (MSE) is:

MSE = (1/N) * Σ (y_trueᵢ – y_predictᵢ)²

This is the value we minimize.


Single-Sample Loss and Gradient

For one sample:

loss = (y_true – y_predict)²

Gradient:

dL/dw = 2 * x * (y_predict – y_true)

This is correct only for one point.



Full-Batch Gradient Descent — Epoch 1 and Epoch 2 …. (with updated w and b)

We use your dataset:

x = [-3, -2, -1, 0, 1, 2, 3]
y_true = [-5, -3, -1, 1, 3, 5, 7]

Start values:

w = 1
b = 0
η (learning rate) = 0.05

EPOCH 1 — FULL STEPS

1) Forward Pass (All Samples)

x y_true y_predict (1*x + 0) error error²
-3 -5 -3 +2 4
-2 -3 -2 +1 1
-1 -1 -1 0 0
0 1 0 -1 1
1 3 1 -2 4
2 5 2 -3 9
3 7 3 -4 16

Total Loss = 35

MSE = 35 / 7 = 5


2) Compute Full-Batch Gradients

Gradient for w

Formula:

dL/dw = (2/N) * Σ[xᵢ * (y_predictᵢ – y_trueᵢ)]

Compute Σ[x * error]:

(-3*2) + (-2*1) + (-1*0) + (0*-1) + (1*-2) + (2*-3) + (3*-4)
= -6 -2 + 0 + 0 -2 -6 -12
= -28

Apply formula:

dL/dw = (2/7) * (-28)
dL/dw = -8

Gradient for b

Formula:

dL/db = (2/N) * Σ[errorᵢ]

Compute Σ error:

2 + 1 + 0 –1 –2 –3 –4 = -7

Now:

dL/db = (2/7) * (-7)
dL/db = -2

3) UPDATE w AND b (Epoch 1)

Update rule:

w_new = w_old – η * dL/dw
b_new = b_old – η * dL/db

Update w

w_new = 10.05 * (-8)
w_new = 1 + 0.4
w_new = 1.4

Update b

b_new = 00.05 * (-2)
b_new = 0 + 0.1
b_new = 0.1

End of Epoch 1

w = 1.4
b = 0.1
MSE = 5

EPOCH 2 — FULL STEPS

Now use:

w = 1.4
b = 0.1

1) Forward Pass (Using New w, b)

Compute predictions:

y_predict = 1.4*x + 0.1
x y_true y_predict error error²
-3 -5 -4.1 +0.9 0.81
-2 -3 -2.7 +0.3 0.09
-1 -1 -1.3 -0.3 0.09
0 1 0.1 -0.9 0.81
1 3 1.5 -1.5 2.25
2 5 2.9 -2.1 4.41
3 7 4.3 -2.7 7.29

Total Loss = 15.75

MSE = 15.75 / 7 ≈ 2.25

Loss dropped from 5 → 2.25 — learning works.


2) Gradients (Full Batch)

Σ x * error

(-3*0.9) + (-2*0.3) + (-1*-0.3) + (0*-0.9) +
(1*-1.5) + (2*-2.1) + (3*-2.7)
= -2.7 -0.6 + 0.3 + 0 -1.5 -4.2 -8.1
= -16.8

dL/dw:

dL/dw = (2/7) * (-16.8)
dL/dw ≈ -4.8

Σ error

0.9 + 0.3 -0.3 -0.9 -1.5 -2.1 -2.7 = -6.3

dL/db:

dL/db = (2/7) * (-6.3)
dL/db ≈ -1.8

3) UPDATE w AND b (Epoch 2)

Update w:

w_new = 1.40.05 * (-4.8)
w_new = 1.4 + 0.24
w_new = 1.64

Update b:

b_new = 0.10.05 * (-1.8)
b_new = 0.1 + 0.09
b_new = 0.19

End of Epoch 2

w = 1.64
b = 0.19
MSE = 2.25

Final Summary Table

Epoch w b MSE
1 1.40 0.10 5.00
2 1.64 0.19 2.25

As training continues, the neuron moves toward the true values: 


Activation function

Why Didn’t We Add an Activation Function in Our Example?

Because in our example you were teaching:

  • a single neuron

  • simple linear regression

  • with the goal to learn

y=2x+1y = 2x + 1

In this case, you must NOT add an activation function,
because any activation will break the linearity and prevent the neuron from learning the correct straight line.


When Do We Actually Add Activation Functions?

Activation functions are needed only when the problem is non-linear.

We add them when we have:

Deep neural networks
Non-linear tasks
Classification problems
XOR (classic non-linear problem)
Images
Audio
Text
Any pattern that is not a straight line

 


חלק ב

ניתוח קובץ אקסל :

תרגיל כיתה א  – שימוש בבינה מלאכותית לניתוח תוצאות של קובץ אקסל CHATGPT 

  1. נתח את קובץ האקסל  exp1  יבא אותו ל chatGpt

1.1 בקשו גרף קורציות מפת חום בין הטבאלות איפה ניראה שיש קורלציות   Correlation Map Between Columns

  1. בקשו הבינה המלאכותית – לנתח את הנתונים

2.1  כמה קבוצות של רמה בחשבון יש  ?

2.2 מה הפרמטרים שמשפעים  על כל קבוצה  – הנמוכה 0 , והקבוצה 3 הגבוהה ביותר

2.3 איזה עצה היית נותן שיש לאנשים הכנסה נמוכה ואין כסף למורים פרטים עבור שילהם שלהם יהיו טובים בחשבון  ?

3.3 לפי הנתונים האלה האם לכל ילד שנולד יש הזדמנות טובה להיות טוב במטמתיקה  ?

 

 

 

 

  1. נתח את קובץ האקסל  exp1  יבא אותו ל chatGpt

1.1 בקשו גרף קורלציות מפת חום בין הטבלאות איפה ניראה שיש קורלציות   Correlation Map Between Columns

  1. בקשו הבינה המלאכותית – לנתח את הנתונים

2.1  כמה קבוצות של רמה בחשבון יש  ?

2.2 מה הפרמטרים שמשפעים  על כל קבוצה  – הנמוכה 0 , והקבוצה 3 הגבוהה ביותר

2.3 איזה עצה היית נותן שיש לאנשים הכנסה נמוכה ואין כסף למורים פרטים עבור שלהם שלהם יהיו טובים בחשבון  ?

3.3 לפי הנתונים האלה האם לכל ילד שנולד יש הזדמנות טובה להיות טוב במתמטיקה  ?


 

שיווק מוצר בעזרת בינה מלאכותית  – תרגיל כיתה 

 


יצירת  וידאו :  מטקסט – שיווק מוצר עם בינה מלאכותית

 


 

יצירת  וידאו : מתמונה וטקסט – שיווק מוצר עם בינה מלאכותית

 


 

2.תרגיל כיתה : פיתוח מוצר בעזרת בינה מלאוכתית

1.1 התחלקו לצוות של 2 או 3 אנשים  , וחשבו על מוצר  המצאה שתרצו לשווק או לייצר  –  מה סוג המוצר ? לשוק דובר השפה האנגלית

2. בידקו בעזרת בינה מלאוכתית מי המתחרים , מה טווח מחירים בקשו קישורים למוצרים בתחום

2.1 איזה אתרים אפשרי לקבל מידע  על מתחרים עבור הנמוצר  בשוק באתרים חפש בעזרת בינה מלאוכתית : אמזון אייבי  ועליקספרסס

3. שאל את הבינה מלאוכתית  , באיזה 50  אתרים  בעולם ניתן וממולץ למכור את המוצר  ומה השלבים ?

הכנת חומר שיווקי עבור המוצר . 

4. הכינו  תמונה של המוצר טקסט ,  הסבר קצר  , ותאור מפורט על המוצר

4.1  מה יהיה מחיר עלות להערכת הבינה מלאכותית ומה מחיר מכירה  ?

5. בעזרת תוכנת canva צרו דמות AVATAR  שמתארת את המוצר  , תמונה של המוצר  בשפה האנגלית

6. צרו את הסרטון והעלו אותו ל YOUTUBE