DocsGPT/application/utils.py

6 lines
175 B
Python
Raw Normal View History

from transformers import GPT2TokenizerFast
def count_tokens(string):
tokenizer = GPT2TokenizerFast.from_pretrained('gpt2')
return len(tokenizer(string)['input_ids'])