Skip to content

Commit 5a0d5dc

Browse files
authored
Add files via upload
1 parent ab13f82 commit 5a0d5dc

20 files changed

+28842
-30
lines changed

Hopfield.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sentence_transformers import SentenceTransformer
99
import pickle
1010

11+
1112
class HopfieldRetrievalModel(nn.Module):
1213
def __init__(self, beta=0.125, update_steps_max=3):
1314
# def __init__(self, beta=0.125):
@@ -44,7 +45,6 @@ def forward(self, memory, trg):
4445
return pair_list
4546

4647

47-
4848
def read_external_knowledge(path):
4949
path = '/Users/jmy/Desktop/ai_for_health_final/exsit_knowledge/my_dict.pkl'
5050
with open(path, 'rb') as file:
@@ -69,10 +69,10 @@ def read_reports(path):
6969
return reports
7070

7171

72-
7372
def retrieval_info(reports, path, k):
7473
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7574
paragraphs = read_external_knowledge(path + '/exsit_knowledge')
75+
print(len(paragraphs))
7676

7777
# sentence_embedding with paragraphs
7878
model = SentenceTransformer('all-mpnet-base-v2')
@@ -82,6 +82,8 @@ def retrieval_info(reports, path, k):
8282
p_embeddings = model.encode(paragraphs)
8383
# sentence_embedding with reports
8484
report_embeddings = model.encode(reports)
85+
print('report', report_embeddings.shape)
86+
print('p_embedding', p_embeddings.shape)
8587
retrievaler = HopfieldRetrievalModel().to(device)
8688
result = retrievaler(torch.tensor(p_embeddings).to(device) * 100, torch.tensor(report_embeddings).to(device) * 100)
8789
input_ids = torch.topk(result, k, dim=1).indices
@@ -100,11 +102,9 @@ def retrieval_info(reports, path, k):
100102
return knowledge
101103

102104

103-
104-
105105
if __name__ == '__main__':
106-
reports = read_reports('/Users/jmy/Desktop/ai_for_health_final/dataset_folder/health_report_{2343}') # 13452
107-
know = retrieval_info(reports,'/Users/jmy/Desktop/ai_for_health_final/',3)
106+
reports = read_reports(
107+
'/Users/chongzhang/PycharmProjects/ai_for_health_final/dataset_folder/health_report_{243}') # 13452
108+
know = retrieval_info(reports, '/Users/chongzhang/PycharmProjects/ai_for_health_final/', 3)
108109
for i in know:
109110
print(i)
110-

Input_feature.txt

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Hunger
2+
Abdominal bloating
3+
Anemia
4+
Bacterial infection
5+
Weight loss
6+
Loss of appetite
7+
Mucus in stool
8+
Menstrual irregularities
9+
Diarrhea
10+
Spasm
11+
Throat burning sensation
12+
Chest pain
13+
Phlegm
14+
Difficulty breathing
15+
Jaundice
16+
Hiccup
17+
Sneeze
18+
Hemorrhoids
19+
Loose stools
20+
Frequent urination
21+
Headache
22+
Urgent urination
23+
Gastrointestinal discomfort
24+
Shortness of breath
25+
Chills
26+
Heartburn
27+
Sore throat
28+
Nasal congestion
29+
Indigestion
30+
Back pain
31+
Stomach ache
32+
Perianal pain
33+
Fatigue
34+
Allergy
35+
Bowel sounds
36+
Cough
37+
Dark stools
38+
Vomiting
39+
Muscle soreness
40+
Dehydration
41+
Intestinal obstruction
42+
Nausea
43+
Numbness in limbs
44+
Fever
45+
Restlessness
46+
Vomiting blood
47+
Dysbiosis
48+
Drowsiness
49+
Dizziness
50+
Abdominal pain
51+
Rectal bleeding
52+
Palpitations
53+
Mental fatigue
54+
Helicobacter pylori infection
55+
Reflux
56+
Edema
57+
Gastrointestinal dysfunction
58+
Enlarged lymph nodes
59+
Difficulty swallowing
60+
Bitter taste in the mouth
33.3 KB
Binary file not shown.

exsit_knowledge/my_dict.pkl

55.7 KB
Binary file not shown.

generate_feature.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import openai
2-
import os
32

43

54
def generate_feature(path):
@@ -11,11 +10,24 @@ def generate_feature(path):
1110
my_feature_list.append(line)
1211
question = []
1312
for i in my_feature_list:
14-
openai.api_key = ""
13+
openai.api_key = "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"
1514
messages = []
16-
system_message = "You are a medical health assistant robot"
15+
system_message = "please list the names of the symptoms in order like these examples\n" + 'Cold ------ Runny ' \
16+
'nose, stuffy nose, ' \
17+
'sneezing, ' \
18+
'sore throat, ' \
19+
'cough, hoarseness, ' \
20+
'headache, ' \
21+
'sore eyes, ' \
22+
'fatigue, ' \
23+
'minor body aches, ' \
24+
'fever or low-grade ' \
25+
'fever, ear pain, ' \
26+
'chest tightness, ' \
27+
'or difficulty ' \
28+
'breathing.'
1729
messages.append({"role": "system", "content": system_message})
18-
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.'
30+
message = f'Please list the symptoms of {i}? in the following format'
1931
messages.append({"role": "user", "content": message})
2032
response = openai.ChatCompletion.create(
2133
model="gpt-3.5-turbo",
@@ -25,19 +37,13 @@ def generate_feature(path):
2537
question.append(reply)
2638
print(reply)
2739

28-
2940
return question
3041

3142

32-
3343
if __name__ == '__main__':
34-
35-
OPENAI_API_KEY = "sk-......."
36-
37-
path = '/Users/jmy/Desktop/ai_for_health_final/label and feature/output_target.txt'
44+
OPENAI_API_KEY = "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"
45+
path = '/Users/chongzhang/PycharmProjects/ai_for_health_final/label and feature/output_target.txt'
3846
question = generate_feature(path)
39-
with open("/Users/jmy/Desktop/ai_for_health_final/training/feature.txt", "w") as file:
40-
for item in question:
41-
file.write("%s\n" % item)
42-
43-
47+
# with open("/Users/jmy/Desktop/ai_for_health_final/training/feature.txt", "w") as file:
48+
# for item in question:
49+
# file.write("%s\n" % item)

label and feature/Input_feature.txt

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Hunger
2+
Abdominal bloating
3+
Anemia
4+
Bacterial infection
5+
Weight loss
6+
Loss of appetite
7+
Mucus in stool
8+
Menstrual irregularities
9+
Diarrhea
10+
Spasm
11+
Throat burning sensation
12+
Chest pain
13+
Phlegm
14+
Difficulty breathing
15+
Jaundice
16+
Hiccup
17+
Sneeze
18+
Hemorrhoids
19+
Loose stools
20+
Frequent urination
21+
Headache
22+
Urgent urination
23+
Gastrointestinal discomfort
24+
Shortness of breath
25+
Chills
26+
Heartburn
27+
Sore throat
28+
Nasal congestion
29+
Indigestion
30+
Back pain
31+
Stomach ache
32+
Perianal pain
33+
Fatigue
34+
Allergy
35+
Bowel sounds
36+
Cough
37+
Dark stools
38+
Vomiting
39+
Muscle soreness
40+
Dehydration
41+
Intestinal obstruction
42+
Nausea
43+
Numbness in limbs
44+
Fever
45+
Restlessness
46+
Vomiting blood
47+
Dysbiosis
48+
Drowsiness
49+
Dizziness
50+
Abdominal pain
51+
Rectal bleeding
52+
Palpitations
53+
Mental fatigue
54+
Helicobacter pylori infection
55+
Reflux
56+
Edema
57+
Gastrointestinal dysfunction
58+
Enlarged lymph nodes
59+
Difficulty swallowing
60+
Bitter taste in the mouth

0 commit comments

Comments
 (0)