Answers.Body: <p>Two Approaches:</p>
  
  <ul>
  <li>Naive Bayes</li>
  <li>LSTM</li>
  </ul>
  
  <p>Train Naive Bayes on a whole dataset learning the probability of the next word given a word.</p>
  
  <p>You can even go with any LSTM approaches, but I'd bet on Naive Bayes.</p>
  
  <p>Eg:</p>
  
  <p>text: hello how are you hello how are you hello No how</p>
  
  <p>to get the suggestion of next word depending on current word - hello</p>
  
  <p>p(how | hello) = 3/4</p>
  
  <p>p(No | hello) = 1/4</p>
  
  <p>take argmax of probabilities.</p>
  
  <p>Also remember to smooth, and train on huge dataset. Training is just finding the probabilities before hand.</p>
  
  <p>Hope it helps ;)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-23T20:42:55.660Z
Answers.LastActivityDate: 2019-03-23T20:42:55.660Z
Answers.UserDisplayName: William Scott
Body: <p>I have a set of topics and each topic consists of a set of words. I want to make meaningful English sentences from these words. Each topic consist of 5 to 10 words and these words are relevant to each other, like <code>{code, language, test, write and function}</code> and <code>{class, public, method, string, int}</code> are two sets. I want to generate a sentence from these set of words using API.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-23T21:25:46.220Z
Comments.Text: Could you clarify what you are aiming at for "meaningful"? With latest ML techniques on their own you can aim for grammatically correct and some rough semantic correctness (e.g. people nouns taking active roles, objects often their typical properties). However, the results are often nonsense - entertaining perhaps, but devoid of any real meaning and more like abstract poetry. Would that sort of thing meet your goals? Perhaps some more explanation of what you are looking for and some examples would help if you added them to the question
Comments.UserDisplayName: Neil Slater
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-23T23:42:33.397Z
Comments.Text: What would be the source of"meaning"? The words of each topic do not suggest any specific meaning. If you want to construct formally correct sentences, you'd need to build a model of the syntactic and semantic roles of the words, and create sentences in which the words take on the given roles. The choice of programming language is irrelevant, and it pretty unclear what you expect from an API here...
Comments.UserDisplayName: Hans-Martin Mosner
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-26T13:23:10.390Z
Comments.Text: Sounds a lot like something I wrote in high-school in the late 1960s, a Fortran program with valid English sentence syntaxes and a sets of words classified by grammatical type.  It produced "meaningful" sentences like: "*their man to their good warmth expands the crowds on its any hands*", "*my faces smell a lot of me*", "*every baby of you grows very orange*", "*his girl kisses into the blue women*", "*the girls burp her dress again again more*", "*the face of few sadistic desires chews her boys down a softly quick crowd*", "*the girls smell the desire also*", and "*my baby laughs sadly*".
Comments.UserDisplayName: Ray Butterworth
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-27T01:35:37.173Z
Comments.Text: a simpler method (but likely not as powerful as @NeilSlater 's solution) might simply construct random sentences based off a list of syntax trees, but admittedly i don't know enough linguistics to evaluate this claim; also iirc there is a lot of difficulty of even evaluating the part of speech of words for many sentences
Comments.UserDisplayName: k.c. sayz 'k.c sayz'
Tags: <machine-learning><natural-language-processing>
Title: How can I make meaningful English sentences from given set of words?
UserDisplayName: shani
ThreadText: # How can I make meaningful English sentences from given set of words?
  
  (Asked by: username_0 on 2019-03-23)
  
  I have a set of topics and each topic consists of a set of words. I want to make meaningful English sentences from these words. Each topic consist of 5 to 10 words and these words are relevant to each other, like `{code, language, test, write and function}` and `{class, public, method, string, int}` are two sets. I want to generate a sentence from these set of words using API.
  
  **Tags:** machine-learning, natural-language-processing
  
  > **Comments:**
  > **username_1**: Could you clarify what you are aiming at for "meaningful"? With latest ML techniques on their own you can aim for grammatically correct and some rough semantic correctness (e.g. people nouns taking active roles, objects often their typical properties). However, the results are often nonsense - entertaining perhaps, but devoid of any real meaning and more like abstract poetry. Would that sort of thing meet your goals? Perhaps some more explanation of what you are looking for and some examples would help if you added them to the question  
  > **username_2**: What would be the source of"meaning"? The words of each topic do not suggest any specific meaning. If you want to construct formally correct sentences, you'd need to build a model of the syntactic and semantic roles of the words, and create sentences in which the words take on the given roles. The choice of programming language is irrelevant, and it pretty unclear what you expect from an API here...  
  > **username_4**: a simpler method (but likely not as powerful as @username_1 's solution) might simply construct random sentences based off a list of syntax trees, but admittedly i don't know enough linguistics to evaluate this claim; also iirc there is a lot of difficulty of even evaluating the part of speech of words for many sentences  
  > **username_3**: Sounds a lot like something I wrote in high-school in the late 1960s, a Fortran program with valid English sentence syntaxes and a sets of words classified by grammatical type.  It produced "meaningful" sentences like: "*their man to their good warmth expands the crowds on its any hands*", "*my faces smell a lot of me*", "*every baby of you grows very orange*", "*his girl kisses into the blue women*", "*the girls burp her dress again again more*", "*the face of few sadistic desires chews her boys down a softly quick crowd*", "*the girls smell the desire also*", and "*my baby laughs sadly*".  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_5 on 2019-03-23. Score: 1
  
  Two Approaches:
  
  * Naive Bayes
  * LSTM
  
  Train Naive Bayes on a whole dataset learning the probability of the next word given a word.
  
  You can even go with any LSTM approaches, but I'd bet on Naive Bayes.
  
  Eg:
  
  text: hello how are you hello how are you hello No how
  
  to get the suggestion of next word depending on current word - hello
  
  p(how | hello) = 3/4
  
  p(No | hello) = 1/4
  
  take argmax of probabilities.
  
  Also remember to smooth, and train on huge dataset. Training is just finding the probabilities before hand.
  
  Hope it helps ;)
  
  
  ---
  
  