LLMs for Paper Writing

Much has been said about AI language models’ role in scientific publishing (see also Mapping the Increasing Use of LLMs in Scientific Papers) and the implications of AI authorship more generally, but it is undeniable that LLM assistance — used properly — can be a force-multiplier for technical writing.

Collaborative editors like Google Docs or Overleaf have made it easier to write papers with human coauthors, and these tools have already acquainted us with the workflows of asynchronous text collaboration. Early in 2023, our team (me, and Drs. Richard Lange, Konrad Kording) cobbled together a simple tool to use a language model to asynchronously edit a paper in the Overleaf editor — the industry standard collaborative editor for LaTeX documents. Today we are open-sourcing this project so that others can adapt and adopt it for their scientific writing workflows as well.

Schematic

Technical approach

Though Overleaf does not have a public-facing editing API, they have a robust git-flavored backend that allows for programmatic editing of documents. We built a simple Python tool to listen for changes to this git repository, and when a change is detected, the tool sends the new text to a language model of your choice. (We’ve been using the OpenAI API for this purpose, but any language model API can be used — including local on-prem models).

Because this tool works at the backend git level, it can be used with any git repository, not just Overleaf. We’ve tested it with GitHub repositories (and plaintext files!) as well, and it works just as well there. (We encourage engineers to check out our PaperRemote abstraction if you want to add support for another editor!) Talking to the backend (rather than implementing this through, say, a browser extension) also means that end users don’t need to install anything. The tool can be run on a server, and the end user can simply use Overleaf as they normally would.

Limitations

As a result of interfacing with git — a tool designed for version control, not real-time collaboration — we had to make some compromises. This library implements its own debouncing and “clobber-avoidance” to prevent the model from editing too close to ongoing changes from human collaborators. This means that the model will not edit the document until it has been stable for a few seconds, or until the human collaborator has moved on to a new section. (In our testing, this was not a significant limitation, since it’s rare that you want AI editing the same text you’re typing.)

We also have chosen to use LaTeX comments (text starting with % @ai:) to trigger the AI model, rather than having the model edit the entire document. This allows for fine-grained control over the AI’s edits, and allows for human collaborators to easily see where the AI has made changes. But naturally, we expect users will want to use the same comment-style task assignment commonly used in Overleaf and other editors like Google Docs, and we believe that this is a natural extension of our tool. But we haven’t figured out how to get programmatic access to Overleaf comments yet… maybe you know what to do? :)

Upshots

Naturally, AI has some very well-known (and some not-well-known) failures and limitations. Hallucination and plagiarism are two of the most common, and we’ve found that the best way to avoid these is to use the AI as an editorial tool, not as a replacement for human thought. And because AI is only as good as its training data, you should never expect AI to understand the logic or overarching themes of your paper, nor should you use it for literature reviews or in lieu of human oversight.

Nonetheless, we’ve found that using LLMs for paper writing has been a boon to our productivity. The AI can help with things like equation formatting, spelling, or rephrasing complex ideas. We’ve found that AI prompted with good paper-writing techniques can be particularly good at annoying but simple tasks, like rephrasing sentences, reformatting text, checking for text flow, or making suggestions about readability and clarity.

We encourage the open source community to take advantage of this tool and — if you’re inspired — to collaborate with us by steering its development. We’re excited to see how this tool and AI tools like it can make the scientific process more efficient and more accessible to all.

Written on June 1, 2024
Comments? Let's chat on mastodon (Or on Twitter if you absolutely must...)