Gradient clipping in keras
Asked Answered
C

1

6

I have a fully implemented LSTM RNN using Keras, and I want to use gradient clipping with the gradient norm limited to 5 (I'm trying to reproduce a research paper). I'm quite a beginner with regards to implementing Neural Networks, how would I implement this ?

Is it just (I'm using rmsprop optimizer):

 sgd = optimizers.rmsprop(lr=0.01, clipnorm=5)

 model.compile(optimizer=sgd,
                  loss='categorical_crossentropy',
                  metrics=['accuracy'])
Correspondence answered 12/12, 2017 at 17:27 Comment(1)
The accurate answer to this question would be "Yes, this is how you do it". Did you try it? Is it not working? Are you experiencing any problems with this code?Pro
E
8

According to the official documentation, any optimizer can have optional arguments clipnorm and clipvalue. If clipnorm provided, gradient will be clipped whenever gradient norm exceeds the threshold.

Elevenses answered 2/9, 2019 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.