class_docstr: Simple neural tagging model
  Supports pytorch embedder models, multi-gpu training, KD from teacher models
  
  Args:
      embedder_model: pytorch embedder model (valid nn.Module model)
      word_vocab (Vocabulary): word vocabulary
      labels (List, optional): list of labels. Defaults to None
      use_crf (bool, optional): use CRF a the classifier (instead of Softmax). Defaults to False.
      device (str, optional): device backend. Defatuls to 'cpu'.
      n_gpus (int, optional): number of gpus. Default to 0.
docstr: Convert examples to valid tagger dataset
  
  Args:
      examples (List[TokenClsInputExample]): List of examples
      max_seq_length (int, optional): max words per sentence. Defaults to 128.
      max_word_length (int, optional): max characters in a word. Defaults to 12.
      pad_id (int, optional): padding int id. Defaults to 0.
      labels_pad_id (int, optional): labels padding id. Defaults to 0.
      include_labels (bool, optional): include labels in dataset. Defaults to True.
  
  Returns:
      TensorDataset: TensorDataset for given examples
code: def convert_to_tensors(
      self,
      examples: List[TokenClsInputExample],
      max_seq_length: int = 128,
      max_word_length: int = 12,
      pad_id: int = 0,
      labels_pad_id: int = 0,
      include_labels: bool = True,
  ) -> TensorDataset:
      """
      Convert examples to valid tagger dataset
  
      Args:
          examples (List[TokenClsInputExample]): List of examples
          max_seq_length (int, optional): max words per sentence. Defaults to 128.
          max_word_length (int, optional): max characters in a word. Defaults to 12.
          pad_id (int, optional): padding int id. Defaults to 0.
          labels_pad_id (int, optional): labels padding id. Defaults to 0.
          include_labels (bool, optional): include labels in dataset. Defaults to True.
  
      Returns:
          TensorDataset: TensorDataset for given examples
      """
  
      features = []
      for example in examples:
          word_tokens = [self.word_vocab[t] for t in example.tokens]
          labels = []
          if include_labels:
              labels = [
                  self.label_str_id.get(label)
                  for label in example.label
              ]
          word_chars = []
          for word in example.tokens:
              word_chars.append([char_to_id(c) for c in word])
          word_shapes = example.shapes
  
          # cut up to max length
          word_tokens = word_tokens[:max_seq_length]
          word_shapes = word_shapes[:max_seq_length]
          if include_labels:
              labels = labels[:max_seq_length]
          word_chars = word_chars[:max_seq_length]
          for i in range(len(word_chars)):
              word_chars[i] = word_chars[i][:max_word_length]
          mask = [1] * len(word_tokens)
  
          # Zero-pad up to the sequence length.
          padding_length = max_seq_length - len(word_tokens)
          input_ids = word_tokens + ([pad_id] * padding_length)
          shape_ids = word_shapes + ([pad_id] * padding_length)
          mask = mask + ([0] * padding_length)
          if include_labels:
              label_ids = labels + ([labels_pad_id] * padding_length)
  
          word_char_ids = []
          # pad word vectors
          for i in range(len(word_chars)):
              word_char_ids.append(
                  word_chars[i]
                  + ([pad_id] * (max_word_length - len(word_chars[i])))
              )
  
          # pad word vectors with remaining zero vectors
          for _ in range(padding_length):
              word_char_ids.append(([pad_id] * max_word_length))
  
          assert len(input_ids) == max_seq_length
          assert len(shape_ids) == max_seq_length
          if include_labels:
              assert len(label_ids) == max_seq_length
          assert len(word_char_ids) == max_seq_length
          for i in range(len(word_char_ids)):
              assert len(word_char_ids[i]) == max_word_length
  
          features.append(
              InputFeatures(
                  input_ids,
                  word_char_ids,
                  shape_ids,
                  mask=mask,
                  label_id=label_ids if include_labels else None,
              )
          )
  
      # Convert to Tensors and build dataset
      all_input_ids = torch.tensor(
          [f.input_ids for f in features], dtype=torch.long
      )
      all_char_ids = torch.tensor(
          [f.char_ids for f in features], dtype=torch.long
      )
      all_shape_ids = torch.tensor(
          [f.shape_ids for f in features], dtype=torch.long
      )
      masks = torch.tensor([f.mask for f in features], dtype=torch.long)
  
      if include_labels:
          is_labeled = torch.tensor(
              [True for f in features], dtype=torch.bool
          )
          all_label_ids = torch.tensor(
              [f.label_id for f in features], dtype=torch.long
          )
          dataset = TensorDataset(
              all_input_ids,
              all_char_ids,
              all_shape_ids,
              masks,
              is_labeled,
              all_label_ids,
          )
      else:
          is_labeled = torch.tensor(
              [False for f in features], dtype=torch.bool
          )
          dataset = TensorDataset(
              all_input_ids,
              all_char_ids,
              all_shape_ids,
              masks,
              is_labeled,
          )
      return dataset
  
imports: import io
  import logging
  import os
  import pickle
  from typing import List
  import numpy
  import torch
  import torch.optim
  from torch.nn import CrossEntropyLoss
  from torch.nn import functional
  from torch.utils.data import DataLoader, SequentialSampler, TensorDataset
  from tqdm import tqdm, trange
  from nlp_architect.data.sequential_tagging import TokenClsInputExample
  from nlp_architect.models import TrainableModel
  from nlp_architect.nn.torch.layers import CRF
  from nlp_architect.nn.torch.distillation import TeacherStudentDistill
  from nlp_architect.nn.torch.modules.embedders import IDCNN
  from nlp_architect.utils.metrics import tagging
  from nlp_architect.utils.text import Vocabulary, char_to_id
label_desc: Use image node_id 2 for calling the NeuralTagger obj's underlying member method code with example usage: obj.convert_to_tensors(examples, max_seq_length, max_word_length, pad_id, labels_pad_id, include_labels) and returns: dataset