def _translate(seq): use_noise.set_value(0.) # sample given an input sequence and obtain scores sample, score = gen_sample(tparams, f_init, f_next, numpy.array(seq).reshape([len(seq), 1]), options, trng=trng, k=k, maxlen=500, stochastic=False, argmax=False) # normalize scores according to sequence lengths if normalize: lengths = numpy.array([len(s) for s in sample]) score = score / lengths sidx = numpy.argmin(score) return sample[sidx]
def _translate(seq): use_noise.set_value(0.) # sample given an input sequence and obtain scores # NOTE : if seq length too small, do something about it sample, score = gen_sample(tparams, f_init, f_next, numpy.array(seq).reshape([len(seq), 1]), options, trng=trng, k=k, maxlen=500, stochastic=False, argmax=False) # normalize scores according to sequence lengths if normalize: lengths = numpy.array([len(s) for s in sample]) score = score / lengths # sidx = numpy.argmin(score) sidx = random.randint(0, len(sample) - 1) return sample[sidx], score[sidx]