Inheriting Optimizer class, wrapping the original optimizer to achieve a new corresponding lazy optimizer.
Here we use gradients are equal to zeros or not to distinguish whether the words are sampled or not.
just replace your original with-momentum optimizer, like Adam(1e-3)
, with LazyOptimizer(Adam(1e-3), embedding_layers)
.
see imdb_lstm_test.py.
继承Optimizer类,包装原有优化器,实现Lazy版优化器。
这里判断一个词是否被采样的方法是检查该词的梯度是否全为0。
直接将原来用的带动量的优化器, 如 Adam(1e-3)
, 替换为 LazyOptimizer(Adam(1e-3), embedding_layers)
就行了.
QQ交流群:67729435,微信群请加机器人微信号spaces_ac_cn