docstr: Return:
      Definitions:
          P is the number of antecedent per mention (number of pairs for the mention)
          S = 250 is the size of the span vector (averaged word embeddings)
          W = 8 is the number of words in a mention (tuned embeddings)
          Fp = 70 is the number of features for a pair of mention
          Fs = 24 is the number of features of a single mention
  
      if there are some pairs:
          inputs = (spans, words, features, ant_spans, ant_words, ana_spans, ana_words, pairs_features)
          targets = (labels, costs, true_ants, false_ants)
      else:
          inputs = (spans, words, features)
          targets = (labels, costs, true_ants)
  
      inputs: Tuple of
          spans => (S,)
          words => (W,)
          features => (Fs,)
          + if there are potential antecedents (P > 0):
              ant_spans => (P, S) or nothing if no pairs
              ant_words => (P, W) or nothing if no pairs
              ana_spans => (P, S) or nothing if no pairs
              ana_words => (P, W) or nothing if no pairs
              pair_features => (P, Fp) or nothing if no pairs
  
      targets: Tuple of
          labels => (P+1,)
          costs => (P+1,)
          true_ant => (P+1,)
          + if there are potential antecedents (P > 0):
              false_ant => (P+1,)
docstr_tok: ["Return",":","Definitions",":","P","is","the","number","of","antecedent","per","mention","(","number","of","pairs","for","the","mention",")","S","=","250","is","the","size","of","the","span","vector","(","averaged","word","embeddings",")","W","=","8","is","the","number","of","words","in","a","mention","(","tuned","embeddings",")","Fp","=","70","is","the","number","of","features","for","a","pair","of","mention","Fs","=","24","is","the","number","of","features","of","a","single","mention","if","there","are","some","pairs",":","inputs","=","(","spans",",","words",",","features",",","ant_spans",",","ant_words",",","ana_spans",",","ana_words",",","pairs_features",")","targets","=","(","labels",",","costs",",","true_ants",",","false_ants",")","else",":","inputs","=","(","spans",",","words",",","features",")","targets","=","(","labels",",","costs",",","true_ants",")","inputs",":","Tuple","of","spans","=",">","(","S",",",")","words","=",">","(","W",",",")","features","=",">","(","Fs",",",")","+","if","there","are","potential","antecedents","(","P",">","0",")",":","ant_spans","=",">","(","P",",","S",")","or","nothing","if","no","pairs","ant_words","=",">","(","P",",","W",")","or","nothing","if","no","pairs","ana_spans","=",">","(","P",",","S",")","or","nothing","if","no","pairs","ana_words","=",">","(","P",",","W",")","or","nothing","if","no","pairs","pair_features","=",">","(","P",",","Fp",")","or","nothing","if","no","pairs","targets",":","Tuple","of","labels","=",">","(","P+1",",",")","costs","=",">","(","P+1",",",")","true_ant","=",">","(","P+1",",",")","+","if","there","are","potential","antecedents","(","P",">","0",")",":","false_ant","=",">","(","P+1",",",")"]
code: def __getitem__(self, mention_idx, debug=False):
      """
      Return:
          Definitions:
              P is the number of antecedent per mention (number of pairs for the mention)
              S = 250 is the size of the span vector (averaged word embeddings)
              W = 8 is the number of words in a mention (tuned embeddings)
              Fp = 70 is the number of features for a pair of mention
              Fs = 24 is the number of features of a single mention
  
          if there are some pairs:
              inputs = (spans, words, features, ant_spans, ant_words, ana_spans, ana_words, pairs_features)
              targets = (labels, costs, true_ants, false_ants)
          else:
              inputs = (spans, words, features)
              targets = (labels, costs, true_ants)
  
          inputs: Tuple of
              spans => (S,)
              words => (W,)
              features => (Fs,)
              + if there are potential antecedents (P > 0):
                  ant_spans => (P, S) or nothing if no pairs
                  ant_words => (P, W) or nothing if no pairs
                  ana_spans => (P, S) or nothing if no pairs
                  ana_words => (P, W) or nothing if no pairs
                  pair_features => (P, Fp) or nothing if no pairs
  
          targets: Tuple of
              labels => (P+1,)
              costs => (P+1,)
              true_ant => (P+1,)
              + if there are potential antecedents (P > 0):
                  false_ant => (P+1,)
  
      """
      (
          features_raw,
          label,
          pairs_length,
          pairs_start_index,
          spans,
          words,
      ) = self.mentions[mention_idx]
      pairs_start_index = pairs_start_index.item()
      pairs_length = pairs_length.item()
  
      # Build features array (float) from raw features (int)
      assert features_raw.shape[0] == SIZE_FS_COMPRESSED
      features = np.zeros((SIZE_FS,))
      features[features_raw[0]] = 1
      features[4:15] = encode_distance(features_raw[1])
      features[15] = features_raw[2].astype(float) / features_raw[
          3
      ].astype(float)
      features[16] = features_raw[4]
      features[features_raw[5] + 17] = 1
  
      if pairs_length == 0:
          spans = torch.from_numpy(spans).float()
          words = torch.from_numpy(words)
          features = torch.from_numpy(features).float()
          inputs = (spans, words, features)
          if self.no_targets:
              return inputs
          true_ant = torch.zeros(
              1
          ).long()  # zeros = indices of true ant
          costs = torch.from_numpy(
              (1 - label) * self.costs["FN"]
          ).float()
          label = torch.from_numpy(label).float()
          targets = (label, costs, true_ant)
          if debug:
              print("inputs shapes: ", [a.size() for a in inputs])
              print("targets shapes: ", [a.size() for a in targets])
          return inputs, targets
  
      start = pairs_start_index
      end = pairs_start_index + pairs_length
      pairs = self.pairs[start:end]
      assert len(pairs) == pairs_length
      assert (
          len(pairs[0]) == 3
      )  # pair[i] = (pairs_ant_index, pairs_features, pairs_labels)
      pairs_ant_index, pairs_features_raw, pairs_labels = list(
          zip(*pairs)
      )
  
      pairs_features_raw = np.stack(pairs_features_raw)
      pairs_labels = np.squeeze(np.stack(pairs_labels), axis=1)
  
      # Build pair features array (float) from raw features (int)
      assert pairs_features_raw[0, :].shape[0] == SIZE_FP_COMPRESSED
      pairs_features = np.zeros((len(pairs_ant_index), SIZE_FP))
      pairs_features[:, 0:6] = pairs_features_raw[:, 0:6]
      pairs_features[:, 6:17] = encode_distance(
          pairs_features_raw[:, 6]
      )
      pairs_features[:, 17:28] = encode_distance(
          pairs_features_raw[:, 7]
      )
      pairs_features[:, 28] = pairs_features_raw[:, 8]
      # prepare antecent features
      ant_features_raw = np.concatenate(
          [
              self.mentions[idx.item()][0][np.newaxis, :]
              for idx in pairs_ant_index
          ]
      )
      ant_features = np.zeros((pairs_length, SIZE_FS - SIZE_GENRE))
      ant_features[:, ant_features_raw[:, 0]] = 1
      ant_features[:, 4:15] = encode_distance(ant_features_raw[:, 1])
      ant_features[:, 15] = ant_features_raw[:, 2].astype(
          float
      ) / ant_features_raw[:, 3].astype(float)
      ant_features[:, 16] = ant_features_raw[:, 4]
      pairs_features[:, 29:46] = ant_features
      # Here we keep the genre
      ana_features = np.tile(features, (pairs_length, 1))
      pairs_features[:, 46:] = ana_features
  
      ant_spans = np.concatenate(
          [
              self.mentions[idx.item()][4][np.newaxis, :]
              for idx in pairs_ant_index
          ]
      )
      ant_words = np.concatenate(
          [
              self.mentions[idx.item()][5][np.newaxis, :]
              for idx in pairs_ant_index
          ]
      )
      ana_spans = np.tile(spans, (pairs_length, 1))
      ana_words = np.tile(words, (pairs_length, 1))
      ant_spans = torch.from_numpy(ant_spans).float()
      ant_words = torch.from_numpy(ant_words)
      ana_spans = torch.from_numpy(ana_spans).float()
      ana_words = torch.from_numpy(ana_words)
      pairs_features = torch.from_numpy(pairs_features).float()
  
      labels_stack = np.concatenate((pairs_labels, label), axis=0)
      assert labels_stack.shape == (pairs_length + 1,)
      labels = torch.from_numpy(labels_stack).float()
  
      spans = torch.from_numpy(spans).float()
      words = torch.from_numpy(words)
      features = torch.from_numpy(features).float()
  
      inputs = (
          spans,
          words,
          features,
          ant_spans,
          ant_words,
          ana_spans,
          ana_words,
          pairs_features,
      )
  
      if self.no_targets:
          return inputs
  
      if label == 0:
          costs = np.concatenate(
              (
                  self.costs["WL"] * (1 - pairs_labels),
                  [self.costs["FN"]],
              )
          )  # Inverse labels: 1=>0, 0=>1
      else:
          costs = np.concatenate(
              (self.costs["FL"] * np.ones_like(pairs_labels), [0])
          )
      assert costs.shape == (pairs_length + 1,)
      costs = torch.from_numpy(costs).float()
  
      true_ants_unpad = np.flatnonzero(labels_stack)
      if len(true_ants_unpad) == 0:
          raise ValueError("Error: no True antecedent for mention")
      true_ants = np.pad(
          true_ants_unpad,
          (0, len(pairs_labels) + 1 - len(true_ants_unpad)),
          "edge",
      )
      assert true_ants.shape == (pairs_length + 1,)
      true_ants = torch.from_numpy(true_ants).long()
  
      false_ants_unpad = np.flatnonzero(1 - labels_stack)
      assert len(false_ants_unpad) != 0
      false_ants = np.pad(
          false_ants_unpad,
          (0, len(pairs_labels) + 1 - len(false_ants_unpad)),
          "edge",
      )
      assert false_ants.shape == (pairs_length + 1,)
      false_ants = torch.from_numpy(false_ants).long()
  
      targets = (labels, costs, true_ants, false_ants)
      if debug:
          print("Mention", mention_idx)
          print("inputs shapes: ", [a.size() for a in inputs])
          print("targets shapes: ", [a.size() for a in targets])
      return inputs, targets
  
imports: import os
  import io
  import numpy
  import torch
  import torch.utils.data
  from torch.utils.data.sampler import Sampler
  from torch.utils.data import Dataset
  from neuralcoref.train.utils import encode_distance, BATCH_SIZE_PATH, SIZE_FP, SIZE_FP_COMPRESSED, SIZE_FS, SIZE_FS_COMPRESSED, SIZE_GENRE, SIZE_PAIR_IN, SIZE_SINGLE_IN
  from neuralcoref.train.conllparser import FEATURES_NAMES
label_desc: Use image node_id 3 for calling the NCDataset obj's underlying member method code with example usage: obj.__getitem__(mention_idx, debug) and returns: inputs,  targets, inputs,  targets, inputs, inputs