dewmal commited on
Commit
d4ceae0
·
verified ·
1 Parent(s): 0768e31

Upload Concept Memory base model

Browse files
Files changed (1) hide show
  1. README.md +53 -143
README.md CHANGED
@@ -34,159 +34,69 @@ The three supported judgment types are:
34
  lowest to highest.
35
  - **Noul (Yes/No):** return a binary judgment for the instruction.
36
 
37
- The idea behind **Concept Memory** is to make a judgment through reusable,
38
- human-readable concepts. For example, when routing a support request, concepts
39
- such as “payment issue” or “integration failure” can connect details in the
40
- input to a possible outcome. The base checkpoint makes the typed judgment and
41
- can rank which concepts are relevant; a Concept Bank adds explicit links from
42
- those concepts to outcomes. This makes the reasoning path inspectable and lets
43
- you adapt the bank to your domain. A relevance score is a relative ranking, not
44
- a calibrated measure of evidence.
45
-
46
- The example below demonstrates Choice. The same `Question` interface supports
47
- the other judgment types by setting `type` to `"score"` or `"noul"` and
48
- providing the corresponding criteria where applicable.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  ## Files
51
 
52
  - `model.pt`: PyTorch state dictionary and training metadata.
53
  - `config.json`: encoder, task, and training run metadata.
54
- - `concept_memory/`: the minimal model runtime modules needed for inference.
55
- - `example.py`: a runnable end to end Choice prediction example.
56
 
57
- ## Run a prediction
 
 
 
58
 
59
- Use Python 3.11 or newer. Install the runtime dependencies:
60
 
61
- ```bash
62
- pip install torch transformers huggingface_hub
63
- ```
64
-
65
- Run the standalone example with:
66
-
67
- ```bash
68
- python example.py
69
- ```
70
-
71
- Download this model repository. It contains only the small `concept_memory`
72
- runtime package needed to load the checkpoint, rather than the full training
73
- project. Then construct a question with the criteria you want the model to
74
- judge and inspect its prediction and probabilities:
75
-
76
- ```python
77
- import torch
78
- import sys
79
- from pathlib import Path
80
- from huggingface_hub import snapshot_download
81
-
82
- repo_id = "Syigen/rgcm"
83
- repo_path = snapshot_download(repo_id)
84
- sys.path.insert(0, repo_path)
85
-
86
- from concept_memory import ConceptMemoryModel
87
- from concept_memory.types import Question
88
-
89
- checkpoint = Path(repo_path) / "model.pt"
90
- payload = torch.load(checkpoint, map_location="cpu", weights_only=False)
91
- model = ConceptMemoryModel.from_pretrained(
92
- payload["encoder"],
93
- decision_size=payload["decision_size"],
94
- max_length=payload["max_length"],
95
- )
96
- model.load_state_dict(payload["model_state_dict"])
97
- model.eval()
98
-
99
- question = Question(
100
- id="intent",
101
- type="choice",
102
- instructions="Which team should handle this customer request?",
103
- criteria=[
104
- {"id": "billing", "description": "Payment or subscription issues"},
105
- {"id": "technical", "description": "Bugs or integration problems"},
106
- {"id": "sales", "description": "Pricing or account questions"},
107
- ],
108
- )
109
-
110
- with torch.inference_mode():
111
- result = model.predict(
112
- "Stripe integration keeps failing after several attempts.", [question]
113
- )[0]
114
-
115
- criteria = question.normalized_criteria()
116
- predicted = criteria[result.prediction.item()]
117
- print("Prediction:", predicted.id, "-", predicted.description)
118
- print("Probabilities:", result.probabilities.tolist())
119
- ```
120
-
121
- ## Use a Concept Bank
122
-
123
- This example builds a small bank of domain concepts. Each concept describes a
124
- pattern and names the outcome it supports or contradicts. The model first
125
- ranks relevant concepts, then the helper blends their linked votes with the
126
- raw Choice probabilities only when the top bank outcome agrees with the raw
127
- model prediction. The helper is included in the repository's minimal runtime
128
- package.
129
-
130
- ```python
131
- from concept_memory.concept_bank import apply_concept_votes
132
-
133
- concepts = [
134
- {
135
- "id": "payment_issue",
136
- "name": "Payment issue",
137
- "description": "A charge, invoice, refund, or subscription problem.",
138
- "supports": ["billing"],
139
- },
140
- {
141
- "id": "integration_failure",
142
- "name": "Integration failure",
143
- "description": "An API, SDK, or third-party integration is failing.",
144
- "supports": ["technical"],
145
- },
146
- {
147
- "id": "purchase_intent",
148
- "name": "Purchase intent",
149
- "description": "The customer is evaluating plans or pricing before buying.",
150
- "supports": ["sales"],
151
- },
152
- ]
153
-
154
- concept_question = Question(
155
- id="concepts",
156
- type="choice",
157
- instructions=f"Which concepts are most relevant to this input and question: {question.instructions}",
158
- criteria=[
159
- {"id": item["id"], "description": f"{item['name']}: {item['description']}"}
160
- for item in concepts
161
- ],
162
- )
163
-
164
- with torch.inference_mode():
165
- raw_result, concept_result = model.predict(
166
- "Stripe integration keeps failing after several attempts.",
167
- [question, concept_question],
168
- )
169
-
170
- outcomes = [
171
- {"id": item.id, "description": item.description}
172
- for item in question.normalized_criteria()
173
- ]
174
- signals = [
175
- {"description": concept["name"], "probability": float(probability)}
176
- for concept, probability in zip(concepts, concept_result.probabilities.tolist())
177
- ]
178
- adjusted_probabilities, contributions = apply_concept_votes(
179
- raw_result.probabilities.tolist(), signals, concepts, outcomes
180
- )
181
-
182
- winner = max(range(len(adjusted_probabilities)), key=adjusted_probabilities.__getitem__)
183
- print("Concept-assisted prediction:", outcomes[winner]["description"])
184
- print("Adjusted probabilities:", adjusted_probabilities)
185
- print("Concept contributions:", contributions)
186
  ```
187
 
188
- The Hub checkpoint is a PyTorch artifact for this project's Python package; it
189
- is not directly compatible with `transformers.AutoModel.from_pretrained`.
 
190
 
191
  ## Training metadata
192
 
 
34
  lowest to highest.
35
  - **Noul (Yes/No):** return a binary judgment for the instruction.
36
 
37
+ ## Concept Memory and the Concept Bank
38
+
39
+ Jev- or Laya-style typed decision systems return a structured judgment, such as
40
+ a Choice label and its probabilities. Concept Memory can make that same kind of
41
+ prediction and optionally add a **Concept Bank**: a separate, editable set of
42
+ human-readable concepts with links to outcomes. For example, “integration
43
+ failure” may support “Technical,” while “payment issue” may support “Billing.”
44
+ This externalizes some domain knowledge from the model's learned weights so it
45
+ can be inspected, reused, and adapted to different tasks or domains.
46
+
47
+ With a bank, inference has two paths: the base model predicts an outcome, and a
48
+ second Choice question ranks which bank concepts are relevant to the input.
49
+ The bank maps those relevant concepts to outcome votes. In the current helper,
50
+ the bank adjusts the probabilities only when its leading outcome agrees with
51
+ the base model's leading outcome; the adjusted distribution is a blend of 20%
52
+ raw model probabilities and 80% normalized bank votes. The bank therefore
53
+ provides constrained decision support rather than an independent rule engine.
54
+
55
+ Concept rankings and declared concept-to-outcome links make part of the
56
+ decision process inspectable. They are not proof of the model's internal
57
+ causal reasoning: relevance is a relative ranking, not calibrated evidence,
58
+ and a ranked concept is not necessarily what caused the raw prediction.
59
+
60
+ ## What this does and does not establish
61
+
62
+ The Concept Bank offers a way to change or extend domain mappings without
63
+ retraining the encoder, but new concepts still need evaluation on representative
64
+ examples. This is an architectural capability, not evidence that Concept
65
+ Memory is more accurate than Jev, Laya, or another model. Accuracy, calibration,
66
+ robustness, and latency need head-to-head evaluation on the same data and
67
+ conditions before making comparative performance claims.
68
+
69
+ The current implementation ranks concepts with a second Choice question and
70
+ uses an agreement gate. It does not independently detect each concept or let a
71
+ bank vote overturn a raw prediction. Concept hierarchies, dependencies,
72
+ contradictions, interventions, and provenance tracking are possible research
73
+ directions, not capabilities of this checkpoint.
74
 
75
  ## Files
76
 
77
  - `model.pt`: PyTorch state dictionary and training metadata.
78
  - `config.json`: encoder, task, and training run metadata.
 
 
79
 
80
+ The Python inference implementation is not distributed in this model
81
+ repository. The checkpoint is a PyTorch artifact and is not directly
82
+ compatible with `transformers.AutoModel.from_pretrained`. For interactive
83
+ inference, use the [Concept Memory playground](https://dewmal--concept-memory-playground-playground.modal.run/).
84
 
85
+ ## Example Concept Bank entry
86
 
87
+ ```json
88
+ {
89
+ "id": "integration_failure",
90
+ "name": "Integration failure",
91
+ "description": "An API, SDK, or third-party integration is failing.",
92
+ "supports": ["technical"],
93
+ "contradicts": ["sales"]
94
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  ```
96
 
97
+ Concept entries describe reusable patterns and link them to outcome IDs or
98
+ labels. Add entries to the playground's Concept Bank field to inspect which
99
+ concepts rank as relevant and how their links contribute to a prediction.
100
 
101
  ## Training metadata
102