auto-sync 2026-07-03T15:40:37Z workspace (part 5)
Browse files
workspace/scripts/train_ctt.py
CHANGED
|
@@ -236,7 +236,9 @@ def load_charts(
|
|
| 236 |
metadata_values = data["metadata_json"]
|
| 237 |
for row in range(chart_ids.shape[0]):
|
| 238 |
chart_id = str(chart_ids[row])
|
| 239 |
-
metadata = _json_loads(str(metadata_values[row]))
|
|
|
|
|
|
|
| 240 |
item = grouped.setdefault(
|
| 241 |
chart_id,
|
| 242 |
{
|
|
|
|
| 236 |
metadata_values = data["metadata_json"]
|
| 237 |
for row in range(chart_ids.shape[0]):
|
| 238 |
chart_id = str(chart_ids[row])
|
| 239 |
+
metadata = _json_loads(str(metadata_values[row])) | {
|
| 240 |
+
"_chart_root": str(index_path.parent)
|
| 241 |
+
}
|
| 242 |
item = grouped.setdefault(
|
| 243 |
chart_id,
|
| 244 |
{
|
workspace/tests/test_chart_features.py
CHANGED
|
@@ -3,7 +3,12 @@ from __future__ import annotations
|
|
| 3 |
import numpy as np
|
| 4 |
import pytest
|
| 5 |
|
| 6 |
-
from cil.chart_features import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def test_base_chart_feature_preserves_original_flattened_base_action() -> None:
|
|
@@ -54,6 +59,31 @@ def test_base_context_feature_does_not_read_outcome_or_hidden_fields() -> None:
|
|
| 54 |
)
|
| 55 |
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
def test_unknown_chart_feature_mode_raises() -> None:
|
| 58 |
with pytest.raises(ValueError, match="unknown chart feature mode"):
|
| 59 |
build_chart_feature(np.zeros((1, 2), dtype=np.float32), mode="outcome")
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import pytest
|
| 5 |
|
| 6 |
+
from cil.chart_features import (
|
| 7 |
+
CONTEXT_HASH_WIDTH,
|
| 8 |
+
OBSERVATION_EMBED_DIM,
|
| 9 |
+
build_chart_feature,
|
| 10 |
+
chart_feature_dim,
|
| 11 |
+
)
|
| 12 |
|
| 13 |
|
| 14 |
def test_base_chart_feature_preserves_original_flattened_base_action() -> None:
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
|
| 62 |
+
def test_base_context_obs_appends_precomputed_observation_embedding(tmp_path) -> None:
|
| 63 |
+
base_action = np.zeros((2, 7), dtype=np.float32)
|
| 64 |
+
embeddings = np.arange(OBSERVATION_EMBED_DIM * 2, dtype=np.float32).reshape(
|
| 65 |
+
2, OBSERVATION_EMBED_DIM
|
| 66 |
+
)
|
| 67 |
+
path = tmp_path / "obs_embeddings.npz"
|
| 68 |
+
np.savez_compressed(path, embeddings=embeddings)
|
| 69 |
+
metadata = {
|
| 70 |
+
"task_id": "PullCube-v1",
|
| 71 |
+
"instruction": "pull the cube",
|
| 72 |
+
"observation_embedding_path": f"{path.name}#embeddings/1",
|
| 73 |
+
"_chart_root": str(tmp_path),
|
| 74 |
+
"scalar_utility": -999.0,
|
| 75 |
+
"label": "negative",
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
feature = build_chart_feature(base_action, metadata, mode="base_context_obs")
|
| 79 |
+
|
| 80 |
+
assert feature.shape == (
|
| 81 |
+
base_action.size + 2 * CONTEXT_HASH_WIDTH + 2 + OBSERVATION_EMBED_DIM,
|
| 82 |
+
)
|
| 83 |
+
assert np.allclose(feature[-OBSERVATION_EMBED_DIM:], embeddings[1])
|
| 84 |
+
assert chart_feature_dim(base_action, mode="base_context_obs") == feature.shape[0]
|
| 85 |
+
|
| 86 |
+
|
| 87 |
def test_unknown_chart_feature_mode_raises() -> None:
|
| 88 |
with pytest.raises(ValueError, match="unknown chart feature mode"):
|
| 89 |
build_chart_feature(np.zeros((1, 2), dtype=np.float32), mode="outcome")
|