python - 如何仅从单词中生成有意义的句子?
问题描述
我想从单词列表中生成一个句子。我尝试过 n-gram 模型,但它只从已经存在的句子生成文本,即我们输入一个句子,它根据 n 的值输出下一个生成的单词。哪个模型将有助于仅从单词列表中生成有意义的句子,以及应该使用哪个数据集来训练模型?
解决方案
您可以使用 GPT-J。它是一个免费的 GPT 模型,其性能可与 GPT-3 媲美。该模型接受您提供的输入,并尝试完成它。
我如何使用 GPT-J 从一组关键字生成句子:
输入:
Make a sentence with the following words: earth, dirt, alligator
Sentence: While the alligator is a species which mainly lives in the water, the earth is not uncommon territory and they like to dig through the dirt.
Make a sentence with the following words: shape, lantern, hair
Sentence:
输出:
Make a sentence with the following words: earth, dirt, alligator
Sentence: While the alligator is a species which mainly lives in the water, the earth is not uncommon territory and they like to dig through the dirt.
Make a sentence with the following words: shape, lantern, hair
Sentence: The hair is so thick on the lantern that it is almost like a shape.
如何调整到某个用例?
在输入中给出您想要的示例(示例关键字 + 句子)可以帮助 GPT 理解所需输出的结构。明确解释 GPT 在输入中期望的任务是什么(造句……)可以帮助它理解我的经验中的任务。
您可以通过将例句更改为以下内容来更改输出句子的复杂性:An alligator likes to dig dirt out of the earth.
如何使用?
Git 仓库:https ://github.com/kingoflolz/mesh-transformer-jax
如repo所示,可以使用模型的web demo进行测试,也可以使用Colab实现。
我不建议尝试在本地运行它。
推荐阅读
- c# - 添加字段时的C#逻辑问题
- arrays - 将结构数组保存/检索到 iCloud
- python - 如何将两列熊猫数据框绘制为水平条形图?
- excel - 编写一个宏,用于在B列中搜索字符串值并获取多行的A列值
- python - 多个子流程需要很长时间才能完成
- javascript - 如何在网页中显示外部 html 页面 - 使用 javascript
- python - 在没有 python 中的所有样板的情况下从 QUiLoader 加载是否安全?
- go - 关闭频道的正确方法
- jquery - 更新 YouTube 频道徽标的 Aria-Label
- sms - Twilio SMS 消息传递 2 路