TopKSampler
類別keras_hub.samplers.TopKSampler(k=5, seed=None, **kwargs)
Top-K 取樣器類別。
此取樣器實作 top-k 搜尋演算法。簡而言之,top-k 演算法會從機率最高的 K 個符元中隨機選取一個符元,選取機率取決於機率值。
引數
k
值。None
。呼叫引數
{{call_args}}
範例
causal_lm = keras_hub.models.GPT2CausalLM.from_preset("gpt2_base_en")
# Pass by name to compile.
causal_lm.compile(sampler="top_k")
causal_lm.generate(["Keras is a"])
# Pass by object to compile.
sampler = keras_hub.samplers.TopKSampler(k=5, temperature=0.7)
causal_lm.compile(sampler=sampler)
causal_lm.generate(["Keras is a"])