Giter VIP home page Giter VIP logo

Comments (3)

voidmagic avatar voidmagic commented on May 17, 2024 2

And I pulled a new request for it just now, see #63
I rewrite it as h = torch.cat([h[0:h.size(0):2], h[1:h.size(0):2]], 2), it is 10% faster on my computer.

from opennmt-py.

voidmagic avatar voidmagic commented on May 17, 2024

Hey, I also confused with question last night, but now I have figured out how it works.

Like this example:

torch.manual_seed(1)
lstm = nn.LSTM(input_size=1,
               num_layers=1,
               bidirectional=True,
               bias=False,
               hidden_size=1)

a = Variable(torch.ones(1, 1, 1))
result, context = lstm(a)
print(context)
output: 
Variable containing:
(0 ,.,.) = 
  0.1321

(1 ,.,.) = 
 -0.0980
[torch.FloatTensor of size 2x1x1]

and then change its layer to 2:

torch.manual_seed(1)
lstm = nn.LSTM(input_size=1,
               num_layers=2,
               bidirectional=True,
               bias=False,
               hidden_size=1)

a = Variable(torch.ones(1, 1, 1))
result, context = lstm(a)
print(context[0])
output: 
Variable containing:
(0 ,.,.) = 
  0.1321

(1 ,.,.) = 
 -0.0980

(2 ,.,.) = 
  0.0037

(3 ,.,.) = 
 -0.0032
[torch.FloatTensor of size 4x1x1]

Because I manually set the random seed, so the parameter of LSTM will be same at each time, and the result shows that the order of h is :
[
layer0_forward
layer0_backward
layer1_forward
layer1_backward
layer2_forward
layer2_backward
...
]
And the same for c.

from opennmt-py.

lan2720 avatar lan2720 commented on May 17, 2024

@voidmagic Great! Thanks.

from opennmt-py.

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.