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

How to create Tokenizer.json? #1410

Closed
kenaii opened this issue Dec 8, 2023 · 2 comments
Closed

How to create Tokenizer.json? #1410

kenaii opened this issue Dec 8, 2023 · 2 comments
Labels

Comments

@kenaii
Copy link

kenaii commented Dec 8, 2023

I have this tokenizer and I want to convert it to tokenizer.json format.

  • added_tokens.json
  • normalizer.json
  • special_tokens_map.json
  • config.json
  • preprocessor_config.json
  • vocab.json
  • merges.txt
  • pytorch_model.bin

Is it possible to replace my tokenizer data with the original tokenizer.json?

import json

j = open('hf/tokenizer.json')
data = json.load(j)

with open('medium-tokenizer/merges.txt') as f:
    merges = f.readlines()
merges.pop(0)

j = open('medium-tokenizer/vocab.json')
vocab = json.load(j)
j = open('medium-tokenizer/added_tokens.json')
added_tokens = json.load(j)
j = open('medium-tokenizer/normalizer.json')
normalizer = json.load(j)

data['added_tokens'] = added_tokens
data['normalizer'] = normalizer
data['model']['vocab'] = vocab
data['model']['merges'] = merges

with open("tokenizer.json", "w") as outfile:
    json.dump(data, outfile)
@ArthurZucker
Copy link
Collaborator

Hey! You should be using the transformers library to load the slow tokenizer in a XXTokenizerFast which will automtically do the conversion if supported

Copy link

github-actions bot commented Jan 9, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jan 9, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants