Skip to content

Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.

fixed validation mel spectogram bug

Karen Mosoyanf3e0f5cfc3f6
diff --git a/src/data.py b/src/data.py
index 3353430..fcfd7da 100644
--- a/src/data.py
+++ b/src/data.py
@@ -256,16 +256,31 @@ def _gcs_cache_upload(cache_id, suffixes):
)
-def load_tool_calls(split="train", max_samples=None):
- """Load tool-calling dataset, splitting 90/10 for train/val."""
+def load_tool_calls(split="train", max_samples=None, return_global_indices=False):
+ """Load tool-calling dataset, splitting 90/10 for train/val.
+
+ If return_global_indices is True, also return a numpy array mapping each
+ split-local row position back to its row id in the full unified dataset.
+ """
ds = _load_unified_dataset()
n = len(ds)
if split in ("validation", "val", "test"):
- ds = ds.select(range(int(n * 0.9), n))
+ start, end = int(n * 0.9), n
elif split == "train":
- ds = ds.select(range(int(n * 0.9)))
+ start, end = 0, int(n * 0.9)
+ else:
+ start, end = 0, n
+
+ global_indices = np.arange(start, end, dtype=np.int64)
+ ds = ds.select(range(start, end))
+
if max_samples:
- ds = ds.select(range(min(max_samples, len(ds))))
+ limit = min(max_samples, len(ds))
+ ds = ds.select(range(limit))
+ global_indices = global_indices[:limit]
+
+ if return_global_indices:
+ return ds, global_indices
return ds
diff --git a/src/tokenize_data.py b/src/tokenize_data.py
index fccde4e..800ba08 100644
--- a/src/tokenize_data.py
+++ b/src/tokenize_data.py
@@ -71,7 +71,11 @@ def tokenize(args):
for split in ("train", "val"):
print(f"\n--- {split} split ---")
- ds = load_tool_calls(split=split, max_samples=args.max_samples)
+ ds, global_indices = load_tool_calls(
+ split=split,
+ max_samples=args.max_samples,
+ return_global_indices=True,
+ )
_, _, _, _, kept_indices = prepare_tool_call_pairs(
ds, tokenizer, max_enc_len=max_enc_len, max_dec_len=max_dec_len
)
@@ -79,7 +83,7 @@ def tokenize(args):
# Precompute mel spectrograms
mel_cache_id = precompute_mels(
- kept_indices, n_mels=n_mels, max_mel_len=max_mel_len,
+ global_indices[kept_indices], n_mels=n_mels, max_mel_len=max_mel_len,
cache_id_prefix=split,
)