DEV Community

shashank ms
shashank ms

Posted on

Using LLM for Research Purposes: A Guide

We're going to build a research synthesis agent that reads raw paper abstracts, scores them for relevance against your research question, extracts structured findings, and writes a concise literature review. It is useful for anyone who needs to survey a field without reading every paper front to back.

What you'll need

Python 3.10 or newer, the OpenAI SDK, and an Oxlo.ai API key from https://portal.oxlo.ai. Install the SDK with pip install openai. We will also create a small JSON corpus of sample abstracts so you can run the pipeline immediately.

Step 1: Bootstrap the client

First, initialize the OpenAI-compatible client pointing at Oxlo.ai. I use llama-3.3-70b as the default workhorse because it handles structured instructions reliably at low temperature.

from openai import OpenAI
import json

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

def ask_llm(system_prompt, user_message, model="llama-3.3-70b"):
    response = client.chat.completions.create(
        model=model,
        messages=[
            {"role": "system", "content": system_prompt},
            {"role": "user", "content": user_message},
        ],
        temperature=0.2,
    )
    return response.choices[0].message.content

Step 2: Prepare the corpus

Instead of forcing you to scrape PDFs, we will define a tiny JSON corpus inline. Each entry has an id, title, authors, year, and abstract. Save this as papers.json in your working directory.

corpus = [
    {
        "id": "zhang-2024",
        "title": "Attention mechanisms in protein folding",
        "authors": "Zhang et al.",
        "year": 2024,
        "abstract": "We introduce a transformer-based model that uses sparse attention to predict tertiary protein structures from primary sequences. Our method reduces training time by 40% compared to full self-attention while maintaining accuracy on CASP14 targets."
    },
    {
        "id": "patel-2023",
        "title": "Energy consumption of large language models",
        "authors": "Patel and Liu",
        "year": 2023,
        "abstract": "This paper quantifies the carbon footprint of training and inference for models exceeding 100B parameters. We propose a scheduling algorithm that reduces energy usage during off-peak hours without degrading throughput."
    },
    {
        "id": "chen-2024",
        "title": "Sparse attention for long-document classification",
        "authors": "Chen et al.",
        "year": 2024,
        "abstract": "We adapt local-plus-global attention patterns to process documents up to 128k tokens. Experiments on legal and biomedical benchmarks show a 12% improvement over sliding-window baselines."
    }
]

with open("papers.json", "w") as f:
    json.dump(corpus, f, indent=2)

Step 3: Define the system prompt

The system prompt grounds the model as a careful research analyst. It insists on structured output and warns against fabricating details not present in the source text.

SYSTEM_PROMPT = """You are a research synthesis assistant. Your job is to help a scientist survey academic literature efficiently.

Rules:
- Base every claim strictly on the provided text. Do not hallucinate methodology or results.
- When scoring relevance, return an integer 0-10 and a one-sentence rationale.
- When extracting findings, return valid JSON with keys: key_finding, method, limitation, confidence (high/medium/low).
- When synthesizing, organize by theme, not by paper, and cite sources using [id] format.
- Be concise. Avoid fluff."""

Step 4: Screen for relevance

We read each abstract and ask the model whether it addresses our research question. I use deepseek-v3.2 here because it offers a free tier on Oxlo.ai, which keeps costs negligible when you are filtering hundreds of abstracts.

def screen_paper(research_question, paper):
    user_msg = f"""Research question: {research_question}
Paper:
Title: {paper['title']}
Abstract: {paper['abstract']}

Return only a JSON object with keys "score" (0-10) and "rationale" (one sentence)."""

    raw = ask_llm(SYSTEM_PROMPT, user_msg, model="deepseek-v3.2")
    clean = raw.replace("

```json", "").replace("```

", "").strip()
    return json.loads(clean)

research_question = "How does sparse attention affect computational efficiency in biological sequence modeling?"

with open("papers.json") as f:
    papers = json.load(f)

for p in papers:
    res = screen_paper(research_question, p)
    print(p["id"], res)

Step 5: Extract structured findings

For papers that scored 5 or higher, we extract a structured summary. Keeping the temperature low reduces hallucinated limitations.

def extract_findings(paper):
    user_msg = f"""Extract structured findings from this paper.

Title: {paper['title']}
Abstract: {paper['abstract']}

Return valid JSON:
{{
  "key_finding": "string",
  "method": "string",
  "limitation": "string",
  "confidence": "high|medium|low"
}}"""

    raw = ask_llm(SYSTEM_PROMPT, user_msg)
    clean = raw.replace("

```json", "").replace("```

", "").strip()
    return json.loads(clean)

relevant = []
for p in papers:
    s = screen_paper(research_question, p)
    if s["score"] >= 5:
        findings = extract_findings(p)
        relevant.append({
            "id": p["id"],
            "title": p["title"],
            "year": p["year"],
            "score": s["score"],
            **findings
        })

print(f"Selected {len(relevant)} papers for synthesis.")

Step 6: Synthesize the report

Now we hand the aggregated findings to the model and ask for a thematic synthesis. I switch to kimi-k2.6 here because its reasoning and long-context abilities help weave disjoint findings into a coherent narrative.

def synthesize_report(research_question, findings):
    findings_text = json.dumps(findings, indent=2)
    user_msg = f"""Research question: {research_question}

Findings from relevant papers:
{findings_text}

Write a short literature review with these sections:
1. Executive Summary (2-3 sentences)
2. Thematic Synthesis (group by theme, cite sources like [zhang-2024])
3. Limitations Across Studies
4. Gaps and Future Work

Use markdown headers."""

    return ask_llm(SYSTEM_PROMPT, user_msg, model="kimi-k2.6")

report = synthesize_report(research_question, relevant)
print(report)

Run it

Putting it all together, the full script reads papers.json, screens each abstract, extracts findings from the relevant subset, and prints a markdown report. Here is the consolidated entry point and an example of the output.

if __name__ == "__main__":
    research_question = "How does sparse attention affect computational efficiency in biological sequence modeling?"

    with open("papers.json") as f:
        papers = json.load(f)

    relevant = []
    for p in papers:
        screen = screen_paper(research_question, p)
        if screen["score"] >= 5:
            extracted = extract_findings(p)
            relevant.append({
                "id": p["id"],
                "title": p["title"],
                "year": p["year"],
                "score": screen["score"],
                **extracted
            })

    print(f"Selected {len(relevant)} papers for synthesis.\n")
    report = synthesize_report(research_question, relevant)
    print(report)

Example output:

Selected 2 papers for synthesis.

## Executive Summary

Sparse attention reduces training and inference costs in sequence modeling, with recent work demonstrating 40% speedups in protein structure prediction and scalable attention patterns for long biomedical documents.

## Thematic Synthesis

### Efficiency Gains through Sparsity

Zhang et al. [zhang-2024] show that replacing full self-attention with sparse attention cuts training time by 40% on protein folding tasks without sacrificing CASP14 accuracy. Similarly, Chen et al. [chen-2024] apply local-plus-global attention to 128k-token documents, improving legal and biomedical classification by 12% over sliding-window approaches.

### Applicability to Biological Sequences

Both studies target sequential data with long-range dependencies. The protein folding work [zhang-2024] validates sparse patterns on 3D structure prediction, while the long-document classifier [chen-2024] focuses on text. Neither explicitly benchmarks the other domain, suggesting cross-application remains unexplored.

## Limitations Across Studies

Zhang et al. do not report inference latency on consumer hardware. Chen et al. limit evaluation to classification and do not address generative modeling. Both studies use proprietary datasets that complicate reproduction.

## Gaps and Future Work

- No direct comparison between sparse attention variants on amino-acid sequences versus natural language.
- Energy metrics are missing from both papers; integrating the scheduling approach from Patel and Liu [patel-2023] could strengthen sustainability claims.
- Open-source benchmarks spanning both domains would improve reproducibility.

Wrap up

The pipeline works end to end on Oxlo.ai. Because Oxlo.ai charges per request rather than per token, running a multi-step screening and extraction workflow over long abstracts stays predictable even when your corpus grows. As a next step, wire in pymupdf or marker to parse real PDFs instead of hand-typed abstracts. If you move to full-text papers, swap the synthesis model to qwen-3-32b or deepseek-r1-671b to handle deeper methodological reasoning without worrying about ballooning context costs. See https://oxlo.ai/pricing for plan details.

Top comments (0)