Skip to content

Commit

Permalink
fix clipnorm
Browse files Browse the repository at this point in the history
  • Loading branch information
icoxfog417 committed Jun 13, 2017
1 parent 610c09f commit 2a5fbcd
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions model/lang_model_sgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
class LangModelSGD(Optimizer):

def __init__(self, setting, verbose=True):
super(LangModelSGD, self).__init__()
super(LangModelSGD, self).__init__(clipnorm=setting.norm_clipping)

self.iterations = K.variable(0., name="iterations")
self.lr = K.variable(1.0, name="lr")
self.epoch_interval = K.variable(setting.epoch_interval)
self.decay = K.variable(setting.decay)
self._clipnorm = setting.norm_clipping
self.verbose = verbose

def get_updates(self, params, constraints, loss):
grads = self.get_gradients(loss, params)
norm = K.sqrt(sum([K.sum(K.square(g)) for g in grads]))
grads = [clip_norm(g, self._clipnorm, norm) for g in grads]

self.updates = []
self.updates.append(K.update_add(self.iterations, 1))
for p, g in zip(params, grads):
Expand Down

0 comments on commit 2a5fbcd

Please sign in to comment.