Commit
·
af042ac
1
Parent(s):
09761e7
Upload untitled29.py
Browse files- untitled29.py +67 -0
untitled29.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""Untitled29.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colaboratory.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1N-tS7HH8VMnT1UtWDn6QW99ff31Vwpfb
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
!pip install transformers
|
| 12 |
+
!pip install langchain
|
| 13 |
+
!pip install huggingface_hub > /dev/null
|
| 14 |
+
!pip install chainlit
|
| 15 |
+
|
| 16 |
+
huggingfacehub_api_token = os.environ['HUGGINGFACEHUB_API_TOKEN']
|
| 17 |
+
|
| 18 |
+
from langchain import HuggingFaceHub
|
| 19 |
+
|
| 20 |
+
repo_id = "tiiuae/falcon-7b-instruct"
|
| 21 |
+
llm = HuggingFaceHub(huggingfacehub_api_token="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",
|
| 22 |
+
repo_id=repo_id,
|
| 23 |
+
model_kwargs={"temperature":0.6, "max_new_tokens":500})
|
| 24 |
+
|
| 25 |
+
from langchain import PromptTemplate, LLMChain
|
| 26 |
+
|
| 27 |
+
template = """
|
| 28 |
+
You are an artificial intelligence assistant. The assistant gives extracted Entities from paragraph text in JSON structure.
|
| 29 |
+
|
| 30 |
+
{question}
|
| 31 |
+
"""
|
| 32 |
+
prompt = PromptTemplate(template=template, input_variables=["question"])
|
| 33 |
+
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
| 34 |
+
|
| 35 |
+
question = """
|
| 36 |
+
extract patient_name, age, disease, drug, dosage entities from below text in JSON format only. \n text: Patient Michale (age 34) was diagnosed with hypertension, a chronic cardiovascular disease characterized by high blood pressure. As part of their treatment plan, the patient was prescribed a daily dosage of 10 milligrams of Lisinopril, an angiotensin-converting enzyme (ACE) inhibitor. Lisinopril is commonly used to manage hypertension by relaxing blood vessels, thus reducing blood pressure. The patient diligently followed their prescribed dosage, and after several weeks, their blood pressure showed significant improvement.
|
| 37 |
+
|
| 38 |
+
Put this message in the following JSON format
|
| 39 |
+
{
|
| 40 |
+
"patient_name":"..",
|
| 41 |
+
"age":"..",
|
| 42 |
+
"disease":"..",
|
| 43 |
+
"drug":"..",
|
| 44 |
+
"dosage":".."
|
| 45 |
+
}
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
print(llm_chain.run(question))
|
| 49 |
+
|
| 50 |
+
from langchain import PromptTemplate, LLMChain
|
| 51 |
+
|
| 52 |
+
template = """
|
| 53 |
+
You are an artificial intelligence assistant. The assistant gives extracted Entities from paragraph text in JSON structure.
|
| 54 |
+
|
| 55 |
+
{question}
|
| 56 |
+
"""
|
| 57 |
+
prompt = PromptTemplate(template=template, input_variables=["question"])
|
| 58 |
+
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
| 59 |
+
|
| 60 |
+
question = """
|
| 61 |
+
extract patient_name, age entities from below text in JSON format only. \n text: Mrs. Johnson, a 65-year-old patient, was diagnosed with rheumatoid arthritis, an autoimmune disease that causes chronic inflammation of the joints. To manage her symptoms, her rheumatologist prescribed a weekly dosage of 20 milligrams of Methotrexate, an immunosuppressant and disease-modifying antirheumatic drug (DMARD). Methotrexate is commonly used in the treatment of rheumatoid arthritis to reduce inflammation and slow down joint damage. Mrs. Johnson diligently followed her prescribed dosage and noticed a significant improvement in her joint pain and mobility after a few weeks of treatment..
|
| 62 |
+
|
| 63 |
+
Put this message into a JSON with keys "patient_name", "age":
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
print(llm_chain.run(question))
|
| 67 |
+
|