2
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ 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 $\endgroup$ – Neil Slater Mar 23 at 21:25
  • 1
    $\begingroup$ 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... $\endgroup$ – Hans-Martin Mosner Mar 23 at 23:42
0
$\begingroup$

**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.**

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

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.