Skip to content

Commit

Permalink
Added RNN
Browse files Browse the repository at this point in the history
  • Loading branch information
bfortuner committed Oct 24, 2017
1 parent 96c9f12 commit 3efdf2c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
8 changes: 5 additions & 3 deletions code/rnn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import torch
import torch.nn as nn
#from torch.autograd import Variable

class RNN(nn.Module):
def __init__(self, n_classes):
Expand All @@ -17,16 +19,16 @@ def forward(self, inputs, hidden):

def train(model, inputs, targets):
for i in range(len(inputs)):
target = Variable([targets[i]])
target = Variable(targets[i])
name = inputs[i]
hidden = Variable(torch.zeros(1,128))
model.zero_grad()

for char in name:
input_ = Variable(torch.FloatTensor(char))
out, hidden = model(input_, hidden)
pred, hidden = model(input_, hidden)

loss = criterion(out, target)
loss = criterion(pred, target)
loss.backward()

for p in model.parameters():
Expand Down
41 changes: 24 additions & 17 deletions docs/deep_learning.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,35 @@ Deep Learning

.. contents:: :local:


General
=======
Autoencoder
===========

Be the first to `contribute! <https://github.com/bfortuner/ml-cheatsheet>`__

Autoencoder
===========
- `Deep Learning Book <http://www.deeplearningbook.org/contents/autoencoders.html>`_


CNN
===

Be the first to `contribute! <https://github.com/bfortuner/ml-cheatsheet>`__

`cnn reference <http://www.deeplearningbook.org/contents/convnets.html>`_
- `Deep Learning Book <http://www.deeplearningbook.org/contents/convnets.html>`_


GAN
===

- `Deep Learning Book <http://www.deeplearningbook.org/contents/generative_models.html>`_


RNN
===

Description of RNN use case and basic architecture.

.. image:: images/relu.png
:align: center
:width: 256 px
:height: 256 px
.. image:: images/rnn.png
:align: center

.. rubric:: Model

Expand All @@ -40,20 +43,24 @@ Description of RNN use case and basic architecture.

.. rubric:: Training

Explanation of training loop
In this example, our input is a list of last names, where each name is
a variable length array of one-hot encoded characters. Our target is is a list of
indices representing the class (language) of the name.

.. literalinclude:: ../code/rnn.py
1. For each input name..
2. Initialize the hidden vector
3. Loop through the characters and predict the class
4. Pass the final character's prediction to the loss function
5. Backprop and update the weights

.. literalinclude:: ../code/rnn.py
:pyobject: train

.. rubric:: Further reading

- `Jupyter notebook <https://github.com/bfortuner/ml-cheatsheet/notebooks/rnn.ipynb>`_
- `Deep Learning Book <http://www.deeplearningbook.org/contents/rnn.html>`_

GAN
===

- ` Deep Learning Book <http://www.deeplearningbook.org/contents/generative_models.html>`_


VAE
===
Expand Down
Binary file added docs/images/rnn.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ Brief visual explanations of machine learning concepts with diagrams, code examp

.. toctree::
:maxdepth: 1
:caption: Algorithms (empty)
:caption: Algorithms

Applications <applications>
Classification <classification_algos>
Clustering <clustering_algos>
Deep Learning <deep_learning>
Generative <generative_algos>
Regression <regression_algos>
Reinforcement Learning <reinforcement_learning>

.. toctree::
:maxdepth: 1
Expand Down
15 changes: 15 additions & 0 deletions docs/reinforcement_learning.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. _reinforcement_learning:

======================
Reinforcement Learning
======================

Be the first to `contribute! <https://github.com/bfortuner/ml-cheatsheet>`__


.. rubric:: References

.. [1] Example Reference
Empty file added notebooks/rnn.ipynb
Empty file.

0 comments on commit 3efdf2c

Please sign in to comment.