For the complete documentation index, see llms.txt. This page is also available as Markdown.

Serialization

Data serialization in DataVec — saving and loading schemas, transform processes, and normalized data

DataVec's serialization support lets you save your data pipeline definitions and normalizer statistics so they can be reloaded in production without rerunning analysis or redefining transforms in code.

The three objects you typically need to serialize are:

  1. Schema — the column layout description

  2. TransformProcess — the ordered list of transforms

  3. Normalizer — fitted mean/std or min/max statistics

Serializing a TransformProcess

TransformProcess serializes to JSON or YAML. The result captures every transform step and can be written to a file or database.

// Serialize
String json = tp.toJson();
String yaml = tp.toYaml();

// Write to file
Files.write(Paths.get("transform_process.json"), json.getBytes(StandardCharsets.UTF_8));

// Deserialize
String savedJson = new String(Files.readAllBytes(Paths.get("transform_process.json")));
TransformProcess loaded = TransformProcess.fromJson(savedJson);
TransformProcess loadedYaml = TransformProcess.fromYaml(yaml);

The JSON includes the full schema and every transform step with all parameters. It is human-readable and can be version-controlled alongside your model artifacts.

JsonSerializer and YamlSerializer

For lower-level serialization of individual DataVec objects (transforms, conditions, filters):

These serializers handle DataVec's polymorphic object model by embedding type information in the JSON/YAML output.

Serializing a Schema

Serializing Normalizers

Normalizers hold the statistics computed during fit(). Two approaches are available.

NormalizerSerializer supports all normalizer types and detects the type automatically during restore.

ModelSerializer (Bundle with Model)

The easiest approach for production is to bundle the normalizer with the model file:

Bundling keeps preprocessing and model weights in a single artifact, reducing the risk of version mismatches.

Full Pipeline Serialization Pattern

What to Save

Artifact
Why

schema.json

Describes expected input columns and types

transform.json

Defines preprocessing steps

model.zip

Contains model weights and embedded normalizer

If you used the normalize() step inside TransformProcess, also save the DataAnalysis object that was passed to it, as it contains the statistics used for that normalization.

Last updated

Was this helpful?