class_docstr: SplitCrossEntropyLoss calculates an approximate softmax
code: def split_on_targets(self, hiddens, targets):
      # Split the targets into those in the head and in the tail
      split_targets = []
      split_hiddens = []
  
      # Determine to which split each element belongs (for each start split value, add 1 if equal or greater)
      # This method appears slower at least for WT-103 values for approx softmax
      # masks = [(targets >= self.splits[idx]).view(1, -1) for idx in range(1, self.nsplits)]
      # mask = torch.sum(torch.cat(masks, dim=0), dim=0)
      ###
      # This is equally fast for smaller splits as method below but scales linearly
      mask = None
      for idx in range(1, self.nsplits):
          partial_mask = targets >= self.splits[idx]
          mask = (
              mask + partial_mask if mask is not None else partial_mask
          )
      ###
      # masks = torch.stack([targets] * (self.nsplits - 1))
      # mask = torch.sum(masks >= self.split_starts, dim=0)
      for idx in range(self.nsplits):
          # If there are no splits, avoid costly masked select
          if self.nsplits == 1:
              split_targets, split_hiddens = [targets], [hiddens]
              continue
          # If all the words are covered by earlier targets, we have empties so later stages don't freak out
          if sum(len(t) for t in split_targets) == len(targets):
              split_targets.append([])
              split_hiddens.append([])
              continue
          # Are you in our split?
          tmp_mask = mask == idx
          split_targets.append(torch.masked_select(targets, tmp_mask))
          split_hiddens.append(
              hiddens.masked_select(
                  tmp_mask.unsqueeze(1).expand_as(hiddens)
              ).view(-1, hiddens.size(1))
          )
      return split_targets, split_hiddens
  
file_path: awd-lstm-lm/splitcross.py
imports: from collections import defaultdict
  import torch
  import torch.nn
  import numpy
label_desc: Use image node_id 3 for calling the SplitCrossEntropyLoss obj's underlying member method code with example usage: obj.split_on_targets(hiddens, targets) and returns: split_targets,  split_hiddens