Giter Site home page Giter Site logo

Comments (4)

WeiFoo avatar WeiFoo commented on May 29, 2024 1

cool, thanks!! The mistake in the official Classifying Names with a Character-Level RNN tutorial
should be fixed as well.

import time
import math

n_epochs = 100000
print_every = 5000
plot_every = 1000

rnn = RNN(n_letters, n_hidden, n_categories)

# Keep track of losses for plotting
current_loss = 0
all_losses = []

from practical-pytorch.

spro avatar spro commented on May 29, 2024

This is because of a mistake where the RNN is initialized twice (once at the top, once below creating the optimizer) - so optimizer is optimizing parameters that aren't being used. Commit 0cc55f5 should fix it.

from practical-pytorch.

WeiFoo avatar WeiFoo commented on May 29, 2024

where the RNN is initialized twice (once at the top, once below creating the optimizer)

I don't understand this.

I checked the commit 0cc55f5, it seems that is same as what I did above using optimizer. The resutls are the same, only very limited correct predictions. most are wrong.

from practical-pytorch.

spro avatar spro commented on May 29, 2024

The problem is lower down, around 0cc55f5#diff-e9a91a525ccafb52f5b1e35131d4011cL51

The RNN was being re-created after the optimizer:

rnn = RNN(n_letters, n_hidden, n_categories) # rnn 1
optimizer = torch.optim.SGD(rnn.parameters(), lr=learning_rate) # Using rnn 1's parameters

def train():
    ...
    rnn(...) # This is going to refer to the rnn 2, because of below
    optimizer(...) # This still has parameters of rnn 1
    ...

rnn = RNN(n_letters, n_hidden, n_categories) # rnn 2 causes the problem, delete this

So the optimizer was not working, because rnn was redefined to and has a completely new set of parameters, while the optimizer has a reference to the old one.

from practical-pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.