I have a simple neural-network which can create new text out of words which are likely to come after a specific word.

The code lacks of comma placement and punctuation.

It also can't transform a sentence into a question.

The code has the following steps:

  • Read the training texts
  • Create the network out the above explained parts
  • Create the new text out of a "Start-Word" e.g. "We" or "I"

I need a approach on how to implement the comma placement and punctuation and optional is to transform a sentence into a question.

Is there a specific schema on how to determine the correct position of a dot?


The dog sits in front of the house George is inside the house

  • 1
    What you want is expansion of your neural network. "simply" add sentence-ending dot or question mark into your training data. But I'm skeptical NN this simple would be able to determine where to end the sentence.
    – Euphoric
    Oct 22, 2018 at 8:07
  • 3
    Try treating punctuation marks as if they were words.
    – Simon B
    Oct 22, 2018 at 10:14
  • @Euphoric: The principle should be the same. If it's already able to evaluate commonly used successor words, then it should be able to similarly evaluate punctuation marks. The odds of success seem to be non unlike those of having a good grammatical sentence to begin with.
    – Flater
    Oct 22, 2018 at 14:03

1 Answer 1


Treat commas, periods and other forms of interpunctuation as if they were words. That allows you to train the neural network to learn when it is appropriate to end a sentence with a period or insert a comma. "End of text" should also be a "word" the neural network should learn to use appropriately.

Turning a statement into a question is a task which is different from generating a text. So you might want to train a separate neural network to do that. Feed it with an appropriate training set of statements and their corresponding questions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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