def decode(self, vec, pretty=False, strict=True):
# TODO: Whether we should use 'strict' mode depends on whether the model
# we got this vector from does softmax sampling of visibles. Anywhere this
# is called on fantasy samples, we should use the model to set this param.
if issparse(vec):
vec = vec.toarray().reshape(-1)
assert vec.shape == (self.nchars * self.maxlen,)
chars = []
for position_index in range(self.maxlen):
# Hack - insert a tab between name parts in binomial mode
if isinstance(self, BinomialShortTextCodec) and pretty and position_index == self.maxlen/2:
chars.append('\t')
subarr = vec[position_index * self.nchars:(position_index + 1) * self.nchars]
if np.count_nonzero(subarr) != 1 and strict:
char = self.MYSTERY
else:
char_index = np.argmax(subarr)
char = self.alphabet[char_index]
if pretty and char == self.FILLER:
# Hack
char = ' ' if isinstance(self, BinomialShortTextCodec) else ''
chars.append(char)
return ''.join(chars)
评论列表
文章目录