Transformers

All extractors inherit from ExtractorInterface[T, R]. Each implements a forward(input) method (synchronous) and gets an aforward(input) method (async) for free.

Base interface

ExtractorInterface

class ExtractorInterface(Module, Generic[T, R])

Bases: Module, Generic[T, R]

Generic interface for an extractor that takes an input of type T and returns an output of type R.

Material extraction

DspyTextExtractor

class DspyTextExtractor(signature, lm, retry_temperatures=None)

Bases: MaterialExtractorInterface

A text extractor that uses dspy to extract any arbitrary text from the publication text.

Implements temperature escalation retry on failures to improve robustness against transient validation errors.

Initialize the extractor with a dspy signature and language model.

Parameters:

NameTypeDescriptionDefault
signatureSignatureThe dspy signature specifying input/output fields.required
lmLMThe language model to use for prediction.required
retry_temperatureslist[float] | NoneTemperatures to try on failures. Defaults to [0.0, 0.3, 0.5].None

Methods

forward(input)
def forward(input)

Extract text from the given str using the language model and signature.

Retries at escalating temperatures on failure.

Parameters:

NameTypeDescriptionDefault
inputstrThe str from which to extract text.required

Returns:

NameTypeDescription
strstrThe extracted text from the str.

make_dspy_text_extractor_signature

def make_dspy_text_extractor_signature(signature_name='DspyTextExtractorSignature', instructions='Extract the synthesis paragraph from the publication text.', input_description='The publication text to extract the synthesis paragraph from.', output_name='synthesis_paragraph', output_description='The extracted synthesis paragraph.')

Create a dspy signature for extracting text from publication text.

Parameters:

NameTypeDescriptionDefault
signature_namestrName of the signature.'DspyTextExtractorSignature'
instructionsstrInstructions for the signature.'Extract the synthesis paragraph from the publication text.'
input_descriptionstrDescription for the publication text input.'The publication text to extract the synthesis paragraph from.'
output_namestrName of the output field.'synthesis_paragraph'
output_descriptionstrDescription for the output field.'The extracted synthesis paragraph.'

Returns:

TypeDescription
type[Signature]dspy.Signature: The constructed dspy signature for text extraction.

Synthesis extraction

DspySynthesisExtractor

class DspySynthesisExtractor(signature, lm, retry_temperatures=None)

Bases: SynthesisExtractorInterface

Extractor that uses dspy to extract a structured synthesis ontology for a specific material from the entire paper text.

Implements temperature escalation retry and bare-JSON recovery on failures to improve robustness without changing the happy-path behavior.

Initialize the extractor with a dspy signature and language model.

Parameters:

NameTypeDescriptionDefault
signatureSignatureThe dspy signature specifying input/output fields.required
lmLMThe language model to use for prediction.required
retry_temperatureslist[float] | NoneTemperatures to try on failures. Defaults to [0.0, 0.3, 0.5].None

Methods

forward(input)
def forward(input)

Extract a structured synthesis ontology for a specific material from the given paper text.

Retries at escalating temperatures on failure. Attempts bare-JSON recovery before escalating. Falls back to a minimal ontology if all attempts are exhausted.

Parameters:

NameTypeDescriptionDefault
inputtuple[str, str]Tuple of (paper_text, material_name).required

Returns:

NameTypeDescription
GeneralSynthesisOntologyGeneralSynthesisOntologyThe structured synthesis ontology for the specific material.

make_dspy_synthesis_extractor_signature

def make_dspy_synthesis_extractor_signature(signature_name='DspySynthesisExtractorSignature', instructions='Extract structured synthesis for a specific material from the paper. Output only a valid JSON with the structured_synthesis field.', paper_text_description='Complete paper text to search for the material synthesis procedure.', material_name_description='The name of the specific material to extract synthesis for.', output_name='structured_synthesis', output_description='The extracted structured synthesis for specific material as a JSON.')

Create signature for extracting a materials-specific synthesis ontology.

Parameters:

NameTypeDescriptionDefault
signature_namestrName of the signature.'DspySynthesisExtractorSignature'
instructionsstrInstructions for the signature.'Extract structured synthesis for a specific material from the paper. Output only a valid JSON with the structured_synthesis field.'
paper_text_descriptionstrDescription for the paper text input.'Complete paper text to search for the material synthesis procedure.'
material_name_descriptionstrDescription for material name input.'The name of the specific material to extract synthesis for.'
output_namestrName of the output field.'structured_synthesis'
output_descriptionstrDescription for the output field.'The extracted structured synthesis for specific material as a JSON.'

Returns:

TypeDescription
type[Signature]dspy.Signature: The dspy signature for synthesis extraction.

PDF extraction

DoclingPDFExtractor

class DoclingPDFExtractor(pipeline='standard', table_mode='accurate', add_page_images=False, use_gpu=True, scale=2.0, format='markdown')

Bases: PdfExtractorInterface

An extractor for extracting content from PDF files using the Docling library.

This class provides functionality to convert PDF files into various formats such as Markdown, doctags, JSON, or tokens. It supports different modes for handling images within the PDF, including embedding, referencing, or using placeholders. The extractor can be configured with various options such as pipeline type, table extraction mode, GPU usage, and scaling.

Attributes:

NameTypeDescription
pipelinestrThe pipeline to use for PDF processing (default: “standard”).
table_modestrThe mode for table extraction (default: “accurate”).
add_page_imagesboolWhether to include page images in the output (default: False).
use_gpuboolWhether to use GPU for processing (default: True).
scalefloatThe scaling factor for images (default: 2.0).
formatstrThe output format. Options are “markdown”, “doctags”, “json”, or “tokens” (default: “markdown”).

Methods:

extract_to_markdown(pdf_data: bytes) -> str:
    Converts a PDF file to Markdown format. Supports different image
    modes and raises a ValueError if an invalid image mode is provided.

Methods

forward(input)
def forward(input)

Extracts text and figures from a PDF and returns them as markdown with embedded figures.

Parameters:

NameTypeDescriptionDefault
pdf_dataThe PDF data as bytes.required

Returns:

TypeDescription
strThe extracted text as markdown with embedded figures.

MistralPDFExtractor

class MistralPDFExtractor(structured=False, mistral_api_key=None, max_retries=3, retry_base_delay=2.0)

Bases: PdfExtractorInterface

A PDF extractor that uses the Mistral OCR API to extract content from PDF files and optionally convert it to Markdown format. This extractor supports embedding images as data URIs and can return structured JSON output if required.

Attributes:

NameTypeDescription
structuredboolDetermines whether the output should be structured JSON.
embed_imagesboolIndicates whether images should be embedded as data URIs in the Markdown output.
mistral_api_keystrThe API key for authenticating with the Mistral OCR API. If not provided, it will be fetched from the environment variable MISTRAL_API_KEY.
mistral_api_clientMistralThe client instance for interacting with the Mistral OCR API.

Methods:

NameDescription
extract_to_markdown(pdf_data: bytes) -> strExtracts content from a PDF file and converts it to Markdown format. Optionally embeds images as data URIs and supports structured JSON output.

Methods

forward(input)
def forward(input)

Extracts text and figures from a PDF and returns them as markdown with embedded figures.

Parameters:

NameTypeDescriptionDefault
pdf_dataThe PDF data as bytes.required

Returns:

TypeDescription
strThe extracted text as markdown with embedded figures.

Plot data extraction

ClaudeLinePlotDataExtractor

class ClaudeLinePlotDataExtractor(model_name, prompt=resources.LINE_CHART_PROMPT_WITH_CONTEXT, max_tokens=1024, temperature=0.0, use_figure_context=True)

Bases: LinePlotDataExtractorInterface

Methods

get_cost()
def get_cost()

Get cumulative cost from Claude client.

reset_cost()
def reset_cost()

Reset costs in Claude client.

LiteLLMPlotDataExtractor

class LiteLLMPlotDataExtractor(model, prompt=resources.LINE_CHART_PROMPT_WITH_CONTEXT, max_tokens=8192, temperature=0.0, api_key=None, api_base=None, extra_kwargs=None, retry_temperatures=None)

Bases: LinePlotDataExtractorInterface

Plot data extractor using litellm — works with any vision model.

Uses the same prompt and parsing logic as ClaudeLinePlotDataExtractor, but routes API calls through litellm for multi-provider support.

Performance linking

SeriesMaterialLinker

class SeriesMaterialLinker(lm, prompt_template=DEFAULT_MATCHING_PROMPT)

Bases: PerformanceLinkingInterface

LLM-based transformer for matching plot series names to material names.

This transformer uses an LLM to semantically match series names from plots (e.g., “575”, “Ni/Al2O3”, “Sample A”) to the actual material names extracted from the paper (e.g., “Mo2(C,N)Tx-575”, “10%Ni/Al2O3”).

Attributes:

NameTypeDescription
lmDSPy language model for making predictions
prompt_templateTemplate for the matching prompt

Initialize the linker.

Parameters:

NameTypeDescriptionDefault
lmLMDSPy language model instancerequired
prompt_templatestrPrompt template with placeholders for materials, series_names, context, plot_title, x_axis_label, x_axis_unit, y_axis_label, y_axis_unitDEFAULT_MATCHING_PROMPT

Methods

forward(input)
def forward(input)

Match plot series names to material names using LLM.

Parameters:

NameTypeDescriptionDefault
inputLinkingInputLinkingInput containing materials, series names, context, and plot metadatarequired

Returns:

TypeDescription
list[SeriesMapping]List of validated SeriesMapping objects