Llama3CausalLMPreprocessor
類別keras_hub.models.Llama3CausalLMPreprocessor(
tokenizer, sequence_length=1024, add_start_token=True, add_end_token=True, **kwargs
)
Llama 3 因果語言模型預處理器。
此預處理層旨在與 keras_hub.models.Llama3CausalLM
一起使用。 預設情況下,它將接收成批的字串,並以 (x, y, sample_weight)
格式傳回輸出,其中 y
標籤是 x
序列中的下一個 token id。
為了用於生成,此層還公開了兩個方法 generate_preprocess()
和 generate_postprocess()
。 當此預處理器附加到 keras_hub.models.Llama3CausalLM
實例時,這些方法將在 generate()
中隱式調用。 它們也可以獨立調用(例如,在單獨的進程中預先計算生成預處理輸入)。
參數
keras_hub.models.Llama3Tokenizer
實例。True
,預處理器將把 tokenizer 開始 token 前置到每個輸入序列。 預設值為 False
。True
,預處理器將把 tokenizer 結束 token 附加到每個輸入序列。 預設值為 False
。調用參數
tf.Tensor
或 Python 字串列表。None
,因為該層生成標籤。None
,因為該層生成標籤權重。sequence_length
。範例
# Load the preprocessor from a preset.
preprocessor = keras_hub.models.Llama3CausalLMPreprocessor.from_preset(
"llama_base_en"
)
# Tokenize and pack a single sentence.
sentence = tf.constant("League of legends")
preprocessor(sentence)
# Same output.
preprocessor("League of legends")
# Tokenize a batch of sentences.
sentences = tf.constant(["Taco tuesday", "Fish taco please!"])
preprocessor(sentences)
# Same output.
preprocessor(["Taco tuesday", "Fish taco please!"])
# Map a dataset to preprocess a single sentence.
features = tf.constant(
[
"Avatar 2 is amazing!",
"Well, I am not sure.",
]
)
labels = tf.constant([1, 0])
ds = tf.data.Dataset.from_tensor_slices((features, labels))
ds = ds.map(preprocessor, num_parallel_calls=tf.data.AUTOTUNE)
# Map a dataset to preprocess unlabled sentences.
ds = tf.data.Dataset.from_tensor_slices(features)
ds = ds.map(preprocessor, num_parallel_calls=tf.data.AUTOTUNE)
from_preset
方法Llama3CausalLMPreprocessor.from_preset(
preset, config_file="preprocessor.json", **kwargs
)
從模型預設實例化 keras_hub.models.Preprocessor
。
預設是一個配置、權重和其他檔案資產的目錄,用於儲存和載入預訓練模型。 preset
可以作為以下其中之一傳遞:
'bert_base_en'
'kaggle://user/bert/keras/bert_base_en'
'hf://user/bert_base_en'
'./bert_base_en'
對於任何 Preprocessor
子類別,您可以運行 cls.presets.keys()
以列出該類別上所有可用的內建預設。
由於給定模型通常有多個預處理類別,因此應在特定子類別(例如 keras_hub.models.BertTextClassifierPreprocessor.from_preset()
)上調用此方法。
參數
範例
# Load a preprocessor for Gemma generation.
preprocessor = keras_hub.models.CausalLMPreprocessor.from_preset(
"gemma_2b_en",
)
# Load a preprocessor for Bert classification.
preprocessor = keras_hub.models.TextClassifierPreprocessor.from_preset(
"bert_base_en",
)
預設 | 參數 | 描述 |
---|---|---|
llama3_8b_en | 8.03B | 80 億參數、32 層、基礎 LLaMA 3 模型。 |
llama3_instruct_8b_en | 8.03B | 80 億參數、32 層、指令微調 LLaMA 3 模型。 |
llama3_8b_en_int8 | 8.03B | 80 億參數、32 層、基礎 LLaMA 3 模型,具有量化為 int8 的激活和權重。 |
llama3_instruct_8b_en_int8 | 8.03B | 80 億參數、32 層、指令微調 LLaMA 3 模型,具有量化為 int8 的激活和權重。 |
tokenizer
屬性keras_hub.models.Llama3CausalLMPreprocessor.tokenizer
用於 token 化字串的 tokenizer。