Downloads · 30 days
0
Vinnybustacap/Medicaltreatmentai
Medicaltreatmentai is a machine learning model from Vinnybustacap. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as openrail.
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM from healthcarenlp import Diseases, SNOMEDCT from healthcarenlp.preprocessing import deidentifytext
Downloads · 30 days
0
Access
Public
Updated Dec 5, 2023
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md4.3 KB · 74%
From the Hugging Face model README
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM from healthcare_nlp import Diseases, SNOMEDCT from healthcare_nlp.preprocessing import de_identify_text
disease_name = input("Enter a disease name (e.g., 'diabetes'): ").lower() disease_concept = SNOMEDCT.query_concept(disease_name) model_name = "allenai/biobert-base-cased" # Clinically-tuned BioBERT model
user_profile = {"age": int(input("Enter your age: "))} tokenizer = AutoTokenizer.from_pretrained(model_name)
user_message = input("Ask your question about " + disease_concept.preferred_term + ": ") deidentified_message = de_identify_text(user_message) # Protect sensitive information
model = AutoModelForSeq2SeqLM.from_pretrained(model_name) inputs = tokenizer(deidentified_message, truncation=True, padding="max_length", return_tensors="pt") generated_ids = model.generate(**inputs, max_length=256) response = tokenizer.decode(generated_ids.squeeze(), clean_up_tokenization=True)
knowledge_base = Diseases.load_disease_info(disease_concept.concept_id) response = personalize_response(response, disease_concept, user_message, user_profile, knowledge_base)
response += ( "\nFeel free to ask any further questions you might have. I am still under development, but I leverage " "clinical knowledge and continuous learning to provide accurate and evidence-based information. " "Remember, I am not a substitute for professional healthcare advice. Please consult your doctor " "for diagnosis and treatment decisions." )
print(response)
def personalize_response(response, disease_concept, user_message, user_profile, knowledge_base): # Highlight relevant knowledge base sections for key, value in knowledge_base.items(): if key.lower() in user_message.lower(): response += f"\nRegarding your query about {key}, here's some relevant information: {value}"
# Adapt response based on disease complexity and user age
response = personalize_with_disease_complexity(response, disease_concept)
response = personalize_with_user_age(response, user_profile)
# Add medical references and adjust communication style based on user preferences
if user_profile["age"] >= 18 and user_profile["preferred_communication_style"] == "informative":
response = add_informative_details(response, knowledge_base)
elif user_profile["age"] >= 18 and user_profile["preferred_communication_style"] == "empathetic":
# Implement empathetic communication style here (e.g., acknowledge feelings, offer support)
pass
else:
# Use simpler language and avoid overwhelming details for younger users or non-informative preferences
pass
# Re-identify anonymized terms for clinical context (optional)
# response = re_identify_text(response, knowledge_base)
return response
def personalize_with_disease_complexity(response, disease_concept): if "complex" in disease_concept.description.lower(): 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." return response
def personalize_with_user_age(response, user_profile): if user_profile["age"] < 18: response += f"\nAs you're under 18, it's crucial to involve your parents or guardians in managing your health and seeking professional guidance." return response
This version enhances professionalism with: