# How can I make meaningful English sentences from given set of words?

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.

• 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 – Neil Slater Mar 23 at 21:25
• 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... – Hans-Martin Mosner Mar 23 at 23:42

**I think the following should work:

Loop over one by one through the words and select the word.Subtract its length from "n"and store the characters in an array of that word. In another nested loop do this. Traverse the other words and sort them according to their maximum substring lengths with the initial word selected. If the remaining alphabets of that string are less than or equal to "n" select that word and add the alphabets to the array. Continue till n<=0.**

• That doesn't really answer the question... – Hans-Martin Mosner Mar 23 at 23:34

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 ;)