Fine-tuning a language model on my blog posts

I fine tuned GPT3.5-turbo on 45 blog posts from last year to see if it could emulate my style.

I’ve been wanting to try fine-tuning a language model on my own writing, I don’t have a whole lot of it yet, but according to OpenAI’s Fine Tuning guide, you can try with as few as 10 examples, and anywhere from 50 to 100 gives decent results.

I have 45 posts on 52weeks (my blog of creative projects from 2023), all in an identical structured format, so I thought I’d give it a shot.

First, I needed to prepare my content into the JSONL format, like this:

I found a Python library, Substack2Markdown to scrape all my Substack posts into Markdown, and then got Claude 3 to write me a script to convert that to JSONL in a single file.

Here’s a snippet of one line:

There was a lot of extraneous HTML in my posts which I should have cleaned up, I’ll show why that was an issue in a minute.

Next, I ran my through the provided validator notebook:

Almost all my blog posts fit neatly within the 4096 token limit, which is great. The notebook also has a cost estimator:

Checking that against the pricing page:

300,000 tokens, training using gpt-3.5-turbo, should cost 0.3M/1M * $8.00 = $2.40. Not too bad!

With that, I uploaded my model (I didn’t upload a validation set as suggested)

And started fine-tuning. It took about 9 minutes:

So, how does it do? The question-answer format is that I provide the post title, and it will write out a blog post.

I thought I’d prompt it with a few ideas from the backlog that I didn’t get to do last year and see what it comes up with. Note that it includes hallucinated links, it also contained hallucinated embedded images that I removed, but that ate up lots of tokens when it generated responses. If I fine tune a model again, I’ll make sure to spend more time cleaning the training data to remove HTML and links.

So here’s some blog posts I generated with my tuned model via the Playground:

Pretty cool! I can definitely notice the style is in the direction of my writing on 52weeks. Having the consistent structure in my input posts probably helped. At the very least, I can test this on new creative ideas I have to see a plausible approach as inspiration.