def variableFromSentence(self, lang, sentence): def indexesFromSentence(lang, sentence): return [lang[word] for word in sentence.split(' ')] indexes = indexesFromSentence(lang, sentence) indexes.append(lang['EOS']) return Variable(LongTensor(indexes).view(-1, 1))
def initHiddenVariable(self): return Variable(zeros(1, 1, self.hidden_size))
def initInputVariable(self, token): return Variable(LongTensor([[token]]))
def initOutputVariables(self, max_length): return Variable(zeros(max_length, self.hidden_size))