RKB109 commited on
Commit
7a653bc
·
verified ·
1 Parent(s): 05a9966

Publish artifacts for contextual-bandit-simulator-20260725

Browse files
Files changed (5) hide show
  1. README.md +61 -0
  2. evaluation.json +5 -0
  3. inference.py +80 -0
  4. model.json +198 -0
  5. project.json +52 -0
README.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: custom
4
+ pipeline_tag: reinforcement-learning
5
+ datasets:
6
+ - RKB109/contextual-bandit-simulator-20260725-dataset
7
+ tags:
8
+ - synthetic-data
9
+ - transparent-baseline
10
+ - reinforcement-learning
11
+ - reinforcement-learning
12
+ - text-classification
13
+ - feature-extraction
14
+ - sentence-similarity
15
+ metrics:
16
+ - accuracy
17
+ ---
18
+
19
+ # Contextual Bandit Decision Simulator Baseline Model
20
+
21
+ ## Model Description
22
+
23
+ This repository contains a small, transparent prototype model for
24
+ **Teams need to validate decision policies offline before exposing users or systems to online reinforcement learning.**
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: average_reward, policy_regret, unsafe_action_block_rate
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
+ - `reinforcement-learning`
46
+ - `text-classification`
47
+ - `feature-extraction`
48
+ - `sentence-similarity`
49
+
50
+ ## Limitations and Risks
51
+
52
+ Offline simulated rewards cannot prove online safety or business impact. Real experiments require review and guardrails.
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,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "format": "daily-project-prototype-v1",
3
+ "project": "contextual-bandit",
4
+ "title": "Contextual Bandit Decision Simulator",
5
+ "domain": "reinforcement-learning",
6
+ "mode": "agent",
7
+ "labels": [
8
+ "recommend-docs",
9
+ "recommend-tutorial",
10
+ "request-human-help"
11
+ ],
12
+ "prototypes": {
13
+ "recommend-docs": {
14
+ "experienced": 3,
15
+ "user": 3,
16
+ "asks": 3,
17
+ "for": 6,
18
+ "api": 3,
19
+ "parameter": 3,
20
+ "details": 3,
21
+ "documentation": 3,
22
+ "is": 5,
23
+ "the": 3,
24
+ "highest": 3,
25
+ "value": 3,
26
+ "action": 3,
27
+ "in": 2,
28
+ "an": 3,
29
+ "operations": 2,
30
+ "review": 2,
31
+ "evaluation": 1,
32
+ "case": 1,
33
+ "developer": 2,
34
+ "needs": 2,
35
+ "exact": 2,
36
+ "error": 2,
37
+ "code": 2,
38
+ "reference": 4,
39
+ "material": 2,
40
+ "appropriate": 2,
41
+ "precise": 2,
42
+ "lookup": 2
43
+ },
44
+ "recommend-tutorial": {
45
+ "in": 2,
46
+ "an": 4,
47
+ "operations": 2,
48
+ "review": 2,
49
+ "new": 2,
50
+ "developer": 2,
51
+ "asks": 2,
52
+ "how": 2,
53
+ "to": 2,
54
+ "build": 2,
55
+ "a": 7,
56
+ "first": 2,
57
+ "integration": 2,
58
+ "guided": 2,
59
+ "tutorial": 2,
60
+ "is": 5,
61
+ "the": 2,
62
+ "highest": 2,
63
+ "value": 2,
64
+ "action": 2,
65
+ "for": 2,
66
+ "evaluation": 2,
67
+ "case": 2,
68
+ "beginner": 3,
69
+ "requests": 3,
70
+ "complete": 3,
71
+ "walkthrough": 3,
72
+ "structured": 3,
73
+ "onboarding": 3,
74
+ "appropriate": 3
75
+ },
76
+ "request-human-help": {
77
+ "user": 2,
78
+ "reports": 2,
79
+ "a": 2,
80
+ "possible": 2,
81
+ "security": 4,
82
+ "compromise": 2,
83
+ "sensitive": 2,
84
+ "issues": 2,
85
+ "require": 2,
86
+ "human": 2,
87
+ "support": 2,
88
+ "for": 2,
89
+ "an": 3,
90
+ "evaluation": 2,
91
+ "case": 2,
92
+ "in": 1,
93
+ "operations": 1,
94
+ "review": 1,
95
+ "customer": 2,
96
+ "indicates": 2,
97
+ "potential": 2,
98
+ "data": 2,
99
+ "loss": 2,
100
+ "high": 2,
101
+ "impact": 2,
102
+ "cases": 2,
103
+ "must": 2,
104
+ "be": 2,
105
+ "escalated": 2
106
+ }
107
+ },
108
+ "idf": {
109
+ "documentation": 2.252763,
110
+ "is": 1.336472,
111
+ "the": 1.847298,
112
+ "highest": 1.847298,
113
+ "value": 1.847298,
114
+ "action": 1.847298,
115
+ "a": 2.252763,
116
+ "guided": 2.252763,
117
+ "tutorial": 2.252763,
118
+ "sensitive": 2.252763,
119
+ "security": 2.252763,
120
+ "issues": 2.252763,
121
+ "require": 2.252763,
122
+ "human": 2.252763,
123
+ "support": 2.252763,
124
+ "reference": 2.252763,
125
+ "material": 2.252763,
126
+ "appropriate": 1.847298,
127
+ "for": 2.252763,
128
+ "precise": 2.252763,
129
+ "lookup": 2.252763,
130
+ "structured": 2.252763,
131
+ "onboarding": 2.252763,
132
+ "high": 2.252763,
133
+ "impact": 2.252763,
134
+ "cases": 2.252763,
135
+ "must": 2.252763,
136
+ "be": 2.252763,
137
+ "escalated": 2.252763
138
+ },
139
+ "documents": [
140
+ {
141
+ "id": "bandit-01",
142
+ "label": "recommend-docs",
143
+ "text": "Documentation is the highest-value action.",
144
+ "metadata": {
145
+ "synthetic": true,
146
+ "domain": "reinforcement-learning"
147
+ }
148
+ },
149
+ {
150
+ "id": "bandit-02",
151
+ "label": "recommend-tutorial",
152
+ "text": "A guided tutorial is the highest-value action.",
153
+ "metadata": {
154
+ "synthetic": true,
155
+ "domain": "reinforcement-learning"
156
+ }
157
+ },
158
+ {
159
+ "id": "bandit-03",
160
+ "label": "request-human-help",
161
+ "text": "Sensitive security issues require human support.",
162
+ "metadata": {
163
+ "synthetic": true,
164
+ "domain": "reinforcement-learning"
165
+ }
166
+ },
167
+ {
168
+ "id": "bandit-04",
169
+ "label": "recommend-docs",
170
+ "text": "Reference material is appropriate for precise lookup.",
171
+ "metadata": {
172
+ "synthetic": true,
173
+ "domain": "reinforcement-learning"
174
+ }
175
+ },
176
+ {
177
+ "id": "bandit-05",
178
+ "label": "recommend-tutorial",
179
+ "text": "Structured onboarding is appropriate.",
180
+ "metadata": {
181
+ "synthetic": true,
182
+ "domain": "reinforcement-learning"
183
+ }
184
+ },
185
+ {
186
+ "id": "bandit-06",
187
+ "label": "request-human-help",
188
+ "text": "High-impact cases must be escalated.",
189
+ "metadata": {
190
+ "synthetic": true,
191
+ "domain": "reinforcement-learning"
192
+ }
193
+ }
194
+ ],
195
+ "graph_edges": [],
196
+ "confidence_threshold": 0.18,
197
+ "trained_on_synthetic_data": true
198
+ }
project.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "Contextual Bandit Decision Simulator",
3
+ "problem": "Teams need to validate decision policies offline before exposing users or systems to online reinforcement learning.",
4
+ "domain": "reinforcement-learning",
5
+ "architecture": "agent",
6
+ "hugging_face_tasks": [
7
+ "reinforcement-learning",
8
+ "text-classification",
9
+ "feature-extraction",
10
+ "sentence-similarity"
11
+ ],
12
+ "recommended_stack": [
13
+ "FastAPI for policy and feedback endpoints",
14
+ "Vowpal Wabbit or River for online-learning baselines",
15
+ "PostgreSQL for contexts, actions, propensities, and rewards",
16
+ "Redis for low-latency policy serving",
17
+ "MLflow for policy versioning",
18
+ "OpenTelemetry for decisions and delayed rewards"
19
+ ],
20
+ "real_world_data_sources": [
21
+ {
22
+ "name": "Hacker News API",
23
+ "url": "https://hacker-news.firebaseio.com/v0/topstories.json",
24
+ "purpose": "Real content candidates for recommendation simulations"
25
+ },
26
+ {
27
+ "name": "Open-Meteo API",
28
+ "url": "https://api.open-meteo.com/v1/forecast?latitude=40.71&longitude=-74.01&current=temperature_2m",
29
+ "purpose": "Real contextual features without authentication"
30
+ }
31
+ ],
32
+ "job_description_skills": [
33
+ "Contextual bandits and offline policy evaluation",
34
+ "Propensity logging and counterfactual metrics",
35
+ "Low-latency decision services",
36
+ "Safe exploration and constrained actions",
37
+ "Delayed-feedback pipelines and policy monitoring"
38
+ ],
39
+ "impact_targets": [
40
+ "Beat a random policy by >= 20% average simulated reward",
41
+ "Report IPS and doubly robust offline estimates",
42
+ "Block 100% of disallowed actions before serving",
43
+ "Serve policy decisions below 50 ms p95"
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
+ }