(encoder, ids, num_reserved)
return encoder.decode(ids.flatten().tolist())
Decode ids.
Decode ids.
Decode ids .
def ids2str(encoder, ids, num_reserved):
  """Decode ids."""
  if num_reserved:
    eos = np.where(ids == 1)[0]
    if np.any(eos):
      ids = ids[:eos[0]]
    reserved_tokens = np.where(ids < num_reserved)[0]
    if reserved_tokens.size:
      split_locations = np.union1d(reserved_tokens, reserved_tokens + 1)
      ids_list = np.split(ids, split_locations)
      text_list = [
          "<%d>" %
          i if len(i) == 1 and i < num_reserved else encoder.decode(i.tolist())
          for i in ids_list
      ]
      return " ".join(text_list)
  return encoder.decode(ids.flatten().tolist())
def ids2str ( encoder , ids , num_reserved ) : if num_reserved : eos = np . where ( ids == 1 ) [ 0 ] if np . any ( eos ) : ids = ids [ : eos [ 0 ] ] reserved_tokens = np . where ( ids < num_reserved ) [ 0 ] if reserved_tokens . size : split_locations = np . union1d ( reserved_tokens , reserved_tokens + 1 ) ids_list = np . split ( ids , split_locations ) text_list = [ "<%d>" % i if len ( i ) == 1 and i < num_reserved else encoder . decode ( i . tolist ( ) ) for i in ids_list ] return " " . join ( text_list ) return encoder . decode ( ids . flatten ( ) . tolist ( ) )