Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MingyuJ666 authored Feb 7, 2024
1 parent ab13f82 commit 5a0d5dc
Show file tree
Hide file tree
Showing 20 changed files with 28,842 additions and 30 deletions.
14 changes: 7 additions & 7 deletions Hopfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sentence_transformers import SentenceTransformer
import pickle


class HopfieldRetrievalModel(nn.Module):
def __init__(self, beta=0.125, update_steps_max=3):
# def __init__(self, beta=0.125):
Expand Down Expand Up @@ -44,7 +45,6 @@ def forward(self, memory, trg):
return pair_list



def read_external_knowledge(path):
path = '/Users/jmy/Desktop/ai_for_health_final/exsit_knowledge/my_dict.pkl'
with open(path, 'rb') as file:
Expand All @@ -69,10 +69,10 @@ def read_reports(path):
return reports



def retrieval_info(reports, path, k):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
paragraphs = read_external_knowledge(path + '/exsit_knowledge')
print(len(paragraphs))

# sentence_embedding with paragraphs
model = SentenceTransformer('all-mpnet-base-v2')
Expand All @@ -82,6 +82,8 @@ def retrieval_info(reports, path, k):
p_embeddings = model.encode(paragraphs)
# sentence_embedding with reports
report_embeddings = model.encode(reports)
print('report', report_embeddings.shape)
print('p_embedding', p_embeddings.shape)
retrievaler = HopfieldRetrievalModel().to(device)
result = retrievaler(torch.tensor(p_embeddings).to(device) * 100, torch.tensor(report_embeddings).to(device) * 100)
input_ids = torch.topk(result, k, dim=1).indices
Expand All @@ -100,11 +102,9 @@ def retrieval_info(reports, path, k):
return knowledge




if __name__ == '__main__':
reports = read_reports('/Users/jmy/Desktop/ai_for_health_final/dataset_folder/health_report_{2343}') # 13452
know = retrieval_info(reports,'/Users/jmy/Desktop/ai_for_health_final/',3)
reports = read_reports(
'/Users/chongzhang/PycharmProjects/ai_for_health_final/dataset_folder/health_report_{243}') # 13452
know = retrieval_info(reports, '/Users/chongzhang/PycharmProjects/ai_for_health_final/', 3)
for i in know:
print(i)

60 changes: 60 additions & 0 deletions Input_feature.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Hunger
Abdominal bloating
Anemia
Bacterial infection
Weight loss
Loss of appetite
Mucus in stool
Menstrual irregularities
Diarrhea
Spasm
Throat burning sensation
Chest pain
Phlegm
Difficulty breathing
Jaundice
Hiccup
Sneeze
Hemorrhoids
Loose stools
Frequent urination
Headache
Urgent urination
Gastrointestinal discomfort
Shortness of breath
Chills
Heartburn
Sore throat
Nasal congestion
Indigestion
Back pain
Stomach ache
Perianal pain
Fatigue
Allergy
Bowel sounds
Cough
Dark stools
Vomiting
Muscle soreness
Dehydration
Intestinal obstruction
Nausea
Numbness in limbs
Fever
Restlessness
Vomiting blood
Dysbiosis
Drowsiness
Dizziness
Abdominal pain
Rectal bleeding
Palpitations
Mental fatigue
Helicobacter pylori infection
Reflux
Edema
Gastrointestinal dysfunction
Enlarged lymph nodes
Difficulty swallowing
Bitter taste in the mouth
Binary file added exsit_knowledge/Knowledge-translated.docx
Binary file not shown.
Binary file added exsit_knowledge/my_dict.pkl
Binary file not shown.
36 changes: 21 additions & 15 deletions generate_feature.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import openai
import os


def generate_feature(path):
Expand All @@ -11,11 +10,24 @@ def generate_feature(path):
my_feature_list.append(line)
question = []
for i in my_feature_list:
openai.api_key = ""
openai.api_key = "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"
messages = []
system_message = "You are a medical health assistant robot"
system_message = "please list the names of the symptoms in order like these examples\n" + 'Cold ------ Runny ' \
'nose, stuffy nose, ' \
'sneezing, ' \
'sore throat, ' \
'cough, hoarseness, ' \
'headache, ' \
'sore eyes, ' \
'fatigue, ' \
'minor body aches, ' \
'fever or low-grade ' \
'fever, ear pain, ' \
'chest tightness, ' \
'or difficulty ' \
'breathing.'
messages.append({"role": "system", "content": system_message})
message = f'Please list the symptoms of {i}? You only need to list the names of the symptoms in order. You do not need to describe the symptoms in detail.'
message = f'Please list the symptoms of {i}? in the following format'
messages.append({"role": "user", "content": message})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
Expand All @@ -25,19 +37,13 @@ def generate_feature(path):
question.append(reply)
print(reply)


return question



if __name__ == '__main__':

OPENAI_API_KEY = "sk-......."

path = '/Users/jmy/Desktop/ai_for_health_final/label and feature/output_target.txt'
OPENAI_API_KEY = "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"
path = '/Users/chongzhang/PycharmProjects/ai_for_health_final/label and feature/output_target.txt'
question = generate_feature(path)
with open("/Users/jmy/Desktop/ai_for_health_final/training/feature.txt", "w") as file:
for item in question:
file.write("%s\n" % item)


# with open("/Users/jmy/Desktop/ai_for_health_final/training/feature.txt", "w") as file:
# for item in question:
# file.write("%s\n" % item)
60 changes: 60 additions & 0 deletions label and feature/Input_feature.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Hunger
Abdominal bloating
Anemia
Bacterial infection
Weight loss
Loss of appetite
Mucus in stool
Menstrual irregularities
Diarrhea
Spasm
Throat burning sensation
Chest pain
Phlegm
Difficulty breathing
Jaundice
Hiccup
Sneeze
Hemorrhoids
Loose stools
Frequent urination
Headache
Urgent urination
Gastrointestinal discomfort
Shortness of breath
Chills
Heartburn
Sore throat
Nasal congestion
Indigestion
Back pain
Stomach ache
Perianal pain
Fatigue
Allergy
Bowel sounds
Cough
Dark stools
Vomiting
Muscle soreness
Dehydration
Intestinal obstruction
Nausea
Numbness in limbs
Fever
Restlessness
Vomiting blood
Dysbiosis
Drowsiness
Dizziness
Abdominal pain
Rectal bleeding
Palpitations
Mental fatigue
Helicobacter pylori infection
Reflux
Edema
Gastrointestinal dysfunction
Enlarged lymph nodes
Difficulty swallowing
Bitter taste in the mouth
Loading

0 comments on commit 5a0d5dc

Please sign in to comment.