The Number Was Valid, but It Meant Something Else
An Interface Can Carry the Right Type in the Wrong Unit
BOTIE
Our temperature service has the same kind of disagreement on a smaller scale. The fitted model saved a Celsius reference, and the new sensor supplies Fahrenheit. We need a semantic contract: an agreement about what the values mean, including their units. Checking field names and numerical types comes first, but the model also needs the measurement expressed in the representation it learned.
Botie’s Temperature Suddenly Looks Dangerous
The sensor response passes its schema checks. It has the expected field, and the value is a finite number. Botie’s model nevertheless reports a much larger score than yesterday. The device started reporting Fahrenheit while the fitted preprocessing still expects Celsius.
The number’s type cannot tell us its unit. We need the meaning of the number to cross the boundary with it, and we need to convert it before using the model’s saved reference. Retrieval scores have a similar trap: a smaller distance can be better, while a larger similarity can be better.
The scores come from a supplied linear rule and have no calibrated probability meaning. This exercise checks conversion and calculation order; sensor calibration and predictive quality require other evidence.
Step 1 of 1
Two readings describe the same physical temperature
Convert to Celsius before using the fitted Celsius centre.
| Incoming value | Declared unit | Model input |
|---|---|---|
| 20 | C | 20 C |
| 68 | F | 20 C |
| 68 | No unit | Cannot infer safely |
20
- Declared unit
- C
- Model input
- 20 C
68
- Declared unit
- F
- Model input
- 20 C
68
- Declared unit
- No unit
- Model input
- Cannot infer safely
Attach a unit before comparing a value
After conversion, the saved centre and coefficient receive temperatures in their original Celsius unit. Equivalent physical readings therefore receive the same illustrative score.
Convert the request before using fitted state
Botie’s fitted Celsius model receives temperatures from a device that may report Fahrenheit.
BOTIE
Scores after conversion to the model’s training unit
- 032
- 152
Follow the operations
1. Incoming temperatures
- 020
- 130
2. Declared temperature unit
C
3. Read the temperature conversion scale
1
4. Multiply
- 020
- 130
5. Read the temperature conversion offset
0
6. Add
- 020
- 130
7. Saved training centre in Celsius
4
8. Subtract
- 016
- 126
9. Coefficient per centred Celsius degree
2
10. Multiply
- 032
- 152
11. Result
- 032
- 152
The scores come from a supplied linear rule and have no calibrated probability meaning. This exercise checks conversion and calculation order; sensor calibration and predictive quality require other evidence.
1. Attach a unit before comparing a value
Temperature in Celsius and temperature in Fahrenheit describe the same kind of quantity using different scales. The number needs its unit before another program can interpret it. A field called value leaves that information out; a documented unit field or a name such as temperature_c can make it explicit.
Guessing from the range is unreliable. Ordinary operating temperatures can produce plausible-looking numbers in either scale, so a range check may accept the value while the model interprets it incorrectly.
A version adapter can make a documented conversion. It should not silently reinterpret an unknown unit.
2. Convert before applying fitted state
The model’s reference temperature was learned in Celsius. Convert the request into that representation first, then subtract the saved centre and apply the coefficient. Reversing those operations changes what the centre means.
Temperature conversion needs an offset as well as a scale. Converting a temperature difference uses the scale without the absolute-temperature offset.
incoming temperature = 68 F
Celsius = (68 - 32) × (5 / 9) = 20 C
saved centre = 4 C
centred reading = 20 - 4 = 16
coefficient = 2
illustrative score = 16 × 2 = 32Both requests now reach the same Celsius input and produce the same illustrative score.
A complete conversion for an unseen measurement
This program converts an absolute temperature and centres it. The challenge adds accepted-unit and numerical-input checks.
fahrenheit = 50
celsius = (fahrenheit - 32) * 5 / 9
training_centre = 4
print(celsius)
print(celsius - training_centre)10.0
6.0Both resulting quantities are expressed relative to the Celsius representation used during fitting.
3. A valid shape can conceal a different score definition
A retrieval tool may return a number beside each passage. That number needs an explanation too. A Euclidean distance describes how far two representations are apart, so the smaller distance comes first. Cosine similarity measures how closely their vector directions align, so the larger similarity comes first. A descending sort cannot be correct for both meanings.
Record the metric and its ranking direction with the index version. A similarity is not automatically a probability of relevance. A probability would need a defined event and evidence that its claimed likelihood agrees with observed outcomes; a finite similarity score supplies neither by itself.
IDs = [A,B,C]
reported distances = [0.7,0.2,0.2]
order for smaller-is-better = [B,C,A]
first two IDs = [B,C]The equal-distance tie keeps the declared incoming order. The score stays attached to its passage ID.
Check yourself
Questions on Parts 1 to 3
Question 1 of 2
Which operation must happen before centring?
Use the information below.
A model’s fitted centre is 4 C. A request supplies 68 F.4. Name the normalisation a score assumes
Dot products, cosine similarities and squared distances are related only under stated assumptions. Cosine similarity divides by vector lengths. A zero vector needs an explicit policy because that division is undefined. Squaring a distance preserves its ordering, but changes its numerical scale and threshold meaning.
Do not transplant a threshold merely because two metrics return the same-shaped array. Keep the preprocessing, metric and threshold as one reviewed configuration.
This lesson’s ranking challenge takes an explicit ordering direction. It does not infer the metric or calibrate its threshold.
5. Validate a batch’s interpretation, not only its length
An array shape tells us how many entries exist, not which axis means examples, features or time. A batch of two examples with three features has a different contract from three examples with two features. A transpose can create a valid matrix that answers a different question.
Document feature names, axis meanings, units and numerical dtype beside the model input. Validate these before relying on broadcasting or a matrix multiplication.
The model’s first coefficient must receive the same named quantity, in the same unit and axis position, that it received during fitting.
6. Test equivalent representations at the boundary
Use two independently specified fixtures that describe the same physical input. Their canonical values and model predictions should agree within a justified numerical tolerance. Include a temperature where an offset matters; testing only a special point can hide a broken conversion.
For score adapters, use a case where the best score is the smallest, a negative-score case where larger is still better, and a tie. These fixtures expose meaning rather than checking only whether the function returned a list.
Equivalent representations must really describe the same situation. Arbitrary perturbations are not automatically prediction invariances.
7. Make an unsupported meaning visible
If a caller sends Kelvin to a C/F-only interface, reject it with an actionable error. Adding Kelvin support later requires an explicit conversion and tests; it does not require guessing today. Similarly, a retrieval response that omits its metric should not inherit an unrelated threshold by accident.
Track contract versions and model versions with incident reports so a discrepancy can be reproduced. Avoid logging complete private prompts merely to record which representation was in use.
When a device changes its calibration, review that assumption alongside the unit contract.
Check yourself
Questions on Parts 1 to 7
Question 1 of 4
Which IDs should remain?
Use the information below.
IDs[A,B,C] have distances[0.7,0.2,0.2]. Smaller is better; ties preserve input order; keep 2.Try it with Botie
Build with Botie
Write and run Python