ai21 tokenizer
v0.12.0
基于 SentencePiece 的分词器,用于 AI21 模型的生产使用
Jamba 1.5 Mini
或Jamba 1.5 Large
的标记器,您将需要请求访问相关模型的 HuggingFace 存储库:pip install ai21-tokenizer
poetry add ai21-tokenizer
from ai21_tokenizer import Tokenizer , PreTrainedTokenizers
tokenizer = Tokenizer . get_tokenizer ( PreTrainedTokenizers . JAMBA_1_5_MINI_TOKENIZER )
# Your code here
另一种方法是直接使用我们的 Jamba 1.5 Mini tokenizer:
from ai21_tokenizer import Jamba1_5Tokenizer
model_path = "<Path to your vocabs file>"
tokenizer = Jamba1_5Tokenizer ( model_path = model_path )
# Your code here
from ai21_tokenizer import Tokenizer , PreTrainedTokenizers
tokenizer = await Tokenizer . get_async_tokenizer ( PreTrainedTokenizers . JAMBA_1_5_MINI_TOKENIZER )
# Your code here
from ai21_tokenizer import Tokenizer , PreTrainedTokenizers
tokenizer = Tokenizer . get_tokenizer ( PreTrainedTokenizers . JAMBA_1_5_LARGE_TOKENIZER )
# Your code here
另一种方法是直接使用我们的 Jamba 1.5 Large tokenizer:
from ai21_tokenizer import Jamba1_5Tokenizer
model_path = "<Path to your vocabs file>"
tokenizer = Jamba1_5Tokenizer ( model_path = model_path )
# Your code here
from ai21_tokenizer import Tokenizer , PreTrainedTokenizers
tokenizer = await Tokenizer . get_async_tokenizer ( PreTrainedTokenizers . JAMBA_1_5_LARGE_TOKENIZER )
# Your code here
from ai21_tokenizer import Tokenizer , PreTrainedTokenizers
tokenizer = Tokenizer . get_tokenizer ( PreTrainedTokenizers . JAMBA_INSTRUCT_TOKENIZER )
# Your code here
另一种方法是直接使用我们的 Jamba 标记器:
from ai21_tokenizer import JambaInstructTokenizer
model_path = "<Path to your vocabs file>"
tokenizer = JambaInstructTokenizer ( model_path = model_path )
# Your code here
from ai21_tokenizer import Tokenizer , PreTrainedTokenizers
tokenizer = await Tokenizer . get_async_tokenizer ( PreTrainedTokenizers . JAMBA_INSTRUCT_TOKENIZER )
# Your code here
另一种方法是使用我们的异步 Jamba tokenizer 类方法 create:
from ai21_tokenizer import AsyncJambaInstructTokenizer
model_path = "<Path to your vocabs file>"
tokenizer = AsyncJambaInstructTokenizer . create ( model_path = model_path )
# Your code here
from ai21_tokenizer import Tokenizer
tokenizer = Tokenizer . get_tokenizer ()
# Your code here
另一种方法是直接使用我们的侏罗纪模型:
from ai21_tokenizer import JurassicTokenizer
model_path = "<Path to your vocabs file. This is usually a binary file that end with .model>"
config = {} # "dictionary object of your config.json file"
tokenizer = JurassicTokenizer ( model_path = model_path , config = config )
from ai21_tokenizer import Tokenizer
tokenizer = await Tokenizer . get_async_tokenizer ()
# Your code here
另一种方法是使用我们的异步 Jamba tokenizer 类方法 create:
from ai21_tokenizer import AsyncJurassicTokenizer
model_path = "<Path to your vocabs file. This is usually a binary file that end with .model>"
config = {} # "dictionary object of your config.json file"
tokenizer = AsyncJurassicTokenizer . create ( model_path = model_path , config = config )
# Your code here
这些函数允许您将文本编码为令牌 ID 列表并返回明文
text_to_encode = "apple orange banana"
encoded_text = tokenizer . encode ( text_to_encode )
print ( f"Encoded text: { encoded_text } " )
decoded_text = tokenizer . decode ( encoded_text )
print ( f"Decoded text: { decoded_text } " )
# Assuming you have created an async tokenizer
text_to_encode = "apple orange banana"
encoded_text = await tokenizer . encode ( text_to_encode )
print ( f"Encoded text: { encoded_text } " )
decoded_text = await tokenizer . decode ( encoded_text )
print ( f"Decoded text: { decoded_text } " )
tokens = tokenizer . convert_ids_to_tokens ( encoded_text )
print ( f"IDs corresponds to Tokens: { tokens } " )
ids = tokenizer . convert_tokens_to_ids ( tokens )
# Assuming you have created an async tokenizer
tokens = await tokenizer . convert_ids_to_tokens ( encoded_text )
print ( f"IDs corresponds to Tokens: { tokens } " )
ids = tokenizer . convert_tokens_to_ids ( tokens )
有关更多示例,请参阅我们的示例文件夹。