Commit ·
566a40e
1
Parent(s): 1c4d298
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
| 1 |
---
|
| 2 |
license: openrail
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: openrail
|
| 3 |
---
|
| 4 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
| 5 |
+
from healthcare_nlp import Diseases, SNOMEDCT
|
| 6 |
+
from healthcare_nlp.preprocessing import de_identify_text
|
| 7 |
+
|
| 8 |
+
# Disease selection and model configuration
|
| 9 |
+
disease_name = input("Enter a disease name (e.g., 'diabetes'): ").lower()
|
| 10 |
+
disease_concept = SNOMEDCT.query_concept(disease_name)
|
| 11 |
+
model_name = "allenai/biobert-base-cased" # Clinically-tuned BioBERT model
|
| 12 |
+
|
| 13 |
+
# Prepare user profile and tokenizer
|
| 14 |
+
user_profile = {"age": int(input("Enter your age: "))}
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 16 |
+
|
| 17 |
+
# Access and process user message
|
| 18 |
+
user_message = input("Ask your question about " + disease_concept.preferred_term + ": ")
|
| 19 |
+
deidentified_message = de_identify_text(user_message) # Protect sensitive information
|
| 20 |
+
|
| 21 |
+
# Generate response with model and personalization
|
| 22 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 23 |
+
inputs = tokenizer(deidentified_message, truncation=True, padding="max_length", return_tensors="pt")
|
| 24 |
+
generated_ids = model.generate(**inputs, max_length=256)
|
| 25 |
+
response = tokenizer.decode(generated_ids.squeeze(), clean_up_tokenization=True)
|
| 26 |
+
|
| 27 |
+
# Enhance response with knowledge base and context
|
| 28 |
+
knowledge_base = Diseases.load_disease_info(disease_concept.concept_id)
|
| 29 |
+
response = personalize_response(response, disease_concept, user_message, user_profile, knowledge_base)
|
| 30 |
+
|
| 31 |
+
# Conclude with informative disclaimer
|
| 32 |
+
response += (
|
| 33 |
+
"\nFeel free to ask any further questions you might have. I am still under development, but I leverage "
|
| 34 |
+
"clinical knowledge and continuous learning to provide accurate and evidence-based information. "
|
| 35 |
+
"Remember, I am not a substitute for professional healthcare advice. Please consult your doctor "
|
| 36 |
+
"for diagnosis and treatment decisions."
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
print(response)
|
| 40 |
+
|
| 41 |
+
def personalize_response(response, disease_concept, user_message, user_profile, knowledge_base):
|
| 42 |
+
# Highlight relevant knowledge base sections
|
| 43 |
+
for key, value in knowledge_base.items():
|
| 44 |
+
if key.lower() in user_message.lower():
|
| 45 |
+
response += f"\nRegarding your query about {key}, here's some relevant information: {value}"
|
| 46 |
+
|
| 47 |
+
# Adapt response based on disease complexity and user age
|
| 48 |
+
response = personalize_with_disease_complexity(response, disease_concept)
|
| 49 |
+
response = personalize_with_user_age(response, user_profile)
|
| 50 |
+
|
| 51 |
+
# Add medical references and adjust communication style based on user preferences
|
| 52 |
+
if user_profile["age"] >= 18 and user_profile["preferred_communication_style"] == "informative":
|
| 53 |
+
response = add_informative_details(response, knowledge_base)
|
| 54 |
+
elif user_profile["age"] >= 18 and user_profile["preferred_communication_style"] == "empathetic":
|
| 55 |
+
# Implement empathetic communication style here (e.g., acknowledge feelings, offer support)
|
| 56 |
+
pass
|
| 57 |
+
else:
|
| 58 |
+
# Use simpler language and avoid overwhelming details for younger users or non-informative preferences
|
| 59 |
+
pass
|
| 60 |
+
|
| 61 |
+
# Re-identify anonymized terms for clinical context (optional)
|
| 62 |
+
# response = re_identify_text(response, knowledge_base)
|
| 63 |
+
|
| 64 |
+
return response
|
| 65 |
+
|
| 66 |
+
# Personalize response with disease complexity
|
| 67 |
+
def personalize_with_disease_complexity(response, disease_concept):
|
| 68 |
+
if "complex" in disease_concept.description.lower():
|
| 69 |
+
response += f"\nPlease note that {disease_concept.preferred_term} is a complex condition. My information offers a starting point, not a definitive explanation. Consult your doctor for a comprehensive understanding."
|
| 70 |
+
return response
|
| 71 |
+
|
| 72 |
+
# Personalize response with user age
|
| 73 |
+
def personalize_with_user_age(response, user_profile):
|
| 74 |
+
if user_profile["age"] < 18:
|
| 75 |
+
response += f"\nAs you're under 18, it's crucial to involve your parents or guardians in managing your health and seeking professional guidance."
|
| 76 |
+
return response
|
| 77 |
+
|
| 78 |
+
# Add medical references or implement different communication styles here based on user preferences
|
| 79 |
+
|
| 80 |
+
# Re-identify anonymized terms with caution, considering ethical implications and potential bias.
|
| 81 |
+
|
| 82 |
+
This version enhances professionalism with:
|
| 83 |
+
|
| 84 |
+
* **De-identification of user message:** Protects sensitive information while processing.
|
| 85 |
+
* **Clinically-informed responses:** Tailored to disease complexity and user age.
|
| 86 |
+
* **
|