Introduction

When classifying relations between two entities in scientific text with an LLM, two practical questions come up right away: should you pass just the sentence containing the pair or the full abstract, and how much does the model rely on memorized domain priors rather than the text itself?

Using structured outputs via ellmer on a derived benchmark built from the LSD600 lifestyle-disease corpus, across gpt-6.2-sol, gpt-6-luna, and local gemma4:e2b, we find two clear patterns. Single-sentence context scores highest for every model tested, mainly because document-level findings leak into sentence-scoped negative pairs when the abstract is included. On single sentences, masking entity names as [FACTOR] and [OUTCOME] barely changes macro-F1 for the two API models (-0.007 on gpt-6.2-sol, -0.002 on gpt-6-luna), while occasionally keeping models from hallucinating relations into paper titles and aim statements.


Data

pacman::p_load(data.table, ggplot2, DT)

LSD600 annotates 600 PubMed abstracts across eight lifestyle-disease relation types. Here I turn it into a sentence-level candidate-pair task: enumerate same-sentence lifestyle-factor/disease pairs, retain the document-level split, normalize the source labels, and add no_relation for unannotated pairs. The resulting test set contains 422 pairs across 78 abstracts and 233 sentences.

This is a relation-classification benchmark conditional on upstream NER and entity typing, not an end-to-end extraction task. The two null labels are distinct: no_relation means the pair is unrelated in the sentence, while no_statistical_association is an explicit null finding. Because every candidate pair is drawn from one sentence, the context experiment measures distraction from extra text rather than cross-sentence recall.

The derived format may also be useful for fine-tuning, few-shot prompting, error analysis, and model comparison. Whether it transfers beyond lifestyle-disease research remains empirical.

Every model gets the same system prompt and a strict 9-class type_enum() schema via ellmer. The two null labels mean different things: no_relation says the pair is not related in the sentence, while no_statistical_association says the sentence explicitly reports no statistical association. For the masking test, we compare masked sentences ([FACTOR] / [OUTCOME]) against inline-tagged unmasked sentences ([FACTOR: alcohol] / [OUTCOME: pancreatic cancer]) so the target pair stays unambiguous while exposing entity identity. The inference step is shown below; the analysis reads cached predictions from results/.

library(ellmer)

type_relation <- type_object(
  relation_type = type_enum(
    c("stat_assoc", "pos_assoc", "causes", "neg_assoc",
      "controls", "prevents", "treats", "no_assoc", "no_relation"),
    "Exactly one short alias for the relation between [FACTOR] and [OUTCOME]."
  )
)

# Inline-tagged unmasked text built from masked_context_text
sent_test[, tagged_text := mapply(
  function(txt, lsf, dis) {
    out <- sub("[FACTOR]", paste0("[FACTOR: ", lsf, "]"), txt, fixed = TRUE)
    sub("[OUTCOME]", paste0("[OUTCOME: ", dis, "]"), out, fixed = TRUE)
  },
  masked_context_text, LSF_entity, disease_entity,
  USE.NAMES = FALSE
)]

ch <- chat_openai(system_prompt = SYSTEM_PROMPT, model = "gpt-6.2-sol", echo = "none")
res <- parallel_chat_structured(
  chat = ch, prompts = as.list(sent_test$tagged_text),
  type = type_relation, convert = TRUE, max_active = 10L, rpm = 500L
)

Context Window and Masking

We first vary how much surrounding text accompanies each masked pair – the target sentence alone (~31 words), ±1 sentence (~72 words), ±2 sentences (~110 words), and the full abstract (~298 words) – with 95% confidence intervals from 1,000 paired bootstrap resamples.

The line plot below tracks macro-F1 across the four context windows for each model with 95% bootstrap confidence bands; sage green marks gpt-6.2-sol, burnt orange marks gpt-6-luna, and muted purple marks local gemma4:e2b, showing that single-sentence context scores highest for every model tested.

model_colors <- c(
  "gpt-6.2-sol" = "#708A81",
  "gpt-6-luna"  = "#DD8E58",
  "gemma4:e2b"  = "#9467bd"
)

ctx_plot_dt <- copy(ctx_summ)
ctx_plot_dt[, context_label := factor(
  context_type,
  levels = c("sentence", "plus1", "plus2", "abstract"),
  labels = c("Sentence\n(~31w)", "±1 Sentence\n(~72w)",
             "±2 Sentences\n(~110w)", "Full Abstract\n(~298w)")
)]
ctx_plot_dt[, model := factor(model, levels = names(model_colors))]

ggplot(ctx_plot_dt, aes(x = context_label, y = macro_f1, color = model, fill = model, group = model)) +
  geom_ribbon(aes(ymin = f1_lo, ymax = f1_hi), alpha = 0.14, color = NA) +
  geom_line(linewidth = 0.9) +
  geom_point(size = 2.6) +
  scale_color_manual(values = model_colors, name = NULL) +
  scale_fill_manual(values = model_colors, name = NULL) +
  scale_y_continuous(limits = c(0, 0.85), breaks = seq(0, 0.8, 0.2)) +
  labs(
    title = "Macro-F1 Across Context Windows (Masked Entities)",
    x = NULL,
    y = "Macro-F1 (95% bootstrap CI)"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16),
    legend.position = "bottom"
  )

Robustness to extra text separates the two API models. gpt-6.2-sol dips modestly from 0.712 to 0.670 (within overlapping CIs, though full abstracts still hurt 42 pairs versus helping 15). gpt-6-luna starts nearly tied on sentences (0.701) and drops 0.204 points to 0.497 on full abstracts. Almost all of the damage hits null labels: abstracts usually report some association in their results, and models project it back onto methods and background sentences. On gpt-6-luna, no_statistical_association drops from 1.00 to 0.31 and no_relation halves from 0.60 to 0.30. The sole exception is treats, which improves with broader context for both GPT-6 models (0.71 -> 0.79 on Sol), likely because therapeutic design cues sit outside the target sentence. Local gemma4:e2b lags well behind throughout and drops 39 of 422 sentence calls to invalid enum outputs.

Locking the benchmark to sentence-only inputs lets us run a compact sentence-level leaderboard comparing masked versus inline-tagged unmasked entities. The masking comparison is complete for the two API models; gemma4:e2b unmasked is still pending a local GPU run.

lb_disp <- copy(lb_wide)[, .(
  Model = model,
  `Masked F1` = sprintf("%.3f", macro_f1_masked),
  `Unmasked F1` = ifelse(is.na(macro_f1_unmasked), "Pending", sprintf("%.3f", macro_f1_unmasked)),
  `Delta` = ifelse(is.na(delta_f1), "--", sprintf("%+.3f", delta_f1)),
  `Accuracy (M / U)` = paste0(
    sprintf("%.3f", accuracy_masked), " / ",
    ifelse(is.na(accuracy_unmasked), "--", sprintf("%.3f", accuracy_unmasked))
  ),
  `no_relation F1 (M / U)` = paste0(
    sprintf("%.3f", no_rel_f1_masked), " / ",
    ifelse(is.na(no_rel_f1_unmasked), "--", sprintf("%.3f", no_rel_f1_unmasked))
  )
)]

DT::datatable(
  lb_disp,
  caption = "LSD600 sentence-only leaderboard: masked versus unmasked entities",
  rownames = FALSE,
  options = list(dom = "t", scrollX = TRUE)
)

Surprisingly, hiding the biomedical terms costs essentially nothing on macro-F1 for the API models. gpt-6.2-sol flips only 22 of 422 predictions (9 helped, 13 hurt), and no_relation F1 actually edges down slightly when unmasked (0.724 to 0.697). gpt-6-luna shifts more under the hood (56 flips: 34 helped, 22 hurt), gaining on directional associations (positive_statistical_association +0.10, pushing accuracy up 2.8 points) while losing on prevents (-0.09) and controls (-0.11, n = 5). These aggregate changes are small, but the individual flips show where entity names can matter.

Where unmasking hurts is telling: familiar entity names can nudge models to supply real-world knowledge that the sentence itself never states:

  • “Psychotherapy for bulimia nervosa and binging.” (title, gold: no_relation) – gpt-6-luna answers no_relation masked, then jumps to treats unmasked.
  • “Professional cleaning and asthma.” (title, gold: no_relation) – gpt-6.2-sol answers no_relation masked, then flips to statistical_association unmasked.
  • “Athletes who develop exercise-induced anaphylaxis may prevent outbreaks by avoiding food before exercise…” (gold: causes) – both GPT-6 models resolve the double negation correctly when masked, and both flip to prevents once food and anaphylaxis appear.

The examples also explain why the masking result is more interesting than its tiny macro-F1 delta suggests: entity identity rarely changes the aggregate score, but it can change the model’s reasoning on exactly the kinds of titles, aims, and compressed statements where sentence-level evidence is weakest.


Error Structure

To see what remains difficult under the best setting, we inspect the confusion matrix for gpt-6.2-sol on masked single sentences (accuracy 0.754, macro-F1 0.712). Invalid structured outputs are counted as errors in the headline metrics; the heatmap shows only valid labeled predictions, so it should be read as the structure of the classified errors rather than a complete accounting of every failed call.

The heatmap below displays row-normalized recall proportions (fill intensity) and raw pair counts for gpt-6.2-sol on masked sentences, with test-set class sizes in parentheses on the y-axis; darker sage-green tiles indicate larger shares of each gold class landing on that predicted label, showing that remaining errors cluster along two specific boundaries rather than spreading randomly.

rel_levels <- c(
  "no_relation",
  "no_statistical_association",
  "statistical_association",
  "positive_statistical_association",
  "negative_statistical_association",
  "causes",
  "prevents",
  "treats",
  "controls"
)

short_names <- c(
  "no_relation" = "no_relation",
  "no_statistical_association" = "no_stat_assoc",
  "statistical_association" = "stat_assoc",
  "positive_statistical_association" = "pos_assoc",
  "negative_statistical_association" = "neg_assoc",
  "causes" = "causes",
  "prevents" = "prevents",
  "treats" = "treats",
  "controls" = "controls"
)

gold_counts <- sent_test[, .N, by = relation_type]
y_labels <- setNames(
  paste0(short_names[rel_levels], " (n=", gold_counts[match(rel_levels, relation_type), N], ")"),
  rel_levels
)

cm_dt <- merge(
  sol_sent_pred[, .(pair_key, pred = predicted)],
  sent_test[, .(pair_key, gold = relation_type)],
  by = "pair_key"
)[!is.na(pred) & nzchar(pred), .N, by = .(gold, pred)]

cm_dt[, `:=`(
  gold = factor(gold, levels = rel_levels),
  pred = factor(pred, levels = rel_levels)
)]
cm_dt[, share := N / sum(N), by = gold]

ggplot(cm_dt, aes(x = pred, y = gold, fill = share)) +
  geom_tile(color = "white", linewidth = 0.4) +
  geom_text(aes(label = N), size = 3.2, color = "#2B2129") +
  scale_fill_gradient(low = "#F7F5F2", high = "#708A81", guide = "none") +
  scale_x_discrete(labels = short_names) +
  scale_y_discrete(limits = rev(rel_levels), labels = y_labels) +
  labs(
    title = "Confusion Matrix: gpt-6.2-sol (Masked Sentences)",
    x = "Predicted relation",
    y = "Gold relation"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 16),
    axis.text.x = element_text(angle = 35, hjust = 1)
  )

Two error pockets account for most misses. First, no_relation leaks into statistical_association and positive_statistical_association where background mentions of risk factors blur into variable lists. Second, treats, controls (only 5 test cases, so noisy), and prevents trade predictions along intervention boundaries. By contrast, no_statistical_association hits 22/22 recall (0.98 F1) because explicit null findings carry clear lexical cues.


Summary

For applied biomedical relation extraction with LLMs, the takeaway is straightforward: once candidate entity pairs are identified and the relation evidence is sentence-local, start with the sentence rather than the abstract, especially with cheaper models where extra text triggers heavy false-positive inflation on negative classes. That conclusion applies to this LSD600-derived candidate-pair benchmark, not automatically to the original corpus or to relation-extraction settings where evidence spans sentences.

Equally useful, masking entity names does not degrade macro-F1 for the two API models tested and acts as a cheap guard against prior-driven hallucinations on titles and study aims. Standardizing on 422 masked and 422 unmasked single sentences keeps this benchmark lightweight enough to update as new local and API models arrive. More broadly, the derived candidate-pair data may serve as training or evaluation material for the relation layer of a biomedical extraction pipeline, provided upstream NER and entity typing are treated as part of the system rather than silently assumed correct.