RandomSampler

[来源]

RandomSampler

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

随机采样器类。

这个采样器实现了随机采样。简而言之,随机采样器从整个词元分布中随机选择一个词元,选择机会由每个词元的概率决定。

参数

  • seed: int. 随机种子。默认为 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"])