class
Adagrad
extends
OptimizerAdagrad(params: Iterable[Parameter] | Iterable[dict[str, object]], lr: float = 0.01, lr_decay: float = 0, weight_decay: float = 0, initial_accumulator_value: float = 0, eps: float = 1e-10)Adaptive Gradient optimizer.
Adagrad adapts the learning rate for each parameter based on the sum of all past squared gradients. Parameters that receive large or frequent gradient updates get smaller effective learning rates:
where the effective learning rate decays with time as:
and is the lr_decay parameter.
Parameters
paramsiterable of Parameter or iterable of dictParameters to optimise, or a list of parameter-group dicts.
lrfloat= 0.01Initial learning rate (default:
1e-2).lr_decayfloat= 0Learning-rate decay applied to the effective LR at each step
(default:
0).weight_decayfloat= 0L2 regularisation coefficient (default:
0).initial_accumulator_valuefloat= 0Value every entry of starts from (default:
0).epsfloat= 1e-10Term added to the denominator for numerical
stability (default:
1e-10).Attributes
param_groupslist of dictParameter groups with keys
"params", "lr", "lr_decay",
"weight_decay", "initial_accumulator_value", and "eps".defaultsdictDefault hyperparameter values.
Notes
Adagrad is particularly well-suited for sparse data (e.g. NLP with
word embeddings) because infrequently updated parameters retain a
larger effective learning rate. The main drawback is that the
accumulated squared-gradient sum only grows, so the
effective learning rate can become vanishingly small over long training
runs. initial_accumulator_value precedes eps in the constructor
signature, matching the reference framework.
Examples
The sparse-feature case it suits — an embedding whose rows are hit
unevenly:
>>> import lucid
>>> import lucid.nn as nn
>>> import lucid.optim as optim
>>> table = nn.Embedding(10, 3)
>>> optimizer = optim.Adagrad(table.parameters(), lr=1e-2)
>>> optimizer.zero_grad()
>>> (table(lucid.tensor([1, 4, 4, 7])) ** 2).sum().backward()
>>> optimizer.step()