Publish artifacts for knowledge-graph-risk-engine-20260808
Browse files- README.md +61 -0
- evaluation.json +5 -0
- inference.py +80 -0
- model.json +192 -0
- project.json +52 -0
README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: custom
|
| 4 |
+
pipeline_tag: feature-extraction
|
| 5 |
+
datasets:
|
| 6 |
+
- RKB109/knowledge-graph-risk-engine-20260808-dataset
|
| 7 |
+
tags:
|
| 8 |
+
- synthetic-data
|
| 9 |
+
- transparent-baseline
|
| 10 |
+
- knowledge-graphs
|
| 11 |
+
- token-classification
|
| 12 |
+
- feature-extraction
|
| 13 |
+
- question-answering
|
| 14 |
+
- sentence-similarity
|
| 15 |
+
metrics:
|
| 16 |
+
- accuracy
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# Knowledge Graph Risk Engine Baseline Model
|
| 20 |
+
|
| 21 |
+
## Model Description
|
| 22 |
+
|
| 23 |
+
This repository contains a small, transparent prototype model for
|
| 24 |
+
**Risk teams need relationship-level explanations instead of opaque entity scores.**
|
| 25 |
+
|
| 26 |
+
The model combines per-label token weights with IDF-weighted evidence
|
| 27 |
+
retrieval. It was generated for reproducible architecture demonstrations and
|
| 28 |
+
does not call a hosted LLM.
|
| 29 |
+
|
| 30 |
+
## Evaluation
|
| 31 |
+
|
| 32 |
+
- Held-out synthetic examples: 4
|
| 33 |
+
- Accuracy: 1
|
| 34 |
+
- Intended metrics: relation_accuracy, path_coverage, entity_resolution_precision
|
| 35 |
+
|
| 36 |
+
## Intended Use
|
| 37 |
+
|
| 38 |
+
- Architecture prototyping
|
| 39 |
+
- CI and evaluation examples
|
| 40 |
+
- Local baseline comparisons
|
| 41 |
+
- Educational experimentation
|
| 42 |
+
|
| 43 |
+
## Hugging Face Task Coverage
|
| 44 |
+
|
| 45 |
+
- `token-classification`
|
| 46 |
+
- `feature-extraction`
|
| 47 |
+
- `question-answering`
|
| 48 |
+
- `sentence-similarity`
|
| 49 |
+
|
| 50 |
+
## Limitations and Risks
|
| 51 |
+
|
| 52 |
+
All entities are fictional. Real identity or financial data requires governance, consent, and bias review.
|
| 53 |
+
|
| 54 |
+
The dataset is synthetic and small. Do not use this model for consequential
|
| 55 |
+
decisions without representative data, expert review, and production-grade
|
| 56 |
+
evaluation.
|
| 57 |
+
|
| 58 |
+
## Reproducibility
|
| 59 |
+
|
| 60 |
+
The linked GitHub repository includes `train.py`, the exact dataset split,
|
| 61 |
+
evaluation code, and the model JSON format.
|
evaluation.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"test_examples": 4,
|
| 3 |
+
"accuracy": 1,
|
| 4 |
+
"synthetic_evaluation": true
|
| 5 |
+
}
|
inference.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Transparent baseline pipeline for the generated AI project."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import json
|
| 6 |
+
import math
|
| 7 |
+
import re
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def tokenize(value: str) -> list[str]:
|
| 12 |
+
return re.findall(r"[a-z0-9]+", value.lower())
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class Pipeline:
|
| 16 |
+
def __init__(self, model: dict):
|
| 17 |
+
self.model = model
|
| 18 |
+
|
| 19 |
+
@classmethod
|
| 20 |
+
def from_file(cls, path: str | Path) -> "Pipeline":
|
| 21 |
+
return cls(json.loads(Path(path).read_text(encoding="utf-8")))
|
| 22 |
+
|
| 23 |
+
def classify(self, text: str) -> tuple[str, float]:
|
| 24 |
+
tokens = tokenize(text)
|
| 25 |
+
scores = {
|
| 26 |
+
label: sum(weights.get(token, 0) for token in tokens)
|
| 27 |
+
for label, weights in self.model["prototypes"].items()
|
| 28 |
+
}
|
| 29 |
+
ranked = sorted(scores.items(), key=lambda item: (-item[1], item[0]))
|
| 30 |
+
label, best = ranked[0]
|
| 31 |
+
total = sum(max(score, 0) for _, score in ranked) or 1
|
| 32 |
+
return label, best / total
|
| 33 |
+
|
| 34 |
+
def search(self, query: str, limit: int = 3) -> list[dict]:
|
| 35 |
+
query_tokens = set(tokenize(query))
|
| 36 |
+
ranked = []
|
| 37 |
+
for document in self.model["documents"]:
|
| 38 |
+
document_tokens = set(tokenize(document["text"]))
|
| 39 |
+
lexical = sum(
|
| 40 |
+
self.model["idf"].get(token, 1.0)
|
| 41 |
+
for token in query_tokens & document_tokens
|
| 42 |
+
)
|
| 43 |
+
ranked.append({**document, "score": round(lexical, 6)})
|
| 44 |
+
return sorted(ranked, key=lambda item: (-item["score"], item["id"]))[:limit]
|
| 45 |
+
|
| 46 |
+
def graph_evidence(self, text: str) -> list[dict]:
|
| 47 |
+
tokens = set(tokenize(text))
|
| 48 |
+
matches = []
|
| 49 |
+
for subject, relation, target in self.model.get("graph_edges", []):
|
| 50 |
+
edge_tokens = set(tokenize(f"{subject} {relation} {target}"))
|
| 51 |
+
overlap = len(tokens & edge_tokens)
|
| 52 |
+
if overlap:
|
| 53 |
+
matches.append(
|
| 54 |
+
{
|
| 55 |
+
"subject": subject,
|
| 56 |
+
"relation": relation,
|
| 57 |
+
"target": target,
|
| 58 |
+
"overlap": overlap,
|
| 59 |
+
}
|
| 60 |
+
)
|
| 61 |
+
return sorted(matches, key=lambda item: -item["overlap"])
|
| 62 |
+
|
| 63 |
+
def run(self, text: str) -> dict:
|
| 64 |
+
label, confidence = self.classify(text)
|
| 65 |
+
evidence = self.search(text)
|
| 66 |
+
result = {
|
| 67 |
+
"prediction": label,
|
| 68 |
+
"confidence": round(confidence, 4),
|
| 69 |
+
"requires_review": confidence < self.model["confidence_threshold"],
|
| 70 |
+
"evidence": evidence,
|
| 71 |
+
}
|
| 72 |
+
if self.model["mode"] == "graph":
|
| 73 |
+
result["graph_evidence"] = self.graph_evidence(text)
|
| 74 |
+
if self.model["mode"] == "agent":
|
| 75 |
+
result["proposed_tool"] = label
|
| 76 |
+
result["approval_required"] = label in {
|
| 77 |
+
"request-approval",
|
| 78 |
+
"request-human-help",
|
| 79 |
+
}
|
| 80 |
+
return result
|
model.json
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"format": "daily-project-prototype-v1",
|
| 3 |
+
"project": "knowledge-graph-risk",
|
| 4 |
+
"title": "Knowledge Graph Risk Engine",
|
| 5 |
+
"domain": "knowledge-graphs",
|
| 6 |
+
"mode": "graph",
|
| 7 |
+
"labels": [
|
| 8 |
+
"ownership",
|
| 9 |
+
"transaction",
|
| 10 |
+
"location"
|
| 11 |
+
],
|
| 12 |
+
"prototypes": {
|
| 13 |
+
"ownership": {
|
| 14 |
+
"who": 3,
|
| 15 |
+
"controls": 6,
|
| 16 |
+
"supplier": 6,
|
| 17 |
+
"alpha": 9,
|
| 18 |
+
"company": 7,
|
| 19 |
+
"in": 2,
|
| 20 |
+
"an": 3,
|
| 21 |
+
"operations": 2,
|
| 22 |
+
"review": 2,
|
| 23 |
+
"for": 1,
|
| 24 |
+
"evaluation": 1,
|
| 25 |
+
"case": 1,
|
| 26 |
+
"which": 2,
|
| 27 |
+
"owns": 4,
|
| 28 |
+
"vendor": 4,
|
| 29 |
+
"gamma": 4,
|
| 30 |
+
"delta": 2
|
| 31 |
+
},
|
| 32 |
+
"transaction": {
|
| 33 |
+
"17": 8,
|
| 34 |
+
"in": 2,
|
| 35 |
+
"an": 4,
|
| 36 |
+
"operations": 2,
|
| 37 |
+
"review": 2,
|
| 38 |
+
"which": 2,
|
| 39 |
+
"account": 10,
|
| 40 |
+
"paid": 4,
|
| 41 |
+
"vendor": 4,
|
| 42 |
+
"beta": 4,
|
| 43 |
+
"for": 2,
|
| 44 |
+
"evaluation": 2,
|
| 45 |
+
"case": 2,
|
| 46 |
+
"what": 3,
|
| 47 |
+
"transfer": 3,
|
| 48 |
+
"connects": 3,
|
| 49 |
+
"and": 3,
|
| 50 |
+
"supplier": 6,
|
| 51 |
+
"alpha": 6,
|
| 52 |
+
"transferred": 3,
|
| 53 |
+
"to": 3
|
| 54 |
+
},
|
| 55 |
+
"location": {
|
| 56 |
+
"where": 2,
|
| 57 |
+
"is": 2,
|
| 58 |
+
"warehouse": 4,
|
| 59 |
+
"north": 4,
|
| 60 |
+
"located": 6,
|
| 61 |
+
"in": 5,
|
| 62 |
+
"region": 6,
|
| 63 |
+
"east": 2,
|
| 64 |
+
"for": 2,
|
| 65 |
+
"an": 3,
|
| 66 |
+
"evaluation": 2,
|
| 67 |
+
"case": 2,
|
| 68 |
+
"operations": 1,
|
| 69 |
+
"review": 1,
|
| 70 |
+
"what": 2,
|
| 71 |
+
"contains": 2,
|
| 72 |
+
"facility": 4,
|
| 73 |
+
"blue": 4,
|
| 74 |
+
"west": 2
|
| 75 |
+
}
|
| 76 |
+
},
|
| 77 |
+
"idf": {
|
| 78 |
+
"17": 1.847298,
|
| 79 |
+
"company": 1.847298,
|
| 80 |
+
"alpha": 1.847298,
|
| 81 |
+
"controls": 2.252763,
|
| 82 |
+
"supplier": 1.847298,
|
| 83 |
+
"account": 1.847298,
|
| 84 |
+
"paid": 2.252763,
|
| 85 |
+
"vendor": 1.847298,
|
| 86 |
+
"beta": 2.252763,
|
| 87 |
+
"warehouse": 2.252763,
|
| 88 |
+
"north": 2.252763,
|
| 89 |
+
"located": 1.847298,
|
| 90 |
+
"in": 1.847298,
|
| 91 |
+
"region": 1.847298,
|
| 92 |
+
"east": 2.252763,
|
| 93 |
+
"delta": 2.252763,
|
| 94 |
+
"owns": 2.252763,
|
| 95 |
+
"gamma": 2.252763,
|
| 96 |
+
"transferred": 2.252763,
|
| 97 |
+
"to": 2.252763,
|
| 98 |
+
"facility": 2.252763,
|
| 99 |
+
"blue": 2.252763,
|
| 100 |
+
"west": 2.252763
|
| 101 |
+
},
|
| 102 |
+
"documents": [
|
| 103 |
+
{
|
| 104 |
+
"id": "graph-01",
|
| 105 |
+
"label": "ownership",
|
| 106 |
+
"text": "company-alpha controls supplier-alpha",
|
| 107 |
+
"metadata": {
|
| 108 |
+
"synthetic": true,
|
| 109 |
+
"domain": "knowledge-graphs"
|
| 110 |
+
}
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"id": "graph-02",
|
| 114 |
+
"label": "transaction",
|
| 115 |
+
"text": "account-17 paid vendor-beta",
|
| 116 |
+
"metadata": {
|
| 117 |
+
"synthetic": true,
|
| 118 |
+
"domain": "knowledge-graphs"
|
| 119 |
+
}
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"id": "graph-03",
|
| 123 |
+
"label": "location",
|
| 124 |
+
"text": "warehouse-north located-in region-east",
|
| 125 |
+
"metadata": {
|
| 126 |
+
"synthetic": true,
|
| 127 |
+
"domain": "knowledge-graphs"
|
| 128 |
+
}
|
| 129 |
+
},
|
| 130 |
+
{
|
| 131 |
+
"id": "graph-04",
|
| 132 |
+
"label": "ownership",
|
| 133 |
+
"text": "company-delta owns vendor-gamma",
|
| 134 |
+
"metadata": {
|
| 135 |
+
"synthetic": true,
|
| 136 |
+
"domain": "knowledge-graphs"
|
| 137 |
+
}
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"id": "graph-05",
|
| 141 |
+
"label": "transaction",
|
| 142 |
+
"text": "account-17 transferred-to supplier-alpha",
|
| 143 |
+
"metadata": {
|
| 144 |
+
"synthetic": true,
|
| 145 |
+
"domain": "knowledge-graphs"
|
| 146 |
+
}
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"id": "graph-06",
|
| 150 |
+
"label": "location",
|
| 151 |
+
"text": "facility-blue located-in region-west",
|
| 152 |
+
"metadata": {
|
| 153 |
+
"synthetic": true,
|
| 154 |
+
"domain": "knowledge-graphs"
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
],
|
| 158 |
+
"graph_edges": [
|
| 159 |
+
[
|
| 160 |
+
"company-alpha",
|
| 161 |
+
"controls",
|
| 162 |
+
"supplier-alpha"
|
| 163 |
+
],
|
| 164 |
+
[
|
| 165 |
+
"account-17",
|
| 166 |
+
"paid",
|
| 167 |
+
"vendor-beta"
|
| 168 |
+
],
|
| 169 |
+
[
|
| 170 |
+
"warehouse-north",
|
| 171 |
+
"located-in",
|
| 172 |
+
"region-east"
|
| 173 |
+
],
|
| 174 |
+
[
|
| 175 |
+
"company-delta",
|
| 176 |
+
"owns",
|
| 177 |
+
"vendor-gamma"
|
| 178 |
+
],
|
| 179 |
+
[
|
| 180 |
+
"account-17",
|
| 181 |
+
"transferred-to",
|
| 182 |
+
"supplier-alpha"
|
| 183 |
+
],
|
| 184 |
+
[
|
| 185 |
+
"facility-blue",
|
| 186 |
+
"located-in",
|
| 187 |
+
"region-west"
|
| 188 |
+
]
|
| 189 |
+
],
|
| 190 |
+
"confidence_threshold": 0.18,
|
| 191 |
+
"trained_on_synthetic_data": true
|
| 192 |
+
}
|
project.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "Knowledge Graph Risk Engine",
|
| 3 |
+
"problem": "Risk teams need relationship-level explanations instead of opaque entity scores.",
|
| 4 |
+
"domain": "knowledge-graphs",
|
| 5 |
+
"architecture": "graph",
|
| 6 |
+
"hugging_face_tasks": [
|
| 7 |
+
"token-classification",
|
| 8 |
+
"feature-extraction",
|
| 9 |
+
"question-answering",
|
| 10 |
+
"sentence-similarity"
|
| 11 |
+
],
|
| 12 |
+
"recommended_stack": [
|
| 13 |
+
"FastAPI for entity and evidence APIs",
|
| 14 |
+
"Neo4j Community or PostgreSQL recursive queries",
|
| 15 |
+
"Sentence Transformers for entity resolution",
|
| 16 |
+
"NetworkX for local graph validation",
|
| 17 |
+
"Kafka-compatible event ingestion",
|
| 18 |
+
"OpenTelemetry for lineage and query traces"
|
| 19 |
+
],
|
| 20 |
+
"real_world_data_sources": [
|
| 21 |
+
{
|
| 22 |
+
"name": "SEC EDGAR submissions API",
|
| 23 |
+
"url": "https://data.sec.gov/submissions/CIK0000320193.json",
|
| 24 |
+
"purpose": "Public company and filing relationships"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"name": "GLEIF LEI API",
|
| 28 |
+
"url": "https://api.gleif.org/api/v1/lei-records?page[size]=5",
|
| 29 |
+
"purpose": "Public legal-entity identifiers and relationships"
|
| 30 |
+
}
|
| 31 |
+
],
|
| 32 |
+
"job_description_skills": [
|
| 33 |
+
"Entity resolution and relation extraction",
|
| 34 |
+
"Knowledge-graph modeling and path queries",
|
| 35 |
+
"Graph-based explainability and provenance",
|
| 36 |
+
"Streaming ingestion and schema evolution",
|
| 37 |
+
"Risk-model evaluation and data quality controls"
|
| 38 |
+
],
|
| 39 |
+
"impact_targets": [
|
| 40 |
+
"Reach entity-resolution precision >= 0.95 on reviewed pairs",
|
| 41 |
+
"Return evidence paths for 100% of emitted risk flags",
|
| 42 |
+
"Process 10,000 relationship events per minute in load tests",
|
| 43 |
+
"Detect schema and orphan-node regressions in CI"
|
| 44 |
+
],
|
| 45 |
+
"baseline_evaluation": {
|
| 46 |
+
"test_examples": 4,
|
| 47 |
+
"accuracy": 1,
|
| 48 |
+
"synthetic_evaluation": true
|
| 49 |
+
},
|
| 50 |
+
"estimated_delivery": "8-12 weeks for one engineer",
|
| 51 |
+
"generated_baseline_is_production_ready": false
|
| 52 |
+
}
|