python - 如何仅从单词生成有意义的句子?

标签 python nlp nlg

我想从单词列表中生成一个句子。我已经尝试过 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 dig dirt out of the earth.

如何使用?

Git 存储库:https://github.com/kingoflolz/mesh-transformer-jax

如repo中所示,您可以使用模型的web demo进行测试,也可以使用Colab实现。

网络演示:https://6b.eleuther.ai/

Colab 笔记本:http://colab.research.google.com/github/kingoflolz/mesh-transformer-jax/blob/master/colab_demo.ipynb

我不建议尝试在本地运行它。

关于python - 如何仅从单词生成有意义的句子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65062141/

相关文章:

java - 使用WordNet进行词干提取,io错误: Too many open files

java - 寻找 Java 拼写检查器库

java - SimpleNLG - 如何获得名词的复数形式?

python - 使用sklearn,如何找到决策树的深度?

python - 如何使用 scrapy 抓取仅给定域 url 的站点

nlp - 词嵌入中的维数是什么?

python - odoo 8 中 bool 字段的 onchange 函数

python - 我可以在命令行中运行 Jupyter 笔记本单元格吗?

java - SimpleNLG - 是否可以让 SimpleNLG 自动检测名词是单数还是复数?