Affine maps

Affine maps are one of the basic building components of deep learning, and are represented as follows:

In this case, the matrix is represented by A and the vectors are represented by x and b. A and b are the parameters that need to be learned, while b is the bias. 

A simple example to explain this is as follows:

import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim

torch.manual_seed(1)
lin = nn.Linear(6, 3) # maps from R^6 to R^3, parameters A, b
# data is 2x5. A maps from 6 to 3... can we map "data" under A?
data = torch.randn(2, 6)
print(lin(data)

After this, run the program with the following command:

$ python3 torch_nlp.py

The output will be as follows:

tensor([[ 1.1105, -0.1102, -0.3235],
[ 0.4800, 0.1633, -0.2515]], grad_fn=<AddmmBackward>)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset