Artificial Intelligence has seen enormous advancements in recent years, notably in the life sciences sector. Various fields of the life sciences, like Biotechnology, Pharmaceuticals, and Medical devices, could be transformed by using AI. This article explains how GPT-3 revolutionized AI in the Life Sciences Industry.
Source: NBC News
The recently released Generative Pretrained Transformer 3 (GPT-3), in particular, has the potential to increase the impact of AI in the life sciences significantly.
This article was published as a part of the Data Science Blogathon.
The life sciences industry is already using AI in various ways, in the fields of drug development, diagnostics, and personalized medicine, showing some of the most promising uses.
Source: Scientific American
Source: Omnia Health
Open AI’s API can be used to understand or generate natural language or code.
Invoking GPT-3 model from Open AI’s API using Python
GPT-3 can be invoked using the OpenAI python library.
After creating an account on OpenAI’s website, you can find or create an API key under API keys in order to access the API.
Here is an illustration of how to use Python and the GPT-3 API to generate text.
import openai
# Set up API key
openai.api_key = "YOUR_API_KEY"
# Generate text
model_engine = "text-davinci-002"
prompt = "Write a short story about a cat."
completions = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completions.choices[0].text
print(message)
The OpenAI library is imported, and the API key is set in this example. The model engine variable is set to the name of the GPT-3 model for use, for example – “text-davinci-002”. The user can enter a text input which can be used to generate the text; for this example, we hardcode the text “Write a short story about a cat.” The method to create from openai. Completion is then used to generate the text, and the parameters are set, like max number of tokens to generate and the temperature for the generation. The generated text is stored in the message variable and is then printed to the console.
It is important to note that the GPT-3 API is very powerful and expensive. Using the API wisely and only when necessary is recommended, as the costs can quickly increase. Additionally, It is important to understand the API’s limitations and biases and use it ethically and responsibly.
Examples of GPT-3 code in Python for the Life sciences Industry
In the life sciences, GPT-3 can be used to automate tasks that are time-consuming and repetitive for humans, such as data analysis and summarization.
Source: Pharmaceutical Online
Example 1:Consider that you have a large genetic sequences dataset and want to summarize the data meaningfully.
This task can be automated using the following code with the help of GPT-3:
import openai
# Set up API key
openai.api_key = "YOUR_API_KEY"
# Define the prompt
prompt = "Please summarize the data in the following table:\n"
prompt += "Gene Sequence\tExpression Level\n"
prompt += "ABC123\t\t\t\t\t\tHigh\n"
prompt += "DEF456\t\t\t\t\t\tLow\n"
prompt += "GHI789\t\t\t\t\t\tModerate\n"
# Generate summary text
model_engine = "text-davinci-002"
completions = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
summary = completions.choices[0].text
print(summary)
The openai library is imported, and the API key is set in this example. The prompt variable contains a table of gene sequence data, and the model_engine variable is set to the name of the GPT-3 model to be used. The openai.The completion. create method is then used to generate the summary of the data, with various parameters such as the maximum number of tokens to generate and the temperature setting for the generation. The generated summary is stored
in the summary variable and is then printed to the console.
GPT-3 can also be used to generate reports, presentations,
and other forms of written communication in the life sciences.
Example 2: Consider a scenario where you need to prepare a report on the latest advances in gene editing. With the help of GPT-3, it is automated using the following code:
import openai
# Set up API key
openai.api_key = "YOUR_API_KEY"
# Define the prompt
prompt = "Please write a report on the latest advances in gene editing.\n"
# Generate report text
model_engine = "text-davinci-002"
completions = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
report = completions.choices[0].text
print(report)
In this example, the process is similar to the previous one. The OpenAI library is imported, and the API key is set. The prompt contains the text for the report, and the model engine variable is set to the name of the GPT-3 model to be used. The openai.Completion. create method is then used to generate the report with similar parameters. The generated report is stored in the report variable and is then printed to the console.
Source: Bio Spectrum Asia
Example 3: Another potential application of GPT-3 in the life sciences is a drug discovery and development. For example, GPT-3 can be used to predict the efficacy of a new drug candidate based on its molecular structure. The following code demonstrates how this can be done using the RDKit library and the openai library:
import openai
import rdkit
from rdkit import Chem
from rdkit.Chem import Draw
openai.api_key = "YOUR_API_KEY"
# SMILES representation of the molecule
smiles = "CCCCCCCCCCCCCCCCCCCCCCCCCCCC(=O)OC(C)(C)C"
# Convert SMILES to a molecule object
mol = Chem.MolFromSmiles(smiles)
# Visualize the molecule
img = Draw.MolToImage(mol)
img.show()
# Use OpenAI's GPT-3 to predict the efficacy of the drug based on its molecular structure
model_engine = "text-davinci-002"
prompt = f"Predict the efficacy of the drug with molecular structure represented
by the SMILES string '{smiles}'"
completions = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completions.choices[0].text
print(message)
This is an example of how you could use RDKit and OpenAI GPT-3 model (text-davinci-002) to predict the efficacy of a drug based on its molecular structure:
In this example, we first use the rdkit library to convert the SMILES string representation of the molecule into a rdkit.Chem. rdchem.Mol object. Then, we visualize the molecule using the rdkit.Chem.Draw module. Finally, we use OpenAI’s GPT-3 model to predict the efficacy of the drug based on the structure at a molecular level by sending text data to the openai.Completion. create method. The resulting text generated by the model is stored in the message variable and can be displayed using the print function.
By automating time-consuming and repetitive processes for people, GPT-3 has the potential to revolutionize the life sciences sector by freeing up critical time and resources to concentrate on more significant elements of research. To utilize AI to its full potential in the life sciences, ethical constraints must be addressed through dialogue between industry experts, academic researchers, and policymakers to ensure AI is used responsibly and equitably. In conclusion, the applications of GPT-3 in the life sciences industry are vast and varied. From data analysis and summarization to report writing and drug discovery, GPT-3 has the potential to revolutionize the way we work in the field of life sciences. By leveraging its language generation capabilities, we can automate time-consuming and repetitive tasks for humans, freeing up valuable time and resources to focus on more important aspects of our research. We may expect to see even more cutting-edge AI applications in the life sciences in the future as the technology develops.
The Key Takeaways of this article are as follows:
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.