Generate sentences from keywords only

Hi everyone, I am trying to generate sentences from a few keywords only. May I know which model and function I shall use? Thank you and I am a very beginner.

E.g.,
Input: “dinner”, “delicious”, “wonderful”, “steak”
Output: “We had a wonderful dinner yesterday and the steak was super delicious.”

Seq2seq models like T5 and BART are well-suited for this. You can fine-tune them on (list of keywords, sentence) pairs in a supervised manner.

1 Like

Thank you very much @nielsr!!
Is there any sample code that I could follow?
Happy Thanksgiving!

Hi,

Yes you can take a look at the notebooks I made regarding fine-tuning T5 on custom data: Transformers-Tutorials/T5 at master · NielsRogge/Transformers-Tutorials · GitHub

Note that seq2seq models like T5/BART are very general: they just take a sequence as input, and produce another sequence as output. So this could be anything, e.g.

  • translating from one language to another (input sequence: French sentence, output sequence: English sentence for instance)
  • summarizing long text (input sequence: long article, output sequence: short summary)
  • text-to-SQL (input sequence: text describing a query in natural language, output sequence: SQL query)
  • code-to-docstring (this is what I do in one of the notebooks linked above)
  • SQL-to-text
  • etc.

So definitely, keywords-to-sentence will also work well.

4 Likes

Hi @nielsr,

Thank you very much for your detailed reply and your effort of making this tutorial. This helps me a lot! So really appreciate it.