Skip to content

Posts from the ‘Computer Generated Fiction’ Category


I added a GUI and made some Progress

As you can see I started working on my GUI front end. I have not gotten around to learning the web front end side so its PYQT5 for now.  Some major hurtles That I got into, around, and then over this past two weeks or so was following up on my previous post. I ended up deleting a good portion of my code and then starting over. I refocused on serializing my data and then working up from there. There is also a plug in I am working on that ouputs my INI files to CSV.

Here you can see I implemented a unique ID called SUID which is unique to the scene file and to each scene. <UNIQUE FILE ID> S <SCENE NUMBER>

A unique scene_and_sequel group ID. <UNIQUE SCENE SEQUEL ID> S <GROUP NUMBER>

Also, each item in the pair is labeled as a scene or sequel.


The first and last pairs are removed from the working pairs. I am now going to start splitting them up and building out plots and subplots. You can also see the randomly generated emotional arc to be used later with the scene and sequels.



I added a bit of code really quick that splits up the working list into three parts of NON EQUAL values, because of course, any random number of working scenes may not be divisible by three.



Turning Generated Scenes into a Novel Format for Plotting

Here is where I am at:

Step 1.

Novel word count is divided into three parts. Each part is then divided into Novel Scenes using a randomly generated lengths specific to average novel Beginning, Middle, and End lengths. Due to this “fuzzy” math you will end up with a longer length novel then required.

Image one shows the input WORDCOUNT being divided into three parts, then each part converted into Scenes.

Image two is an example output of what the Scenes INI output file looks like. The file name indicates there were 105 Scenes created with a total of 101700 words. The original input was 100,000. The extra 1700 words were created by the fuzzy math during Scene generation however as you will see in the next step some of it will be lost.



Clip from a Scene INI file.

Step 2.

Creating Scenes and Squeals. Here is a good site on what they are. Did you read it? good. They did a good job. The original Scenes are divided into pairs and if there is an extra Scene, well, there is no longer an extra Scene.  Scenes and Squeals feed off of each other.Capture.PNG

Step 3.

The beginning pair and the end pair are special. They introduce the overall conflict and conclude the overall conflict. They are removed from the next steps.


Step 4.

The three act structure again. Due to so much data being moved around the three acts are recreated again as PAIRS, NOT including the beginning or ending pairs.


Step 5.

Beginning to Plot. In each act, a random pair is selected for a secondary Plot, or the Sub-Plot. I may potentially move to a four act structure and even add in a randomized function for how many pairs per act are given to the sub-plot.  Something along the lines of per N-thousands of words, 1+X number of possible pairs per act for the Sub-plot.

Step 6.

The final product. This particular case is entirely for example of course. As you can see in the INI file above, there would have been 52 pairs in that example. That is just to many for me to make in visio.



This is where I am at right now. I am always open to suggestions and comments.


Fuzzy Scene Generation and Choosing One of the Six Emotional Arcs

Today I worked on randomly generating one of the Six Emotional Arcs.  The class allows the user to specify one of course, but will generate one for you if you don’t supply it. This was simple to implement but I made sure to structure the code in a way that lets me go back and add weights to which Arc is selected and how future machine code will attach to it.


Now the fun part, the beginning of the Scene building process. I want to make sure that I can later import the files into Scrivener and Aeon Timeline 2, since I have both of those products. I will export and/or convert my INI files to CSV later on.

I scrounged around on the internet and I  came up with a starting formula for building the Scenes. The length of the fiction is divided into thirds, Beginning, Middle, and End. Each third of the fiction has two values High, and Low respectively. These are the minimum and maximum words in a scene in that third. The Middle and End sections of the fiction have smaller ranges than the beginning.


For each third, a scene is generated with a length of X until the third is full. There is also some fuzzy rounding going on in there to keep things different each iteration so I noticed that the scene word count is longer than the input word count. Here is a snip-it of a 10,000 word novel I generated. Each scene will eventually have all of the attributes in it such as its Characters, Location, Time, etc.


That’s all for now, have a good day.


Creating a bias towards character generation.


While working on my Fiction Generator and creating Characters I noticed that I was indeed getting a randomized type of character. This ended up not being realistic and so I started working on finding a way to make the randomized character be biased towards generic. Thanks to Brad and John for last nights conversation.

In the characters class I have a variable that has nine levels. I am using the Enneagram model however in the first instance the first nine levels are from Good to Evil and not personality types.  I wanted to create a bias towards the median when generating a random characters. This means that I will generate more moderate characters and fewer extreme characters.  I will later add a second Enneagram attribute for their personality type.

The levels and percentages are categorized as follows.
Heroic to Altruistic – levels 1 through 3
Average – levels 4 through 6
Thief to Villain – levels 7 through 9

1 – 2% Hero
2 – 3% Benevolent
3 – 10% Meritorious
4 – 20% Intellectual
5 – 30% Average Joe
6 – 20% Meat Head
7 – 10% Criminal
8 – 3% Tyrant
9 – 2% Villain

I ended up going with the following model because it allows me to easily adjust the percentages for each level individually. I generate a random int between 0 and 100 and compare it to the following stack:


Here is output from generating some random characters. Yes, there is also a bias set for gender generation that can be easily changed.


You will also notice that they each have random names. I used the existing names package and added a middle name function to it and I will also be adding other functions for webscraping names and adding them to the list. To-easy. Inside my class you can create characters with the same First, Middle, Last, or any combination of names. Here is an example.


That’s all for now folks. Keep on writing code.


Let the Programming Begin!

The exciting time of putting code to PyDev has officially begun. I gathered a few of my existing books together and then after an exhaustive search online decided on a few more to round out what I would need to help me. While I have years of programming experience, this project is meant to expand my Software Engineering capabilities to the absolute limit. I intend to teach myself Machine Learning, Natural Language Processing, and also Django.


I have gotten some great advice from the very few people that I have talked to about this project. One of the big pieces of advice that I feel that I should mention is one that I did not even think about before. One of the large untapped areas of reference for computer generated fiction is the role playing community. There are an entire community of people who have created interesting projects for creating procedurally generated dungeons, text based adventure maps, room descriptions, etc. While not being EXACTLY what I am looking for, they are ONE_OFF.

There are also other projects [ or select portions of projects ] created in other programming languages that I want to replicate in python. An exhaustive list of those to come later.

Another interesting thing is that this blog has shown up on a search engine and has begun to get traffic. I find that interesting and flattering. I might actually spend some time making wordpress look a little better if more people are interested. If YOU volunteer to make it look better, hey that’s more programming time for me.

I intend to use as much original code, if not entirely original code for the project. That’s the goal. Learn.

Another thing I have done is reach other to some writers and people who help other people write. I spend quite a bit of time thinking about thinking but I will often find myself needing an outside opinion of a different point of view or perspective on a problem to solve it. A compelling and unique solution to a computer generating fiction that a human can consume is the secret to success.

I have a theory. We, humans, don’t simply WRITE a story from beginning to end. We also don’t write them from word to word, sentence to sentence, or paragraph to paragraph. I have done some intermediate research on machine learning and natural language processing and from what I understand that is a condensed and simplified way of describing how they work.

However, we, Humans write a story in stages. For example the snowflake method. From one sentence to an entire Novel. I believe that using lots and lots of iteration, data analysis, and theory, I can incorporate backwards and forwards recursion to BUILD the data UP.

That’s all for now, if you have any questions or comments please feel free to get involved.



Curated Notes 

Procedural genererated polygonal planets. Procedural generated pologonal region terrain maps. Triangulated distances between primary objects, primary and secondary objects, tertersy and secondary objects, and so on. Distance from a ship around a planet is calculated by getting the distance to the planet, distance from the planet to the sun, distance from the sun to the next sun, the next sun to the next planet.

Novel backfill. Use a series of functions and objects to fill out an endpoint objective then after that work backwards in steps to reach that objective.  Work backwards at each step while building the novel backbone.

Pandas for data points? 

Start making scapy and beautifulsoup bots to get text novels and book descriptors, types of novels, character development traits, all sorts of things.

Pick a database backend.

Pick a web frontend.

Get a logo, just for the hell of it.

Establish the line between cowriter and author?


Generating Fiction and the Three Laws of Criss

*If you are reading this and continue to read on, then you will find that not only do I tend to ramble, but my thoughts are also all over the place. Well for that I say, sorry. If you are still reading these words just know that there were many, many more words that came before them and I chose to delete most of them for your sake.

The first Laws of Generating Fiction. The Three Laws of Criss.

Lets all take a moment to remember the greats of the past and acknowledge that sometimes inspiration comes from the most unwilling and unsuspecting of places. For instance, a young man in the military who would stray away and spend hours writing and would become one of the fathers of Science Fiction. While I did spend eleven years in the Navy, that man was not me. It was Asimov. I just couldn’t sleep and was thinking about thinking again.

Computer Generated Fiction and The Three Laws of Criss. ( we touched on the third law already. )

The First Law – The Universe and its attributes are immutable after creation.

The Second Law – They think therefor they must exist. 

The Third Law – For every character transformation there has to be an equal and opposite number of outside influences over an integer that is equal to time. 

What does this translate to in python ( my chosen programming language ) and how will this make my program completely different and revolutionary from every other program that is currently out there?

The First Law – The Universe and its attributes are immutable after creation.

Lets use a metaphor. In the original Star Wars episode 4, it opens up with…… “A long time ago in a galaxy far, far away….” Thus George spoke and a universe was created. A reference point was established. A big pointer that said, “you are here” that points backwards somewhere to “a long time ago”. *(somewhere to the left). You are in the present and behind you is a long time ago.

Thus, the great story teller you are you have just established a Universe and as a bonus a timeline as well. Good job. From now on, you can load the “Star Wars” universe whenever you want to edit it and you can move forward or backward in time and when you are done you can close the “Star Wars” universe.

Attributes and Immutability. This should be common sense but I will spell it out for you. In the beginning of your Universe you decided that Up was Up and Down was Down. You also Decided if Magic exists, if interstellar travel exists, ghosts can go “boo” and if zombies can or cannot run. They cannot by the way. If you are a programmer like me, then imagine that this is a Tuple. You don’t get to change it, you use it. I won’t insult your intelligence because if you are going to be programming your own machine to write a novel you should either be agreeing or disagreeing with me right now. If you have no idea what I’t talking about then we are two far apart for this conversation to have any real meaning and why are you here?

The Second Law – They think therefor they must exist. 

If a character is going to be used in any way, then that character MUST exist. That means that they must have a full beginning to end accountability of their actions with the Universe from the moment they enter the Universe and until the end of time or until they depart the Universe. This means setting a minimum standard level of attributes for each character.

The level of attributes can be deterministic, but there should be and will be at least a minimum for the program to run. Different levels of attributes and accountability can be set for primary, secondary, and tertiary characters. Much like a game, you set up the pieces and then let them play out and keep track of what happens, where and when. Only then can your computer truly keep track of the interactions of the characters within its Universe.

while universe:

for each timeline:

for each character:

for each interaction:


The Third Law – For every character transformation there has to be an equal and opposite number of outside influences over an integer that is equal to time. 

I covered this in detail already. Every conversation, action, event, everything, has attributes, and everything affects everything in some way either + or – or neutral. Everything is tracked and impacts the world around it, just like the real world.

Minor changes happen slowly over time. Major changes can happen suddenly. A person does not change suddenly from minor events and be believable. The data needs to be there to support that. I don’t want rehash the whole thing for those who read the last one. Still working out the math and formula there, but I think the idea is sound.



What is the Universe?

I spend a lot of time thinking and even then I spend a lot of that time thinking about thinking. If you can not wrap your mind around that, please look up metadata. It is data about data. Yes, you have HAVE the information, but exactly can you tell me about the information? You know that completely rational conclusion that your arrived at? How exactly did you arrive at that conclusion and what were the mechanics behind it. That is the tip of the iceberg when it comes to thinking about thinking.

A character does not spontaneously pop into and out of existence. They have to exist somewhere, move forward on a timeline, in at least one scene, and every interaction with their environment has a + or – impact on them. If the readers perspective changes and the character is still alive the character still exists and therefor must still move forward in time at the same pace as the reader. Because realistic characters are not static they would have interacted with their environment while the reader was not focused on them.

It is conceivable that a moderately nice character we visited on a dreary afternoon at the beginning of the novel underwent a tremendous transformation when we see them again at the end of the novel. It is not conceivable for that same character to change drastically in a short period of time without any outside influences. Think Newton’s third law here, but modified. Let’s call it the Criss’s Third law.  For every character transformation there has to be an equal and opposite number of outside influences over time. I will find the first two later.

So, using this new formula, we can see that slow gradual changes can happen by small increments over a long period of time. Your character lives in their universe and moves forward in time. Even though they are a complete jerk, everyday after work they pass by a homeless guy and feel pity for him. That is a small + but a steady one on whichever value you assign it.

A sudden change would be a the same character being mugged and stabbed by the homeless guy.  The jerk suddenly become a vigilante. A huge  decrease -.

Using this method, the Universe can be loaded and saved.  The metaphor I have for the Universe compared to what a writer does is a simple sheet of paper. The paper is the entire Universe and when the characters are written down they have a existence and a frame of reference. By being able to load and save a Universe, the program can back fill the story line in preparation for its starting point. It can also create parallel storylines that interact with each other or even potentially write a series of novels using the same storyline, characters, and plots.

I have a feeling that the metadata generated for a single novel of 50,000 words will be several times larger than the finished novel alone.  Maybe that will be an entry? Finishing up this train of thought, I am not at all concerned with the processing COST of generating a novel.


Computer Generated Fiction

There are many ways to approach the problem of how to generate the “fiction”. The simplest solution is to simple print the word “fiction” 50,000 times and and call it a day. Simple, easy, and a novel of fiction full of fiction. <insert Exhibit meme here>.

There are also many more complex examples which include using twitter bots, neural networks, and some which are more complex combinations of word for word replacements of existing books with neural learning networks and twitter bots. I have looked at many of these and I love their code, however as a fiction lover I am not a fan of their output.  I want to be able to read the output of these programs as if I am reading a new Science Fiction novel.

When there is a need, fill it.

I started my journey without first knowing that there was even a yearly competition for the exact same thing. Being a lover of data and working in the Computer Security industry prepared me for the research. I first broke down the problem into a simple question of what exactly I was trying to accomplish?

The answer is generate fiction.

That led me to researching what the elements of fiction were. Let me warn you ahead of time. If you are a fan of fiction, don’t do the insane amount of research I did into the elements and patterns that go into writing it. You will begin to find yourself seeing the patterns and focusing on what the writer is doing wright or wrong and critiquing them and losing some/a lot of the pleasure of the story.

As an example of this, one of the elements of a character is their personal progression over time. In any given scene a character can only progress or digress up or down the character development ladder so far for it to be believable.  This means that a relatively happy person cannot believably become a evil person or saint over night or in one scene. I track this by incriminating or decrementing every action that takes place that affects a character.

As a father of two little kids I made the switch to audio-books a few years ago as my main source of fiction. Since I started researching the elements of fiction, listening to an audio-book has become a game of counting cards. I subconsciously start keeping track of each character and placing the character in their particular state and then keeping track of their state. When one characters state becomes top-heavy (  A superhero with no super villain or vice versa ) or when one one of the characters state suddenly changes without the data to back it up, it’s … it’s like having Leto as Joker. You have a steady stream of Jokers and stability of character and then suddenly, brain fart. Welcome to my thought process.

Characters all affect each other. Therefor each character has to be tracked and each interaction they have will affect how future interactions will take place. Just like in real life.

I could continue on with my thought process and how I arrived to my conclusion however I believe that no one actually wants to read page after page of rambling. What is important however is the conclusion itself.

What am I trying to accomplish? Generate fiction.

Ok. How do writers do that? I know that you are thinking what I first thought, that some of the Greats just sat down and simply let the words flow from their fingers and thus the Novel was born. The rest of the world has to Plot their works and develop their creations in their minds for years sometimes before writing them.

Do you know any such accomplished computer programs or Shakespearean neural networks?  Me either.  Therefor the logical approach to me is to have my computer generated fiction first perform this tedious task of plotting, researching, character development, scene development, and so on. Some of the computer generated fiction has begun to develop this process into a coherent model.

However there is still a problem.  I could not figure it out. I just knew that there was a problem.  I will just skip ahead and tell you the answer because I realized that so far no one I have looked at has yet to consider it. Universe. We, humans, exist. When we are telling a story we are using the world around us as a frame of reference.  Everyone has considered the timeline at one point or the other and possibly tracking how their characters interact with one another.

If we truly wanted a computer program to create a novel, it then needs to know everything about the world around it. It cant just know the main character and whom they interact with and how they affect each other, it needs to know every person in the story and how their interactions affect each other and the world around them before the novel and throughout the novel.  True world building that a character can move throughout.

I believe that the Universe, of the Point of Reference is a critical element to the riddle of Computer Generated Fiction and making it indistinguishable from something written wholly by a person. Another possible name for it might be Reality?

  • Universe
    • Time
      • Scene
        • Event
          • Character
            • Action
            • Dialogue