class_docstr: Implements the Model-Agnostic Meta-Learning algorithm for low data learning.
  
  The algorithm is described in Finn et al., "Model-Agnostic Meta-Learning for Fast
  Adaptation of Deep Networks" (https://arxiv.org/abs/1703.03400).  It is used for
  training models that can perform a variety of tasks, depending on what data they
  are trained on.  It assumes you have training data for many tasks, but only a small
  amount for each one.  It performs "meta-learning" by looping over tasks and trying
  to minimize the loss on each one *after* one or a few steps of gradient descent.
  That is, it does not try to create a model that can directly solve the tasks, but
  rather tries to create a model that is very easy to train.
  
  To use this class, create a subclass of MetaLearner that encapsulates the model
  and data for your learning problem.  Pass it to a MAML object and call fit().
  You can then use train_on_current_task() to fine tune the model for a particular
  task.
class_docstr_tok: ["Implements","the","Model-Agnostic","Meta-Learning","algorithm","for","low","data","learning",".","The","algorithm","is","described","in","Finn","et","al.",",","``","Model-Agnostic","Meta-Learning","for","Fast","Adaptation","of","Deep","Networks","''","(","https",":","\/\/arxiv.org\/abs\/1703.03400",")",".","It","is","used","for","training","models","that","can","perform","a","variety","of","tasks",",","depending","on","what","data","they","are","trained","on",".","It","assumes","you","have","training","data","for","many","tasks",",","but","only","a","small","amount","for","each","one",".","It","performs","``","meta-learning","''","by","looping","over","tasks","and","trying","to","minimize","the","loss","on","each","one","*","after","*","one","or","a","few","steps","of","gradient","descent",".","That","is",",","it","does","not","try","to","create","a","model","that","can","directly","solve","the","tasks",",","but","rather","tries","to","create","a","model","that","is","very","easy","to","train",".","To","use","this","class",",","create","a","subclass","of","MetaLearner","that","encapsulates","the","model","and","data","for","your","learning","problem",".","Pass","it","to","a","MAML","object","and","call","fit","(",")",".","You","can","then","use","train_on_current_task","(",")","to","fine","tune","the","model","for","a","particular","task","."]
docstr: Create an object for performing meta-optimization.
  
  Parameters
  ----------
  learner: MetaLearner
      defines the meta-learning problem
  learning_rate: float or Tensor
      the learning rate to use for optimizing each task (not to be confused with the one used
      for meta-learning).  This can optionally be made a variable (represented as a
      Tensor), in which case the learning rate will itself be learnable.
  optimization_steps: int
      the number of steps of gradient descent to perform for each task
  meta_batch_size: int
      the number of tasks to use for each step of meta-learning
  optimizer: Optimizer
      the optimizer to use for meta-learning (not to be confused with the gradient descent
      optimization performed for each task)
  model_dir: str
      the directory in which the model will be saved.  If None, a temporary directory will be created.
docstr_tok: ["Create","an","object","for","performing","meta-optimization",".","Parameters","--","--","--","--","--","learner",":","MetaLearner","defines","the","meta-learning","problem","learning_rate",":","float","or","Tensor","the","learning","rate","to","use","for","optimizing","each","task","(","not","to","be","confused","with","the","one","used","for","meta-learning",")",".","This","can","optionally","be","made","a","variable","(","represented","as","a","Tensor",")",",","in","which","case","the","learning","rate","will","itself","be","learnable",".","optimization_steps",":","int","the","number","of","steps","of","gradient","descent","to","perform","for","each","task","meta_batch_size",":","int","the","number","of","tasks","to","use","for","each","step","of","meta-learning","optimizer",":","Optimizer","the","optimizer","to","use","for","meta-learning","(","not","to","be","confused","with","the","gradient","descent","optimization","performed","for","each","task",")","model_dir",":","str","the","directory","in","which","the","model","will","be","saved",".","If","None",",","a","temporary","directory","will","be","created","."]
code: def __init__(
      self,
      learner,
      learning_rate=0.001,
      optimization_steps=1,
      meta_batch_size=10,
      optimizer=Adam(),
      model_dir=None,
  ):
      """Create an object for performing meta-optimization.
  
      Parameters
      ----------
      learner: MetaLearner
          defines the meta-learning problem
      learning_rate: float or Tensor
          the learning rate to use for optimizing each task (not to be confused with the one used
          for meta-learning).  This can optionally be made a variable (represented as a
          Tensor), in which case the learning rate will itself be learnable.
      optimization_steps: int
          the number of steps of gradient descent to perform for each task
      meta_batch_size: int
          the number of tasks to use for each step of meta-learning
      optimizer: Optimizer
          the optimizer to use for meta-learning (not to be confused with the gradient descent
          optimization performed for each task)
      model_dir: str
          the directory in which the model will be saved.  If None, a temporary directory will be created.
      """
      # Record inputs.
  
      self.learner = learner
      self.learning_rate = learning_rate
      self.optimization_steps = optimization_steps
      self.meta_batch_size = meta_batch_size
      self.optimizer = optimizer
  
      # Create the output directory if necessary.
  
      self._model_dir_is_temp = False
      if model_dir is not None:
          if not os.path.exists(model_dir):
              os.makedirs(model_dir)
      else:
          model_dir = tempfile.mkdtemp()
          self._model_dir_is_temp = True
      self.model_dir = model_dir
      self.save_file = "%s/%s" % (self.model_dir, "model")
  
      # Create the optimizers for meta-optimization and task optimization.
  
      self._global_step = tf.Variable(0, trainable=False)
      self._tf_optimizer = optimizer._create_tf_optimizer(
          self._global_step
      )
      task_optimizer = GradientDescent(learning_rate=self.learning_rate)
      self._tf_task_optimizer = task_optimizer._create_tf_optimizer(
          self._global_step
      )
  
      # Create a Checkpoint for saving.
  
      self._checkpoint = tf.train.Checkpoint()
      self._checkpoint.listed = learner.variables
  
file_path: deepchem/deepchem/metalearning/maml.py
imports: import os
  import shutil
  import tempfile
  import time
  import tensorflow
  from deepchem.models.optimizers import Adam, GradientDescent
label_desc: Use image node_id 1 to create a new MAML object from inherited base classes: object with example: obj = MAML(learner, learning_rate, optimization_steps, meta_batch_size, optimizer, model_dir)