112 lines (111 with data), 3.7 kB
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The idea of this approach is to generate a prompt to ask a Pretrained LLM to label all the tokens with one of the labels we are considering."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"prompt_context = '''I need to perform a named entity recognition task on a text related with inclusion criteria in clinical trials.\n",
"The entities you need to recognize are: Condition, Value, Drug, Procedure, Measurement, Temporal, Observation, Person, Mood, Device and Pregnancy_considerations.\n",
"Particularly you have to produce the ouput in the BIO format. I will show you an example of the expected output.\n",
"Input text: Patients with symptomatic CNS metastases or leptomeningeal involvement \n",
"Output:\n",
"Patients O\n",
"with O\n",
"symptomatic O\n",
"CNS B-Condition\n",
"metastases I-Condition\n",
"or O\n",
"leptomeningeal B-Condition\n",
"involvement I-Condition\n",
"\n",
"You can see that tokens without any entity are labeled as O, and the tokens that are part of an entity are labeled as B-<entity> or I-<entity> depending on if they are the beginning or the inside of the entity.'''\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def gen_prompt(text):\n",
" return f'''{prompt_context}\n",
"Input text: {text}\n",
"Given this input text, produce the output in the format I gave you.\n",
"Output:'''"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I need to perform a named entity recognition task on a text related with inclusion criteria in clinical trials.\n",
"The entities you need to recognize are: Condition, Value, Drug, Procedure, Measurement, Temporal, Observation, Person, Mood, Device and Pregnancy_considerations.\n",
"Particularly you have to produce the ouput in the BIO format. I will show you an example of the expected output.\n",
"Input text: Patients with symptomatic CNS metastases or leptomeningeal involvement \n",
"Output:\n",
"Patients O\n",
"with O\n",
"symptomatic O\n",
"CNS B-Condition\n",
"metastases I-Condition\n",
"or O\n",
"leptomeningeal B-Condition\n",
"involvement I-Condition\n",
"\n",
"You can see that tokens without any entity are labeled as O, and the tokens that are part of an entity are labeled as B-<entity> or I-<entity> depending on if they are the beginning or the inside of the entity.\n",
"Input text: Patients with symptomatic CNS metastases or leptomeningeal involvement\n",
"Given this input text, produce the output in the format I gave you.\n",
"Output:\n"
]
}
],
"source": [
"# Example of a generated prompt\n",
"p = gen_prompt('Patients with symptomatic CNS metastases or leptomeningeal involvement')\n",
"print(p)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "TER",
"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.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}