nomadicsynth commited on
Commit
28f7e6c
Β·
1 Parent(s): fd9957e

Enhance abstract analysis function with input validation and improved reasoning prompts; update UI text for clarity and relevance

Browse files
Files changed (1) hide show
  1. app.py +87 -65
app.py CHANGED
@@ -283,11 +283,29 @@ def embed_text(text: str | list[str]) -> torch.Tensor:
283
 
284
  def analyse_abstracts(query_abstract: str, compare_abstract: dict) -> str:
285
  """Analyze the relationship between two abstracts and return formatted analysis"""
286
- # Highlight the synergies in thesede papers that would justify further research
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  messages = [
288
- {
289
- "role": "user",
290
- "content": f"""You are trained in evaluating connections between research papers. Please **identify and analyze the links** between these two papers:
291
 
292
  Paper 1 Abstract:
293
  {query_abstract}
@@ -295,58 +313,59 @@ Paper 1 Abstract:
295
  Paper 2 Abstract:
296
  {compare_abstract["abstract"]}
297
 
298
- Consider the following aspects in your evaluation:
299
 
300
- * **Methodological Cross-Pollination**: How do the methods or approaches from one paper **directly enhance or inform** the other?
301
- * **Principle or Mechanism Extension**: Do the papers **share underlying principles or mechanisms** that can be **combined or extended** to yield new insights?
302
- * **Interdisciplinary Connections**: Are there **clear opportunities** for interdisciplinary collaborations or knowledge transfer between the two papers?
303
- * **Solution or Application Bridge**: Can the solutions or applications presented in one paper be **directly adapted or integrated** with the other to create **novel, actionable outcomes**?
304
 
305
- Consider the connections in either direction, that is, from Paper 1 -> Paper 2, or vice versa, from Paper 2 -> Paper 1
306
 
307
- Return a valid JSON object with this structure:
308
  {{
309
- "reasoning": "Step-by-step analysis of the papers, highlighting **key established connections**, identified synergies, and **concrete complementarities**. Emphasize the most **critical, actionable insights** or **key takeaways** from the analysis using markdown bold.",
310
 
311
- # Main connecting concepts, methods, or principles
312
  "key_connections": [
313
  {{
314
  "connection": "connection 1",
315
- "description": "Brief description (1-2 sentences) for the **established connection**, explaining its **direct relevance** to the synergy analysis."
316
  }},
317
- ...
318
  ],
319
 
320
- "synergies_and_complementarities": [
321
  {{
322
- "type": ["Methodological Cross-Pollination", "Principle or Mechanism Extension", "Interdisciplinary Connections", "Solution or Application Bridge"], # Choose only one type per entry, and only include relevant types to this analysis
323
- "description": "Brief explanation (1-2 sentences) of the **identified, concrete synergy** or **complementarity**, and a **specific, actionable example** to illustrate the concept."
324
  }},
325
- ...
326
  ],
327
 
328
- # Novel, actionable outcomes or applications emerging from the synergies
329
  "research_potential": [
330
  {{
331
- "potential": "Actionable outcome or application 1",
332
- "description": "Brief description (1-2 sentences) of the **concrete potential outcome** or **application**, and a **specific scenario** to illustrate its **direct impact**."
333
  }},
334
- ...
335
  ],
336
 
337
- "rating": 1-5, # Overall rating of the papers' synergy potential, where:
338
- # 1 = **No synergy or connection** (definitely no link between the papers)
339
- # 2 = **Low potential for synergy** (some vague or speculative connection, but highly uncertain)
340
- # 3 = **Plausible synergy potential** (some potential connections, but requiring further investigation to confirm)
341
- # 4 = **Established synergy with potential for growth** (clear connections with opportunities for further development)
342
- # 5 = **High established synergy with direct, clear opportunities** (strong, concrete links with immediate, actionable outcomes)
343
 
344
- "confidence": 0.0-1.0, # Confidence in your analysis, as a floating-point value representing the probability of your assessment being accurate
 
 
345
  }}
346
 
347
- Return only the JSON object, with double quotes around key names and all string values.""",
348
- },
349
- ]
 
350
 
351
  # Generate analysis
352
  try:
@@ -507,9 +526,9 @@ def create_interface():
507
  gr.HTML(
508
  """
509
  <div style="text-align: center; margin-bottom: 1rem">
510
- <h1>Research Compass</h1>
511
- <p>Find synergistic papers to enrich your research</p>
512
- <p>An experiment in AI-driven research synergy analysis</p>
513
  </div>
514
  """
515
  )
@@ -517,22 +536,25 @@ def create_interface():
517
  with gr.Accordion(label="Instructions and Privacy Policy", open=False):
518
  gr.Markdown(
519
  """
520
- This tool helps you find papers that are synergistic with your research.
521
- It uses AI to analyze the connections between papers and provides insights into their potential synergies.
522
-
523
- Please ask any questions or provide feedback on the tool to help us improve it by starting a discussion on
524
- the [Community Tab](https://huggingface.co/spaces/nomadicsynth/research-compass/discussions).
 
525
 
 
 
 
 
 
526
 
527
  **Privacy Policy**: The abstract or research description you provide will be included in any feedback
528
  you submit and may be used to improve the model, and published in a public dataset.
529
  Please ensure that you have the right to share this information.
530
  By submitting feedback, you agree to the use of this information for research purposes.
531
- Your feedback will be used to improve the model and the research process.
532
- Please do not include any personally identifiable information, proprietary or sensitive information,
533
- or any other information you do not want to share.
534
 
535
-
536
  **Disclaimer**: This tool is in alpha testing and is not intended for production use.
537
  The results are not guaranteed to be accurate or reliable. Use at your own risk.
538
  The tool is provided "as is" without any warranties or guarantees.
@@ -542,11 +564,11 @@ def create_interface():
542
  )
543
  gr.Markdown(
544
  """
545
- 1. **Enter Abstract**: Paste an abstract or describe your research details in the text box.
546
- 2. **Search for Synergistic Papers**: Click the button to find papers with similar themes.
547
- 3. **Select a Paper**: Click on a row in the results table to view paper details.
548
- 4. **Analyze Connection Potential**: Click the button to analyze the synergy potential between the papers.
549
- 5. **Synergy Analysis**: View the detailed analysis of the connection potential between the papers.
550
  """
551
  )
552
 
@@ -556,7 +578,7 @@ def create_interface():
556
  lines=8,
557
  key="abstract",
558
  )
559
- search_btn = gr.Button("Search for Synergistic Papers", variant="primary")
560
 
561
  # Store full paper data
562
  paper_data_state = gr.State([])
@@ -572,7 +594,7 @@ def create_interface():
572
  headers=["Title", "Authors", "Categories", "Date", "Match Score"],
573
  datatype=["markdown", "markdown", "str", "date", "str"],
574
  latex_delimiters=latex_delimiters,
575
- label="Synergistic Papers",
576
  interactive=False,
577
  wrap=False,
578
  line_breaks=False,
@@ -589,25 +611,26 @@ def create_interface():
589
  show_copy_button=True,
590
  key="paper_details",
591
  )
592
- analyze_btn = gr.Button("Analyze Connections", variant="primary", visible=False)
593
  with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as paper_feedback_accordion:
594
  gr.Markdown(
595
  """
596
- Please provide feedback on the paper match and analysis to improve the model.
 
597
  """
598
  )
599
- # Add thumbs up/down for paper match
600
  paper_feedback = gr.Radio(
601
- ["πŸ‘ Good Match", "πŸ‘Ž Poor Match"], label="Is this paper a good match?",
 
602
  )
603
  paper_expert = gr.Checkbox(label="I am an expert in this field", value=False)
604
- paper_comment = gr.Textbox(label="Additional feedback on this paper match (optional)")
605
  flag_paper_btn = gr.Button("Submit Paper Feedback")
606
 
607
  with gr.Column(scale=1):
608
  analysis_output = gr.Markdown(
609
- value="# Synergy Analysis",
610
- label="Synergy Analysis",
611
  latex_delimiters=latex_delimiters,
612
  show_copy_button=True,
613
  key="analysis_output",
@@ -615,17 +638,16 @@ def create_interface():
615
  with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as analysis_feedback_accordion:
616
  gr.Markdown(
617
  """
618
- The analysis is generated by an AI model and may not be perfect.
619
- If you find any errors or have suggestions for improvement, please let us know.
620
- Your feedback is valuable and will be used to improve the model and prompt.
621
  """
622
  )
623
- # Add thumbs up/down for analysis
624
  analysis_feedback = gr.Radio(
625
- ["πŸ‘ Helpful", "πŸ‘Ž Not Helpful"], label="Was this analysis helpful?",
 
626
  )
627
  analysis_expert = gr.Checkbox(label="I am an expert in this field", value=False)
628
- analysis_comment = gr.Textbox(label="Additional feedback on analysis (optional)")
629
  flag_analysis_btn = gr.Button("Submit Analysis Feedback")
630
 
631
  # Set up logging directories
 
283
 
284
  def analyse_abstracts(query_abstract: str, compare_abstract: dict) -> str:
285
  """Analyze the relationship between two abstracts and return formatted analysis"""
286
+ global reasoning_model
287
+ # Check if the compare_abstract is valid
288
+ if not isinstance(compare_abstract, dict) or "abstract" not in compare_abstract:
289
+ return "Invalid compare_abstract format. Expected a dictionary with 'abstract' key."
290
+ if not query_abstract or not compare_abstract["abstract"]:
291
+ return "Invalid input. Please provide both query_abstract and compare_abstract."
292
+ # Check if the query_abstract is a string
293
+ if not isinstance(query_abstract, str):
294
+ return "Invalid query_abstract format. Expected a string."
295
+ # Check if the compare_abstract is a string
296
+ if not isinstance(compare_abstract["abstract"], str):
297
+ return "Invalid compare_abstract format. Expected a string."
298
+ # Check if the query_abstract is empty
299
+ if not query_abstract.strip():
300
+ return "Invalid query_abstract format. Expected a non-empty string."
301
+ # Check if the compare_abstract is empty
302
+ if not compare_abstract["abstract"].strip():
303
+ return "Invalid compare_abstract format. Expected a non-empty string."
304
+
305
  messages = [
306
+ {
307
+ "role": "user",
308
+ "content": f"""You are trained in evaluating conceptual and methodological connections between research papers. Please **identify and analyze the reasoning-based links** between the following two papers:
309
 
310
  Paper 1 Abstract:
311
  {query_abstract}
 
313
  Paper 2 Abstract:
314
  {compare_abstract["abstract"]}
315
 
316
+ In your evaluation, consider the following dimensions:
317
 
318
+ * **Methodological Cross-Pollination**: Do the methods or approaches from one paper **directly inform, enhance, or contrast with** the other?
319
+ * **Principle or Mechanism Extension**: Do the papers **share core principles, mechanisms, or assumptions** that could be **combined or extended** to generate new understanding or tools?
320
+ * **Interdisciplinary Bridges**: Are there clear opportunities for **knowledge transfer or collaboration** across fields or problem domains?
321
+ * **Solution or Application Overlap**: Can the solutions, frameworks, or applications in one paper be **adapted or repurposed** to benefit the work in the other, leading to **tangible, novel outcomes**?
322
 
323
+ Assess these connections in both directions (Paper 1 β†’ Paper 2 and Paper 2 β†’ Paper 1). Focus on **relevant and practically meaningful links** β€” especially those that might be **missed in practice** due to the sheer volume of publications or the separation between research communities. These are often connections that would be **immediately apparent to an expert** familiar with both papers, but easily overlooked otherwise.
324
 
325
+ Return a valid JSON object in the following structure:
326
  {{
327
+ "reasoning": "Step-by-step conceptual analysis of how the papers relate, highlighting **key connections**, complementary methods, or shared ideas. Emphasize the most **relevant, practically useful takeaways**, and use markdown bold to highlight major points.",
328
 
 
329
  "key_connections": [
330
  {{
331
  "connection": "connection 1",
332
+ "description": "1–2 sentence explanation of the **main conceptual or methodological link**, emphasizing its practical or theoretical relevance."
333
  }},
334
+ ...
335
  ],
336
 
337
+ "complementarities": [
338
  {{
339
+ "type": ["Methodological Cross-Pollination", "Principle or Mechanism Extension", "Interdisciplinary Bridges", "Solution or Application Overlap"], # Use only the most relevant label per entry
340
+ "description": "A concise explanation (1–2 sentences) of the **identified complementarity** or **productive relationship**, including a specific example or outcome it could enable."
341
  }},
342
+ ...
343
  ],
344
 
 
345
  "research_potential": [
346
  {{
347
+ "potential": "Potential application or outcome 1",
348
+ "description": "1–2 sentence explanation of the **concrete potential impact**, framed in terms of a **realistic scenario or use case**."
349
  }},
350
+ ...
351
  ],
352
 
353
+ "rating": 1-5, # Overall strength of the connection:
354
+ # 1 = No meaningful connection
355
+ # 2 = Weak or speculative connection
356
+ # 3 = Plausible but unproven connection
357
+ # 4 = Solid connection with future potential
358
+ # 5 = Strong, well-aligned connection with immediate, valuable implications
359
 
360
+ "confidence": 0.0-1.0 # Confidence score in your assessment (e.g., 0.85 for high confidence, 1.0 for absolute certainty)
361
+ # Note: The confidence score should reflect your level of certainty in the analysis, not the strength of the connection itself.
362
+ # A score of 0.0 indicates no confidence in the analysis, while 1.0 indicates absolute certainty.
363
  }}
364
 
365
+ Return only the JSON object. All key names and string values must be in double quotes.
366
+ """,
367
+ },
368
+ ]
369
 
370
  # Generate analysis
371
  try:
 
526
  gr.HTML(
527
  """
528
  <div style="text-align: center; margin-bottom: 1rem">
529
+ <h1>Inkling</h1>
530
+ <p>Discover papers with deep conceptual connections to your research</p>
531
+ <p>An experiment in AI-assisted research discovery and insight generation</p>
532
  </div>
533
  """
534
  )
 
536
  with gr.Accordion(label="Instructions and Privacy Policy", open=False):
537
  gr.Markdown(
538
  """
539
+ This tool helps you uncover research papers with **deep, meaningful connections** to your ideas.
540
+ It uses AI to go beyond keyword or semantic similarity β€” analyzing how papers relate **conceptually** and **contextually**,
541
+ even when the surface topics differ.
542
+
543
+ The focus is on surfacing *novel insights* β€” connections that may not be obvious at a glance,
544
+ but could **spark new perspectives**, **deepen understanding**, or **highlight relationships that might otherwise be overlooked**.
545
 
546
+ It’s designed to act more like a research collaborator than a search engine β€” helping you explore conceptual bridges and
547
+ unexpected pathways in the literature.
548
+
549
+ Please ask any questions or provide feedback on the tool to help us improve it by starting a discussion on
550
+ the [Community Tab](https://huggingface.co/spaces/nomadicsynth/inkling/discussions).
551
 
552
  **Privacy Policy**: The abstract or research description you provide will be included in any feedback
553
  you submit and may be used to improve the model, and published in a public dataset.
554
  Please ensure that you have the right to share this information.
555
  By submitting feedback, you agree to the use of this information for research purposes.
556
+ Do not include personally identifiable, proprietary, or sensitive information.
 
 
557
 
 
558
  **Disclaimer**: This tool is in alpha testing and is not intended for production use.
559
  The results are not guaranteed to be accurate or reliable. Use at your own risk.
560
  The tool is provided "as is" without any warranties or guarantees.
 
564
  )
565
  gr.Markdown(
566
  """
567
+ 1. **Enter Abstract**: Paste an abstract or describe your research question or idea in the text box.
568
+ 2. **Find Related Papers**: Click the button to explore conceptually related research.
569
+ 3. **Select a Paper**: Click on a row in the results table to view more details.
570
+ 4. **Analyze Connection**: Click the analysis button to explore the potential connection between the papers.
571
+ 5. **Insight Analysis**: Review the model’s reasoning about how and why these papers may relate meaningfully.
572
  """
573
  )
574
 
 
578
  lines=8,
579
  key="abstract",
580
  )
581
+ search_btn = gr.Button("Find Related Papers", variant="primary")
582
 
583
  # Store full paper data
584
  paper_data_state = gr.State([])
 
594
  headers=["Title", "Authors", "Categories", "Date", "Match Score"],
595
  datatype=["markdown", "markdown", "str", "date", "str"],
596
  latex_delimiters=latex_delimiters,
597
+ label="Related Papers",
598
  interactive=False,
599
  wrap=False,
600
  line_breaks=False,
 
611
  show_copy_button=True,
612
  key="paper_details",
613
  )
614
+ analyze_btn = gr.Button("Analyze Connection", variant="primary", visible=False)
615
  with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as paper_feedback_accordion:
616
  gr.Markdown(
617
  """
618
+ Please provide feedback on the relevance of this paper to your input.
619
+ This helps us improve how well the system identifies meaningful research connections.
620
  """
621
  )
 
622
  paper_feedback = gr.Radio(
623
+ ["πŸ‘ Good Match", "πŸ‘Ž Poor Match"],
624
+ label="Is this paper meaningfully related to your query?",
625
  )
626
  paper_expert = gr.Checkbox(label="I am an expert in this field", value=False)
627
+ paper_comment = gr.Textbox(label="Additional feedback on this match (optional)")
628
  flag_paper_btn = gr.Button("Submit Paper Feedback")
629
 
630
  with gr.Column(scale=1):
631
  analysis_output = gr.Markdown(
632
+ value="# Connection Analysis",
633
+ label="Connection Analysis",
634
  latex_delimiters=latex_delimiters,
635
  show_copy_button=True,
636
  key="analysis_output",
 
638
  with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as analysis_feedback_accordion:
639
  gr.Markdown(
640
  """
641
+ This connection analysis was generated by an AI model trained to reason about conceptual links between research papers.
642
+ If you find the explanation helpful, unclear, or off-base, your feedback will help refine the model’s reasoning process.
 
643
  """
644
  )
 
645
  analysis_feedback = gr.Radio(
646
+ ["πŸ‘ Helpful", "πŸ‘Ž Not Helpful"],
647
+ label="Was this explanation useful in understanding the connection?",
648
  )
649
  analysis_expert = gr.Checkbox(label="I am an expert in this field", value=False)
650
+ analysis_comment = gr.Textbox(label="Additional feedback on the analysis (optional)")
651
  flag_analysis_btn = gr.Button("Submit Analysis Feedback")
652
 
653
  # Set up logging directories