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

Offline tokenization produces empty token_strings #493

Open
yifanmai opened this issue May 7, 2024 · 3 comments · May be fixed by #494
Open

Offline tokenization produces empty token_strings #493

yifanmai opened this issue May 7, 2024 · 3 comments · May be fixed by #494
Assignees

Comments

@yifanmai
Copy link

yifanmai commented May 7, 2024

When I run the script on this doc: https://docs.cohere.com/reference/tokenize

response = co.tokenize(text="tokenize me! :D", model="command")

I get:

tokens=[10002, 2261, 2012, 8, 2792, 43] token_strings=[] meta=None

where token_strings is an empty array, even thought the docs suggests that it should be non-empty. However, if I run:

response = co.tokenize(text="tokenize me! :D", model="command", offline=False)

I get the token_strings as expected:

tokens=[10002, 2261, 2012, 8, 2792, 43] token_strings=['token', 'ize', ' me', '!', ' :', 'D'] meta=ApiMeta(api_version=ApiMetaApiVersion(version='1', is_deprecated=None, is_experimental=None), billed_units=None, tokens=None, warnings=None)

It would be nice if token_strings could be supported for offline tokenization, so that the online and offline behavior is identical. I'll attach a pull request for how this could be done.

Copy link

elaineg commented May 8, 2024

Hi, thanks for catching any discrepancies in documentation, we had updated https://docs.cohere.com/docs/tokens-and-tokenizers#tokenization-in-python-sdk and the release note https://docs.cohere.com/changelog/python-sdk-v520-release.

Do you use the token_strings? I wonder if it would be acceptable to remove them from the network call to achieve identical behaviour.

@elaineg elaineg self-assigned this May 8, 2024
@yifanmai
Copy link
Author

yifanmai commented May 8, 2024

Yes, token_strings removing from the network call would also make things more uniform.

I have a use case that uses token_strings, however, I can work around this issue - I can get the token strings by using the Hugging Face tokenizers library directly with the downloaded tokenizer.json files.

@yifanmai
Copy link
Author

yifanmai commented May 8, 2024

Another alternative would be to add a parameter that controls whether token_strings are returned (in both the library and the server API).

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

Successfully merging a pull request may close this issue.

2 participants