MoonshineTokenizer
类keras_hub.tokenizers.MoonshineTokenizer(proto, **kwargs)
基于 keras_hub.models.LlamaTokenizer
的 Moonshine 分词器层。
此分词器类是 LlamaTokenizer
的别名,但专用于 Moonshine 模型。它使用 SentencePiece 词汇表进行分词。
参数
str
或 bytes
。可以是 SentencePiece proto 文件的字符串路径,也可以是包含序列化 SentencePiece proto 的字节对象。有关格式的详细信息,请参阅 SentencePiece 存储库。LlamaTokenizer
的其他关键字参数。示例
from keras_hub.tokenizers import MoonshineTokenizer
# Initialize tokenizer.
tokenizer = MoonshineTokenizer(
"keras_hub/src/tests/test_data/llama_test_vocab.spm"
)
# Single input example.
single_input = "the quick brown fox"
single_tokens = tokenizer(single_input)
print("Single input tokenization:")
print(f"Input text: {single_input}")
print(f"Tokenized: {single_tokens}")
# Batched input example.
batch_input = ["the quick brown fox", "the earth is round"]
batch_tokens = tokenizer(batch_input)
print("Batch input tokenization:")
print(f"Input texts: {batch_input}")
print(f"Tokenized: {batch_tokens}")
# Detokenization example.
encoded = tokenizer(single_input)
decoded = tokenizer.detokenize(encoded)
print("Detokenization:")
print(f"Original text: {single_input}")
print(f"Encoded: {encoded}")
print(f"Decoded: {decoded}")
from_preset
方法MoonshineTokenizer.from_preset(preset, config_file="tokenizer.json", **kwargs)
从模型预设实例化一个 keras_hub.models.Tokenizer
。
预设是一个包含配置、权重和其他文件资产的目录,用于保存和加载预训练模型。preset
可以作为以下之一传递:
'bert_base_en'
'kaggle://user/bert/keras/bert_base_en'
'hf://user/bert_base_en'
'./bert_base_en'
对于任何 Tokenizer
子类,您都可以运行 cls.presets.keys()
来列出该类上所有可用的内置预设。
此构造函数可以通过两种方式调用。可以从基类调用,如 keras_hub.models.Tokenizer.from_preset()
,或者从模型类调用,如 keras_hub.models.GemmaTokenizer.from_preset()
。如果从基类调用,返回对象的子类将根据预设目录中的配置推断。
参数
示例
# Load a preset tokenizer.
tokenizer = keras_hub.tokenizer.Tokenizer.from_preset("bert_base_en")
# Tokenize some input.
tokenizer("The quick brown fox tripped.")
# Detokenize some input.
tokenizer.detokenize([5, 6, 7, 8, 9])
预设 | 参数 | 描述 |
---|---|---|
llama2_7b_en | 6.74B | 70 亿参数,32 层,基础 LLaMA 2 模型。 |
llama2_instruct_7b_en | 6.74B | 70 亿参数,32 层,指令微调 LLaMA 2 模型。 |
vicuna_1.5_7b_en | 6.74B | 70 亿参数,32 层,指令微调 Vicuna v1.5 模型。 |
llama2_7b_en_int8 | 6.74B | 70 亿参数,32 层,基础 LLaMA 2 模型,激活和权重均量化为 int8。 |
llama2_instruct_7b_en_int8 | 6.74B | 70 亿参数,32 层,指令微调 LLaMA 2 模型,激活和权重均量化为 int8。 |
llama3.2_1b | 15.0 亿 | 10 亿参数、16 层的 LLaMA 3.2 基础模型。 |
llama3.2_instruct_1b | 15.0 亿 | 10 亿参数、16 层的经过指令调优的 LLaMA 3.2 模型。 |
llama3.2_guard_1b | 15.0 亿 | 10 亿参数、16 层的 LLaMA 3.2 基础模型,为同意安全分类进行了微调。 |
llama3.2_3b | 36.1 亿 | 30 亿参数、26 层的 LLaMA 3.2 基础模型。 |
llama3.2_instruct_3b | 36.1 亿 | 30 亿参数、28 层的经过指令调优的 LLaMA 3.2 模型。 |
llama3_8b_en | 80.3 亿 | 80 亿参数、32 层的 LLaMA 3 基础模型。 |
llama3_instruct_8b_en | 80.3 亿 | 80 亿参数、32 层的经过指令调优的 LLaMA 3 模型。 |
llama3.1_8b | 80.3 亿 | 80 亿参数、32 层的 LLaMA 3.1 基础模型。 |
llama3.1_instruct_8b | 80.3 亿 | 80 亿参数、32 层的经过指令调优的 LLaMA 3.1 模型。 |
llama3.1_guard_8b | 80.3 亿 | 80 亿参数、32 层的 LLaMA 3.1 模型,为同意安全分类进行了微调。 |
llama3_8b_en_int8 | 80.3 亿 | 80 亿参数、32 层的 LLaMA 3 基础模型,其激活和权重被量化为 int8。 |
llama3_instruct_8b_en_int8 | 80.3 亿 | 80 亿参数、32 层的经过指令调优的 LLaMA 3 模型,其激活和权重被量化为 int8。 |