Skip to content

Commit

Permalink
revise using AI model\n\nUsing the OpenAI model gpt-3.5-turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenAI model gpt-3.5-turbo committed Mar 7, 2023
1 parent 26f3fbf commit d6f8916
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 1 deletion.
14 changes: 14 additions & 0 deletions content/01.abstract.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
## Abstract {.page_break_before}

<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
Internal server error {
"error": {
"message": "Internal server error",
"type": "auth_subrequest_error",
"param": null,
"code": "internal_error"
}
}
500 {'error': {'message': 'Internal server error', 'type': 'auth_subrequest_error', 'param': None, 'code': 'internal_error'}} {'Date': 'Tue, 07 Mar 2023 15:50:49 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '166', 'Connection': 'keep-alive', 'Vary': 'Origin', 'X-Request-Id': '51f6e4c5036574e1b5bdc79ed5642334', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains'}
-->
In this work, we investigate how models with advanced natural language processing capabilities can be used to reduce the time-consuming process of writing and revising scholarly manuscripts.
To this end, we integrate large language models into the Manubot publishing ecosystem to suggest revisions for scholarly text.
Our AI-based revision workflow uses a prompt generator that integrates metadata from the manuscript into prompt templates to generate section-specific instructions for the language model.
Expand All @@ -8,3 +21,4 @@ We tested our AI-based revision workflow in three case studies of existing manus
Our results suggest that these models can capture the concepts in the scholarly text and produce high-quality revisions that improve clarity.
All changes to the manuscript are tracked using a version control system, providing transparency into the human or machine origin of text.
Given the amount of time that researchers put into crafting prose, we anticipate that this advance will significantly improve the type of knowledge work performed by academics.

18 changes: 18 additions & 0 deletions content/02.introduction.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
## Introduction

<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
Manuscripts have been around for thousands of years, but scientific journals have only been around for about 350 years [@isbn:0810808447].
External peer review, which is used by many journals, is even more recent, having been around for less than 100 years [@doi:10/d26d8b].
Most manuscripts are written by humans or teams of humans working together to describe new advances, summarize existing literature, or argue for changes in the status quo.
However, scholarly writing is a time-consuming process where results of a study are presented using a specific style and format.
Academics can sometimes be long-winded in getting to key points, making writing more impenetrable to their audience [@doi:10.1038/d41586-018-02404-4].


<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
Recent advances in computing capabilities and the widespread availability of text, images, and other data on the internet have laid the foundation for artificial intelligence (AI) models with billions of parameters.
Large language models, in particular, are opening the floodgates to new technologies with the capability to transform how society operates [@arxiv:2102.02503].
OpenAI's models, for instance, have been trained on vast amounts of data and can generate human-like text [@arxiv:2005.14165].
Expand All @@ -14,10 +25,17 @@ The most well-known of these models is the Generative Pre-trained Transformer 3
Scientists are already using these tools to improve scientific writing [@doi:10.1038/d41586-022-03479-w].
This technology has the potential to revolutionize how scientists write and revise scholarly manuscripts, saving time and effort and enabling researchers to focus on more high-level tasks such as data analysis and interpretation.


<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
We present a novel AI-assisted revision tool that envisions a future where authors collaborate with large language models in the writing of their manuscripts.
This workflow builds on the Manubot infrastructure for scholarly publishing [@doi:10.1371/journal.pcbi.1007128], a platform designed to enable both individual and large-scale collaborative projects [@doi:10.1098/rsif.2017.0387; @pmid:34545336].
Our workflow involves parsing the manuscript, utilizing a large language model with section-specific prompts for revision, and then generating a set of suggested changes to be integrated into the main document.
These changes are presented to the user through the GitHub interface for review.
To evaluate our workflow, we conducted a case study with three Manubot-authored manuscripts that included sections of varying complexity.
Our findings indicate that, in most cases, the models were able to maintain the original meaning of text, improve the writing style, and even interpret mathematical expressions.
Our AI-assisted writing workflow can be incorporated into any Manubot manuscript, and we anticipate it will help authors more effectively communicate their work.

68 changes: 67 additions & 1 deletion content/03.methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,61 @@ The prompt for the Methods section includes the formatting of equations with ide
All sections' prompts include these instructions: *"the text grammar is correct, spelling errors are fixed, and the text has a clear sentence structure"*, although these are only shown for abstracts.
](images/figure_1.svg "AI-based revision applied on a Manubot manuscript"){#fig:ai_revision width="85%"}

<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
We implemented an AI-based revision infrastructure in Manubot [@doi:10.1371/journal.pcbi.1007128], a tool for collaborative writing of scientific manuscripts.
Manubot integrates with popular version control platforms such as GitHub, allowing authors to easily track changes and collaborate on writing in real time.
Furthermore, Manubot automates the process of generating a formatted manuscript (such as HTML, PDF, DOCX; Figure {@fig:ai_revision}a shows the HTML output).
Built on this modern and open paradigm, our AI-based revision software was developed using GitHub Actions, which allows the user to easily trigger an automated revision task on the entire manuscript or specific sections of it.



<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
When the user triggers the action, the manuscript is parsed by section and then by paragraph (Figure {@fig:ai_revision}b) and passed to the language model along with a set of custom prompts.
The model then returns a revised version of the text.
Our workflow then uses the GitHub API to generate a new pull request, allowing the user to review and modify the output before merging the changes into the manuscript.
This workflow attributes text to either the human user or to the AI language model, which may be important in light of potential future legal decisions that alter the copyright landscape around the outputs of generative models.



<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
We used the [OpenAI API](https://openai.com/api/) for access to these models.
Since this API incurs a cost with each run that depends on manuscript length, we implemented a workflow in GitHub Actions that can be manually triggered by the user.
Our implementation allows users to tune the costs to their needs by allowing them to select specific sections to be revised instead of the entire manuscript.
Additionally, several model parameters can be adjusted to tune costs even further, such as the language model version (including Davinci and Curie, and potentially newly published ones), how much risk the model will take, or the "quality" of the completions.
For instance, using Davinci models (the most complex and capable ones), the cost per run is under $0.50 for most manuscripts.



### Implementation details

<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
Our tools are comprised of Python scripts that perform the AI-based revision ([https://github.com/greenelab/manubot-ai-editor](https://github.com/greenelab/manubot-ai-editor)) and a GitHub Actions workflow integrated with Manubot.
To run the workflow, the user must specify the branch that will be revised, select the files/sections of the manuscript (optional), specify the language model to use (`text-davinci-003` by default), and provide the output branch name.
For more advanced users, it is also possible to change most of the tool's behavior or the language model parameters.



<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
When the workflow is triggered, it downloads the manuscript by cloning the specified branch.
It revises all of the manuscript files, or only some of them if the user specifies a subset.
Next, each paragraph in the file is read and submitted to the OpenAI API for revision.
Expand All @@ -46,6 +75,12 @@ If the error cannot be handled or the maximum number of retries is reached, the
This allows the user to debug the problem and attempt to fix it if desired.



<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
As shown in Figure {@fig:ai_revision}b, each API request comprises a prompt (the instructions given to the model) and the paragraph to be revised.
The prompt uses the manuscript title and keywords, so both must be accurate to obtain the best revision outcomes.
The other key component to process a paragraph is its section.
Expand All @@ -56,20 +91,38 @@ Therefore, we designed section-specific prompts, which we found led to the most
Figures and tables captions, as well as paragraphs that contain only one or two sentences and less than sixty words, are not processed and are copied directly to the output file.



<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
The section of a paragraph is automatically inferred from the file name using a simple strategy, such as if "introduction" or "methods" is part of the file name.
If the tool fails to infer a section from the file, then the user is still able to specify which section the file belongs to.
The section can be a standard one (abstract, introduction, results, methods, or discussion) for which a specific prompt is used (Figure {@fig:ai_revision}b), or a non-standard one for which a default prompt is used to instruct the model to perform basic revision (minimizing the use of jargon, ensuring text grammar is correct, fixing spelling errors, and making sure the text has a clear sentence structure).



### Properties of language models

<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
Our AI-based revision workflow uses [text completion](https://beta.openai.com/docs/guides/completion) to process each paragraph.
We tested our tool using Davinci and Curie models, including `text-davinci-003`, `text-davinci-edit-001` and `text-curie-001`.
Davinci models are the most powerful GPT-3 model, whereas Curie ones are less capable but faster and less expensive.
We mainly focused on the completion endpoint, as the edits endpoint is currently in beta.
All models can be fine-tuned using different parameters (see [OpenAI - API Reference](https://beta.openai.com/docs/api-reference/completions)), and the most important ones can be easily adjusted using our tool.



<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
Language models for text completion have a context length that indicates the limit of tokens they can process (tokens are common character sequences in text).
This limit includes the size of the prompt and the paragraph, as well as the maximum number of tokens to generate for the completion (parameter `max_tokens`).
For instance, the context length of Davinci models is 4,000 and 2,048 for Curie (see [OpenAI - Models overview](https://beta.openai.com/docs/models/overview)).
Expand All @@ -83,6 +136,12 @@ The tool automatically adjusts this parameter and performs the request again if
The user can also force the tool to either use a fixed value for `max_tokens` for all paragraphs, or change the fraction of maximum tokens based on the estimated paragraph size (two by default).



<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
The language models used are stochastic, meaning they generate a different revision for the same input paragraph each time.
This behavior can be adjusted by using the "sampling temperature" or "nucleus sampling" parameters (we use `temperature=0.5` by default).
Although we selected default values that worked well across multiple manuscripts, these parameters can be changed to make the model more deterministic.
Expand All @@ -92,9 +151,16 @@ Additionally, our workflow allows the user to process either the entire manuscri
This allows for more cost-effective control while focusing on a single piece of text, wherein the user can run the tool several times and pick the preferred revised text.



### Installation and use

<!--
ERROR: the paragraph below could not be revised with the AI model due to the following error:
This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?
-->
We have contributed our workflow ([https://github.com/manubot/rootstock/pull/484](https://github.com/manubot/rootstock/pull/484)) to the standard Manubot template manuscript, which is called rootstock and available at [https://github.com/manubot/rootstock](https://github.com/manubot/rootstock).
Users who wish to use the workflow only need to follow the standard procedures to install Manubot.
The section "AI-assisted authoring", in the file `USAGE.md` of the rootstock repository, explains how to enable the tool.
The section "AI-assisted authoring", in the file `USAGE.md` of the rootstock repository, explains how to enable the tool.
After that, the workflow (named `ai-revision`) will be available and ready to use under the Actions tab of the user's manuscript repository.

Loading

0 comments on commit d6f8916

Please sign in to comment.