class_docstr: This class allows to extend optimizers with the lookahead mechanism.
  
  The mechanism is proposed by Michael R. Zhang et.al in the paper
  [Lookahead Optimizer: k steps forward, 1 step back]
  (https://arxiv.org/abs/1907.08610v1). The optimizer iteratively updates two
  sets of weights: the search directions for weights are chosen by the inner
  optimizer, while the "slow weights" are updated each `k` steps based on the
  directions of the "fast weights" and the two sets of weights are
  synchronized. This method improves the learning stability and lowers the
  variance of its inner optimizer.
  
  Example of usage:
  
  ```python
  opt = tf.keras.optimizers.SGD(learning_rate)
  opt = tfa.optimizers.Lookahead(opt)
  ```
class_docstr_tok: ["This","class","allows","to","extend","optimizers","with","the","lookahead","mechanism",".","The","mechanism","is","proposed","by","Michael","R.","Zhang","et.al","in","the","paper","[","Lookahead","Optimizer",":","k","steps","forward",",","1","step","back","]","(","https",":","\/\/arxiv.org\/abs\/1907.08610v1",")",".","The","optimizer","iteratively","updates","two","sets","of","weights",":","the","search","directions","for","weights","are","chosen","by","the","inner","optimizer",",","while","the","``","slow","weights","''","are","updated","each","`","k","`","steps","based","on","the","directions","of","the","``","fast","weights","''","and","the","two","sets","of","weights","are","synchronized",".","This","method","improves","the","learning","stability","and","lowers","the","variance","of","its","inner","optimizer",".","Example","of","usage",":","``","`","python","opt","=","tf.keras.optimizers.SGD","(","learning_rate",")","opt","=","tfa.optimizers.Lookahead","(","opt",")","``","`"]
docstr: Wrap optimizer with the lookahead mechanism.
  
  Args:
      optimizer: The original optimizer that will be used to compute
          and apply the gradients.
      sync_period: An integer. The synchronization period of lookahead.
          Enable lookahead mechanism by setting it with a positive value.
      slow_step_size: A floating point value.
          The ratio for updating the slow weights.
      name: Optional name for the operations created when applying
          gradients. Defaults to "Lookahead".
      **kwargs: keyword arguments. Allowed to be {`clipnorm`,
          `clipvalue`, `lr`, `decay`}. `clipnorm` is clip gradients
          by norm; `clipvalue` is clip gradients by value, `decay` is
          included for backward compatibility to allow time inverse
          decay of learning rate. `lr` is included for backward
          compatibility, recommended to use `learning_rate` instead.
docstr_tok: ["Wrap","optimizer","with","the","lookahead","mechanism",".","Args",":","optimizer",":","The","original","optimizer","that","will","be","used","to","compute","and","apply","the","gradients",".","sync_period",":","An","integer",".","The","synchronization","period","of","lookahead",".","Enable","lookahead","mechanism","by","setting","it","with","a","positive","value",".","slow_step_size",":","A","floating","point","value",".","The","ratio","for","updating","the","slow","weights",".","name",":","Optional","name","for","the","operations","created","when","applying","gradients",".","Defaults","to","``","Lookahead","''",".","*","*","kwargs",":","keyword","arguments",".","Allowed","to","be","{","`","clipnorm","`",",","`","clipvalue","`",",","`","lr","`",",","`","decay","`","}",".","`","clipnorm","`","is","clip","gradients","by","norm",";","`","clipvalue","`","is","clip","gradients","by","value",",","`","decay","`","is","included","for","backward","compatibility","to","allow","time","inverse","decay","of","learning","rate",".","`","lr","`","is","included","for","backward","compatibility",",","recommended","to","use","`","learning_rate","`","instead","."]
code: def __init__(
      self,
      optimizer: types.Optimizer,
      sync_period: int = 6,
      slow_step_size: types.FloatTensorLike = 0.5,
      name: str = "Lookahead",
      **kwargs,
  ):
      r"""Wrap optimizer with the lookahead mechanism.
  
      Args:
          optimizer: The original optimizer that will be used to compute
              and apply the gradients.
          sync_period: An integer. The synchronization period of lookahead.
              Enable lookahead mechanism by setting it with a positive value.
          slow_step_size: A floating point value.
              The ratio for updating the slow weights.
          name: Optional name for the operations created when applying
              gradients. Defaults to "Lookahead".
          **kwargs: keyword arguments. Allowed to be {`clipnorm`,
              `clipvalue`, `lr`, `decay`}. `clipnorm` is clip gradients
              by norm; `clipvalue` is clip gradients by value, `decay` is
              included for backward compatibility to allow time inverse
              decay of learning rate. `lr` is included for backward
              compatibility, recommended to use `learning_rate` instead.
      """
      super().__init__(name, **kwargs)
  
      if isinstance(optimizer, str):
          if (
              hasattr(tf.keras.optimizers, "legacy")
              and KerasLegacyOptimizer
              == tf.keras.optimizers.legacy.Optimizer
          ):
              optimizer = tf.keras.optimizers.get(
                  optimizer, use_legacy_optimizer=True
              )
          else:
              optimizer = tf.keras.optimizers.get(optimizer)
      if not isinstance(optimizer, KerasLegacyOptimizer):
          raise TypeError(
              "optimizer is not an object of tf.keras.optimizers.legacy.Optimizer "
          )
  
      self._optimizer = optimizer
      self._set_hyper("sync_period", sync_period)
      self._set_hyper("slow_step_size", slow_step_size)
      self._initialized = False
      self._track_trackable(self._optimizer, "lh_base_optimizer")
  
imports: import tensorflow
  from tensorflow_addons.utils import types
  from tensorflow_addons.optimizers import KerasLegacyOptimizer
  from typeguard import typechecked
label_desc: Use image node_id 1 to create a new Lookahead object from inherited base classes: KerasLegacyOptimizer with example: obj = Lookahead(optimizer, sync_period, slow_step_size, name)