Features from a pretrained model
Turn a column of images, sounds or texts into number columns with a frozen encoder, and know what the app does to each file before the model sees it.
What runs in CodeSplash
You will be able to
- Explain what a frozen encoder adds and why it can't leak between training and test rows
- Describe how files are decoded the same way every time, and when exported code can differ
- Save the features as columns and handle files that can't be read
Pictures and sounds as numbers
ReadMost methods need numbers in columns. A frozen encoderFrozen encoderA pretrained model used as-is to turn each image, sound or text into a vector; it learns nothing from your data. turns each image, clip or text into a vector: the same file always gets the same vector, and the model learns nothing from your rows.
Features from a pretrained model runs one encoder over a column and returns one row of features per row of data.
Make a guess
PredictPredict first
The 8 × 8 gray thumbnail encoder keeps every pixel of a small copy. How many features does each image get?
Make your guess between 1 and 1024 features, then reveal.
Reveal
Each image gets 64 features, one per pixel of the 8 × 8 copy.
Decoded once, the same way
Read12 of 12 rows were encoded with Thumbnail pixels (8 × 8 gray) into 64 features each; the mean vector length is 3.797.
- Rows encoded
- 12
- Features per row
- 64
- Mean vector length
- 3.797
First 10 rows (first 4 of 64 features)
| Row | path | Feature 1 | Feature 2 | Feature 3 | Feature 4 |
|---|---|---|---|---|---|
| 1 | media/images/gradient_0.png | 0.6463 | 0.6402 | 0.6080 | 0.5460 |
| 2 | media/images/gradient_1.png | 0.5591 | 0.6064 | 0.6446 | 0.6627 |
| 3 | media/images/gradient_2.png | 0.6464 | 0.6465 | 0.6465 | 0.6465 |
| 4 | media/images/gradient_3.jpg | 0.4968 | 0.5356 | 0.5734 | 0.6045 |
| 5 | media/images/rings_0.png | 0.3228 | 0.4575 | 0.3293 | 0.3029 |
| 6 | media/images/rings_1.png | 0.3937 | 0.4636 | 0.4133 | 0.3725 |
| 7 | media/images/rings_2.png | 0.5617 | 0.4778 | 0.3287 | 0.2573 |
| 8 | media/images/rings_3.jpg | 0.3825 | 0.4545 | 0.4237 | 0.3860 |
| 9 | media/images/checker_0.png | 0.3513 | 0.6041 | 0.3959 | 0.6041 |
| 10 | media/images/checker_1.png | 0.3367 | 0.5516 | 0.5516 | 0.3780 |
The exact R script · R R version 4.5.1 (2025-06-13)
# Features from a pretrained model (images, audio, text)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method transform.extract 1.0.0 · spec 0ffabb291139a11c
# Dataset: media_images (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
COLUMN <- "path"
ENCODER <- "thumbnail"
BATCH <- as.integer(32)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/media_images.parquet", col_select = c("path")))
n_input <- nrow(df)
df[["path"]] <- factor(df[["path"]], levels = sort(unique(df[["path"]]), method = "radix"))
df <- df[stats::complete.cases(df[c("path")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("path")) # infinite values stop the run (registry/errors.yaml)
out <- cs_ml_out_dir("target/academy-parity/run-8142/transform.extract/images_thumbnail/out-r")
enc <- cs_encoder_get(ENCODER)
if (!("r" %in% enc$engines)) stop(sprintf("%s runs in Python only; choose another encoder in R.", enc$label), call. = FALSE)
n <- nrow(df); d <- enc$dim
rows <- as.integer(rownames(df)) - 1L # each row's position in the input
X <- matrix(NA_real_, n, d)
ok <- rep(FALSE, n)
# %% Media files (image column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
media <- cs_media_setup(jsonlite::fromJSON("{\"ids_column\":\"media_id\",\"kind\":\"image\",\"path_column\":\"path\",\"role\":\"column\",\"transform\":{\"filter\":\"triangle\",\"fit\":\"stretch\",\"mode\":\"gray\",\"normalize\":\"none\",\"size\":[8,8]}}", simplifyVector = FALSE), "target/academy-parity/run-8142/transform.extract/images_thumbnail/out-r", df,
"tests/parity/fixtures/media_images.parquet")
media_ids <- cs_media_ids(media, df)
# %% Encode the decoded files (each distinct file once; unreadable files get missing values)
status <- cs_media_status(media, media_ids)
ok <- is.na(status)
if (!any(ok)) {
first <- which(!ok)[1]
cs_media_fail(media, media_ids[first], status[first])
}
good <- media_ids[ok]
uniq <- unique(good)
E <- cs_encoder_embed(ENCODER, media, BATCH, ids = uniq)
X[ok, ] <- E[match(good, uniq), , drop = FALSE]
skipped <- which(!ok)
if (length(skipped)) {
warnings <- c(warnings, cs_warning("CS_W_MEDIA_SKIPPED", count = length(skipped), total = n,
file = as.character(df[[COLUMN]][skipped[1]])))
}
# %% Summary
Xo <- X[ok, , drop = FALSE]
norms <- sqrt(rowSums(Xo^2))
weights_grid <- outer(seq_len(nrow(Xo)) - 1, seq_len(d) - 1, function(i, j) ((i * 31 + j * 7) %% 13) + 1)
values <- list(
n_rows = n_input,
n_encoded = sum(ok),
n_skipped = sum(!ok),
dim = d,
encoder = enc$label,
modality = enc$modality,
mean_norm = mean(norms),
checksum = sum(Xo * weights_grid)
)
for (j in seq_len(min(8, d))) values[[sprintf("mean[%d]", j)]] <- mean(Xo[, j])
emb <- data.frame(row = rows)
for (j in seq_len(d)) emb[[sprintf("emb_%d", j)]] <- X[, j]
nanoparquet::write_parquet(emb, file.path(out, "embedding.parquet"))
show <- min(10, n)
k_show <- min(4, d)
preview <- lapply(seq_len(show), function(k) {
rec <- list(row = rows[k] + 1L, value = substr(as.character(df[[COLUMN]][k]), 1, 80))
for (j in seq_len(k_show)) rec[[sprintf("emb_%d", j)]] <- if (ok[k]) X[k, j] else NA
rec
})
tables <- list(list(
key = "preview",
title = sprintf("First %d rows (first %d of %d features)", show, k_show, d),
columns = c(list(list(key = "row", label = "Row", type = "integer"), list(key = "value", label = COLUMN, type = "string")),
lapply(seq_len(k_show), function(j) list(key = sprintf("emb_%d", j), label = sprintf("Feature %d", j), type = "number"))),
rows = preview
))
summary <- paste0(values$n_encoded, " of ", values$n_rows, " rows were encoded with ", enc$label, " into ", d, " features each",
if (values$n_skipped > 0) paste0(" (", values$n_skipped, " files couldn't be decoded and got missing values)") else "",
"; the mean vector length is ", sprintf("%.3f", values$mean_norm), ".")
statistics <- list(
list(key = "n_encoded", label = "Rows encoded", value = values$n_encoded),
list(key = "dim", label = "Features per row", value = d),
list(key = "mean_norm", label = "Mean vector length", value = values$mean_norm)
)
cs_publish(list(
title = "Features from a pretrained model (images, audio, text)",
engine = cs_engine_info("nanoparquet", "jsonlite"),
n = sum(ok),
summary = summary,
statistics = statistics,
tables = tables,
values = values,
warnings = warnings,
artifacts = list(list(key = "embedding", path = file.path(out, "embedding.parquet"), format = "parquet",
title = "Features (one row per input row)"))
))
12 of 12 rows were encoded with Thumbnail pixels (8 × 8 gray) into 64 features each; the mean vector length is 3.797.
- Rows encoded
- 12
- Features per row
- 64
- Mean vector length
- 3.797
First 10 rows (first 4 of 64 features)
| Row | path | Feature 1 | Feature 2 | Feature 3 | Feature 4 |
|---|---|---|---|---|---|
| 1 | media/images/gradient_0.png | 0.6463 | 0.6402 | 0.6080 | 0.5460 |
| 2 | media/images/gradient_1.png | 0.5591 | 0.6064 | 0.6446 | 0.6627 |
| 3 | media/images/gradient_2.png | 0.6464 | 0.6465 | 0.6465 | 0.6465 |
| 4 | media/images/gradient_3.jpg | 0.4968 | 0.5356 | 0.5734 | 0.6045 |
| 5 | media/images/rings_0.png | 0.3228 | 0.4575 | 0.3293 | 0.3029 |
| 6 | media/images/rings_1.png | 0.3937 | 0.4636 | 0.4133 | 0.3725 |
| 7 | media/images/rings_2.png | 0.5617 | 0.4778 | 0.3287 | 0.2573 |
| 8 | media/images/rings_3.jpg | 0.3825 | 0.4545 | 0.4237 | 0.3860 |
| 9 | media/images/checker_0.png | 0.3513 | 0.6041 | 0.3959 | 0.6041 |
| 10 | media/images/checker_1.png | 0.3367 | 0.5516 | 0.5516 | 0.3780 |
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Features from a pretrained model (images, audio, text)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method transform.extract 1.0.0 · spec 0ffabb291139a11c
# Dataset: media_images (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash import encoders
from codesplash import ml as csml
COLUMN = "path"
ENCODER = "thumbnail"
BATCH = int(32)
# %% Data
df = pd.read_parquet("tests/parity/fixtures/media_images.parquet", columns=["path"])
n_input = len(df)
df["path"] = pd.Categorical(df["path"], categories=sorted(df["path"].dropna().unique()))
df = df.dropna(subset=["path"]) # listwise deletion over the analysis columns
df["path"] = df["path"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["path"]) # infinite values stop the run (registry/errors.yaml)
out = csml.out_dir("target/academy-parity/run-8142/transform.extract/images_thumbnail/out-python")
enc = encoders.get(ENCODER)
n, d = len(df), enc.dim
rows = df.index.to_numpy(dtype=np.int64) # each row's position in the input
X = np.full((n, d), np.nan)
ok = np.zeros(n, dtype=bool)
# %% Media files (image column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
import json as _media_json
from codesplash import media as cs_media
media = cs_media.setup(_media_json.loads("{\"ids_column\":\"media_id\",\"kind\":\"image\",\"path_column\":\"path\",\"role\":\"column\",\"transform\":{\"filter\":\"triangle\",\"fit\":\"stretch\",\"mode\":\"gray\",\"normalize\":\"none\",\"size\":[8,8]}}"), "target/academy-parity/run-8142/transform.extract/images_thumbnail/out-python", df, "tests/parity/fixtures/media_images.parquet")
media_ids = cs_media.ids_of(media, df)
# %% Encode the decoded files (each distinct file once; unreadable files get missing values)
status = cs_media.status(media, media_ids)
ok = np.array([s is None for s in status], dtype=bool)
if not ok.any():
first = int(np.flatnonzero(~ok)[0])
cs_media.fail(media, media_ids[first], status[first])
good = [m for m, o in zip(media_ids, ok) if o]
uniq = list(dict.fromkeys(good))
E = encoders.embed(ENCODER, media, BATCH, ids=uniq)
pos = {m: k for k, m in enumerate(uniq)}
X[ok] = E[[pos[m] for m in good]]
skipped = np.flatnonzero(~ok)
if len(skipped):
warnings.append(cs.cs_warning("CS_W_MEDIA_SKIPPED", count=int(len(skipped)), total=int(n),
file=str(df[COLUMN].iloc[int(skipped[0])])))
# %% Summary
Xo = X[ok]
norms = np.sqrt((Xo ** 2).sum(axis=1))
i_idx, j_idx = np.meshgrid(np.arange(Xo.shape[0]), np.arange(d), indexing="ij")
weights_grid = ((i_idx * 31 + j_idx * 7) % 13 + 1).astype(np.float64)
values = {
"n_rows": int(n_input),
"n_encoded": int(ok.sum()),
"n_skipped": int((~ok).sum()),
"dim": int(d),
"encoder": enc.label,
"modality": enc.modality,
"mean_norm": float(norms.mean()),
"checksum": float((Xo * weights_grid).sum()),
}
for j in range(min(8, d)):
values[f"mean[{j + 1}]"] = float(Xo[:, j].mean())
emb = pd.DataFrame({"row": rows})
for j in range(d):
emb[f"emb_{j + 1}"] = pd.array(X[:, j], dtype="Float64")
emb.to_parquet(f"{out}/embedding.parquet", index=False)
show = min(10, n)
k_show = min(4, d)
preview = []
for k in range(show):
rec = {"row": int(rows[k]) + 1, "value": str(df[COLUMN].iloc[k])[:80]}
for j in range(k_show):
rec[f"emb_{j + 1}"] = None if not ok[k] else float(X[k, j])
preview.append(rec)
tables = [{
"key": "preview",
"title": f"First {show} rows (first {k_show} of {d} features)",
"columns": [{"key": "row", "label": "Row", "type": "integer"}, {"key": "value", "label": COLUMN, "type": "string"}]
+ [{"key": f"emb_{j + 1}", "label": f"Feature {j + 1}", "type": "number"} for j in range(k_show)],
"rows": preview,
}]
summary = (f"{values['n_encoded']} of {values['n_rows']} rows were encoded with {enc.label} into {d} features each"
+ (f" ({values['n_skipped']} files couldn't be decoded and got missing values)" if values["n_skipped"] else "")
+ f"; the mean vector length is {values['mean_norm']:.3f}.")
statistics = [
{"key": "n_encoded", "label": "Rows encoded", "value": values["n_encoded"]},
{"key": "dim", "label": "Features per row", "value": d},
{"key": "mean_norm", "label": "Mean vector length", "value": values["mean_norm"]},
]
cs.publish({
"title": "Features from a pretrained model (images, audio, text)",
"engine": cs.engine_info("numpy", "pandas"),
"n": int(ok.sum()),
"summary": summary,
"statistics": statistics,
"tables": tables,
"values": values,
"warnings": warnings,
"artifacts": [{"key": "embedding", "path": f"{out}/embedding.parquet", "format": "parquet", "title": "Features (one row per input row)"}],
})
Before any model runs, the app turns each file into a media tensorMedia tensorAn image or sound decoded into numbers (pixels or samples) the same way every time, cached by the file's content.. Images are turned upright, resized with a fixed filter and scaled to 0–1 (the image transformImage transformHow an image becomes a fixed grid: orientation, resize (stretch, crop or letterbox), gray or color, and scaling of values.). The image profile works the other way: it measures each picture as stored. Clips are mixed to mono and resampledAudio resamplingChanging a recording's sample rate (for example to 16 kHz) with a low-pass filter so no false tones appear; stereo is averaged to mono. to 16 kHz.
This happens once per file and setting, then both Python and R read the same numbers. Here 12 images were encoded.
Check yourself
Why does the app decode each file once and give both engines the same arrays?
Show the answer
Answer: b
Shared decoding means any difference between engines comes from the model code, not from preprocessing. It also avoids decoding the same file in every run.
Sounds too
Explore9 of 9 rows were encoded with Loudness envelope (32 parts) into 32 features each; the mean vector length is 1.669.
- Rows encoded
- 9
- Features per row
- 32
- Mean vector length
- 1.669
First 9 rows (first 4 of 32 features)
| Row | path | Feature 1 | Feature 2 | Feature 3 | Feature 4 |
|---|---|---|---|---|---|
| 1 | media/audio/tone_0.wav | 0.1565 | 0.3836 | 0.4225 | 0.4206 |
| 2 | media/audio/tone_1.wav | 0.1552 | 0.3783 | 0.4222 | 0.4271 |
| 3 | media/audio/tone_2.wav | 0.1522 | 0.3806 | 0.4234 | 0.4251 |
| 4 | media/audio/chirp_0.wav | 0.3570 | 0.3483 | 0.3527 | 0.3584 |
| 5 | media/audio/chirp_1.wav | 0.3526 | 0.3536 | 0.3535 | 0.3541 |
| 6 | media/audio/chirp_2_stereo.wav | 0.2075 | 0.2015 | 0.2094 | 0.2039 |
| 7 | media/audio/noise_0.wav | 0.2033 | 0.1814 | 0.1985 | 0.1880 |
| 8 | media/audio/noise_1.wav | 0.1514 | 0.1405 | 0.1420 | 0.1299 |
| 9 | media/audio/noise_2_float.wav | 0.1459 | 0.1492 | 0.1380 | 0.1456 |
The exact R script · R R version 4.5.1 (2025-06-13)
# Features from a pretrained model (images, audio, text)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method transform.extract 1.0.0 · spec 914febf7800edc35
# Dataset: media_audio (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
COLUMN <- "path"
ENCODER <- "loudness_envelope"
BATCH <- as.integer(4)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/media_audio.parquet", col_select = c("path")))
n_input <- nrow(df)
df[["path"]] <- factor(df[["path"]], levels = sort(unique(df[["path"]]), method = "radix"))
df <- df[stats::complete.cases(df[c("path")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("path")) # infinite values stop the run (registry/errors.yaml)
out <- cs_ml_out_dir("target/academy-parity/run-8142/transform.extract/audio_loudness_envelope/out-r")
enc <- cs_encoder_get(ENCODER)
if (!("r" %in% enc$engines)) stop(sprintf("%s runs in Python only; choose another encoder in R.", enc$label), call. = FALSE)
n <- nrow(df); d <- enc$dim
rows <- as.integer(rownames(df)) - 1L # each row's position in the input
X <- matrix(NA_real_, n, d)
ok <- rep(FALSE, n)
# %% Media files (audio column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
media <- cs_media_setup(jsonlite::fromJSON("{\"ids_column\":\"media_id\",\"kind\":\"audio\",\"path_column\":\"path\",\"role\":\"column\",\"transform\":{\"max_seconds\":null,\"mono\":true,\"offset_seconds\":0,\"sample_rate\":16000}}", simplifyVector = FALSE), "target/academy-parity/run-8142/transform.extract/audio_loudness_envelope/out-r", df,
"tests/parity/fixtures/media_audio.parquet")
media_ids <- cs_media_ids(media, df)
# %% Encode the decoded files (each distinct file once; unreadable files get missing values)
status <- cs_media_status(media, media_ids)
ok <- is.na(status)
if (!any(ok)) {
first <- which(!ok)[1]
cs_media_fail(media, media_ids[first], status[first])
}
good <- media_ids[ok]
uniq <- unique(good)
E <- cs_encoder_embed(ENCODER, media, BATCH, ids = uniq)
X[ok, ] <- E[match(good, uniq), , drop = FALSE]
skipped <- which(!ok)
if (length(skipped)) {
warnings <- c(warnings, cs_warning("CS_W_MEDIA_SKIPPED", count = length(skipped), total = n,
file = as.character(df[[COLUMN]][skipped[1]])))
}
# %% Summary
Xo <- X[ok, , drop = FALSE]
norms <- sqrt(rowSums(Xo^2))
weights_grid <- outer(seq_len(nrow(Xo)) - 1, seq_len(d) - 1, function(i, j) ((i * 31 + j * 7) %% 13) + 1)
values <- list(
n_rows = n_input,
n_encoded = sum(ok),
n_skipped = sum(!ok),
dim = d,
encoder = enc$label,
modality = enc$modality,
mean_norm = mean(norms),
checksum = sum(Xo * weights_grid)
)
for (j in seq_len(min(8, d))) values[[sprintf("mean[%d]", j)]] <- mean(Xo[, j])
emb <- data.frame(row = rows)
for (j in seq_len(d)) emb[[sprintf("emb_%d", j)]] <- X[, j]
nanoparquet::write_parquet(emb, file.path(out, "embedding.parquet"))
show <- min(10, n)
k_show <- min(4, d)
preview <- lapply(seq_len(show), function(k) {
rec <- list(row = rows[k] + 1L, value = substr(as.character(df[[COLUMN]][k]), 1, 80))
for (j in seq_len(k_show)) rec[[sprintf("emb_%d", j)]] <- if (ok[k]) X[k, j] else NA
rec
})
tables <- list(list(
key = "preview",
title = sprintf("First %d rows (first %d of %d features)", show, k_show, d),
columns = c(list(list(key = "row", label = "Row", type = "integer"), list(key = "value", label = COLUMN, type = "string")),
lapply(seq_len(k_show), function(j) list(key = sprintf("emb_%d", j), label = sprintf("Feature %d", j), type = "number"))),
rows = preview
))
summary <- paste0(values$n_encoded, " of ", values$n_rows, " rows were encoded with ", enc$label, " into ", d, " features each",
if (values$n_skipped > 0) paste0(" (", values$n_skipped, " files couldn't be decoded and got missing values)") else "",
"; the mean vector length is ", sprintf("%.3f", values$mean_norm), ".")
statistics <- list(
list(key = "n_encoded", label = "Rows encoded", value = values$n_encoded),
list(key = "dim", label = "Features per row", value = d),
list(key = "mean_norm", label = "Mean vector length", value = values$mean_norm)
)
cs_publish(list(
title = "Features from a pretrained model (images, audio, text)",
engine = cs_engine_info("nanoparquet", "jsonlite"),
n = sum(ok),
summary = summary,
statistics = statistics,
tables = tables,
values = values,
warnings = warnings,
artifacts = list(list(key = "embedding", path = file.path(out, "embedding.parquet"), format = "parquet",
title = "Features (one row per input row)"))
))
9 of 9 rows were encoded with Loudness envelope (32 parts) into 32 features each; the mean vector length is 1.669.
- Rows encoded
- 9
- Features per row
- 32
- Mean vector length
- 1.669
First 9 rows (first 4 of 32 features)
| Row | path | Feature 1 | Feature 2 | Feature 3 | Feature 4 |
|---|---|---|---|---|---|
| 1 | media/audio/tone_0.wav | 0.1565 | 0.3836 | 0.4225 | 0.4206 |
| 2 | media/audio/tone_1.wav | 0.1552 | 0.3783 | 0.4222 | 0.4271 |
| 3 | media/audio/tone_2.wav | 0.1522 | 0.3806 | 0.4234 | 0.4251 |
| 4 | media/audio/chirp_0.wav | 0.3570 | 0.3483 | 0.3527 | 0.3584 |
| 5 | media/audio/chirp_1.wav | 0.3526 | 0.3536 | 0.3535 | 0.3541 |
| 6 | media/audio/chirp_2_stereo.wav | 0.2075 | 0.2015 | 0.2094 | 0.2039 |
| 7 | media/audio/noise_0.wav | 0.2033 | 0.1814 | 0.1985 | 0.1880 |
| 8 | media/audio/noise_1.wav | 0.1514 | 0.1405 | 0.1420 | 0.1299 |
| 9 | media/audio/noise_2_float.wav | 0.1459 | 0.1492 | 0.1380 | 0.1456 |
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Features from a pretrained model (images, audio, text)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method transform.extract 1.0.0 · spec 914febf7800edc35
# Dataset: media_audio (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash import encoders
from codesplash import ml as csml
COLUMN = "path"
ENCODER = "loudness_envelope"
BATCH = int(4)
# %% Data
df = pd.read_parquet("tests/parity/fixtures/media_audio.parquet", columns=["path"])
n_input = len(df)
df["path"] = pd.Categorical(df["path"], categories=sorted(df["path"].dropna().unique()))
df = df.dropna(subset=["path"]) # listwise deletion over the analysis columns
df["path"] = df["path"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["path"]) # infinite values stop the run (registry/errors.yaml)
out = csml.out_dir("target/academy-parity/run-8142/transform.extract/audio_loudness_envelope/out-python")
enc = encoders.get(ENCODER)
n, d = len(df), enc.dim
rows = df.index.to_numpy(dtype=np.int64) # each row's position in the input
X = np.full((n, d), np.nan)
ok = np.zeros(n, dtype=bool)
# %% Media files (audio column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
import json as _media_json
from codesplash import media as cs_media
media = cs_media.setup(_media_json.loads("{\"ids_column\":\"media_id\",\"kind\":\"audio\",\"path_column\":\"path\",\"role\":\"column\",\"transform\":{\"max_seconds\":null,\"mono\":true,\"offset_seconds\":0,\"sample_rate\":16000}}"), "target/academy-parity/run-8142/transform.extract/audio_loudness_envelope/out-python", df, "tests/parity/fixtures/media_audio.parquet")
media_ids = cs_media.ids_of(media, df)
# %% Encode the decoded files (each distinct file once; unreadable files get missing values)
status = cs_media.status(media, media_ids)
ok = np.array([s is None for s in status], dtype=bool)
if not ok.any():
first = int(np.flatnonzero(~ok)[0])
cs_media.fail(media, media_ids[first], status[first])
good = [m for m, o in zip(media_ids, ok) if o]
uniq = list(dict.fromkeys(good))
E = encoders.embed(ENCODER, media, BATCH, ids=uniq)
pos = {m: k for k, m in enumerate(uniq)}
X[ok] = E[[pos[m] for m in good]]
skipped = np.flatnonzero(~ok)
if len(skipped):
warnings.append(cs.cs_warning("CS_W_MEDIA_SKIPPED", count=int(len(skipped)), total=int(n),
file=str(df[COLUMN].iloc[int(skipped[0])])))
# %% Summary
Xo = X[ok]
norms = np.sqrt((Xo ** 2).sum(axis=1))
i_idx, j_idx = np.meshgrid(np.arange(Xo.shape[0]), np.arange(d), indexing="ij")
weights_grid = ((i_idx * 31 + j_idx * 7) % 13 + 1).astype(np.float64)
values = {
"n_rows": int(n_input),
"n_encoded": int(ok.sum()),
"n_skipped": int((~ok).sum()),
"dim": int(d),
"encoder": enc.label,
"modality": enc.modality,
"mean_norm": float(norms.mean()),
"checksum": float((Xo * weights_grid).sum()),
}
for j in range(min(8, d)):
values[f"mean[{j + 1}]"] = float(Xo[:, j].mean())
emb = pd.DataFrame({"row": rows})
for j in range(d):
emb[f"emb_{j + 1}"] = pd.array(X[:, j], dtype="Float64")
emb.to_parquet(f"{out}/embedding.parquet", index=False)
show = min(10, n)
k_show = min(4, d)
preview = []
for k in range(show):
rec = {"row": int(rows[k]) + 1, "value": str(df[COLUMN].iloc[k])[:80]}
for j in range(k_show):
rec[f"emb_{j + 1}"] = None if not ok[k] else float(X[k, j])
preview.append(rec)
tables = [{
"key": "preview",
"title": f"First {show} rows (first {k_show} of {d} features)",
"columns": [{"key": "row", "label": "Row", "type": "integer"}, {"key": "value", "label": COLUMN, "type": "string"}]
+ [{"key": f"emb_{j + 1}", "label": f"Feature {j + 1}", "type": "number"} for j in range(k_show)],
"rows": preview,
}]
summary = (f"{values['n_encoded']} of {values['n_rows']} rows were encoded with {enc.label} into {d} features each"
+ (f" ({values['n_skipped']} files couldn't be decoded and got missing values)" if values["n_skipped"] else "")
+ f"; the mean vector length is {values['mean_norm']:.3f}.")
statistics = [
{"key": "n_encoded", "label": "Rows encoded", "value": values["n_encoded"]},
{"key": "dim", "label": "Features per row", "value": d},
{"key": "mean_norm", "label": "Mean vector length", "value": values["mean_norm"]},
]
cs.publish({
"title": "Features from a pretrained model (images, audio, text)",
"engine": cs.engine_info("numpy", "pandas"),
"n": int(ok.sum()),
"summary": summary,
"statistics": statistics,
"tables": tables,
"values": values,
"warnings": warnings,
"artifacts": [{"key": "embedding", "path": f"{out}/embedding.parquet", "format": "parquet", "title": "Features (one row per input row)"}],
})
The loudness envelope measures how loud each of 32 equal parts of a clip is. It's a quick baseline: a tone, a sweep and noise rise and fall differently. Each clip gets 32 features.
Files that can't be read
Checkpoint4 of 6 rows were encoded with Thumbnail pixels (8 × 8 gray) into 64 features each (2 files couldn't be decoded and got missing values); the mean vector length is 4.127.
- Rows encoded
- 4
- Features per row
- 64
- Mean vector length
- 4.127
First 6 rows (first 4 of 64 features)
| Row | path | Feature 1 | Feature 2 | Feature 3 | Feature 4 |
|---|---|---|---|---|---|
| 1 | media/images/gradient_0.png | 0.6463 | 0.6402 | 0.6080 | 0.5460 |
| 2 | media/images/gradient_1.png | 0.5591 | 0.6064 | 0.6446 | 0.6627 |
| 3 | media/images/gradient_2.png | 0.6464 | 0.6465 | 0.6465 | 0.6465 |
| 4 | media/images/gradient_3.jpg | 0.4968 | 0.5356 | 0.5734 | 0.6045 |
| 5 | media/images/broken.png | — | — | — | — |
| 6 | media/images/notes.txt | — | — | — | — |
- 2 of 6 files couldn't be decoded, so their rows got missing values (first: media/images/broken.png).
The exact R script · R R version 4.5.1 (2025-06-13)
# Features from a pretrained model (images, audio, text)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method transform.extract 1.0.0 · spec 16142882b349c3af
# Dataset: media_images_bad (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
COLUMN <- "path"
ENCODER <- "thumbnail"
BATCH <- as.integer(32)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/media_images_bad.parquet", col_select = c("path")))
n_input <- nrow(df)
df[["path"]] <- factor(df[["path"]], levels = sort(unique(df[["path"]]), method = "radix"))
df <- df[stats::complete.cases(df[c("path")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("path")) # infinite values stop the run (registry/errors.yaml)
out <- cs_ml_out_dir("target/academy-parity/run-8142/transform.extract/images_some_unreadable/out-r")
enc <- cs_encoder_get(ENCODER)
if (!("r" %in% enc$engines)) stop(sprintf("%s runs in Python only; choose another encoder in R.", enc$label), call. = FALSE)
n <- nrow(df); d <- enc$dim
rows <- as.integer(rownames(df)) - 1L # each row's position in the input
X <- matrix(NA_real_, n, d)
ok <- rep(FALSE, n)
# %% Media files (image column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
media <- cs_media_setup(jsonlite::fromJSON("{\"ids_column\":\"media_id\",\"kind\":\"image\",\"path_column\":\"path\",\"role\":\"column\",\"transform\":{\"filter\":\"triangle\",\"fit\":\"stretch\",\"mode\":\"gray\",\"normalize\":\"none\",\"size\":[8,8]}}", simplifyVector = FALSE), "target/academy-parity/run-8142/transform.extract/images_some_unreadable/out-r", df,
"tests/parity/fixtures/media_images_bad.parquet")
media_ids <- cs_media_ids(media, df)
# %% Encode the decoded files (each distinct file once; unreadable files get missing values)
status <- cs_media_status(media, media_ids)
ok <- is.na(status)
if (!any(ok)) {
first <- which(!ok)[1]
cs_media_fail(media, media_ids[first], status[first])
}
good <- media_ids[ok]
uniq <- unique(good)
E <- cs_encoder_embed(ENCODER, media, BATCH, ids = uniq)
X[ok, ] <- E[match(good, uniq), , drop = FALSE]
skipped <- which(!ok)
if (length(skipped)) {
warnings <- c(warnings, cs_warning("CS_W_MEDIA_SKIPPED", count = length(skipped), total = n,
file = as.character(df[[COLUMN]][skipped[1]])))
}
# %% Summary
Xo <- X[ok, , drop = FALSE]
norms <- sqrt(rowSums(Xo^2))
weights_grid <- outer(seq_len(nrow(Xo)) - 1, seq_len(d) - 1, function(i, j) ((i * 31 + j * 7) %% 13) + 1)
values <- list(
n_rows = n_input,
n_encoded = sum(ok),
n_skipped = sum(!ok),
dim = d,
encoder = enc$label,
modality = enc$modality,
mean_norm = mean(norms),
checksum = sum(Xo * weights_grid)
)
for (j in seq_len(min(8, d))) values[[sprintf("mean[%d]", j)]] <- mean(Xo[, j])
emb <- data.frame(row = rows)
for (j in seq_len(d)) emb[[sprintf("emb_%d", j)]] <- X[, j]
nanoparquet::write_parquet(emb, file.path(out, "embedding.parquet"))
show <- min(10, n)
k_show <- min(4, d)
preview <- lapply(seq_len(show), function(k) {
rec <- list(row = rows[k] + 1L, value = substr(as.character(df[[COLUMN]][k]), 1, 80))
for (j in seq_len(k_show)) rec[[sprintf("emb_%d", j)]] <- if (ok[k]) X[k, j] else NA
rec
})
tables <- list(list(
key = "preview",
title = sprintf("First %d rows (first %d of %d features)", show, k_show, d),
columns = c(list(list(key = "row", label = "Row", type = "integer"), list(key = "value", label = COLUMN, type = "string")),
lapply(seq_len(k_show), function(j) list(key = sprintf("emb_%d", j), label = sprintf("Feature %d", j), type = "number"))),
rows = preview
))
summary <- paste0(values$n_encoded, " of ", values$n_rows, " rows were encoded with ", enc$label, " into ", d, " features each",
if (values$n_skipped > 0) paste0(" (", values$n_skipped, " files couldn't be decoded and got missing values)") else "",
"; the mean vector length is ", sprintf("%.3f", values$mean_norm), ".")
statistics <- list(
list(key = "n_encoded", label = "Rows encoded", value = values$n_encoded),
list(key = "dim", label = "Features per row", value = d),
list(key = "mean_norm", label = "Mean vector length", value = values$mean_norm)
)
cs_publish(list(
title = "Features from a pretrained model (images, audio, text)",
engine = cs_engine_info("nanoparquet", "jsonlite"),
n = sum(ok),
summary = summary,
statistics = statistics,
tables = tables,
values = values,
warnings = warnings,
artifacts = list(list(key = "embedding", path = file.path(out, "embedding.parquet"), format = "parquet",
title = "Features (one row per input row)"))
))
4 of 6 rows were encoded with Thumbnail pixels (8 × 8 gray) into 64 features each (2 files couldn't be decoded and got missing values); the mean vector length is 4.127.
- Rows encoded
- 4
- Features per row
- 64
- Mean vector length
- 4.127
First 6 rows (first 4 of 64 features)
| Row | path | Feature 1 | Feature 2 | Feature 3 | Feature 4 |
|---|---|---|---|---|---|
| 1 | media/images/gradient_0.png | 0.6463 | 0.6402 | 0.6080 | 0.5460 |
| 2 | media/images/gradient_1.png | 0.5591 | 0.6064 | 0.6446 | 0.6627 |
| 3 | media/images/gradient_2.png | 0.6464 | 0.6465 | 0.6465 | 0.6465 |
| 4 | media/images/gradient_3.jpg | 0.4968 | 0.5356 | 0.5734 | 0.6045 |
| 5 | media/images/broken.png | — | — | — | — |
| 6 | media/images/notes.txt | — | — | — | — |
- 2 of 6 files couldn't be decoded, so their rows got missing values (first: media/images/broken.png).
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Features from a pretrained model (images, audio, text)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method transform.extract 1.0.0 · spec 16142882b349c3af
# Dataset: media_images_bad (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash import encoders
from codesplash import ml as csml
COLUMN = "path"
ENCODER = "thumbnail"
BATCH = int(32)
# %% Data
df = pd.read_parquet("tests/parity/fixtures/media_images_bad.parquet", columns=["path"])
n_input = len(df)
df["path"] = pd.Categorical(df["path"], categories=sorted(df["path"].dropna().unique()))
df = df.dropna(subset=["path"]) # listwise deletion over the analysis columns
df["path"] = df["path"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["path"]) # infinite values stop the run (registry/errors.yaml)
out = csml.out_dir("target/academy-parity/run-8142/transform.extract/images_some_unreadable/out-python")
enc = encoders.get(ENCODER)
n, d = len(df), enc.dim
rows = df.index.to_numpy(dtype=np.int64) # each row's position in the input
X = np.full((n, d), np.nan)
ok = np.zeros(n, dtype=bool)
# %% Media files (image column path)
# In the app the files were decoded once into float32 arrays (media.json in the run folder). Elsewhere they are
# decoded here the same way: PNG and WAV give the app's values; JPEG, MP3 and other lossy files can differ slightly.
import json as _media_json
from codesplash import media as cs_media
media = cs_media.setup(_media_json.loads("{\"ids_column\":\"media_id\",\"kind\":\"image\",\"path_column\":\"path\",\"role\":\"column\",\"transform\":{\"filter\":\"triangle\",\"fit\":\"stretch\",\"mode\":\"gray\",\"normalize\":\"none\",\"size\":[8,8]}}"), "target/academy-parity/run-8142/transform.extract/images_some_unreadable/out-python", df, "tests/parity/fixtures/media_images_bad.parquet")
media_ids = cs_media.ids_of(media, df)
# %% Encode the decoded files (each distinct file once; unreadable files get missing values)
status = cs_media.status(media, media_ids)
ok = np.array([s is None for s in status], dtype=bool)
if not ok.any():
first = int(np.flatnonzero(~ok)[0])
cs_media.fail(media, media_ids[first], status[first])
good = [m for m, o in zip(media_ids, ok) if o]
uniq = list(dict.fromkeys(good))
E = encoders.embed(ENCODER, media, BATCH, ids=uniq)
pos = {m: k for k, m in enumerate(uniq)}
X[ok] = E[[pos[m] for m in good]]
skipped = np.flatnonzero(~ok)
if len(skipped):
warnings.append(cs.cs_warning("CS_W_MEDIA_SKIPPED", count=int(len(skipped)), total=int(n),
file=str(df[COLUMN].iloc[int(skipped[0])])))
# %% Summary
Xo = X[ok]
norms = np.sqrt((Xo ** 2).sum(axis=1))
i_idx, j_idx = np.meshgrid(np.arange(Xo.shape[0]), np.arange(d), indexing="ij")
weights_grid = ((i_idx * 31 + j_idx * 7) % 13 + 1).astype(np.float64)
values = {
"n_rows": int(n_input),
"n_encoded": int(ok.sum()),
"n_skipped": int((~ok).sum()),
"dim": int(d),
"encoder": enc.label,
"modality": enc.modality,
"mean_norm": float(norms.mean()),
"checksum": float((Xo * weights_grid).sum()),
}
for j in range(min(8, d)):
values[f"mean[{j + 1}]"] = float(Xo[:, j].mean())
emb = pd.DataFrame({"row": rows})
for j in range(d):
emb[f"emb_{j + 1}"] = pd.array(X[:, j], dtype="Float64")
emb.to_parquet(f"{out}/embedding.parquet", index=False)
show = min(10, n)
k_show = min(4, d)
preview = []
for k in range(show):
rec = {"row": int(rows[k]) + 1, "value": str(df[COLUMN].iloc[k])[:80]}
for j in range(k_show):
rec[f"emb_{j + 1}"] = None if not ok[k] else float(X[k, j])
preview.append(rec)
tables = [{
"key": "preview",
"title": f"First {show} rows (first {k_show} of {d} features)",
"columns": [{"key": "row", "label": "Row", "type": "integer"}, {"key": "value", "label": COLUMN, "type": "string"}]
+ [{"key": f"emb_{j + 1}", "label": f"Feature {j + 1}", "type": "number"} for j in range(k_show)],
"rows": preview,
}]
summary = (f"{values['n_encoded']} of {values['n_rows']} rows were encoded with {enc.label} into {d} features each"
+ (f" ({values['n_skipped']} files couldn't be decoded and got missing values)" if values["n_skipped"] else "")
+ f"; the mean vector length is {values['mean_norm']:.3f}.")
statistics = [
{"key": "n_encoded", "label": "Rows encoded", "value": values["n_encoded"]},
{"key": "dim", "label": "Features per row", "value": d},
{"key": "mean_norm", "label": "Mean vector length", "value": values["mean_norm"]},
]
cs.publish({
"title": "Features from a pretrained model (images, audio, text)",
"engine": cs.engine_info("numpy", "pandas"),
"n": int(ok.sum()),
"summary": summary,
"statistics": statistics,
"tables": tables,
"values": values,
"warnings": warnings,
"artifacts": [{"key": "embedding", "path": f"{out}/embedding.parquet", "format": "parquet", "title": "Features (one row per input row)"}],
})
A damaged image or a text file can't become pixels. Those rows get missing features and the run says how many: 2 here.
Check yourself
Two files in a folder couldn't be decoded. What happens to their rows?
Show the answer
Answer: b
Filling in an average would invent data. Missing values keep the gap visible, so you can fix the files or filter the rows.
Check yourself
You save features from a frozen encoder and train a classifier on them. Can test rows leak into training through the features?
Show the answer
Answer: a
A frozen encoder is a fixed function of each file. Features learned from all rows (like a map fitted on every row) would be different.
Do it on your own data
In the appAdd an image or audio folder in Data (the files stay where they are), then open Features from a pretrained model in Discover. Pick an encoder made for the column's data, run it, and use Save to dataset to add <column>_emb_1 … columns. Pretrained encoders ask before their one-time download.
from codesplash import encoders, media as cs_media
media = cs_media.setup({"path_column": "path", "kind": "image",
"transform": {"size": [8, 8], "mode": "gray"}}, df=df)
ids = cs_media.ids_of(media, df)
X = encoders.embed("thumbnail", media, ids=ids) # (n, 64)library(codesplashr)
media <- cs_media_setup(list(path_column = "path", kind = "image",
transform = list(size = c(8, 8), mode = "gray")), df = df)
ids <- cs_media_ids(media, df)
X <- cs_encoder_embed("thumbnail", media, ids = ids) # n x 64Recap
Recap- A frozen encoder turns each file or text into a vector without learning from your rows.
- The app decodes each file once with fixed settings; Python and R read identical arrays. Exported code decodes PNG and WAV the same way, JPEG and MP3 can differ slightly.
- Unreadable files get missing features and are counted, never filled in.
Concepts in this lesson