def sample(self, input, steps): """ Sample outputs from LM. """ inputs = [[onehot(self.input_dim, x) for x in input]] for _ in range(steps): target = self.compute(inputs)[0, -1].argmax() input.append(target) inputs[0].append(onehot(self.input_dim, target)) return input
def prepare(self): if not self.cached: return onehot_matrix = [] for i in xrange(self.vocab_size): onehot_matrix.append(onehot(self.vocab_size, i)) onehot_matrix = np.array(onehot_matrix, dtype=FLOATX) self.onehot_list = self.create_matrix(self.vocab_size, self.vocab_size, "onehot_list") self.onehot_list.set_value(onehot_matrix)
def random_vector(): return onehot(VECTOR_SIZE, random.randint(0, VECTOR_SIZE - 1))