Answers.Body: <p>What a difference a few years make. When this was first asked in April 2019, the parts-of-speech tagging required for grammatical correctness was possible but hard, whilst the constraint of being semantically correct was nigh impossible with any technique at the time, other than in carefully controlled scenarios - e.g. strongly limiting the words allowed for input.</p>
  <p>Moving forward 3+ years, now one way to do what you want is via a prompt to a pre-trained large language model (LLM), perhaps via an API, which would be possible on e.g. OpenAI's GPT model.</p>
  <p>For instance, I did this in GPT 3.5 playground:</p>
  <blockquote>
  <p><em>Construct a sentence containing the words &quot;cat&quot;, &quot;fish&quot; and &quot;lake&quot;.</em></p>
  <p>The cat eagerly watched as the fish swam gracefully in the tranquil lake.</p>
  </blockquote>
  <p>If results are all that matters to you, not learning to make such a model from scratch, then this is the way to go. There are open-source LLMs at various scales that you could use, and the task is simple enough (compared to the high end capabilities of the larger LLMs, such as passing bar exams) that even basic smaller ones should be capable.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-24T16:31:03.370Z
Answers.LastActivityDate: 2023-08-24T16:53:01.493Z
Answers.LastEditDate: 2023-08-24T16:53:01.493Z
Answers.UserDisplayName: Neil Slater
Answers.Body: <p>One way is by defining a grammar for your sentences manually. But that's going to be a trivial task because after creating a grammar you have to create a parsing tree based on your defined grammar to generate a sentence.</p>
  <p>Other way is to use LSTM(Long Short term memory) architecture for this purpose but you have to fine tune your model perfectly (which will not give a very good result but it can give you a above average result) or you will get a gibberish.</p>
  <p>In this case you can use BLEU (Bil-lingual evaluation under study) instead by evaluating your results manually for selecting the statements with above 0.6 score to get a above average result</p>
  <p>You can also check this research paper : <a href="https://arxiv.org/abs/1702.04066" rel="nofollow noreferrer">https://arxiv.org/abs/1702.04066</a></p>
  <p>Repo : <a href="https://github.com/keisks/jfleg" rel="nofollow noreferrer">https://github.com/keisks/jfleg</a></p>
  <p><strong>JFLEG: A Fluency Corpus and Benchmark for Grammatical Error Correction</strong></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-01T14:54:59.920Z
Answers.LastActivityDate: 2022-04-01T14:54:59.920Z
Answers.UserDisplayName: JOGI
Body: <p>Is there an AI application that can produce syntactically (and semantically) correct sentences given a bag of words? For example, suppose I am given the words "cat", "fish", and "lake", then one possible sentence could be "cat eats fish by the lake".</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-15T20:37:28.533Z
Comments.Text: It is possible to construct many syntactically correct sentences here, but most of them would be nonsense. For instance "cat pretends to be a fish that has swallowed a lake" or "purple cat sings about yellow fish flying high above a lake" or "lake eats cat by the fish" (not realisable physically, but semantically correct as it has meaning).  Can you describe how the possible sentences should be constrained? Could you give some more examples and some information about your goal?
Comments.UserDisplayName: Neil Slater
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-16T05:26:56.133Z
Comments.Text: In my case any sentence which contains these words are OK, if it makes sense.My goal is to describe a scene to join words together, it would be wonderful if there's provided web service online, I can input words and it returns a sentence to me
Comments.UserDisplayName: gloomyson
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-16T08:13:06.833Z
Comments.Text: There might be a service online, but I doubt it would be anything but a toy or research example. Could you please add "if it makes sense" and *define* that  carefully in the question? You can use the [edit] link to add clarifying details. For instance, do any of my example sentences "make sense". Please add more examples of inputs/outputs that both do make sense, and that do not make sense.
Comments.UserDisplayName: Neil Slater
Tags: <machine-learning><natural-language-processing>
Title: How do I create syntactically correct sentences given several words?
UserDisplayName: gloomyson
ThreadText: # How do I create syntactically correct sentences given several words?
  
  (Asked by: username_0 on 2019-04-15)
  
  Is there an AI application that can produce syntactically (and semantically) correct sentences given a bag of words? For example, suppose I am given the words "cat", "fish", and "lake", then one possible sentence could be "cat eats fish by the lake".
  
  **Tags:** machine-learning, natural-language-processing
  > **Comments:**
  > **username_1**: It is possible to construct many syntactically correct sentences here, but most of them would be nonsense. For instance "cat pretends to be a fish that has swallowed a lake" or "purple cat sings about yellow fish flying high above a lake" or "lake eats cat by the fish" (not realisable physically, but semantically correct as it has meaning).  Can you describe how the possible sentences should be constrained? Could you give some more examples and some information about your goal?  
  > **username_0**: In my case any sentence which contains these words are OK, if it makes sense.My goal is to describe a scene to join words together, it would be wonderful if there's provided web service online, I can input words and it returns a sentence to me  
  > **username_1**: There might be a service online, but I doubt it would be anything but a toy or research example. Could you please add "if it makes sense" and *define* that  carefully in the question? You can use the [edit] link to add clarifying details. For instance, do any of my example sentences "make sense". Please add more examples of inputs/outputs that both do make sense, and that do not make sense.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-08-24. Score: 2
  
  What a difference a few years make. When this was first asked in April 2019, the parts-of-speech tagging required for grammatical correctness was possible but hard, whilst the constraint of being semantically correct was nigh impossible with any technique at the time, other than in carefully controlled scenarios - e.g. strongly limiting the words allowed for input.
  
  Moving forward 3+ years, now one way to do what you want is via a prompt to a pre-trained large language model (LLM), perhaps via an API, which would be possible on e.g. OpenAI's GPT model.
  
  For instance, I did this in GPT 3.5 playground:
  
  > *Construct a sentence containing the words "cat", "fish" and "lake".*
  >
  > The cat eagerly watched as the fish swam gracefully in the tranquil lake.
  
  If results are all that matters to you, not learning to make such a model from scratch, then this is the way to go. There are open-source LLMs at various scales that you could use, and the task is simple enough (compared to the high end capabilities of the larger LLMs, such as passing bar exams) that even basic smaller ones should be capable.
  
  
  ---
  
  ### Answer by username_2 on 2022-04-01. Score: 1
  
  One way is by defining a grammar for your sentences manually. But that's going to be a trivial task because after creating a grammar you have to create a parsing tree based on your defined grammar to generate a sentence.
  
  Other way is to use LSTM(Long Short term memory) architecture for this purpose but you have to fine tune your model perfectly (which will not give a very good result but it can give you a above average result) or you will get a gibberish.
  
  In this case you can use BLEU (Bil-lingual evaluation under study) instead by evaluating your results manually for selecting the statements with above 0.6 score to get a above average result
  
  You can also check this research paper : <https://arxiv.org/abs/1702.04066>
  
  Repo : <https://github.com/keisks/jfleg>
  
  **JFLEG: A Fluency Corpus and Benchmark for Grammatical Error Correction**
  
  
  ---
  
  