目前,我正在使用包含gpt-2的拥抱面转换器库的示例脚本run_generation.py从左侧上下文生成文本:
$ python transformers/examples/run_generation.py \
--model_type gpt2 \
--model_name_or_path gpt2 \
--prompt "Hi, " --length 5
=== GENERATED SEQUENCE 1 ===
Hi, could anyone please inform me我想要生成简短的完整句子。有没有办法告诉模型在length单词之前完成一个句子?
注:我不介意改变模式,但更喜欢自回归模式。
发布于 2020-10-26 18:25:41
不幸的是,没有办法这样做。您可以将length参数设置为更大的值,然后在末尾丢弃不完整的部分。
甚至GPT3也不支持在特定的length之前完成一个句子。不过,GPT3支持“序列”。序列迫使模型在满足一定条件时停止。您可以在thi 文章中找到更多有关信息。
发布于 2022-04-30 02:20:17
此参数帮助您获得结果:
'''
model_name is the model name, such as "124M" or "345M" and relies on
models_dir.
• models_dir defines the directory containing the models.
• seed sets a random integer for random generators. The seed can be set to
reproduce results.
• nsamples is the number of samples to return. If it is set to 0, it will continue
to generate samples until you double-click on the run button of the cell or
press Ctrl + M.
• batch_size determines the size of a batch and has an impact on memory
and speed.
• length is the number of tokens of generated text. If set to none, it relies on
the hyperparameters of the model.
• temperature determines the level of Boltzmann distributions. If the
temperature is high, the completions will be more random. If the temperature
is low, the results will become more deterministic.
• top_k controls the number of tokens taken into consideration by Top-k at
each step. 0 means no restrictions. 40 is the recommended value.
• top_p controls Top-p
'''希望它能帮到你!
https://stackoverflow.com/questions/61121982
复制相似问题