Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable bad_token_ids policies #8

Open
dxoigmn opened this issue Jan 27, 2025 · 0 comments
Open

Customizable bad_token_ids policies #8

dxoigmn opened this issue Jan 27, 2025 · 0 comments

Comments

@dxoigmn
Copy link
Contributor

dxoigmn commented Jan 27, 2025

llmart has the capability of banning "bad" tokens from the adversarial optimization.

Right now bad_token_ids implements a static policy for what is considered a "bad" token (non-printability, ascii-only):

def bad_token_ids(self) -> torch.Tensor:
added_tokens = self.added_tokens_encoder.keys()
tokens = [
self.convert_tokens_to_string([token])
for token in self.convert_ids_to_tokens(list(range(self.__vocab_size)))
]
printable_tokens = torch.tensor(
[
token.isprintable()
and token.isascii()
and token not in added_tokens
and len(token.strip()) > 0
for token in tokens
],
)
return torch.where(~printable_tokens)[0]

Being able to add configurable policies would help with non-ascii languages. Additionally, being able to ban a set of tokens would also be beneficial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants