(self, params)
?
?
?
def set_parameters(self, params):
        """ ? """
        self.params = []
        self.sparse_params = []
        for k, p in params:
            if p.requires_grad:
                if self.method != 'sparseadam' or "embed" not in k:
                    self.params.append(p)
                else:
                    self.sparse_params.append(p)
        if self.method == 'sgd':
            self.optimizer = optim.SGD(self.params, lr=self.learning_rate)
        elif self.method == 'adagrad':
            self.optimizer = optim.Adagrad(self.params, lr=self.learning_rate)
            for group in self.optimizer.param_groups:
                for p in group['params']:
                    self.optimizer.state[p]['sum'] = self.optimizer\
                        .state[p]['sum'].fill_(self.adagrad_accum)
        elif self.method == 'adadelta':
            self.optimizer = optim.Adadelta(self.params, lr=self.learning_rate)
        elif self.method == 'adam':
            self.optimizer = optim.Adam(self.params, lr=self.learning_rate,
                                        betas=self.betas, eps=1e-9)
        elif self.method == 'sparseadam':
            self.optimizer = MultipleOptimizer(
                [optim.Adam(self.params, lr=self.learning_rate,
                            betas=self.betas, eps=1e-8),
                 optim.SparseAdam(self.sparse_params, lr=self.learning_rate,
                                  betas=self.betas, eps=1e-8)])
        else:
            raise RuntimeError("Invalid optim method: " + self.method)
def set_parameters ( self , params ) : self . params = [ ] self . sparse_params = [ ] for k , p in params : if p . requires_grad : if self . method != 'sparseadam' or "embed" not in k : self . params . append ( p ) else : self . sparse_params . append ( p ) if self . method == 'sgd' : self . optimizer = optim . SGD ( self . params , lr = self . learning_rate ) elif self . method == 'adagrad' : self . optimizer = optim . Adagrad ( self . params , lr = self . learning_rate ) for group in self . optimizer . param_groups : for p in group [ 'params' ] : self . optimizer . state [ p ] [ 'sum' ] = self . optimizer . state [ p ] [ 'sum' ] . fill_ ( self . adagrad_accum ) elif self . method == 'adadelta' : self . optimizer = optim . Adadelta ( self . params , lr = self . learning_rate ) elif self . method == 'adam' : self . optimizer = optim . Adam ( self . params , lr = self . learning_rate , betas = self . betas , eps = 1e-9 ) elif self . method == 'sparseadam' : self . optimizer = MultipleOptimizer ( [ optim . Adam ( self . params , lr = self . learning_rate , betas = self . betas , eps = 1e-8 ) , optim . SparseAdam ( self . sparse_params , lr = self . learning_rate , betas = self . betas , eps = 1e-8 ) ] ) else : raise RuntimeError ( "Invalid optim method: " + self . method )