original_docstring: 
      Define loss function for RefNet.
      
      :param ref_weight: weight of refiner loss
      :param criterion: criterion for supervised loss
      :param input_to_float: whether to convert input to float or not
      
docstring: Define loss function for RefNet.
docstring_tokens: Define loss function for RefNet .
code: def RefNet_objective(ref_weight, criterion=torch.nn.CrossEntropyLoss(), input_to_float=True):
      """
      Define loss function for RefNet.
      
      :param ref_weight: weight of refiner loss
      :param criterion: criterion for supervised loss
      :param input_to_float: whether to convert input to float or not
      """
      ss_criterion = torch.nn.CosineEmbeddingLoss()
  
      def actualfunc(pred, truth, args):
          ce_loss = _criterioning(pred, truth, criterion)
          refiner = args['refiner']
          fused = args['fused']
          inps = args['inputs']
          refinerout = refiner(fused)
          if input_to_float:
              inputs = [torch.flatten(t, start_dim=1).float().cuda()
                        for t in inps]
          else:
              inputs = [torch.flatten(t, start_dim=1).cuda() for t in inps]
  
          inputsizes = [t.size(1) for t in inputs]
          ss_loss = 0.0
          loc = 0
          for i in range(len(inps)):
              out = refinerout[:, loc:loc+inputsizes[i]]
              loc += inputsizes[i]
              ss_loss += ss_criterion(out,
                                      inputs[i], torch.ones(out.size(0)).cuda())
          return ce_loss + ss_loss*ref_weight
      return actualfunc
code_tokens: def RefNet_objective ( ref_weight , criterion = torch . nn . CrossEntropyLoss ( ) , input_to_float = True ) : ss_criterion = torch . nn . CosineEmbeddingLoss ( ) def actualfunc ( pred , truth , args ) : ce_loss = _criterioning ( pred , truth , criterion ) refiner = args [ 'refiner' ] fused = args [ 'fused' ] inps = args [ 'inputs' ] refinerout = refiner ( fused ) if input_to_float : inputs = [ torch . flatten ( t , start_dim = 1 ) . float ( ) . cuda ( ) for t in inps ] else : inputs = [ torch . flatten ( t , start_dim = 1 ) . cuda ( ) for t in inps ] inputsizes = [ t . size ( 1 ) for t in inputs ] ss_loss = 0.0 loc = 0 for i in range ( len ( inps ) ) : out = refinerout [ : , loc : loc + inputsizes [ i ] ] loc += inputsizes [ i ] ss_loss += ss_criterion ( out , inputs [ i ] , torch . ones ( out . size ( 0 ) ) . cuda ( ) ) return ce_loss + ss_loss * ref_weight return actualfunc
short_docstring: Define loss function for RefNet.
short_docstring_tokens: Define loss function for RefNet .
comment: """
      Define loss function for RefNet.
      
      :param ref_weight: weight of refiner loss
      :param criterion: criterion for supervised loss
      :param input_to_float: whether to convert input to float or not
      """