File size: 6,313 Bytes
2b084d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# Requires vllm>=0.8.5
import torch
import vllm
from vllm import LLM
from pathlib import Path
import os
import json

def get_detailed_instruct(task_description: str, query: str) -> str:
    return f'Instruct: {task_description}\nQuery:{query}'


keywords = ["Quantum mechanics",
    "Gene editing",
    "Folding",
    "System biology",
    "Antibody",
    "Heterogeneity",
    "Ligand",
    "Drug repurpose",
    "Kinetics",
    "Next-generation sequencing",
    "Pharmacogenetics",
    "Phase-field technique",
    "Human",
    "Potential",
    "Hartree-Fock",
    "Flow matching",
    "Lipid",
    "Biomedical",
    "Antigen",
    "Stochastic modeling",
    "Coupled cluster",
    "Quantum biology",
    "Spatial biology",
    "Antagonist",
    "Free energy perturbation",
    "Cycle",
    "Pharmacology",
    "Redox",
    "Physiology",
    "Protein-Protein Interactions",
    "Single-cell",
    "Screening",
    "Hydrophobic",
    "First-principles based DFT",
    "Molecular biology",
    "Mechanism",
    "Reproduction number",
    "Spatial Transcriptomics",
    "Ion",
    "Computational Materials",
    "Absorption",
    "Pharmacometrics",
    "GAN",
    "Compartmental model",
    "Diagnostics",
    "Lead discovery",
    "QAPR",
    "Rosettafold",
    "Autoregressive",
    "Pharmacokinetics",
    "Biotechnology",
    "Hydrophilic",
    "3D",
    "Protein",
    "QM/MM",
    "Activation",
    "AMR",
    "Networks",
    "Genotype",
    "Gene regulatory networks",
    "Biologics",
    "Phenotype",
    "Nowcasting",
    "DFT",
    "AlphaFold",
    "Pandemic",
    "Immunology",
    "Pathology",
    "Chemical space",
    "Transformer",
    "Homeostasis",
    "Score",
    "High-throughput",
    "Cheminformatics",
    "Hit-to-lead",
    "Sequencing",
    "Enzyme",
    "Antimicrobial resistance modeling",
    "Allosteric",
    "Inhibition",
    "Computational Biochemistry",
    "Bioinformatics",
    "Transcriptomics",
    "Diffusion",
    "Anomaly detection",
    "Multi-omics",
    "Biology",
    "Pathway",
    "Metabolomics",
    "Synthetic biology",
    "Microbial",
    "Proteomics",
    "Pharmaceutics",
    "Organoid",
    "Network pharmacology",
    "Imaging",
    "Generative adversarial networks",
    "Microbiology",
    "Organ-on-a-chip",
    "De novo",
    "Substrate",
    "Personalized",
    "Drug",
    "Transcription",
    "RNA",
    "Explainable AI",
    "Generate",
    "Docking",
    "Pathogens",
    "Bio foundation model",
    "Reinforcement learning",
    "Mechanism of action",
    "Generative",
    "Metabolic",
    "Metabolic Flux Analysis",
    "Computational Chemistry",
    "Vaccine",
    "Biophysics",
    "Integration",
    "Biochemistry",
    "Physiologically based pharmacokinetics model",
    "Medicine",
    "Crystal",
    "Conjugate",
    "Variational autoencoders",
    "In Silico",
    "Protein-protein",
    "CRISPR",
    "Spatial transcriptomics",
    "Gene",
    "Translation",
    "Glycomics",
    "Lead optimization",
    "Pharmacodynamics",
    "Ab initio",
    "System immunology",
    "Pseudotime analysis",
    "Generative AI",
    "RNN",
    "Regulatory networks",
    "PBPK model",
    "Beta-blocker",
    "Lipidomics",
    "Reaction",
    "Bio",
    "Genesis",
    "Evolution",
    "Computational Biology",
    "VAE",
    "Pharmacogenomics",
    "Assay",
    "Sensors",
    "Conformation",
    "Finite element method",
    "Human atlas",
    "Translational medicine",
    "Neurology",
    "Genomics",
    "Cell biology",
    "Porous",
    "Biomarker",
    "Bioengineering",
    "Allele",
    "Recurrent neural networks",
    "Carbohydrate",
    "Metamaterial",
    "Virtual human",
    "DNA",
    "Omics",
    "Agonist",
    "Receptor",
    "Cofactor",
    "Metabolic flux analysis",
    "Cell atlas",
    "Signaling",
    "Electronic structure",
    "Monte Carlo",
    "Genomic surveillance",
    "Agent-based model",
    "Biosensors",
    "2D",
    "QSAR",
    "Codon",
    "Coenzyme",
    "Nucleic acids",
    "Dynamics",
    "Ensemble",
    "Spectrometry",
    "Multi-scale modeling",
    "ADMET",
    "Marker",
    "Toxicology",
    "Profiling",
    "Design",
    "Viral",
    "Chemistry",
    "Epigenetics",
    "Homo-Lumo",
    "Modeling",
    "Prediction",
    "Quantum Chemistry",
    "Half-life",
    "Material",
    "Disease",
    "Phylodynamic model",
    "Metagenomics",
    "Digital twin",
    "Cancer biology",
    "Discovery",
    "Bioavailability",
    "Digital PCR"
    ]

# Each query must come with a one-sentence instruction that describes the task
task = 'Given a web search query, retrieve relevant passages that answer the query'

queries = [
    get_detailed_instruct(task, ' '.join(keywords))
]

def get_md_contents(dir):
    subdirs = sorted([d for d in os.listdir(dir) if os.path.isdir(os.path.join(dir, d))])
    contents = []
    for subdir in subdirs:
        json_path = os.path.join(dir, subdir, 'readme_summary.json')
        if os.path.exists(json_path):
            with open(json_path, 'r', encoding='utf-8') as f:
                contents.append(json.load(f)['readme_summary'])
    return contents


md_contents = get_md_contents('/home/weifengsun/tangou1/step2/step22/dataset')
# print(len(md_contents))
# print(md_contents[0])




# No need to add instruction for retrieval documents
documents = md_contents
input_texts = queries + documents

model = LLM(model="Qwen/Qwen3-Embedding-0.6B", task="embed")

outputs = model.embed(input_texts)
embeddings = torch.tensor([o.outputs.embedding for o in outputs])
scores = (embeddings[0] @ embeddings[1:].T)
# print(scores.tolist())
# [[0.7620252966880798, 0.14078938961029053], [0.1358368694782257, 0.6013815999031067]]


dataset_dir = '/home/weifengsun/tangou1/step2/step22/dataset'
subdirs = sorted([d for d in os.listdir(dataset_dir) if os.path.isdir(os.path.join(dataset_dir, d))])
valid_subdirs = [d for d in subdirs if os.path.exists(os.path.join(dataset_dir, d, 'readme_summary.json'))]

score_list = scores.tolist()
for i, subdir in enumerate(valid_subdirs):
    json_path = os.path.join(dataset_dir, subdir, 'readme_summary.json')
    with open(json_path, 'r', encoding='utf-8') as f:
        data = json.load(f)
    data['score'] = score_list[i]
    with open(json_path, 'w', encoding='utf-8') as f:
        json.dump(data, f, ensure_ascii=False, indent=4)