← back

nlp & llms · spring 2024

fine-tuning gpt to write like shakespeare

tl;dr: fine-tuned gpt-2 and davinci to rewrite modern english in shakespeare's style, retaining poetic depth a style-transfer baseline lost.

fine-tuning gpt to write like shakespeare

the question

can generative ai accurately emulate william shakespeare's writing style? the project set out to measure exactly that, comparing several models on stylistic accuracy using bleu, rouge-n, cosine similarity, jaccard similarity, and pinc score.

fine-tuning

i fine-tuned gpt-2 and gpt davinci on the shakescleare dataset, which pairs modern english passages with their shakespearean translations. a style transformer model was used as an additional baseline.

gpt-2 needed a specialised format: each row became a start token, the english translation, an end token, a separator, then the shakespearean translation wrapped in its own start/end tokens. davinci, with its native prompt-completion setup, was given an instruction-style prompt and the shakespearean line as the completion.

results

across test examples, gpt-2 and davinci consistently retained the poetic depth of the original text, while the style transformer baselines tended to flatten and simplify the phrasing. the example below shows each model's attempt at a single line.

sourceoutput
englishmy generosity to you is limitless as the sea, and my love is as deep
shakespeare (target)my bounty is boundless as the sea, my love as deep
gpt-2my goodness to thee is as infinite as the sea, and my love as deep
gpt davincimy love to you is sound, sans crack or flaw
style transformeri'm boundless, love is deep
one test example across models.