Writer’s Diary #15: Programming Challenge: Ordering a book of fragments?

An update on the beach idea. It works, I think.

What was it? What problem does it solve?

I have a draft of an incomplete manuscript in Tinderbox: a book of ethnographic shorts. The idea? Get a sense of a place and time along the vein of Kathleen Stewart’s Ordinary Affects. It’s got some gems, but the whole draft has been stalled.

The problem? How to order the fragments. 255 fragments, 85,000 words. I do not know how to organize them all. The problem, trying to think about the whole, which is too much.

Some fragments I’ve spent weeks polishing. Others are very rough. But, every time I’ve tried to get into it, the whole seems further away.

I’ve tried various solutions: randomizing notes, linking them and following the links, reading and reorganizing them, etc. But, it’s still too much. The question of order has impeded the actual work that is required. I could probably edit a short to make it good in about 30 minutes. Do that a hundred times over a hundred days, and I have a book. But the second I try to do the whole thing, it falls apart.

A few days ago, while walking on the beach after reading Word Virus, an anthology of William S. Burroughs’ work, I had an idea for a twenty-first century cut-up method using ChatGPT?

At the time, I didn’t quite understand the cut up method, in its nuts and bolts. But, suffice, it’s a way to bring in the random to the writing. More on that tomorrow.

My question on the beach.

Could ChatGPT order the fragments into a book?

I tested the technique with ten fragments, by hand. The results were intriguing enough to make me think it could work.

Round 1: Doing it by hand

What did I do?

First, I asked ChatGPT to create a TITLE, TAGS, and SUMMARY for ten fragments, and return it as a spreadsheet.

Then I asked it to order them.

You are my writing assistant. Help me organize the text fragments. I am using the cut-up method of William S. Burroughs. So I will give you a CSV spreadsheet with a TITLE, TAGS, and SUMMARY. Please give me back a better order. This is for an ethnography. It’s a book of fragments. All I want is the order you suggest. And then a paragraph explaining the order. No need to give a summary or anything. Just the order, then a short paragraph explaining why.

After some tinkering, ChatGPT spit out a plausible order. I tried it out and liked the result.

Round 2: How to do it programmatically

The challenge, how to do this with 258 fragments? The answer, mostly programmatically. But the devil is in the details.

So, first in Tinderbox, I connected Tinderbox to ChatGPT via a Python command line script I’d written in the Spring, with the aid of ChatGPT. After a morning of work, I am able to ask Tinderbox to use ChatGPT to generate a $SubTitle, $Summary, $Tags, and $WritingStyle attribute for each note, automatically.

It took a while for all the agents to run.

But, after playing catch with the kids for a bit, I came back, and each fragment had these updated attributes. (There are some bugs I need to fix. But it’s a personal project, so I’ll just fix them by hand.

What I did next was export a subset of these to a CSV file, using the $ID to keep track of each fragment. I did twenty or so.

I then asked ChatGPT to work its magic.

It returned an order of IDs and an explanation. It seemed plausible. The order was intriguing, and frankly, better than I had. It’s good enough for me to want to keep working on it.

The next challenge was how to import the new order back into Tinderbox.

Round 3: How to reorder notes in Tinderbox

What’s the situation? I have a Tinderbox document with a draft container comprising all the fragments. I have a list generated by ChatGPT of a new order, comprising the $ID.

The question? How to get the latter back into the former so that the fragments were reorganized.

Since everything is a hammer, e.g. use the tools you know, my first thought was to use agents. I could create an agent that took as its own name a search query, and I could use that to find each note, and then update the $Order for each note from the text of the agent. But it felt clunky. Was there a better way?

Dicitonaries. A dictionary can hold a series of paired values:

$MyDictionary=dictionary(“cat:animal; dog:animal; rock: mineral”); 

I’ve never used them. But, why not?
It worked. First, I used ChatGPT’s output to create a list in the form of $ID:$Outline.
1:1688302519; 2:1688301878; 3:1688301879; 4:1688301880; 5:1688301899; 6:1688301893; 7:1688302517; 8:1688301881; 9:1688301887; 10:1688301886; 11: 1688301888; 12:1688301890; 13:1688301891; 14:1688301892; 15:1688301894; 16:1688301895; 17:1688301896; 18:1688301897; 19:1688301898; 20:1688301900; 21: 1688301901; 22:1688301902; 23:1688301903; 24:1688301904; 25:1688301905; 26:1688301906; 27:1688301907; 28:1688301908; 29:1688301909; 30:1688301910; 31: 1688301911; 32:1688301912; 33:1688301913; 34:1688301914; 35:1688301883; 36:1688301884; 37:1688301885; 38:1688301882; 39:1688301889; 40:1688301900;

Then I use the following function to reorder the notes:

function fChatGPTReorderNotes(){ var:string vIDString
var:string vIDString;
var:integer vOutline;
var:string vPath;
$MyString=;
$MyDictionary=;

$MyDictionary=dictionary($Text);
$MyDictionary.keys.each(x){ vOutline = x
vOutline = x;
vIDString = $MyDictionary[x];
vPath = $Path(vIDString);
$ChatGPTOutline(vPath)=vOutline;
$MyString=$MyString+vOutline+":"+vIDString + “ [“ + vPath + “]; “;

};
};

That is, the function updates the $ChatGPTOutline for each note, using the imported dictionary held in the $Text field of a note.

I then simply run an agent that searches for ChatGPTOutline>0, and is sorted by the ChatGPTOutline. Bingo, I’ve got the book of fragments in the right order.

I now have the fragments, reordered according to ChatGPT’s recommendation. That’s good. The challenge now is how to reorganize all 258 notes.

Round 4: 258 Notes

Here, it’s tricky. ChatGPT has limited memory and can’t iterate on 258 items at once. It seems to be able to do about 20 to 40 at a time. I see three ways to approach this.

  1. Try to get access to ChatGPT’s gpt-4-32k-0613 model which has the ability to work with 32,768 tokens. I’ve signed up for the waiting list. But, I suspect I’m small potatoes.
  2. Use ChatGPT to create a list of 250 notes, but in which each row is much shorter, with ten tokens per line at most.
  3. Programmatically iterate through the all the fragments, comparing each one to the next, and asking what order they should go in. This would be a bit like Tinderbox’s dance feature. The order would evolve over time. I could probably safely do five at once and then run it via agents. I’m not sure, but this is probably the right answer.

In any case, since #1 is beyond my control and #3 is a harder programming challenge, and I’m running out of steam, I’m going to give #2 a try. Cut down the data to something very short. I suspect this means it will be not as a strong a result. But, at this point, the goal is less perfection, and more does this work. I can then come back and try to do the third option another time.

Suffice to say, if you can get the list short enough, it works. Is the list useful, I’m not sure. But, I’m going to try it out, and then get to writing,