NaNoGenMo / 2022

National Novel Generation Month, 2022 edition.
51 stars 0 forks source link

A novel factory #14

Open bensteinberg opened 1 year ago

bensteinberg commented 1 year ago

This is an experiment in the (mis)use of factory_boy and Faker, Python packages for generating test fixtures.

bensteinberg commented 1 year ago

An initial version is up at https://github.com/bensteinberg/a-novel-factory. A sample novel is in the repo in Markdown, PDF, and epub formats. The first paragraph of the first chapter, "First blood human", reads

Concern simply event month wrong six. His really job account remember response machine. Before sing lose where improve culture beyond. Better add reduce suddenly early along.

bensteinberg commented 1 year ago

I'd love to know if anyone's tried using factory_boy or Faker for NaNoGenMo, or in any other artistic/recreational/non-testing context.

lizadaly commented 1 year ago

What a great writeup of the approach!

bensteinberg commented 1 year ago

Recent advances in manufacturing technology have resulted in the construction of a Factory for Characters. In this arrangement, the Novel gets a cast of Characters, and each Chapter gets a subset of these, passing them down to Paragraphs and Sentences in turn, where they are used by a custom Provider. This system is a little clunky, but not too bad. I think this is fairly idiomatic for factory_boy; the Ideas page in the documentation proposes

When a Factory is built or created, pass the calling context throughout the calling chain instead of custom solutions everywhere

which might simplify the handling of Characters.

The current version's output, approximately 71,798 words, is in the repo in Markdown, PDF, and epub formats.

The first paragraph of the first chapter, "Often during trip mind", reads

Zachary Hubbard fell in love with Dale Gonzalez. Sea then often. Zachary asked Dale for the time. Dale Gonzalez took a cab. Zachary Hubbard took a cab. Zachary Hubbard fell in love with Dale Gonzalez. Dale asked Zachary for the time. Dale Gonzalez took a cab. Zachary thought "Heavy woman out evening later this." Mr. Hubbard's shoes were too tight. Dale Gonzalez wept. State hotel amount first. Zachary thought "Return low look actually space market should." Dale Gonzalez sang, "Also point real certain." Campaign cup consider media owner. Level ten including sense beat road the. Instead early end meet rich American tell. Hotel thousand because would. Dale Gonzalez wept. Zachary thought "Out debate deal recognize." Produce both avoid. Be possible issue trip.

nmifsud commented 1 year ago

This is a neat concept, and the current version already has the semblance of a narrative voice.

Something about the clipped cadence and poetically dense word clusters – together with the emotional gestures of your simple hard-coded sentence structures – makes it seem like the machine is trying to tell a story but has a tenuous grasp of English: "Sea then often", as if Zachary and Dale began travelling together soon after falling in love; they took cabs to hotels, of course; while there, "Instead early end meet rich American tell", meaning they put an early end to a high-stakes poker player... I look forward to reading your next version!

bensteinberg commented 1 year ago

Thanks, @nmifsud. I've been thinking a lot about the character of the random output, and how our minds find sense in it. Other outputs, even before the addition of characters, have seemed to me completely about real estate, or government, or family, etc., as this one seems like a love story/travelogue. Or in your reading, a murder mystery? Or maybe Zachary and Dale are Thelma and Louise....

bensteinberg commented 1 year ago

This is a minor change that includes corpora as a git submodule and uses the American Time Use Survey activities from it as input to the custom Provider.

An example of the current version's output, approximately 62,800 words, is in the repo in Markdown, PDF, and epub formats.

A random paragraph's text, showing the new activities, is

Thus standard ready. Poor off probably growth happen lose red. Stand enjoy their hope enjoy result different. Blood door although official. David Keith fell in love with Michelle Mendez. Trouble another everyone experience white. Michelle Mendez eyed Rebecca Hart. Rebecca was attending a concert. Michelle Mendez said "Section leave end rich lot test itself ball." Rebecca Hart took a cab. Rebecca was making plumbing improvements.

bensteinberg commented 1 year ago

Another minor change adds places to the material pulled from corpora by the custom Provider.

An example of the current version's output, a novel entitled Game go rule of approximately 66,580 words, is in the repo in Markdown, PDF, and epub formats.

A paragraph from the first chapter, "But dog", reads

Cynthia Coleman fell in love with Christopher Stewart. Christopher Stewart wept. Send little employee movement yard. Christopher asked, "Develop unit citizen run?" Sea can everything region travel news. Of direction population heavy research. Expert time add quickly space list whose. Cynthia asked Larry for the time. Cynthia was setting the table. Christopher and Larry moved to Delta. Cynthia and Christopher were waiting for architect. Christopher Stewart sang, "Per near system pattern blood our wall."

bensteinberg commented 1 year ago

OK! After a certain amount of fussing, I have added a means of controlling the random seed used to generate the novel. I was on the verge of throwing in the towel; thanks to @lizadaly for discussion today of randomness in Python. (The trick in this case was that the arbitrariness of set() does not come from random.)

An example of the current version's output, setting the random seed, is the novel Role Task of approximately 64,349 words; it is in the repo in Markdown, PDF, and epub formats.

The first paragraph of the first chapter, "Pressure", reads

"Mr. Jackson, I presume," said Colin Mcguire. Arrive else bit father different red. James handed Brent an eraser. Mx. Mcguire's shoes were too tight. Message simple close ok. Some tell billion work describe capital. Look at Colin go! Pretty son education happen energy adult if thank. Brent Anderson took a cab to Richmond.

I think I'm going to call this project done. There's still some November left to go, so it's possible I'll tweak the custom sentence provider or dig in to the recording of the random seeds used when not set by the user, but for now, enjoy!

bensteinberg commented 1 year ago

(BTW, somewhat interesting: a subsequent run with the same seed reveals that while the Markdown output is identical, the PDF and epub outputs change.)