Giter VIP home page Giter VIP logo

Comments (2)

kellywzhang avatar kellywzhang commented on July 23, 2024

Hello, so I replicated this issue when using the newest version of PyTorch. The issue seems to be just differences in the default dimensions (whether they're kept or squeezed). I didn't try it with the pre-trained model, but changing the generate method in model.py to the following fixed it for me:

    def generate(self, hidden, maxlen, sample=True, temp=1.0):
            """Generate through decoder; no backprop"""

            batch_size = hidden.size(0)

            if self.hidden_init:
                    # initialize decoder hidden state to encoder output
                    state = (hidden.unsqueeze(0), self.init_state(batch_size))
            else:
                    state = self.init_hidden(batch_size)

            # <sos>
            self.start_symbols.data.resize_(batch_size)
            self.start_symbols.data.fill_(1)

            embedding = self.embedding_decoder(self.start_symbols)
            inputs = torch.cat([embedding, hidden], 1).unsqueeze(1)

            # unroll
            all_indices = []
            for i in range(maxlen):
                    output, state = self.decoder(inputs, state)
                    overvocab = self.linear(output.squeeze(1))

            if not sample:
                    vals, indices = torch.max(overvocab, 1)
            else:
                    # sampling
                    probs = F.softmax(overvocab/temp)
                    indices = torch.multinomial(probs, 1).squeeze(1)

            all_indices.append(indices.unsqueeze(1))

            embedding = self.embedding_decoder(indices)
            inputs = torch.cat([embedding, hidden], 1).unsqueeze(1)

            max_indices = torch.cat(all_indices, 1)

            return max_indices`

I'm thinking to make an update to the code at some point, but not yet as I don't want to change something that would lead to problems when running with the old version of PyTorch.

Let me know if you run into other issues. Best!

from arae.

JulesGM avatar JulesGM commented on July 23, 2024

Hello. I would propose that this (#8 (comment)) be pushed to the main version, if you so desire, because it's been a while.
thanks for the help!

from arae.

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.