隨機取樣器

[原始碼]

RandomSampler 類別

keras_hub.samplers.RandomSampler(seed=None, **kwargs)

隨機取樣器類別。

此取樣器實作隨機取樣。簡而言之,隨機取樣器會從所有詞元的完整分佈中隨機選擇一個詞元,選擇機率由每個詞元的機率決定。

參數

  • seed:整數。隨機種子。預設為 None

呼叫參數

{{call_args}}

範例

causal_lm = keras_hub.models.GPT2CausalLM.from_preset("gpt2_base_en")

# Pass by name to compile.
causal_lm.compile(sampler="random")
causal_lm.generate(["Keras is a"])

# Pass by object to compile.
sampler = keras_hub.samplers.RandomSampler(temperature=0.7)
causal_lm.compile(sampler=sampler)
causal_lm.generate(["Keras is a"])