original_docstring: 
          A single train step. Apply back-propation and return the loss
          
docstring: A single train step. Apply back-propation and return the loss
docstring_tokens: A single train step . Apply back - propation and return the loss
code: def train_step(model, optimizer, train_iterator, args):
          '''
          A single train step. Apply back-propation and return the loss
          '''
  
          model.train()
  
          optimizer.zero_grad()
  
          positive_sample, negative_sample, subsampling_weight, mode = next(train_iterator)
  
          if args.cuda:
              positive_sample = positive_sample.cuda()
              negative_sample = negative_sample.cuda()
              subsampling_weight = subsampling_weight.cuda()
  
          negative_score = model((positive_sample, negative_sample), mode=mode)
          negative_score = F.logsigmoid(-negative_score).mean(dim = 1)
  
          positive_score = model(positive_sample)
  
          positive_score = F.logsigmoid(positive_score).squeeze(dim = 1)
  
          if args.uni_weight:
              positive_sample_loss = - positive_score.mean()
              negative_sample_loss = - negative_score.mean()
          else:
              positive_sample_loss = - (subsampling_weight * positive_score).sum()/subsampling_weight.sum()
              negative_sample_loss = - (subsampling_weight * negative_score).sum()/subsampling_weight.sum()
  
          loss = (positive_sample_loss + negative_sample_loss)/2 + 0.1 * model.rloss(positive_sample)
          
          if args.regularization != 0.0:
              #Use L3 regularization for ComplEx and DistMult
              regularization = args.regularization * (
                  model.entity_embedding.norm(p = 3)**3 + 
                  model.relation_embedding.norm(p = 3).norm(p = 3)**3
              )
              loss = loss + regularization
              regularization_log = {'regularization': regularization.item()}
          else:
              regularization_log = {}
              
          loss.backward()
  
          optimizer.step()
  
          log = {
              **regularization_log,
              'positive_sample_loss': positive_sample_loss.item(),
              'negative_sample_loss': negative_sample_loss.item(),
              'loss': loss.item()
          }
  
          return log
code_tokens: def train_step ( model , optimizer , train_iterator , args ) : model . train ( ) optimizer . zero_grad ( ) positive_sample , negative_sample , subsampling_weight , mode = next ( train_iterator ) if args . cuda : positive_sample = positive_sample . cuda ( ) negative_sample = negative_sample . cuda ( ) subsampling_weight = subsampling_weight . cuda ( ) negative_score = model ( ( positive_sample , negative_sample ) , mode = mode ) negative_score = F . logsigmoid ( - negative_score ) . mean ( dim = 1 ) positive_score = model ( positive_sample ) positive_score = F . logsigmoid ( positive_score ) . squeeze ( dim = 1 ) if args . uni_weight : positive_sample_loss = - positive_score . mean ( ) negative_sample_loss = - negative_score . mean ( ) else : positive_sample_loss = - ( subsampling_weight * positive_score ) . sum ( ) / subsampling_weight . sum ( ) negative_sample_loss = - ( subsampling_weight * negative_score ) . sum ( ) / subsampling_weight . sum ( ) loss = ( positive_sample_loss + negative_sample_loss ) / 2 + 0.1 * model . rloss ( positive_sample ) if args . regularization != 0.0 : regularization = args . regularization * ( model . entity_embedding . norm ( p = 3 ) ** 3 + model . relation_embedding . norm ( p = 3 ) . norm ( p = 3 ) ** 3 ) loss = loss + regularization regularization_log = { 'regularization' : regularization . item ( ) } else : regularization_log = { } loss . backward ( ) optimizer . step ( ) log = { ** regularization_log , 'positive_sample_loss' : positive_sample_loss . item ( ) , 'negative_sample_loss' : negative_sample_loss . item ( ) , 'loss' : loss . item ( ) } return log
short_docstring: A single train step.
short_docstring_tokens: A single train step .
comment: '''
          A single train step. Apply back-propation and return the loss
          '''$SEP$#Use L3 regularization for ComplEx and DistMult