1 of 50

COSI 115b - Lab 4

2/7/2025

2 of 50

Review

  • What is Bayes rule?
  • What is Naive Bayes?
  • What is Logistic Regression?
  • What is a perceptron?
  • What is a structured perceptron?
  • What is an activation function?
  • What is softmax?
  • What is a loss function?
  • What is regularization?
  • What is an optimizer?

3 of 50

Perceptron

  • Simpler than logistic regression
  • Activation function is {1,0}

4 of 50

Perceptron

  • Learning Algorithm
    • If ŷ = y, then ŷ - y = 0
      • No update

5 of 50

Perceptron

  • Learning Algorithm
    • If ŷ = y, then ŷ - y = 0
      • No update
    • If ŷ = 0 and y = 1, then ŷ - y = - 1
      • ∇ L = -x
      • θt+1 = θt + ηx
      • Increment the weights

6 of 50

Perceptron

  • Learning Algorithm
    • If ŷ = y, then ŷ - y = 0
      • No update
    • If ŷ = 0 and y = 1, then ŷ - y = - 1
      • ∇ L = -x
      • θt+1 = θt + ηx
      • Increment the weights
    • If ŷ = 1 and y = 0, then ŷ - y = 1
      • ∇ L = x
      • θt+1 = θt - ηx
      • Decrement the weights

7 of 50

Perceptron Loss

L(ŷ,y) = (ŷ-y)z

8 of 50

9 of 50

10 of 50

11 of 50

12 of 50

13 of 50

14 of 50

Perceptron Example

Suppose pos = 1 and neg = 0.

We have features weights:

“dog”: -0.5

“like”: 0.2

“tacos”: -0.3

“not”: -0.7

“coffee”: 0.4

bias: 0.1

We get neg example, “The dog does not like fish”

What is the gradient?

(y_hat - y) x what is y_hat?

y_hat = sign(-0.5 * 0.2 * -0.7 * 0.1)

y_hat = 1

(1 - 0) x = (1)[1, 1, 0, 1, 0, 1] = [1, 1, 0, 1, 0, 1]

How do we update the current weights?

[-0.5, -0.2, -0.3, -0.7, 0.4, 0.1] - (lr *[1, 1, 0, 1, 0, 1])

What would happen if the gold label (true class) was positive?

We would get it right so no update (yhat - y) = 0

15 of 50

POS Tagging:

NER:

The

dog

ate

tacos

DT

NN

VBD

NNS

Brandeis

University

is

in

Massachusetts

B-ORG

I-ORG

O

O

B-LOC

16 of 50

17 of 50

18 of 50

19 of 50

20 of 50

21 of 50

22 of 50

23 of 50

24 of 50

25 of 50

26 of 50

27 of 50

28 of 50

29 of 50

30 of 50

31 of 50

32 of 50

33 of 50

34 of 50

35 of 50

36 of 50

37 of 50

38 of 50

39 of 50

40 of 50

41 of 50

42 of 50

43 of 50

44 of 50

45 of 50

46 of 50

47 of 50

48 of 50

49 of 50

50 of 50