PythiloLesson 10 of 12 · progress kept in this browser

Bind model bytes to ordered features and preprocessing

A weights file alone does not identify a reproducible predictor. Feature order, preprocessing version and schema determine how those weights are used. Compute an artifact identifier from a canonical metadata representation and a digest of the exact weight bytes.

Dictionary key ordering should not change identity, but changing feature order must change it. This is content identity, not proof of who produced an artifact. A trusted registry or authenticated signature supplies provenance. Do not load arbitrary serialized Python objects merely because their bytes have a matching locally supplied hash.

import hashlib,json
metadata={"features":["a","b"],"pipeline":"v1"}
encoded=json.dumps(metadata,sort_keys=True,separators=(",",":")).encode()
print(hashlib.sha256(encoded).hexdigest()[:12])
Your task

Implement model_identity(weights,features,pipeline) returning SHA256 hex of canonical UTF-8 JSON {weights_sha256,features,pipeline}, sort_keys=True,separators=(",",":"),ensure_ascii=False. Feature order matters; require distinct feature names.