All problems
Gradient Clip by Value Vector
Problem
Value clipping clamps each gradient coordinate into [-clip, clip] independently.
Given the gradient and the clip value, return the clipped gradient.
Hint
Apply the box projection coordinatewise.
Test cases
case 1
in: [[5,-5,0],2]
expected: [2,-2,0]
case 2
in: [[0.5],1]
expected: [0.5]
case 3
in: [[-3,3],3]
expected: [-3,3]
Starter codePython
def gradient_clip_by_value_vector(grad, clip):
# Your code here
pass3 test cases · run your code against them in the editor