Extracting Structured Knowledge from Language Models
Listen to the summary
Uses a voice available on your device
Audio options
On this page 5 sections
Related concepts 2 concepts
Key Takeaways
- The system achieves a macro-F1 score of 0.62 on the official test set when powered by the Mistral-Small-24B-Instruct-2501 model.
- The method demonstrates high precision in specific relational extraction tasks, achieving macro-F1 scores of 0.95 for countryLandBordersCountry and 0.73 for companyTradesAtStockExchange.
- The architecture handles complex knowledge extraction tasks without requiring model fine-tuning.
- Performance can vary slightly between runs due to stochastic sampling for specific relations and non-deterministic computation on TPU v5e-8 hardware.
Summary & Methodology Analysis
The REAP system utilizes a two-stage architecture designed to transform unstructured text generated by Large Language Models (LLMs) into structured database records. The first stage, Relation-Aware Elicitation, uses Chain-of-Thought (CoT) prompting, a technique that encourages the model to generate intermediate reasoning steps before providing a final answer, to extract evidence specific to the target relation. This stage employs task-specific strategies such as geographical scanning and a reasoning-based gate to handle empty sets when the model lacks data for a particular entity. The system was validated against three instruction-tuned models, specifically Mistral-Small-24B-Instruct-2501, Gemma-2-9B-it, and Llama-3.1-8B-Instruct. By utilizing these models in a closed-book setting, the authors avoid the need for external training data updates. The second stage, Hybrid Parsing, processes these outputs by primarily attempting deterministic JSON extraction, falling back to LLM-based parsing when output structures are ambiguous or irregular. Post-processing steps like noise filtering and deduplication ensure the final output remains clean and queryable. While effective, the system faces limitations regarding its parametric knowledge, which is the internal knowledge base stored within the model weights during pre-training, particularly for rare or long-tail entities. Furthermore, results exhibit minor run-to-run variance, attributed to the combination of stochastic sampling, where the model randomly samples from its probability distribution, and non-deterministic distributed computation performed on TPU v5e-8 infrastructure. This means that repeated inferences on the same input may yield slightly different results for certain relations.
Interactive System Flowchart
Illustrative Implementation
A short sketch of the paper's core idea, not the authors' own code.
# Illustrative sketch (not from the paper)
import json, re
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load a small instruction-tuned model (e.g., Mistral-Small-24B-Instruct-2501)
model_name = "Mistral-Small-24B-Instruct-2501"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained(model_name)
model.eval()
def elicit_relation(entity, relation):
"""Stage 1: Relation‑aware elicitation via CoT prompting."""
# Simple relation‑specific prompt (illustrative only)
prompt = f"Answer the following with a step‑by‑step chain‑of‑thought.\nEntity: {entity}\nRelation: {relation}\nProvide the answer as a JSON array."
inputs = tokenizer(prompt, return_tensors="pt")
with torch.no_grad():
output = model.generate(**inputs, max_new_tokens=200)
return tokenizer.decode(output[0], skip_special_tokens=True)
def hybrid_parse(raw_text):
"""Stage 2: Deterministic JSON parsing with LLM fallback."""
try:
# Direct deterministic parsing
return json.loads(raw_text)
except json.JSONDecodeError:
# Fallback: ask LLM to re‑format (mocked here as empty list)
return []
def post_process(records):
"""Automated cleaning: title/noise filter, parentheses removal, case‑insensitive deduplication."""
cleaned = []
seen = set()
for rec in records:
# Remove surrounding whitespace and parentheses content
rec = rec.strip()
rec = re.sub(r"\s*\(.*?\)\s*", "", rec)
# Simple title/noise filter (skip empty strings)
if not rec:
continue
key = rec.lower()
if key not in seen:
seen.add(key)
cleaned.append(rec)
return cleaned
# Example usage
entity = "Apple Inc."
relation = "companyTradesAtStockExchange"
raw = elicit_relation(entity, relation)
records = hybrid_parse(raw)
final = post_process(records)
print(final)
// Illustrative sketch (not from the paper)
const fs = require('fs');
const { pipeline } = require('stream');
const { TextDecoder } = require('util');
// Placeholder for an LLM inference call (e.g., via HuggingFace Inference API)
async function elicitRelation(entity, relation) {
const prompt = `Answer with a step-by-step chain-of-thought.\nEntity: ${entity}\nRelation: ${relation}\nProvide the answer as a JSON array.`;
// In practice, send `prompt` to the model and get `rawOutput`
const rawOutput = await mockLLMGenerate(prompt);
return rawOutput;
}
async function mockLLMGenerate(prompt) {
// Mocked response – replace with real API call
return '["NASDAQ", "NYSE"]';
}
function hybridParse(rawText) {
try {
// Direct deterministic parsing
return JSON.parse(rawText);
} catch (e) {
// Fallback extraction (return empty array as placeholder)
return [];
}
}
function postProcess(records) {
const cleaned = [];
const seen = new Set();
for (let rec of records) {
rec = rec.trim();
// Remove parenthetical content
rec = rec.replace(/\s*\(.*?\)\s*/g, '');
if (!rec) continue; // title/noise filter
const key = rec.toLowerCase();
if (!seen.has(key)) {
seen.add(key);
cleaned.push(rec);
}
}
return cleaned;
}
(async () => {
const entity = 'Apple Inc.';
const relation = 'companyTradesAtStockExchange';
const raw = await elicitRelation(entity, relation);
const records = hybridParse(raw);
const final = postProcess(records);
console.log(final);
})();
Cross-Examination & FAQs
A deeper dive clarifying mechanics, constraints, and baseline evaluations.
Q1. What is the primary goal of the REAP system?
The goal is to build knowledge bases from large language models without fine-tuning or access to external knowledge sources.
Q2. Which models did the researchers test?
The researchers evaluated Gemma-2-9B-it, Llama-3.1-8B-Instruct, and Mistral-Small-24B-Instruct-2501.
Q3. Does this system require fine-tuning?
No, the system is designed to work in a closed-book setting without fine-tuning.
Q4. What is the reported performance on the official test set?
The system achieves a macro-F1 score of 0.62 on the official test set using the Mistral-Small-24B-Instruct-2501 model.
Q5. How does the system handle complex data extraction?
It uses a hybrid parsing approach that attempts deterministic JSON extraction first, with a fallback to LLM-based extraction for more complex outputs.
Q6. What are the limitations regarding data coverage?
The system's parametric knowledge is incomplete when dealing with very rare or long-tail entities.
Q7. Why is there variation in results across different runs?
Variation is caused by stochastic sampling for relations like awardWonBy and the non-deterministic nature of distributed computation on TPU v5e-8 hardware.
Q8. What is the best performance reported for a specific relation?
The system achieves a macro-F1 score of 0.95 for the countryLandBordersCountry relation.
Q9. Does the paper specify the exact number of entities in the test set?
The paper does not specify the exact number of entities in the test set.