Publish artifacts for knowledge-graph-risk-engine-20260729
Browse filesFiles changed (5)
- README.mdAdded+61
- evaluation.jsonAdded+5
- inference.pyAdded+80
- model.jsonAdded+192
- project.jsonAdded+52
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061---license: mitlibrary_name: custompipeline_tag: feature-extractiondatasets:- RKB109/knowledge-graph-risk-engine-20260729-datasettags:- synthetic-data- transparent-baseline- knowledge-graphs- token-classification- feature-extraction- question-answering- sentence-similaritymetrics:- accuracy---
# Knowledge Graph Risk Engine Baseline Model
## Model Description
This repository contains a small, transparent prototype model for**Risk teams need relationship-level explanations instead of opaque entity scores.**
The model combines per-label token weights with IDF-weighted evidenceretrieval. It was generated for reproducible architecture demonstrations anddoes not call a hosted LLM.
## Evaluation
- Held-out synthetic examples: 4- Accuracy: 1- Intended metrics: relation_accuracy, path_coverage, entity_resolution_precision
## Intended Use
- Architecture prototyping- CI and evaluation examples- Local baseline comparisons- Educational experimentation
## Hugging Face Task Coverage
- `token-classification`- `feature-extraction`- `question-answering`- `sentence-similarity`
## Limitations and Risks
All entities are fictional. Real identity or financial data requires governance, consent, and bias review.
The dataset is synthetic and small. Do not use this model for consequentialdecisions without representative data, expert review, and production-gradeevaluation.
## Reproducibility
The linked GitHub repository includes `train.py`, the exact dataset split,evaluation code, and the model JSON format.12345{ "test_examples": 4, "accuracy": 1, "synthetic_evaluation": true}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980"""Transparent baseline pipeline for the generated AI project."""
from __future__ import annotations
import jsonimport mathimport refrom pathlib import Path
def tokenize(value: str) -> list[str]: return re.findall(r"[a-z0-9]+", value.lower())
class Pipeline: def __init__(self, model: dict): self.model = model
@classmethod def from_file(cls, path: str | Path) -> "Pipeline": return cls(json.loads(Path(path).read_text(encoding="utf-8")))
def classify(self, text: str) -> tuple[str, float]: tokens = tokenize(text) scores = { label: sum(weights.get(token, 0) for token in tokens) for label, weights in self.model["prototypes"].items() } ranked = sorted(scores.items(), key=lambda item: (-item[1], item[0])) label, best = ranked[0] total = sum(max(score, 0) for _, score in ranked) or 1 return label, best / total
def search(self, query: str, limit: int = 3) -> list[dict]: query_tokens = set(tokenize(query)) ranked = [] for document in self.model["documents"]: document_tokens = set(tokenize(document["text"])) lexical = sum( self.model["idf"].get(token, 1.0) for token in query_tokens & document_tokens ) ranked.append({**document, "score": round(lexical, 6)}) return sorted(ranked, key=lambda item: (-item["score"], item["id"]))[:limit]
def graph_evidence(self, text: str) -> list[dict]: tokens = set(tokenize(text)) matches = [] for subject, relation, target in self.model.get("graph_edges", []): edge_tokens = set(tokenize(f"{subject} {relation} {target}")) overlap = len(tokens & edge_tokens) if overlap: matches.append( { "subject": subject, "relation": relation, "target": target, "overlap": overlap, } ) return sorted(matches, key=lambda item: -item["overlap"])
def run(self, text: str) -> dict: label, confidence = self.classify(text) evidence = self.search(text) result = { "prediction": label, "confidence": round(confidence, 4), "requires_review": confidence < self.model["confidence_threshold"], "evidence": evidence, } if self.model["mode"] == "graph": result["graph_evidence"] = self.graph_evidence(text) if self.model["mode"] == "agent": result["proposed_tool"] = label result["approval_required"] = label in { "request-approval", "request-human-help", } return result123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192{ "format": "daily-project-prototype-v1", "project": "knowledge-graph-risk", "title": "Knowledge Graph Risk Engine", "domain": "knowledge-graphs", "mode": "graph", "labels": [ "ownership", "transaction", "location" ], "prototypes": { "ownership": { "who": 3, "controls": 6, "supplier": 6, "alpha": 9, "company": 7, "in": 2, "an": 3, "operations": 2, "review": 2, "for": 1, "evaluation": 1, "case": 1, "which": 2, "owns": 4, "vendor": 4, "gamma": 4, "delta": 2 }, "transaction": { "17": 8, "in": 2, "an": 4, "operations": 2, "review": 2, "which": 2, "account": 10, "paid": 4, "vendor": 4, "beta": 4, "for": 2, "evaluation": 2, "case": 2, "what": 3, "transfer": 3, "connects": 3, "and": 3, "supplier": 6, "alpha": 6, "transferred": 3, "to": 3 }, "location": { "where": 2, "is": 2, "warehouse": 4, "north": 4, "located": 6, "in": 5, "region": 6, "east": 2, "for": 2, "an": 3, "evaluation": 2, "case": 2, "operations": 1, "review": 1, "what": 2, "contains": 2, "facility": 4, "blue": 4, "west": 2 } }, "idf": { "17": 1.847298, "company": 1.847298, "alpha": 1.847298, "controls": 2.252763, "supplier": 1.847298, "account": 1.847298, "paid": 2.252763, "vendor": 1.847298, "beta": 2.252763, "warehouse": 2.252763, "north": 2.252763, "located": 1.847298, "in": 1.847298, "region": 1.847298, "east": 2.252763, "delta": 2.252763, "owns": 2.252763, "gamma": 2.252763, "transferred": 2.252763, "to": 2.252763, "facility": 2.252763, "blue": 2.252763, "west": 2.252763 }, "documents": [ { "id": "graph-01", "label": "ownership", "text": "company-alpha controls supplier-alpha", "metadata": { "synthetic": true, "domain": "knowledge-graphs" } }, { "id": "graph-02", "label": "transaction", "text": "account-17 paid vendor-beta", "metadata": { "synthetic": true, "domain": "knowledge-graphs" } }, { "id": "graph-03", "label": "location", "text": "warehouse-north located-in region-east", "metadata": { "synthetic": true, "domain": "knowledge-graphs" } }, { "id": "graph-04", "label": "ownership", "text": "company-delta owns vendor-gamma", "metadata": { "synthetic": true, "domain": "knowledge-graphs" } }, { "id": "graph-05", "label": "transaction", "text": "account-17 transferred-to supplier-alpha", "metadata": { "synthetic": true, "domain": "knowledge-graphs" } }, { "id": "graph-06", "label": "location", "text": "facility-blue located-in region-west", "metadata": { "synthetic": true, "domain": "knowledge-graphs" } } ], "graph_edges": [ [ "company-alpha", "controls", "supplier-alpha" ], [ "account-17", "paid", "vendor-beta" ], [ "warehouse-north", "located-in", "region-east" ], [ "company-delta", "owns", "vendor-gamma" ], [ "account-17", "transferred-to", "supplier-alpha" ], [ "facility-blue", "located-in", "region-west" ] ], "confidence_threshold": 0.18, "trained_on_synthetic_data": true}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152{ "name": "Knowledge Graph Risk Engine", "problem": "Risk teams need relationship-level explanations instead of opaque entity scores.", "domain": "knowledge-graphs", "architecture": "graph", "hugging_face_tasks": [ "token-classification", "feature-extraction", "question-answering", "sentence-similarity" ], "recommended_stack": [ "FastAPI for entity and evidence APIs", "Neo4j Community or PostgreSQL recursive queries", "Sentence Transformers for entity resolution", "NetworkX for local graph validation", "Kafka-compatible event ingestion", "OpenTelemetry for lineage and query traces" ], "real_world_data_sources": [ { "name": "SEC EDGAR submissions API", "url": "https://data.sec.gov/submissions/CIK0000320193.json", "purpose": "Public company and filing relationships" }, { "name": "GLEIF LEI API", "url": "https://api.gleif.org/api/v1/lei-records?page[size]=5", "purpose": "Public legal-entity identifiers and relationships" } ], "job_description_skills": [ "Entity resolution and relation extraction", "Knowledge-graph modeling and path queries", "Graph-based explainability and provenance", "Streaming ingestion and schema evolution", "Risk-model evaluation and data quality controls" ], "impact_targets": [ "Reach entity-resolution precision >= 0.95 on reviewed pairs", "Return evidence paths for 100% of emitted risk flags", "Process 10,000 relationship events per minute in load tests", "Detect schema and orphan-node regressions in CI" ], "baseline_evaluation": { "test_examples": 4, "accuracy": 1, "synthetic_evaluation": true }, "estimated_delivery": "8-12 weeks for one engineer", "generated_baseline_is_production_ready": false}README.mdAdded+61
evaluation.jsonAdded+5
inference.pyAdded+80
model.jsonAdded+192
project.jsonAdded+52