Tiktoken#
tiktoken is a fast
BPE
tokeniser created byOpenAI
.
How the text is split: by
tiktoken
tokensHow the chunk size is measured: by
tiktoken
tokens
#!pip install tiktoken
# This is a long document we can split up.
with open('../../../state_of_the_union.txt') as f:
state_of_the_union = f.read()
from langchain.text_splitter import TokenTextSplitter
text_splitter = TokenTextSplitter(chunk_size=10, chunk_overlap=0)
texts = text_splitter.split_text(state_of_the_union)
print(texts[0])
Madam Speaker, Madam Vice President, our