RandomSampler
类keras_nlp.samplers.RandomSampler(seed=None, **kwargs)
随机采样器类。
此采样器实现随机采样。简而言之,随机采样器从所有 token 的整个分布中随机选择一个 token,选择机会由每个 token 的概率决定。
参数
None
。调用参数
{{call_args}}
示例
causal_lm = keras_nlp.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_nlp.samplers.RandomSampler(temperature=0.7)
causal_lm.compile(sampler=sampler)
causal_lm.generate(["Keras is a"])