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: Perform meta-learning to train the model.
  
  Parameters
  ----------
  steps: int
      the number of steps of meta-learning to perform
  max_checkpoints_to_keep: int
      the maximum number of checkpoint files to keep.  When this number is reached, older
      files are deleted.
  checkpoint_interval: float
      the time interval at which to save checkpoints, measured in seconds
  restore: bool
      if True, restore the model from the most recent checkpoint before training
      it further
docstr_tok: ["Perform","meta-learning","to","train","the","model",".","Parameters","--","--","--","--","--","steps",":","int","the","number","of","steps","of","meta-learning","to","perform","max_checkpoints_to_keep",":","int","the","maximum","number","of","checkpoint","files","to","keep",".","When","this","number","is","reached",",","older","files","are","deleted",".","checkpoint_interval",":","float","the","time","interval","at","which","to","save","checkpoints",",","measured","in","seconds","restore",":","bool","if","True",",","restore","the","model","from","the","most","recent","checkpoint","before","training","it","further"]
code: def fit(
      self,
      steps,
      max_checkpoints_to_keep=5,
      checkpoint_interval=600,
      restore=False,
  ):
      """Perform meta-learning to train the model.
  
      Parameters
      ----------
      steps: int
          the number of steps of meta-learning to perform
      max_checkpoints_to_keep: int
          the maximum number of checkpoint files to keep.  When this number is reached, older
          files are deleted.
      checkpoint_interval: float
          the time interval at which to save checkpoints, measured in seconds
      restore: bool
          if True, restore the model from the most recent checkpoint before training
          it further
      """
      if restore:
          self.restore()
      manager = tf.train.CheckpointManager(
          self._checkpoint, self.model_dir, max_checkpoints_to_keep
      )
      checkpoint_time = time.time()
  
      # Main optimization loop.
  
      learner = self.learner
      variables = learner.variables
      for i in range(steps):
          for j in range(self.meta_batch_size):
              learner.select_task()
              meta_loss, meta_gradients = self._compute_meta_loss(
                  learner.get_batch(), learner.get_batch(), variables
              )
              if j == 0:
                  summed_gradients = meta_gradients
              else:
                  summed_gradients = [
                      s + g
                      for s, g in zip(summed_gradients, meta_gradients)
                  ]
          self._tf_optimizer.apply_gradients(
              zip(summed_gradients, variables)
          )
  
          # Do checkpointing.
  
          if (
              i == steps - 1
              or time.time() >= checkpoint_time + checkpoint_interval
          ):
              manager.save()
              checkpoint_time = time.time()
  
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 3 for calling the MAML obj's underlying member method code with example usage: obj.fit(steps, max_checkpoints_to_keep, checkpoint_interval, restore) without return types