Skip to content

Week 4 Lecture 2

Neural networks

Different ways to categorize neural networks:

  • feed-forward NN recurrent networks
  • supervised unsupervised

The function 𝑧𝑖(π‘₯) represents the output of neuron 𝑖.

x is often omitted for simplicity

Modeling real world neurons, the idea is that neurons integrate their inputs, and fire over some threshold.

Pre-activation:

π‘Žπ‘–=βˆ‘π‘—=1𝑑𝑀𝑖𝑗π‘₯𝑗+𝑀𝑖0

Then we apply some transfer function (activation function) β„Ž to it:

𝑧𝑖=β„Ž(π‘Žπ‘–)=β„Ž(βˆ‘π‘—=1𝑑𝑀𝑖𝑗π‘₯𝑗+𝑀𝑖0)

One of the β€œdefault” choices for β„Ž is the logistic function (or any non-polynomial function)

A single neuron by itself is not very useful (can’t even compute XOR).

A neural network is a DAG network of neurons

𝑑=Number of input neurons
𝑀=Number of hidden neurons
𝐾=Number of output neurons

Activation function of neuron 𝑖 is denoted β„Žπ‘–

Neuron 𝑖 can only get input from neuron 𝑗<𝑖, making sure the graph stays acyclic.

Pre-activation of neuron 𝑖>𝑑 (non-input neuron):

π‘Žπ‘–=βˆ‘(𝑗,𝑖)βˆˆπ΄π‘€π‘–π‘—π‘§π‘—

𝑀𝑖𝑗 means β€œweight from 𝑗 to 𝑖”.

𝑧𝑖=β„Žπ‘–(π‘Žπ‘–)
  • 𝑧0 is always 1 since z_0 is associated with the bias parameter
  • 𝑧𝑖=π‘₯π‘–βˆ€π‘–βˆˆπ‘‰input (The results on the input neurons is exactly the input)
Gradient descent will return in Machine Learning A

We are going to use sum-of-squares error for regression

Classification

one-hot encoding

Class 𝑖 from 𝑛 can be encoded as: (00…1…0)

Binary Classification

If we assume the sum of 𝑓(π‘₯𝑖) are 1, and are all non-negative (i.e. our 𝑓 models probabilities):

𝑝(π‘₯belongs to class encoded by y|π‘₯)=βˆπ‘˜=1𝐾[𝑓(π‘₯)]π‘¦π‘˜
i.e. the element of 𝑓(π‘₯) that’s indexed by 𝑦

Giving the negative log-likelihood (called cross-entropy):

βˆ’ln𝑝(𝑆)=βˆ’βˆ‘π‘›=1π‘βˆ‘π‘˜=1𝐾[𝑦𝑛]π‘˜ln(𝑓(π‘₯𝑛))π‘˜

Multi-class Classification

We could use soft-max (still making sure of the sum to be 1)

𝑓(π‘₯)𝑗=π‘’π‘Žπ‘€+𝑑+π‘—βˆ‘π‘˜=1πΎπ‘’π‘Žπ‘€+𝑑+π‘˜

Thus, we can have a neural network, with soft-max as its last activation, and then a cross-entropy layer for training.

In reality, the model would output the values BEFORE soft-max. During training we could use a loss combining soft-max and log-likelihood, and during inference just add a soft-max.

Layers

A layer is a collection of neurons, where each neuron has the same inputs, and does the same calculation (has the same activation)

Layers can be numbered 𝑙, and each layer 𝑙 only gets inputs from 𝑙′<𝑙

β„Ž(𝑙) is the activation of layer 𝑙

Inputs of layer 𝑙 is gathered into a vector π‘₯(𝑙)

We can denote the weights of the 𝑖th neuron in layer 𝑙 by 𝑀𝑖(𝑙), and the bias by 𝑏𝑖(𝑙). This way the result is:

β„Žπ‘–(𝑙)(π‘₯)=β„Žπ‘–(𝑙)([π‘₯𝑖(𝑙)]𝑇π‘₯+𝑏𝑖(𝑙))

Or, in matrix form (assuming implicit bias):

𝐻(𝑙)(𝑋(𝑙))=β„Ž(𝑙)(π‘Š(𝑙)[𝑋(𝑙)]𝑇)

(where β„Ž(𝑙) acts component-wise)

Epoch: one pass through the training data