mattbitzesty commited on
Commit
2796908
·
1 Parent(s): 5093425

fix: skip non-formulation records in dataset loader; keep feedback separate from dataset JSONL

Browse files
Files changed (2) hide show
  1. src/pino/feedback.py +52 -14
  2. src/pino/pimt_model.py +2 -0
src/pino/feedback.py CHANGED
@@ -51,9 +51,11 @@ class FeedbackLoopManager:
51
  """
52
  Atomic append-only recorder for real-world corrections.
53
 
54
- Manages `data/incremental_feedback.jsonl`, merges feedback with the original
55
- 5,000-sample pool, pushes the updated dataset to the Hugging Face Dataset Hub,
56
- and can trigger a fresh T4 training job.
 
 
57
  """
58
 
59
  def __init__(
@@ -98,11 +100,30 @@ class FeedbackLoopManager:
98
  critiques.append(Critique.from_record(json.loads(line)))
99
  return critiques
100
 
101
- def merge_with_original_pool(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  self,
103
  original_path: str | Path | None = None,
104
  ) -> list[dict[str, Any]]:
105
- """Merge feedback rows with the original 5,000-sample dataset."""
106
  if original_path is None:
107
  original_path = hf_hub_download(
108
  repo_id=self.dataset_repo,
@@ -111,24 +132,40 @@ class FeedbackLoopManager:
111
  )
112
 
113
  original_path = Path(original_path)
114
- records = []
115
  with original_path.open("r", encoding="utf-8") as f:
116
  for line in f:
117
  line = line.strip()
118
- if line:
119
- records.append(json.loads(line))
 
 
 
 
 
 
 
 
120
 
121
- for critique in self.read_all():
122
- records.append({"formula_id": f"critique_{critique.formula_id}", "feedback": critique.to_record()})
 
 
 
 
123
 
124
- return records
 
 
 
 
125
 
126
  def push_merged_pool(
127
  self,
128
  original_path: str | Path | None = None,
129
  path_in_repo: str = "synthetic_dataset_v2.jsonl",
130
  ) -> str:
131
- """Write merged records to JSONL and push to the Hugging Face Dataset Hub."""
132
  merged = self.merge_with_original_pool(original_path)
133
  local_path = Path("/tmp/pino_merged_dataset.jsonl")
134
  with local_path.open("w", encoding="utf-8") as f:
@@ -150,7 +187,9 @@ class FeedbackLoopManager:
150
  job_config_path: str | Path = "hf_job.yaml",
151
  ) -> dict[str, Any]:
152
  """
153
- If new feedback exists, merge + push to the Hub and trigger a fresh training job.
 
 
154
  """
155
  new_count = self.count()
156
  if new_count == 0:
@@ -161,7 +200,6 @@ class FeedbackLoopManager:
161
  return {
162
  "action": "sync",
163
  "feedback_samples": new_count,
164
- "merged_samples": new_count + 5000,
165
  "dataset_hub_path": hub_path,
166
  "training_job_triggered": True,
167
  }
 
51
  """
52
  Atomic append-only recorder for real-world corrections.
53
 
54
+ Feedback critiques live in a dedicated ``data/incremental_feedback.jsonl``
55
+ file and are NEVER appended to the formulation dataset JSONL. When the
56
+ flywheel triggers, only valid formulation records from the original pool are
57
+ pushed to the Hugging Face Dataset Hub so a cloud training job can consume a
58
+ clean corpus.
59
  """
60
 
61
  def __init__(
 
100
  critiques.append(Critique.from_record(json.loads(line)))
101
  return critiques
102
 
103
+ @staticmethod
104
+ def _is_valid_formulation_record(record: dict[str, Any]) -> bool:
105
+ """
106
+ Return True only for records that conform to the formulation schema.
107
+
108
+ A valid formulation record carries both the ``formula`` payload and the
109
+ ``trajectory`` array produced by the dataset builder, which is exactly
110
+ what :class:`~pino.pimt_model.FragranceTrajectoryDataset` requires on
111
+ every line. Critique/feedback rows (which carry ``feedback`` instead)
112
+ are explicitly excluded so they never leak into the formulation dataset
113
+ JSONL.
114
+ """
115
+ return bool(
116
+ isinstance(record, dict)
117
+ and record.get("formula")
118
+ and record.get("trajectory")
119
+ and not record.get("feedback")
120
+ )
121
+
122
+ def _load_original_pool(
123
  self,
124
  original_path: str | Path | None = None,
125
  ) -> list[dict[str, Any]]:
126
+ """Load and return only valid formulation records from the original pool."""
127
  if original_path is None:
128
  original_path = hf_hub_download(
129
  repo_id=self.dataset_repo,
 
132
  )
133
 
134
  original_path = Path(original_path)
135
+ records: list[dict[str, Any]] = []
136
  with original_path.open("r", encoding="utf-8") as f:
137
  for line in f:
138
  line = line.strip()
139
+ if not line:
140
+ continue
141
+ record = json.loads(line)
142
+ if self._is_valid_formulation_record(record):
143
+ records.append(record)
144
+
145
+ logger.debug(
146
+ "Loaded %d valid formulation records from %s", len(records), original_path
147
+ )
148
+ return records
149
 
150
+ def merge_with_original_pool(
151
+ self,
152
+ original_path: str | Path | None = None,
153
+ ) -> list[dict[str, Any]]:
154
+ """
155
+ Return only valid formulation records from the original pool.
156
 
157
+ Feedback critiques are intentionally NOT appended here. They live in the
158
+ separate ``incremental_feedback.jsonl`` file so the formulation dataset
159
+ schema stays clean. Use ``read_all()`` to access raw feedback rows.
160
+ """
161
+ return self._load_original_pool(original_path)
162
 
163
  def push_merged_pool(
164
  self,
165
  original_path: str | Path | None = None,
166
  path_in_repo: str = "synthetic_dataset_v2.jsonl",
167
  ) -> str:
168
+ """Write valid formulation records to JSONL and push to the Hugging Face Dataset Hub."""
169
  merged = self.merge_with_original_pool(original_path)
170
  local_path = Path("/tmp/pino_merged_dataset.jsonl")
171
  with local_path.open("w", encoding="utf-8") as f:
 
187
  job_config_path: str | Path = "hf_job.yaml",
188
  ) -> dict[str, Any]:
189
  """
190
+ If new feedback exists, push the clean formulation pool to the Hub and
191
+ trigger a fresh training job. Feedback rows are preserved in the separate
192
+ feedback file and never mixed into the formulation dataset.
193
  """
194
  new_count = self.count()
195
  if new_count == 0:
 
200
  return {
201
  "action": "sync",
202
  "feedback_samples": new_count,
 
203
  "dataset_hub_path": hub_path,
204
  "training_job_triggered": True,
205
  }
src/pino/pimt_model.py CHANGED
@@ -61,6 +61,8 @@ class FragranceTrajectoryDataset(Dataset):
61
  f.seek(self._index_offsets[idx])
62
  record = json.loads(f.readline())
63
 
 
 
64
  formula = record["formula"]
65
  trajectory = record["trajectory"]
66
 
 
61
  f.seek(self._index_offsets[idx])
62
  record = json.loads(f.readline())
63
 
64
+ if "formula" not in record or "trajectory" not in record:
65
+ raise IndexError(f"Record {idx} is not a formulation sample")
66
  formula = record["formula"]
67
  trajectory = record["trajectory"]
68