Project: Build an Auditable Entity and Relation Extractor

MetaCyberGuru Academy

IntermediateEstimated learning effort: 100 minutesFree, no sign-up requiredPublished by Muhammad AzharCourse version: August 2026

Back to Linguistic Analysis and Information Extraction

The checkpoint combines entities, rules and sentence context into structured records that a reviewer can verify without reading model internals.

You will extract product-version mentions and named organisations, attach offsets and provenance, then reconcile every output with its source document.

The system abstains when required arguments are missing. It separates observed text from any normalised value and never presents a mention as an external fact.

Ship Evidence with Every Extracted Entity and Relation

  • Design a JSON schema for evidence, labels, normalised values and rule or model versions.
  • Create a small reviewed evaluation set with both positive and negative documents.
  • Reconcile counts and analyse failures by extraction route.
  • Reconcile extracted counts against reviewed documents and retain the evidence span for every accepted value.

Evidence-first records

Each record needs source ID, exact quote, offsets, extraction type and producer version. Optional normalisation belongs beside, not instead of, the quote.

Schema validation catches missing provenance before records reach analytics or search.

A confidence label needs meaning

Do not invent a decimal score for deterministic rules. Use categories such as rule_exact, model_reviewed or needs_review with documented behavior.

Evaluation mirrors the review task

Report exact entity spans, relation argument accuracy and false positives by rule ID. A single combined accuracy hides where the pipeline fails.

Sample no-result documents too. Silence can mean no relevant information or a broken extractor.

Package the handoff

Include install commands, model name, test data licence, expected output and a limitations note.

A portfolio reader should be able to reproduce one run and inspect one error.

Build the Project Build an Auditable Entity and Relation Extractor example

The final assertion verifies that offsets reconstruct the quote exactly. Keep this invariant after any text-storage or serialisation change.

The producer field distinguishes model output from deterministic rule output. Add dependency versions to the run manifest.

Install:

python -m pip install spacy jsonschema
python -m spacy download en_core_web_sm
import json, spacy
from spacy.matcher import Matcher
nlp = spacy.load('en_core_web_sm')
matcher = Matcher(nlp.vocab)
matcher.add('VERSION_MENTION', [[{'LOWER':'version'},{'TEXT':{'REGEX':r'^\d+(?:\.\d+){0,2}$'}}]])

def extract(doc_id, text):
    doc = nlp(text)
    records=[]
    for ent in doc.ents:
        if ent.label_ == 'ORG':
            records.append({'source_id':doc_id,'type':'organisation_mention','quote':ent.text,'start':ent.start_char,'end':ent.end_char,'producer':'en_core_web_sm'})
    for _,start,end in matcher(doc):
        span=doc[start:end]
        records.append({'source_id':doc_id,'type':'version_mention','quote':span.text,'start':span.start_char,'end':span.end_char,'producer':'rule_version_1'})
    return records

result=extract('doc-7','Acme announced version 2.4 today.')
print(json.dumps(result,indent=2))
assert all(r['quote']=='Acme announced version 2.4 today.'[r['start']:r['end']] for r in result)

Expected Extraction Audit Output

Two evidence records: an organisation mention for Acme and a version mention for version 2.4. Each contains source ID, exact quote, offsets and producer.

One sentence cannot validate the system. Build a held-out reviewed set and save errors as fixtures.

If personal or confidential documents are involved, replace the sample with synthetic text and design access controls before storing excerpts.

Diagnose failures in Project Build an Auditable Entity and Relation Extractor

Trace one output from JSON back to the exact source slice, then compare with the reviewed label.

Checks for the Project: Build an Auditable Entity and Relation Extractor example
SymptomLikely causeUseful check
Quotes fail the offset assertionInference ran on transformed text while offsets refer to raw textRun extraction on source text or maintain an explicit offset map
Duplicate overlapping records appearRule and model identify the same mentionDefine deterministic overlap resolution and retain provenance
The job succeeds with zero outputsInput loading or model setup may have failed silentlyTrack documents processed, sentences parsed and outputs per route

Complete the extraction checkpoint

Build a command-line extractor, a JSON Schema, a reviewed fixture set and an evaluation report.

  1. Process at least thirty mixed documents
  2. Validate every output record against the schema
  3. Check quote and offset invariants
  4. Report errors by type and producer
  5. Document privacy, language and domain limits

Definition of done: Another learner can run the command, reproduce the sample output and inspect at least five documented failure cases.

Stretch task: Add a review file that accepts corrections without overwriting original predictions.

Check your Project Build an Auditable Entity and Relation Extractor reasoning

Inspect the project decisions before revealing the explanations. Focus on provenance, relation evidence and reviewer correction paths.

1. Why separate quote and normalised value?
Check the answer

Answer: To preserve exact evidence while supporting a clearly marked derived value.

2. What should a zero-output run trigger?
Check the answer

Answer: Health checks, because silence can indicate no matches or a broken route.

3. What does producer identify?
Check the answer

Answer: The extraction route and version responsible for the record.

Primary references for Project Build an Auditable Entity and Relation Extractor

Re-run the extraction checkpoint after model, matcher or relation rules change. Archive source spans, component versions and the reviewed evaluation set.

Save your place

Completion is stored only in this browser on this device.

Share this page

Share this page with the people who will use it next.

X Facebook LinkedIn WhatsApp Email

Discussion

No comments yet. Add the first useful question or observation.