Difficulty: Easy Tags: Optimization
PayPal's fraud model occasionally sees gradient spikes from rare, extreme-value transactions. Global-norm gradient clipping is the seatbelt that keeps one outlier batch from blowing up training.
if ||g||_2 > tau:
g <- g * (tau / ||g||_2)
else:
g <- g
d tau
g_1 ... g_d
Clipped gradient, d values, 6 decimals.
1 <= d <= 10^4, tau > 0Input
2 2.0
3.0 4.0
Output
1.200000 1.600000
Explanation: ||g||_2 = 5.0 > tau = 2.0, so scale by 2.0/5.0 = 0.4:
(3.0, 4.0) * 0.4 = (1.2, 1.6).
No results yet
Run your code to check it against the examples, or submit to run every test.