Generating dialogue
autogenerated contentUntil now, all generated text has been blindly built from Markov chains, themselves built form novels. Any dialogue has been patchy and random. Now time to add a bit more structure…
A novel made up purely of descriptive passages with no dialogue would be a hard read. People talk, all the time, and being social creatures, we like to hear what they’re saying. Visually, dialogue also breaks up a page of text, which I think also makes things easier on the reader.
My plan is to start with a list of speakers’s names - ultimately, this would itself be generated from the parsed texts, but for now, let’s just stick to some common names:
speaker_names = ["Alice", "Bob", "Carol", "Dan"]
In most scenes, the dialgoue goes back and forth between two speakers, alternating. So the sequence of speakers is not random but can be modelled by another Markov-chain style process. I create a matrix of transition probabilities, and randomly make some of these much higher than others in a symmetric way. Thus Alice usually transitions to Bob but occasionally to Carol or Dan. Conversely, Bob usually replies to Alice. Eventually, the conversation will switch to a dialogue between Carol and Dan, transitioning to each other, and only occasionally back to Alice or Bob. Thus we have two pairs of speakers. (Later, I plan to introduce a ‘prose’ dummy-speaker, which will generate non-speech text between blocks of dialogue).
So the speaker sequence might be something like:
Alice said, ‘…‘
Bob said, ‘…‘
Alice said, ‘…‘
Alice said, ‘…‘
Bob said, ‘…‘
Carol said, ‘…‘
Dan said, ‘…‘
Carol said, ‘…‘
Dan said, ‘…‘
The actual speeches, the ‘…’ bits, will be generated later by the existing prose-generating Markov chain code.
But that’s not quite right! No writer would keep repeating peoples’ names that way - it’s too dull to read. So we need some processing to decide when to replace names with pronounts, when to skip names entirely, and when speeches can spread over several sentences. The (ad hoc) rules I can up with include if the same person speaks twice in a row, skip the second use of the name. If two speakers alternate, don’t repeat the names (after the first time). The actual output of the current system looks like this:
Alice said ‘<SENTENCE>.’
Bob said ‘<SENTENCE>.’
Carol said ‘<SENTENCE>.’’<SENTENCE>.’
Alice shouted ‘<SENTENCE>.’
Bob said ‘<SENTENCE>.’
‘<SENTENCE>.’
Carol said ‘<SENTENCE>.’
‘<SENTENCE>.’
Bob said ‘<SENTENCE>.’
Dan said ‘<SENTENCE>.’’<SENTENCE>.’
Bob said ‘<SENTENCE>.’
Alice said ‘<SENTENCE>.’
Dan cried ‘<SENTENCE>.’’<SENTENCE>.’’<SENTENCE>.’’<SENTENCE>.’
In this example, there are two paragraphs with no named speaker. Implcitly the both of these are said by Alice, first in reply to Bob and then in reply to Carol. I’m not sure this is clear to the reader…
Note that most speech-verbs are ‘said’ but occasionally that becomes ‘cried’, ‘shouted’ etc. That’s just a random selection for now.
Next steps include adding the actual text of the speeches (need to decide how to keep topics consistent between speakers and speeches etc.); varying the speech a bit more (e.g. moving the verb-of-speaking to be in the middle or at the end of some sentences); using pronouns where appropriate, perhaps with verbs of continuation: “Hello,” Bob said. “World,” he added.
A second sample of output. Is it clear who is speaking? And how much does that matter?
Alice said ‘<SENTENCE>.’’<SENTENCE>.’’<SENTENCE>.’
Carol said ‘<SENTENCE>.’
Dan said ‘<SENTENCE>.’
‘<SENTENCE>.’
‘<SENTENCE>.’
‘<SENTENCE>.’
Alice said ‘<SENTENCE>.’
Dan said ‘<SENTENCE>.’
Bob said ‘<SENTENCE>.’’<SENTENCE>.’’<SENTENCE>.’’<SENTENCE>.’’<SENTENCE>.’
Carol said ‘<SENTENCE>.’’<SENTENCE>.’
Dan said ‘<SENTENCE>.’
Alice said ‘<SENTENCE>.’
Carol said ‘<SENTENCE>.’