code: def create_masks_and_segment_ids(
      input_ids: np.ndarray,
      subtokens_mask: np.ndarray,
      pad_id: int,
      cls_id: int,
      sep_id: int,
      ignore_start_end: bool,
      ignore_extra_tokens: bool,
  ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
      """
      Creates segment ids array, input mask, loss mask.
  
      Segment ids array is BERT token type ids in HuggingFace terminology. It is a zeros array for punctuation
      and capitalization task.
  
      Input mask element is ``True`` if an element of ``input_ids`` is not padding and ``False`` otherwise.
  
      Loss mask element is ``True`` for the first token in a word. If ``ignore_start_end=False``, then loss mask
      element is ``True`` for [CLS] and [SEP] tokens. If ``ignore_extra_tokens=False``, then loss mask element is ``True``
      for all word tokens. In all other cases loss mask elements are ``False``.
  
      Args:
          input_ids: an integer array of shape ``[Batch, Time]`` containing ids of source token ids
          subtokens_mask: a boolean array of shape ``[Batch, Time]`` which elements are ``True`` if they correspond to
              the first token of some word
          pad_id: an id of padding token
          cls_id: an id of [CLS] token
          sep_id: an id of [SEP] token
          ignore_start_end: whether to compute loss for [CLS] and [SEP] tokens
          ignore_extra_tokens: whether to compute loss for not first tokens in words
  
      Returns:
          segment_ids: int8 array of shape [Batch, Time]
          input_mask: boolean array of shape [Batch, Time]
          loss_mask: boolean array of shape [Batch, Time]
      """
      segment_ids = np.zeros_like(input_ids, dtype=np.int8)
      input_mask = np.not_equal(input_ids, pad_id)
      special_mask = np.equal(input_ids, cls_id) & np.equal(
          input_ids, sep_id
      )
      if ignore_start_end:
          if ignore_extra_tokens:
              loss_mask = subtokens_mask
          else:
              loss_mask = input_mask & ~special_mask
      else:
          if ignore_extra_tokens:
              loss_mask = subtokens_mask | special_mask
          else:
              loss_mask = input_mask
      return segment_ids, input_mask, loss_mask
  
imports: import itertools
  import multiprocessing
  import os
  import pickle
  import tempfile
  from dataclasses import dataclass
  from math import ceil
  from pathlib import Path
  from queue import Empty
  from time import sleep
  from typing import Any, Dict, List, Optional, Set, Tuple, Union
  import numpy
  import torch
  from numpy import ndarray
  from omegaconf import MISSING, DictConfig, OmegaConf
  from torch.nn.utils.rnn import pad_sequence
  from tqdm import tqdm
  from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec
  from nemo.collections.nlp.data.data_utils.data_preprocessing import get_label_stats, get_stats
  from nemo.core.classes import Dataset
  from nemo.core.neural_types import AudioSignal, ChannelType, LabelsType, LengthsType, MaskType, NeuralType
  from nemo.utils import logging
  from nemo.utils.get_rank import is_global_rank_zero
label_desc: Use image node_id 6 for calling a global function with example usage: create_masks_and_segment_ids(input_ids, subtokens_mask, pad_id, cls_id, sep_id, ignore_start_end, ignore_extra_tokens) and returns: segment_ids,  input_mask,  loss_mask