TL;DR
Symlog is a function that takes any real number and returns a smaller one with the same sign. It is the natural logarithm of one plus the size of the number, multiplied by the sign: . Large values, positive or negative, get compressed. Values near zero pass through almost unchanged. Its inverse, symexp, turns predictions back into the original units.
Training a network on symlog-transformed targets lets one fixed loss work whether the targets are around 1 or around a million.
Where you'll see it: DreamerV3 uses symlog to scale observations, reward predictions and value targets for reinforcement learning across many domains with one set of hyperparameters.
Intuition
A ruler that stretches near zero and squeezes the ends
Picture a ruler where the marks near zero are wide apart and the marks far away are packed tightly. Ordinary numbers sit on a straight ruler, so 1000 is a thousand times further from zero than 1. Symlog bends that ruler. The distance from 0 to 1 becomes . The distance from 0 to 1000 becomes . A thousandfold change in input is only about a tenfold change in output.
The sign is kept, so negative numbers stay on the negative side of the ruler. That is what separates symlog from a plain logarithm. The logarithm is undefined for zero and negative inputs, so it cannot represent a reward of or a temperature below zero.
Why does a network need this? Suppose it must predict a reward that is sometimes 0.1 and sometimes 10000. A squared loss on the raw reward is dominated by the rare huge values, and its gradients swing wildly. Squeezing the targets first means the network works on numbers of similar size, and the loss stays well behaved.
- symlog(x)
- identity scaled by 1/10
Why not just use a logarithm?
Three things go wrong with a plain logarithm for regression targets:
- It only accepts positive inputs. Targets that can be zero or negative cannot be transformed at all.
- Its derivative at small inputs is huge. near blows up, so small targets get unstable treatment.
- It has no symmetric version for negative numbers. Symlog is odd: , so a positive target and its negative mirror image are treated the same way.
Symlog fixes all three by adding one inside the logarithm. The means the argument is at least 1 for any input, so the logarithm is always defined and never negative in its argument.
The math
Definition
For a real number , the symmetric logarithm is
where is for , for , and for . Its inverse, the symmetric exponential, is
Here is the absolute value of , and is the natural logarithm, which is the logarithm base . The inside makes the argument of at least 1, so the function is defined on the whole real line. The function is a member of the bi-symmetric logarithmic family, which Webber (2012) introduced for wide-range data.
Checking that the two functions are inverses
Take . Then . Applying symexp:
For a negative input, gives , and symexp of that returns . The sign is carried through both directions, so the two maps invert each other on all of .
Behaviour near zero and far from zero
Differentiate for . The derivative is
For between and the slope is between and , and at it is exactly 1. So near zero, symlog is the identity. For large the slope falls off like , which gives the logarithmic compression. Writing for small positive makes the identity behaviour explicit: the first-order term is just .
The symlog squared loss
DreamerV3 trains a network to predict a transformed target and reads out predictions with the inverse:
The gradient with respect to the network output is . Because grows only logarithmically in , this gradient grows only logarithmically in the size of the target. That is the point of the construction.
Twohot classification for rewards and values
For stochastic targets such as rewards or returns, DreamerV3 goes one step further. The network outputs logits over a set of exponentially spaced bins , defined as in the paper's notation. The prediction is the probability-weighted average of the bin positions:
The target is "twohot" encoded: the two bins nearest to itself (the bins are already spaced exponentially, so no extra symlog is applied) get weights that sum to 1 and split in proportion to closeness. The loss is then the cross-entropy between the predicted Softmax distribution and the twohot target:
This loss depends on the probabilities the network assigns to bins, not on the bin positions themselves. So the gradient size does not depend on the size of the target, which is the same robustness goal reached in a different way.
Worked examples
Compute for four targets, each step on its own line.
- .
- .
- .
- .
Interpretation: the inputs and differ by a factor of 1000, but their symlog values differ only by a factor of about 10. The target maps to the mirror image of , so the sign is preserved and the magnitude is compressed the same way.
A reward target is and the network currently outputs . Compare the raw and symlog squared losses.
- Raw squared loss: .
- Symlog target: .
- Symlog squared loss: .
- Gradient with respect to (symlog case): , a magnitude of about 6.9.
- Gradient with respect to (raw case): , a magnitude of 1000.
Interpretation: the raw loss is about 21 000 times larger and its gradient is about 145 times larger. Symlog keeps the update large enough to move the prediction, yet it does not explode. The network can then recover from a wrong guess without the loss scale dominating training.
The network outputs and we want the predicted target.
- Apply symexp: .
- Compute , so the bracket is .
- The sign is , so .
Interpretation: is exactly the symlog of 10, so the round trip recovers the target. The network works in the compressed space and the readout returns the original units.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Targets are all positive and of similar size | Symlog adds complexity for little gain | Plain targets with MSE, or a log transform on positive data |
| Targets span many orders of magnitude and can be negative | Plain squared loss diverges on large values | Symlog squared loss |
| Need a calibrated full distribution over a noisy reward | A single symlog regression gives only a point estimate | Twohot classification over bins |
| Target scale changes over training | A fixed symlog still works, but the bins may cover the wrong range | Pick bin range to cover the expected targets |
| Small errors in the compressed space matter a lot | A small error at a large target can correspond to a large absolute error | Check the readout error in original units, not just the loss |
The main weakness is the readout. An error of 0.1 in symlog space is small in loss terms, but near a target of 10000 it corresponds to an error of about in the original units, because the slope of symexp there is about . Keep track of errors after symexp when reporting results.
Symlog also does not truncate or clip, unlike Huber losses, which stop learning from very large targets. It is one of several ways to make regression robust, alongside target normalisation and clipping.
History
Symlog belongs to the family of bi-symmetric logarithmic transforms. Webber (2012) introduced that family for wide-range measurement data, in the journal Measurement Science and Technology. Hafner, Pasukonis, Ba and Lillicrap (2023) used it in DreamerV3 to make a single reinforcement learning configuration work across many domains. The paper argues that symlog avoids both the truncation of large targets from Huber losses and the non-stationarity that comes from normalising targets with running statistics.
Check yourself
QuestionWhat is , and why is that value useful?Show answer
. Because the sign of 0 is 0, and , the function passes through the origin. This matters because it means a target of zero stays zero after the transform and does not shift the network's bias.
QuestionCompute to three decimal places.Show answer
. Note that .
QuestionWhy can symlog represent negative targets while a plain logarithm cannot?Show answer
A plain logarithm is defined only for positive arguments, so it cannot take a negative target at all. Symlog takes the logarithm of , which is always at least 1, so the logarithm is defined. It then multiplies by the sign of , so negative targets map to negative values symmetric to their positive mirror images.
QuestionA network predicts for a target . What is the symlog squared loss?Show answer
The symlog target is . The difference is . The loss is .
QuestionApplied scenario: a reward model is trained with symlog targets, and one training batch has a reward of 10000. Should you worry about the gradient for that sample?Show answer
The symlog gradient for that sample has magnitude , so for a near-zero prediction it is about 9.2. That is large compared with a reward of 0.1, but it is a logarithmic rather than linear dependence on the target. The network sees a strong update, not an explosive one. You should still check that the readout after symexp is in a plausible range, since small errors in the transformed space are amplified on the way back.
Sources
- Hafner, D., Pasukonis, J., Ba, J., Lillicrap, T. (2023). Mastering Diverse Domains through World Models. arXiv:2301.04104.
- Webber, J. B. W. (2012). A bi-symmetric log transformation for wide-range data. Measurement Science and Technology, 24(2), 027001. Cited in the DreamerV3 reference list.
- Logarithm (Wikipedia)