Multiclass SVM Loss

Tldr

Given an example (xi,yi) where xi is the image and yi is the label, and using the shorthand for the scores vector s=f(xi,W)

The SVM loss has the form

Li=jyimax(0,sjsyi+1)
def L_i_vectorized(x, y, w):
	scores = W.dot(x)
	margins = np.maximum(0, scores - scores[y] + 1)
	margins[y] = 0
	loss_i = np.sum(margins)
	return loss_i

Loss over full dataset is average of each loss

Pasted image 20241130153942.png

Example

Pasted image 20241130154230.png