How a recipe becomes a row
Think of an average biopharmaceutical formulation and you will think of a recipe: 20 mM histidine, 8% sucrose, 0.02% polysorbate 80, pH 5.5. Great for a human, not much use for a predictive model which requires a row of numbers. As a consequence, everything it can and cannot learn about that formulation will be influenced by the chosen translation approach, usually long before anyone fits anything.
An encoding which seems obvious but leads nowhere
Imagine treating a formulation as a label: assign an integer to each formulation and put it in a column. That column now claims formulation 7 sits between 6 and 8 which tells us nothing. What about one-hot encoding? One column per formulation with a single 1 per row, not much use either.
With 642 formulations that produces 642 columns and there is an even deeper problem: nothing transfers. A formulation the model has not seen is a row of zeros, the composition it shares with familiar ones stays invisible - identity was encoded but composition never was.
Picture a supermarket that gives every pre-made meal its own barcode and records nothing else. It can tell you what sold but it cannot answer which meals contain nuts because the question is about ingredients and the data was encoded with regard to identities.
The data model is the encoding
How do we solve the problem? AssayVault decomposes formulations through a bridge table against a shared excipient dimension. Each formulation becomes a set of components with concentrations which in matrix form is a multi-hot encoding carrying magnitudes. One column per excipient, holding an amount rather than a bare 1.
Two things follow naturally. “Which formulations contain polysorbate 80 above 0.01%” becomes a straightforward query. Secondly, a formulation nobody has run before suddenly becomes representable: it is just a new combination of columns that already exist. The downstream risk model profits as well and gets to score a candidate composition because it will know about the composition instead of the identity.
Different categories require different treatment
Picture the three storage conditions of a typical stability study: 5, 25 and 40 °C. How do we encode them? Three encodings are available that make different claims:
- One-hot treats them as three unrelated states. It learns each condition separately and cannot interpolate between them.
- Ordinal (0, 1, 2) assumes the steps are equally spaced which is false as well.
- Numeric (the temperature itself) claims the effect varies with temperature which is the relationship we are looking for: degradation kinetics depend on temperature and the Arrhenius relationship is the reason an accelerated condition says anything about a long-term one.
Numeric is right for temperature and wrong for the quality attribute, where aggregation, fragmentation and potency have no order at all and one-hot is the honest form.
Choose the encoding approach carefully
Target encoding replaces a category with the mean outcome for that category. It is compact, it often works, and it is the easiest way to leak. Computed across the whole dataset it puts the answer into the feature. What about limiting its computation to the training fold? That still carries information about the group which under grouped data is the failure mode described in Your random split is lying to you.
All of the above leads to one thing worth considering before any fitting starts. An encoding is a claim about which things are comparable. That claim needs to be checked carefully against the domain since the model cannot check it for you.
This is the first of three notes on the same move in three different projects. Next: How a molecule becomes a vector and How a page becomes a vector.