def decoder(idx_vec, itos):
    """Return a SMILES string from an index vector (deals with reversal)"""
    if len(idx_vec) < 2:
        return ""
    if idx_vec[1] == 1:  # SMILES string is in fwd direction
        return ''.join(itos[x] for x in idx_vec if x > 3)
    if idx_vec[1] == 2:  # SMILES string is in bwd direction
        return ''.join(itos[x] for x in idx_vec[::-1] if x > 3)
    else: # don't know how to deal with it---do your best
        return ''.join(itos[x] for x in idx_vec if x > 3)