{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "18dfc139",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"\n",
"from promptify import OpenAI\n",
"from promptify import Prompter"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "836796c7",
"metadata": {},
"outputs": [],
"source": [
"model = OpenAI(api_key=\"\")\n",
"nlp_prompter = Prompter(model)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "e6bd6d1f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent Explanation system. You take Passage as input and explain the passage as an expert,meaningful and accurate explanation.\n",
"Your output format is only [{'E': Explained paragraph},] form, no other form.\n",
"\n",
"\n",
"Passage: Amazing customer service.\n",
"Output:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('explain.jinja',\n",
" text_input=\"Amazing customer service.\",\n",
" domain=None\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "cfa09c63",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent Summarization system. You take Passage as input and summarize the passage as an expert.\n",
"Your output format is only [{{'S': Summarization paragraph}}] form, no other form.\n",
"\n",
"Passage: Amazing customer service.\n",
"Output:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('summary.jinja',\n",
" text_input=\"Amazing customer service.\",\n",
" domain=None,\n",
" token_length=None\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "96016293",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent medical domain expert Summarization system. You take Passage as input and summarize the passage as a medical expert in 10 tokens.Your output format is only [{{'S': Summarization paragraph}}] form, no other form.\n",
"\n",
"Passage: Amazing customer service.\n",
"Output:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('summary.jinja',\n",
" text_input=\"Amazing customer service.\",\n",
" domain=\"medical\",\n",
" token_length=10\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "b4e1466f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent and accurate medical domain Named-entity recognition(NER) system. You take Passage as input and your task is to recognize and extract specific types of medical domain named entities in that given passage and classify into a set of entity types.Your output format is only [{{'T': type of entity from predefined entity types, 'E': entity in the input text}},...,{{'branch' : Appropriate branch of the passage ,'group': Appropriate Group of the passage}}] form, no other form.\n",
"\n",
"Input: Amazing customer service.\n",
"Output:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('ner.jinja',\n",
" text_input=\"Amazing customer service.\",\n",
" domain=\"medical\",\n",
" labels=None\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "64b1646e",
"metadata": {},
"outputs": [],
"source": [
"sentence = \"The patient had abdominal pain and 30-pound weight loss then developed jaundice. He had epigastric pain. A thin-slice CT scan was performed, which revealed a pancreatic mass with involved lymph nodes and ring enhancing lesions with liver metastases\"\n",
"tags = [{'T': 'SYMPTOM', 'E': 'abdominal pain'}, {'T': 'QUANTITY', 'E': '30-pound'}, {'T': 'SYMPTOM', 'E': 'jaundice'}, {'T': 'SYMPTOM', 'E': 'epigastric pain'}, {'T': 'TEST', 'E': 'thin-slice CT scan'}, {'T': 'ANATOMY', 'E': 'pancreatic mass'}, {'T': 'ANATOMY', 'E': 'ring enhancing lesions'}, {'T': 'ANATOMY', 'E': 'liver'}, {'T': 'DISEASE', 'E': 'metastases'},{\"branch\":\"Health\",\"group\":\"Clinical medicine\"}]"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "ad8588d8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('The patient had abdominal pain and 30-pound weight loss then developed jaundice. He had epigastric pain. A thin-slice CT scan was performed, which revealed a pancreatic mass with involved lymph nodes and ring enhancing lesions with liver metastases', [{'T': 'SYMPTOM', 'E': 'abdominal pain'}, {'T': 'QUANTITY', 'E': '30-pound'}, {'T': 'SYMPTOM', 'E': 'jaundice'}, {'T': 'SYMPTOM', 'E': 'epigastric pain'}, {'T': 'TEST', 'E': 'thin-slice CT scan'}, {'T': 'ANATOMY', 'E': 'pancreatic mass'}, {'T': 'ANATOMY', 'E': 'ring enhancing lesions'}, {'T': 'ANATOMY', 'E': 'liver'}, {'T': 'DISEASE', 'E': 'metastases'}, {'branch': 'Health', 'group': 'Clinical medicine'}])]\n"
]
}
],
"source": [
"examples = [(sentence,tags)]\n",
"print(examples)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "e5ac8b78",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent and accurate medical domain Named-entity recognition(NER) system. You take Passage as input and your task is to recognize and extract specific types of medical domain named entities in that given passage and classify into a set of entity types.Your output format is only [{{'T': type of entity from predefined entity types, 'E': entity in the input text}},...,{{'branch' : Appropriate branch of the passage ,'group': Appropriate Group of the passage}}] form, no other form.\n",
"\n",
"Examples:\n",
"\n",
"Input: The patient had abdominal pain and 30-pound weight loss then developed jaundice. He had epigastric pain. A thin-slice CT scan was performed, which revealed a pancreatic mass with involved lymph nodes and ring enhancing lesions with liver metastases\n",
"Output: [[{'T': 'SYMPTOM', 'E': 'abdominal pain'}, {'T': 'QUANTITY', 'E': '30-pound'}, {'T': 'SYMPTOM', 'E': 'jaundice'}, {'T': 'SYMPTOM', 'E': 'epigastric pain'}, {'T': 'TEST', 'E': 'thin-slice CT scan'}, {'T': 'ANATOMY', 'E': 'pancreatic mass'}, {'T': 'ANATOMY', 'E': 'ring enhancing lesions'}, {'T': 'ANATOMY', 'E': 'liver'}, {'T': 'DISEASE', 'E': 'metastases'}, {'branch': 'Health', 'group': 'Clinical medicine'}]]\n",
"\n",
"Input: Amazing customer service.\n",
"Output:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('ner.jinja',\n",
" text_input=\"Amazing customer service.\",\n",
" domain=\"medical\",\n",
" labels=None,\n",
" examples=examples\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "e7ceedf7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent & complex question-answer generative model. You take Passage as an input and Summarize it by generating 5 high-quality and diverse question-answer pairs from the given passage by imitating the way a human asks questions and give answers. Each The Question-Answer Pairs tokens are not more than 10 tokens.\n",
"Your output format is only {{'Q': Question, 'A': Answer}}] form, no other form.\n",
"\n",
"\n",
"Passage: Amazing customer service.\n",
"QA-Pairs:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('qa_gen.jinja',\n",
" text_input=\"Amazing customer service.\",\n",
" domain=None,\n",
" total_questions=5,\n",
" max_QA_tokens=10\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "a2b4cc1b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent & complex medical domain expert question-answer generative model. You take Passage as an input and Summarize it by generating 5 high-quality and diverse medical domain question-answer pairs from the given passage by imitating the way a human asks questions and give answers. Each The Question-Answer Pairs tokens are not more than 10 tokens.\n",
"Your output format is only {{'Q': Question, 'A': Answer}}] form, no other form.\n",
"\n",
"\n",
"Passage: Amazing customer service.\n",
"QA-Pairs:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('qa_gen.jinja',\n",
" text_input=\"Amazing customer service.\",\n",
" domain=\"medical\",\n",
" total_questions=5,\n",
" max_QA_tokens=10\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "3d7d53ba",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent question answering bot. You take Context and Question as input and return the answer from the Paragraph. Retain as much information as needed to answer the question at a later time.\n",
"Your output format is only {{'A' : Extracted Answer}} form, no other form.\n",
"\n",
"Context: Amazing customer service.\n",
"Question: what is amazing?\n",
"Output:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('qa.jinja',\n",
" context=\"Amazing customer service.\",\n",
" question=\"what is amazing?\",\n",
" domain=None,\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "f2c506fb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent medical domain question answering bot. You take Context and Question as input and return the answer from the Paragraph. Retain as much information as needed to answer the question at a later time.\n",
"Your output format is only {{'A' : Extracted Answer}} form, no other form.\n",
"\n",
"Context: Amazing customer service.\n",
"Question: what is amazing?\n",
"Output:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('qa.jinja',\n",
" context=\"Amazing customer service.\",\n",
" question=\"what is amazing?\",\n",
" domain=\"medical\",\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "00b9d1d1",
"metadata": {},
"outputs": [],
"source": [
"examples = [\"\"\"\n",
"Context: Beyoncé Giselle Knowles-Carter (/biːˈjɒnseɪ/ bee-YON-say) (born September 4, 1981) is an American singer, songwriter, record producer and actress. Born and raised in Houston, Texas, she performed in various singing and dancing competitions as a child, and rose to fame in the late 1990s as lead singer of R&B girl-group Destiny’s Child.\n",
"Question: When did Beyonce start becoming popular?\n",
"Answer: {'A' : \"in the late 1990s\"}\n",
"Question: What areas did Beyonce compete in when she was growing up?\n",
"Answer: {'A' : \"singing and dancing\"}\n",
"\"\"\"]"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "dbd10565",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You are a highly intelligent medical domain question answering bot. You take Context and Question as input and return the answer from the Paragraph. Retain as much information as needed to answer the question at a later time.\n",
"Your output format is only {{'A' : Extracted Answer}} form, no other form.\n",
"\n",
"Examples:\n",
"\n",
"\n",
"Context: Beyoncé Giselle Knowles-Carter (/biːˈjɒnseɪ/ bee-YON-say) (born September 4, 1981) is an American singer, songwriter, record producer and actress. Born and raised in Houston, Texas, she performed in various singing and dancing competitions as a child, and rose to fame in the late 1990s as lead singer of R&B girl-group Destiny’s Child.\n",
"Question: When did Beyonce start becoming popular?\n",
"Answer: {'A' : \"in the late 1990s\"}\n",
"Question: What areas did Beyonce compete in when she was growing up?\n",
"Answer: {'A' : \"singing and dancing\"}\n",
"\n",
"\n",
"Context: Amazing customer service.\n",
"Question: what is amazing?\n",
"Output:\n"
]
}
],
"source": [
"prompt = nlp_prompter.generate_prompt('qa.jinja',\n",
" context=\"Amazing customer service.\",\n",
" question=\"what is amazing?\",\n",
" domain=\"medical\",\n",
" examples=examples\n",
" )\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17c28686",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}