Code Refactoring with GPT-3: Practical Prompt Patterns That Work

Code-capable language models can automatically refactor entire codebases and translate code between languages to deliver faster, more efficient implementations.

Early on with GPT-3, there were a lot of discoveries that showed what was possible. One of the clearest examples was code: the fact that it could write code led directly to code generation efforts, then Codex, and now something that’s basically evolved into an entire platform unto itself.

And sure, it was delightful to realize the model could translate between English and Korean (and Korean and English) or generate code, but it also wasn’t terribly surprising—these are language models. What started to stand out was what “really good” translation could mean in practice, beyond just language: better ways to communicate across distance, time, and languages.

With code, we found something even more immediately concrete. You could take Python and just tell the model, “rewrite this in a language like R,” and all of a sudden you could instantly make something much more efficient. That’s still one of the most exciting areas as these models become more capable: we’re watching them refactor entire codebases. And people who aren’t as experienced in the language they’re switching to can still do really cool things.

In hindsight, I think that should have been a bigger signal to people about the power of this. Just the fact that you had a model that could take most of the code written in the world and make it dramatically faster and more efficient is obviously of huge value—and I don’t think people have actually priced that in yet.