Spaces:
Sleeping
Sleeping
Chunhua Liao
commited on
Commit
·
e07720a
1
Parent(s):
d268365
add explanation for each step
Browse files- README.md +1 -1
- proposal-gen-v1.py +74 -1
README.md
CHANGED
@@ -65,7 +65,7 @@ The system will generate a list of hypotheses related to the research goal. Each
|
|
65 |
* Novelty and feasibility assessments (HIGH, MEDIUM, LOW)
|
66 |
* An Elo score (representing its relative strength)
|
67 |
* Comments from the LLM review
|
68 |
-
* References (if found by the LLM)
|
69 |
|
70 |
The web interface will display the top-ranked hypotheses after each cycle, along with a meta-review critique and suggested next steps. The results are iterative, meaning that the hypotheses should improve over multiple cycles. Log files are created in the `results/` directory for each run.
|
71 |
|
|
|
65 |
* Novelty and feasibility assessments (HIGH, MEDIUM, LOW)
|
66 |
* An Elo score (representing its relative strength)
|
67 |
* Comments from the LLM review
|
68 |
+
* References (if found by the LLM). These are PubMed identifiers (PMIDs).
|
69 |
|
70 |
The web interface will display the top-ranked hypotheses after each cycle, along with a meta-review critique and suggested next steps. The results are iterative, meaning that the hypotheses should improve over multiple cycles. Log files are created in the `results/` directory for each run.
|
71 |
|
proposal-gen-v1.py
CHANGED
@@ -218,6 +218,62 @@ def generate_unique_id(prefix="H") -> str:
|
|
218 |
|
219 |
import json
|
220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
def call_llm_for_generation(prompt: str, num_hypotheses: int = 3) -> List[Dict]:
|
222 |
"""
|
223 |
Calls a Large Language Model (LLM) for generating hypotheses.
|
@@ -595,7 +651,7 @@ class MetaReviewAgent:
|
|
595 |
"research_overview": {
|
596 |
"top_ranked_hypotheses": [h.to_dict() for h in best_hypotheses],
|
597 |
"suggested_next_steps": [
|
598 |
-
"Conduct further in
|
599 |
"Collect domain expert feedback and refine constraints."
|
600 |
]
|
601 |
}
|
@@ -823,12 +879,27 @@ async def root():
|
|
823 |
|
824 |
let resultsHTML = `<h3>Iteration: ${data.iteration}</h3>`;
|
825 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
826 |
// Display details for each step
|
827 |
for (const stepName in data.steps) {
|
828 |
if (data.steps.hasOwnProperty(stepName)) {
|
829 |
const step = data.steps[stepName];
|
830 |
resultsHTML += `<h4>Step: ${stepName}</h4>`;
|
831 |
|
|
|
|
|
|
|
|
|
|
|
832 |
if (step.hypotheses) {
|
833 |
resultsHTML += `<h5>Hypotheses:</h5><ul>`;
|
834 |
step.hypotheses.sort((a, b) => b.elo_score - a.elo_score).forEach(hypo => {
|
@@ -875,6 +946,8 @@ async def root():
|
|
875 |
}
|
876 |
|
877 |
if (step.adjacency_graph) {
|
|
|
|
|
878 |
resultsHTML += `<p>Adjacency Graph: ${JSON.stringify(step.adjacency_graph)}</p>`;
|
879 |
}
|
880 |
}
|
|
|
218 |
|
219 |
import json
|
220 |
|
221 |
+
# --- VIS.JS INTEGRATION ---
|
222 |
+
def generate_visjs_graph(adjacency_graph: Dict) -> str:
|
223 |
+
"""
|
224 |
+
Generates HTML and JavaScript code for a vis.js graph.
|
225 |
+
|
226 |
+
Args:
|
227 |
+
adjacency_graph (Dict): The adjacency graph data.
|
228 |
+
|
229 |
+
Returns:
|
230 |
+
str: A string containing the HTML and JavaScript code to embed the graph.
|
231 |
+
"""
|
232 |
+
nodes = []
|
233 |
+
edges = []
|
234 |
+
|
235 |
+
for node_id, connections in adjacency_graph.items():
|
236 |
+
nodes.append(f"{{id: '{node_id}', label: '{node_id}'}}")
|
237 |
+
for connection in connections:
|
238 |
+
if connection['similarity'] > 0.2:
|
239 |
+
edges.append(f"{{from: '{node_id}', to: '{connection['other_id']}', label: '{connection['similarity']:.2f}', arrows: 'to'}}")
|
240 |
+
|
241 |
+
nodes_str = ",\n".join(nodes)
|
242 |
+
edges_str = ",\n".join(edges)
|
243 |
+
|
244 |
+
return f"""
|
245 |
+
<div id="mynetwork"></div>
|
246 |
+
<p>
|
247 |
+
<b>How to read the graph:</b><br>
|
248 |
+
- Each node (circle) represents an item.<br>
|
249 |
+
- Lines (edges) between nodes indicate a relationship.<br>
|
250 |
+
- The number on each edge represents the similarity score between the connected nodes. Higher numbers mean greater similarity. Only similarities above 0.2 are shown.<br>
|
251 |
+
</p>
|
252 |
+
<script type="text/javascript" src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
|
253 |
+
<script type="text/javascript">
|
254 |
+
var nodes = new vis.DataSet([
|
255 |
+
{nodes_str}
|
256 |
+
]);
|
257 |
+
var edges = new vis.DataSet([
|
258 |
+
{edges_str}
|
259 |
+
]);
|
260 |
+
var container = document.getElementById('mynetwork');
|
261 |
+
var data = {{
|
262 |
+
nodes: nodes,
|
263 |
+
edges: edges
|
264 |
+
}};
|
265 |
+
var options = {{
|
266 |
+
edges: {{
|
267 |
+
smooth: {{
|
268 |
+
enabled: true,
|
269 |
+
type: "dynamic",
|
270 |
+
}},
|
271 |
+
}},
|
272 |
+
}};
|
273 |
+
var network = new vis.Network(container, data, options);
|
274 |
+
</script>
|
275 |
+
"""
|
276 |
+
|
277 |
def call_llm_for_generation(prompt: str, num_hypotheses: int = 3) -> List[Dict]:
|
278 |
"""
|
279 |
Calls a Large Language Model (LLM) for generating hypotheses.
|
|
|
651 |
"research_overview": {
|
652 |
"top_ranked_hypotheses": [h.to_dict() for h in best_hypotheses],
|
653 |
"suggested_next_steps": [
|
654 |
+
"Conduct further in experiments on top hypotheses.",
|
655 |
"Collect domain expert feedback and refine constraints."
|
656 |
]
|
657 |
}
|
|
|
879 |
|
880 |
let resultsHTML = `<h3>Iteration: ${data.iteration}</h3>`;
|
881 |
|
882 |
+
// Define step explanations
|
883 |
+
const stepExplanations = {
|
884 |
+
generation: "Generates new hypotheses based on the research goal and current context.",
|
885 |
+
reflection: "Reviews the generated hypotheses for novelty and feasibility.",
|
886 |
+
ranking1: "Ranks hypotheses based on a pairwise comparison (tournament).",
|
887 |
+
evolution: "Combines the top-ranked hypotheses to create new, evolved hypotheses.",
|
888 |
+
ranking2: "Ranks hypotheses again after the evolution step.",
|
889 |
+
proximity: "Analyzes the similarity between hypotheses.",
|
890 |
+
};
|
891 |
+
|
892 |
// Display details for each step
|
893 |
for (const stepName in data.steps) {
|
894 |
if (data.steps.hasOwnProperty(stepName)) {
|
895 |
const step = data.steps[stepName];
|
896 |
resultsHTML += `<h4>Step: ${stepName}</h4>`;
|
897 |
|
898 |
+
// Add explanation if available
|
899 |
+
if (stepExplanations[stepName]) {
|
900 |
+
resultsHTML += `<p>${stepExplanations[stepName]}</p>`;
|
901 |
+
}
|
902 |
+
|
903 |
if (step.hypotheses) {
|
904 |
resultsHTML += `<h5>Hypotheses:</h5><ul>`;
|
905 |
step.hypotheses.sort((a, b) => b.elo_score - a.elo_score).forEach(hypo => {
|
|
|
946 |
}
|
947 |
|
948 |
if (step.adjacency_graph) {
|
949 |
+
// this does not work somehow TODO
|
950 |
+
// resultsHTML += generate_visjs_graph(step.adjacency_graph);
|
951 |
resultsHTML += `<p>Adjacency Graph: ${JSON.stringify(step.adjacency_graph)}</p>`;
|
952 |
}
|
953 |
}
|