Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

05 — Multilayer Perceptron

A linear model can only draw a straight line. Stack two linear layers with a non-linearity between them and you get something that can curve, twist, and approximate (in theory) any continuous function.

What's new

  • nn.Module — the base class for every model. Holds parameters, supports .to(device), .train(), .eval(), etc.
  • nn.Sequential — sugar for "apply these layers in order".
  • ReLUmax(0, x). The most common activation. Cheap and works well.
  • CrossEntropyLoss — for multi-class classification. Combines log-softmax + NLL.
  • Adam — an optimizer that adapts the learning rate per-parameter. Usually a good default.

Why non-linearities matter

Two linear layers without an activation collapse into a single linear layer (matrix multiplication is associative). The non-linearity in between is what gives the model expressive power.

Things to try

  • Remove the nn.ReLU() lines — accuracy collapses to a logistic-regression baseline.
  • Shrink hidden to 4 — under-fitting.
  • Train for 3000 epochs — over-fitting (loss keeps dropping but the model memorizes noise).

Run

python 05_mlp/main.py