Answers.Body: <p>The underlying problem is combinatorial, as you note, but I'm not getting how you're ascribing value to words.</p>
  
  <p>The key element of deciding line breaks, beyond the visual, is rhythmic. <em>(There are other factors, as Bob Salita notes, but you've gotta start somewhere.)</em>  </p>
  
  <p>It seems to me you need to teach the computer how to scan a phrase in the poetic sense, which relates to rhythm.  This is obviously a very difficult task, but the number of syllables and stresses is fundamental numerical data of poetry.</p>
  
  <p>In order to validate to human tastes, you'd then have to use a captcha crowdsourcing method, for both the rhythmic stresses as input, and getting human reactions to different line-break configurations.  You would then reinforce the positive reactions, and the AI would tailor the line-break process to the audience.</p>
  
  <p>However, instead of utilizing human tastes and aesthetic sensibilities, you could instead let the AI decide what is preferred, which would probably be comprised of some sort of symmetry considered optimal to an algorithm.</p>
  
  <p>Following this logic, you wouldn't even need to have the AI learn the stresses, instead just focusing on raw syllables, or, numeric representation based on any factor. (With this method, the object is not to reformat poetry for humans, but for machines :)  </p>
  
  <p>This is more about the aesthetics, but Cameron Browne's <a href="http://www.cameronius.com/games/shibumi/browne-elegance-5.pdf" rel="nofollow noreferrer">Elegance in Game Design</a> would seem to suggest there are engineering solutions to the type of aesthetic issues at the root of your problem.</p>
  
  <p>I might start by teaching it to count the syllables of the poem, then having it look at the divisors. If it's roughly 10, it might be iambic pentameter. The AI doesn't care about the label, but it likes 10.  </p>
  
  <p>20 syllables might represent a couplet in that meter:</p>
  
  <blockquote>
    <p>The time is out of joint, oh cursed spite</p>
    
    <p>that ever I was born to set it right</p>
  </blockquote>
  
  <p>I'd definitely start by feeding it older poetry, particularly poets that keep to strict meter. It's been a while since I've read Spencer and so forth, but I'd think poets of his time would be useful.  Dr. Seuss, perhaps the greatest wielder of the rhyming couplet, would surely be extraordinarily useful. </p>
  
  <p>The evaluation method would have to be fuzzy, because there would be increasing degrees of variance the more modern the poetry, ultimately resulting in free structures, except in the case of forms such as rap, which strongly utilize regularized rhythm. Machine learning is all about estimation and reinforcement, and is proving to be extremely useful dealing with fuzziness.</p>
  
  <blockquote>
    <p>Dead mountain mouth of carious teeth that cannot spit</p>
  </blockquote>
  
  <p>is a great example of modern line of poetry: the floor of 13 syllables / 2 makes a 6 beat line.  Understanding that in context with the surrounding verse is much more difficult and illustrates the nature of the problem. Even scanning the poem correctly to that point to determine would be extremely difficult. </p>
  
  <p>However, a different poem by the same author is extremely useful:</p>
  
  <blockquote>
    <p>What is the late November doing / With the disturbance of the spring / And creatures of the summer heat, / And snowdrops writhing under feet / And hollyhocks that aim too high / Red into grey and tumble down / Late roses filled with early snow? / Thunder rolled by the rolling stars / Simulates triumphal cars / Deployed in constellated wars / Scorpion fights against the sun / Until the Sun and Moon go down / Comets weep and Leonids fly / Hunt the heavens and the plains / Whirled in a vortex that shall bring / The world to that destructive fire / Which burns before the ice-cap reigns</p>
  </blockquote>
  
  <p>All lines of roughly 8 syllables, easy to pick out because of capitalization.  But the real question is: ~136 13 lines of roughly 10 syllables, or 17 lines of roughly 8?  It would want to calculate based on word blocks (words that cross syllabic thresholds and at least tell you where the break <em>cannot</em> be, and it should be possible to statistically divine the pattern, at least for regularized verse.)  </p>
  
  <blockquote>
    <p>The wounded surgeon plies the steel / That questions the distempered part; /
    Beneath the bleeding hands we feel / The sharp compassion of the healer's art 
    / Resolving the enigma of the fever chart.</p>
  </blockquote>
  
  <p>This verse highlight the problem.  5 lines of 4 beats, but syllabically: 8, 8, 8, 10, 12.  </p>
  
  <p>Most likely: </p>
  
  <ul>
  <li>46/5 = 9.2</li>
  <li>46/4 = 11.5</li>
  <li>46/6 = 7.66</li>
  </ul>
  
  <p>Less likely:</p>
  
  <ul>
  <li>46/3 = 15.3</li>
  <li>46/2 = 23  </li>
  <li>46/7 = 6.57</li>
  </ul>
  
  <p>2 lines has less perfect symmetry, but 5 lines is more likely, based on the overall number of syllables, and of the likely choices, has the least variance. </p>
  
  <p>Ultimately it would be looking for the underlying structure, or lack of structure, and try to reorganize the unbroken text into something <em>close</em> to the original structure.  While exactness is not always required because the process is ultimately subjective, and currently intractable, certain wrong choices would yield disastrous results. </p>
  
  <p>In the prior example it may be able to discern the likelihood of a 5 line pattern, but it would have to figure out on which lines to place the extra syllables.  Differentiating between particles and other parts of speech provides a clue, because the poet's language is very compact: there are 19 nouns, verbs, or prepositions.  </p>
  
  <p>More likely:
   - 19/5 = 3.8
   - 19/4 = 4.75</p>
  
  <p>Less likely:
   - 19/3 = 6.33
   - 19/6 = 3.16
   - 19/7 = 2.71</p>
  
  <p>Further analysis might narrow it down.  But extremely regularized verse remains the best place to start.  7 lines of roughly 10 syllables is "poetic":</p>
  
  <blockquote>
    <p>‘The aged man that coffers-up his gold<br>
    Is plagu’d with cramps and gouts and painful fits;<br>
    And scarce hath eyes his treasure to behold,<br>
    But like still-pining Tantalus he sits,<br>
    And useless barns the harvest of his wits;<br>
    Having no other pleasure of his gain<br>
    But torment that it cannot cure his pain.</p>
  </blockquote>
  
  <p>It cares about both X and Y values.</p>
  
  <p>Initially you want to keep it to a single language, because syllables may be treated differently.  That said, having the AI look for something like <a href="https://en.wikipedia.org/wiki/Dactylic_hexameter" rel="nofollow noreferrer">Dactylic hexameter</a> would be extremely useful, because you could feed it Homer. You could also feed it Homer in English in many different forms of English meter, and in almost every other living language. By definition, the AI would value works such as these, because max number_of_translations provides the most robust data set. When it starts to value meaning, this will be especially important.</p>
  
  <p>Understanding different ways of treating syllables(long/short vs. stressed/unstressed) will also be essential as it transitions into more modern poetry.  </p>
  
  <p><a href="http://www.writing.upenn.edu/~afilreis/88/meter.html" rel="nofollow noreferrer">Here is a good link for basic English meter.</a>  Iambic and Trochaic meters will be easy, while meters that employ Anapests, Dactyls and Spondees will be more challenging. </p>
  
  <p>In some cases, however, these will be mathematically interchangeable.  </p>
  
  <blockquote>
    <p>I went to the Garden of Love, / And saw what I never had seen: / A Chapel was built in the midst, / Where I used to play on the green. </p>
  </blockquote>
  
  <p>It doesn't matter if the lines above are iambic/trochaic or dactylic/anapestic, it's still 4 lines of roughly 8 syllables.  Thus "I went to the Garden of Love" is the same as "The wounded surgeon plies the steel", even though the beats for the lines are 3 and 4, respectively.</p>
  
  <hr>
  
  <p>It should also have a stanza marker, (possibly 00?). Because it looks for patterns within patterns, stanzas are valued.  Not all poetry has a stanza structure, but it arguably could. Deciding if stanzas are appropriate is partly a function of taking a syllabic divisor, breaking the poem down into number_of_lines, and looking at the divisors of that number. </p>
  
  <p>It would need an added function to be able to recognize meaning patterns.  For instance, repetition of proper nouns is the marker of plays. (From a meaning perspective, imo, plays is the ideal place to start because the marker is so easy to learn, and names all belong to a single set, and imply communication. It's no different functionally than any other identifier, and a concept all computers "understand".)</p>
  
  <p>Eventually it would want to look for phonetic patterns, rhymes and near rhymes, which would also be indicators of potential good places for line breaks.</p>
  
  <p>There is a very big data set that it can look at, and who knows what it might discern?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-15T04:39:10.893Z
Answers.LastActivityDate: 2017-02-19T21:55:04.943Z
Answers.LastEditDate: 2017-02-19T21:55:04.943Z
Answers.UserDisplayName: DukeZhou
Answers.Body: <p>You should try <a href="http://karpathy.github.io/2015/05/21/rnn-effectiveness/" rel="nofollow noreferrer">to use an RNN</a>. You feed in letter by letter and have a binary output of linebreak - no linebreak. If you have enough data it might actually work. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-20T19:56:27.227Z
Answers.Text: I bet this would even work for something simple like turning literary quotes in sentence form into a free, stanzaic form for the purpose of manufacturing content (although it's doubtful the output will improve upon the original structure;)
Answers.UserDisplayName: DukeZhou
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-16T14:39:14.837Z
Answers.LastActivityDate: 2017-02-16T14:39:14.837Z
Answers.UserDisplayName: BlindKungFuMaster
Body: <p>I want to create a network to predict the break up of poetry lines. The program would receive as input an unbroken poem, and would output the poem broken into lines.</p>
  <p>For example, an unbroken poem could be</p>
  <pre><code>And then the day came, when the risk to remain tight in a bud was more painful
  </code></pre>
  <p>which should be converted to</p>
  <pre><code>And then the day came,
  when the risk
  to remain tight
  in a bud
  was more painful
  than the risk
  it took
  to Blossom.
  </code></pre>
  <p>How should I go about this? I have been using classifiers for various tasks, but this seems to be a different type of task.</p>
  <p>I'm thinking of it as an array of words (doesn't matter how they're represented for now), which would look like</p>
  <pre><code>[6, 32, 60, 203, 40, 50, 60, 230 ...] 
  </code></pre>
  <p>and needs to map into an array representing line breaks</p>
  <pre><code>[0, 0, 1, 0, 0, 0, 1, 0, 0, 1 ...]
  </code></pre>
  <p>where 1 (at optimal) means there should be a line break after the word in that index (in this idea, the two arrays are of the same length).</p>
  <p>Unfortunately, I couldn't find an algorithm that could train a network of this shape.</p>
  <p>What machine learning or deep learning algorithm can be used for this task?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-11T10:36:12.217Z
Comments.Text: Some further things to consider. Poems often have line breaks based on syntax, phonetics, meter, footing and rhyme.
Comments.UserDisplayName: BSalita
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-14T19:43:19.193Z
Comments.Text: As someone practiced in the craft of poety. I can tell you that there is no single way to break up a poem by lines.  Poets ultimately make this determination based on many factors, and different poets give precedence to different factors.  What you have now seems to break it down by phrases, which is legit, but not the only way to do it.  What you're ultimately looking to do is teach a machine the concept of aesthetics and taste.  I'd recommend looking into the concept of [Shibui](http://ieeexplore.ieee.org/document/6194295/?reload=true) and research into it related to game theory.
Comments.UserDisplayName: DukeZhou
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-14T19:54:17.990Z
Comments.Text: Continuing my last comment, Combinatorics is likely necessary.  For instance: is it more graceful for "when the risk
  to remain tight" to be a single line or two?  Similarly with "it took to Blossom".  Phillip Roth, considered to be a great stylist one wrote that he is merely a "re-arranger of sentences".  This is in reference to the necessary rigor of combining and recombining the elements in a literary text, *ad nauseam*, until the best combination is determined. Unfortunately, that   determination is subjective, and relies on taste.
Comments.UserDisplayName: DukeZhou
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-20T23:14:22.883Z
Comments.Text: Combinatorics is useful: Phillip Roth, widely considered to be a great stylist, once wrote that he is merely a "re-arranger of sentences". This is in reference to the necessary rigor of combining and recombining the elements in a literary text, ad nauseam, until the optimal combination is determined. Unfortunately, that determination is subjective, and relies on taste, where the good poet's taste is superior to the audience's.
Comments.UserDisplayName: DukeZhou
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-20T23:19:30.913Z
Comments.Text: The way the example is broken up reveals the problem with arbitrary line breaks.  The meaning of the Nin quote is best conveyed when the last two (or three) lines are combined: "the risk it took to blossom".  Point being, the halting rhythm of the first 5 lines mirrors the meaning, but maintain the halting rhythm for the final lines actually undercuts their meaning.  It looks good, but is not optimal from an editorial standpoint. Any process without meaningful understanding will almost always result in "form devoid of substance".
Comments.UserDisplayName: DukeZhou
Tags: <neural-networks><machine-learning><recurrent-neural-networks><reference-request>
Title: Which machine learning algorithm could I use to break up a poem by lines?
UserDisplayName: TastySpaceApple
ThreadText: # Which machine learning algorithm could I use to break up a poem by lines?
  
  (Asked by: username_0 on 2017-02-11)
  
  I want to create a network to predict the break up of poetry lines. The program would receive as input an unbroken poem, and would output the poem broken into lines.
  For example, an unbroken poem could be
  And then the day came, when the risk to remain tight in a bud was more painful
  
  which should be converted to
  And then the day came,
  when the risk
  to remain tight
  in a bud
  was more painful
  than the risk
  it took
  to Blossom.
  
  How should I go about this? I have been using classifiers for various tasks, but this seems to be a different type of task.
  I'm thinking of it as an array of words (doesn't matter how they're represented for now), which would look like
  [6, 32, 60, 203, 40, 50, 60, 230 ...] 
  
  and needs to map into an array representing line breaks
  [0, 0, 1, 0, 0, 0, 1, 0, 0, 1 ...]
  
  where 1 (at optimal) means there should be a line break after the word in that index (in this idea, the two arrays are of the same length).
  Unfortunately, I couldn't find an algorithm that could train a network of this shape.
  What machine learning or deep learning algorithm can be used for this task?
  
  **Tags:** neural-networks, machine-learning, recurrent-neural-networks, reference-request
  > **Comments:**
  > **username_1**: Some further things to consider. Poems often have line breaks based on syntax, phonetics, meter, footing and rhyme.  
  > **username_2**: As someone practiced in the craft of poety. I can tell you that there is no single way to break up a poem by lines.  Poets ultimately make this determination based on many factors, and different poets give precedence to different factors.  What you have now seems to break it down by phrases, which is legit, but not the only way to do it.  What you're ultimately looking to do is teach a machine the concept of aesthetics and taste.  I'd recommend looking into the concept of [Shibui](http://ieeexplore.ieee.org/document/6194295/?reload=true) and research into it related to game theory.  
  > **username_2**: Continuing my last comment, Combinatorics is likely necessary.  For instance: is it more graceful for "when the risk to remain tight" to be a single line or two?  Similarly with "it took to Blossom".  Phillip Roth, considered to be a great stylist one wrote that he is merely a "re-arranger of sentences".  This is in reference to the necessary rigor of combining and recombining the elements in a literary text, *ad nauseam*, until the best combination is determined. Unfortunately, that   determination is subjective, and relies on taste.  
  > **username_2**: Combinatorics is useful: Phillip Roth, widely considered to be a great stylist, once wrote that he is merely a "re-arranger of sentences". This is in reference to the necessary rigor of combining and recombining the elements in a literary text, ad nauseam, until the optimal combination is determined. Unfortunately, that determination is subjective, and relies on taste, where the good poet's taste is superior to the audience's.  
  > **username_2**: The way the example is broken up reveals the problem with arbitrary line breaks.  The meaning of the Nin quote is best conveyed when the last two (or three) lines are combined: "the risk it took to blossom".  Point being, the halting rhythm of the first 5 lines mirrors the meaning, but maintain the halting rhythm for the final lines actually undercuts their meaning.  It looks good, but is not optimal from an editorial standpoint. Any process without meaningful understanding will almost always result in "form devoid of substance".  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2017-02-16. Score: 3 | Accepted answer
  
  You should try [to use an RNN](http://karpathy.github.io/2015/05/21/rnn-effectiveness/). You feed in letter by letter and have a binary output of linebreak - no linebreak. If you have enough data it might actually work.
  
  > **Comments:**
  > **username_2**: I bet this would even work for something simple like turning literary quotes in sentence form into a free, stanzaic form for the purpose of manufacturing content (although it's doubtful the output will improve upon the original structure;)  
  
  ---
  
  ### Answer by username_2 on 2017-02-15. Score: 2
  
  The underlying problem is combinatorial, as you note, but I'm not getting how you're ascribing value to words.
  
  The key element of deciding line breaks, beyond the visual, is rhythmic. *(There are other factors, as Bob Salita notes, but you've gotta start somewhere.)*
  
  It seems to me you need to teach the computer how to scan a phrase in the poetic sense, which relates to rhythm. This is obviously a very difficult task, but the number of syllables and stresses is fundamental numerical data of poetry.
  
  In order to validate to human tastes, you'd then have to use a captcha crowdsourcing method, for both the rhythmic stresses as input, and getting human reactions to different line-break configurations. You would then reinforce the positive reactions, and the AI would tailor the line-break process to the audience.
  
  However, instead of utilizing human tastes and aesthetic sensibilities, you could instead let the AI decide what is preferred, which would probably be comprised of some sort of symmetry considered optimal to an algorithm.
  
  Following this logic, you wouldn't even need to have the AI learn the stresses, instead just focusing on raw syllables, or, numeric representation based on any factor. (With this method, the object is not to reformat poetry for humans, but for machines :)
  
  This is more about the aesthetics, but Cameron Browne's [Elegance in Game Design](http://www.cameronius.com/games/shibumi/browne-elegance-5.pdf) would seem to suggest there are engineering solutions to the type of aesthetic issues at the root of your problem.
  
  I might start by teaching it to count the syllables of the poem, then having it look at the divisors. If it's roughly 10, it might be iambic pentameter. The AI doesn't care about the label, but it likes 10.
  
  20 syllables might represent a couplet in that meter:
  
  > The time is out of joint, oh cursed spite
  >
  > that ever I was born to set it right
  
  I'd definitely start by feeding it older poetry, particularly poets that keep to strict meter. It's been a while since I've read Spencer and so forth, but I'd think poets of his time would be useful. Dr. Seuss, perhaps the greatest wielder of the rhyming couplet, would surely be extraordinarily useful.
  
  The evaluation method would have to be fuzzy, because there would be increasing degrees of variance the more modern the poetry, ultimately resulting in free structures, except in the case of forms such as rap, which strongly utilize regularized rhythm. Machine learning is all about estimation and reinforcement, and is proving to be extremely useful dealing with fuzziness.
  
  > Dead mountain mouth of carious teeth that cannot spit
  
  is a great example of modern line of poetry: the floor of 13 syllables / 2 makes a 6 beat line. Understanding that in context with the surrounding verse is much more difficult and illustrates the nature of the problem. Even scanning the poem correctly to that point to determine would be extremely difficult.
  
  However, a different poem by the same author is extremely useful:
  
  > What is the late November doing / With the disturbance of the spring / And creatures of the summer heat, / And snowdrops writhing under feet / And hollyhocks that aim too high / Red into grey and tumble down / Late roses filled with early snow? / Thunder rolled by the rolling stars / Simulates triumphal cars / Deployed in constellated wars / Scorpion fights against the sun / Until the Sun and Moon go down / Comets weep and Leonids fly / Hunt the heavens and the plains / Whirled in a vortex that shall bring / The world to that destructive fire / Which burns before the ice-cap reigns
  
  All lines of roughly 8 syllables, easy to pick out because of capitalization. But the real question is: ~136 13 lines of roughly 10 syllables, or 17 lines of roughly 8? It would want to calculate based on word blocks (words that cross syllabic thresholds and at least tell you where the break *cannot* be, and it should be possible to statistically divine the pattern, at least for regularized verse.)
  
  > The wounded surgeon plies the steel / That questions the distempered part; /
  > Beneath the bleeding hands we feel / The sharp compassion of the healer's art
  > / Resolving the enigma of the fever chart.
  
  This verse highlight the problem. 5 lines of 4 beats, but syllabically: 8, 8, 8, 10, 12.
  
  Most likely:
  
  * 46/5 = 9.2
  * 46/4 = 11.5
  * 46/6 = 7.66
  
  Less likely:
  
  * 46/3 = 15.3
  * 46/2 = 23
  * 46/7 = 6.57
  
  2 lines has less perfect symmetry, but 5 lines is more likely, based on the overall number of syllables, and of the likely choices, has the least variance.
  
  Ultimately it would be looking for the underlying structure, or lack of structure, and try to reorganize the unbroken text into something *close* to the original structure. While exactness is not always required because the process is ultimately subjective, and currently intractable, certain wrong choices would yield disastrous results.
  
  In the prior example it may be able to discern the likelihood of a 5 line pattern, but it would have to figure out on which lines to place the extra syllables. Differentiating between particles and other parts of speech provides a clue, because the poet's language is very compact: there are 19 nouns, verbs, or prepositions.
  
  More likely:
  - 19/5 = 3.8
  - 19/4 = 4.75
  
  Less likely:
  - 19/3 = 6.33
  - 19/6 = 3.16
  - 19/7 = 2.71
  
  Further analysis might narrow it down. But extremely regularized verse remains the best place to start. 7 lines of roughly 10 syllables is "poetic":
  
  > ‘The aged man that coffers-up his gold  
  > Is plagu’d with cramps and gouts and painful fits;  
  > And scarce hath eyes his treasure to behold,  
  > But like still-pining Tantalus he sits,  
  > And useless barns the harvest of his wits;  
  > Having no other pleasure of his gain  
  > But torment that it cannot cure his pain.
  
  It cares about both X and Y values.
  
  Initially you want to keep it to a single language, because syllables may be treated differently. That said, having the AI look for something like [Dactylic hexameter](https://en.wikipedia.org/wiki/Dactylic_hexameter) would be extremely useful, because you could feed it Homer. You could also feed it Homer in English in many different forms of English meter, and in almost every other living language. By definition, the AI would value works such as these, because max number\_of\_translations provides the most robust data set. When it starts to value meaning, this will be especially important.
  
  Understanding different ways of treating syllables(long/short vs. stressed/unstressed) will also be essential as it transitions into more modern poetry.
  
  [Here is a good link for basic English meter.](http://www.writing.upenn.edu/~afilreis/88/meter.html) Iambic and Trochaic meters will be easy, while meters that employ Anapests, Dactyls and Spondees will be more challenging.
  
  In some cases, however, these will be mathematically interchangeable.
  
  > I went to the Garden of Love, / And saw what I never had seen: / A Chapel was built in the midst, / Where I used to play on the green.
  
  It doesn't matter if the lines above are iambic/trochaic or dactylic/anapestic, it's still 4 lines of roughly 8 syllables. Thus "I went to the Garden of Love" is the same as "The wounded surgeon plies the steel", even though the beats for the lines are 3 and 4, respectively.
  
  ---
  
  It should also have a stanza marker, (possibly 00?). Because it looks for patterns within patterns, stanzas are valued. Not all poetry has a stanza structure, but it arguably could. Deciding if stanzas are appropriate is partly a function of taking a syllabic divisor, breaking the poem down into number\_of\_lines, and looking at the divisors of that number.
  
  It would need an added function to be able to recognize meaning patterns. For instance, repetition of proper nouns is the marker of plays. (From a meaning perspective, imo, plays is the ideal place to start because the marker is so easy to learn, and names all belong to a single set, and imply communication. It's no different functionally than any other identifier, and a concept all computers "understand".)
  
  Eventually it would want to look for phonetic patterns, rhymes and near rhymes, which would also be indicators of potential good places for line breaks.
  
  There is a very big data set that it can look at, and who knows what it might discern?
  
  
  ---
  
  