class_docstr: A nested field.
  
  A nested field holds another field (called *nesting field*), accepts an untokenized
  string or a list string tokens and groups and treats them as one field as described
  by the nesting field. Every token will be preprocessed, padded, etc. in the manner
  specified by the nesting field. Note that this means a nested field always has
  ``sequential=True``. The two fields' vocabularies will be shared. Their
  numericalization results will be stacked into a single tensor. And NestedField will
  share the same include_lengths with nesting_field, so one shouldn't specify the
  include_lengths in the nesting_field. This field is
  primarily used to implement character embeddings. See ``tests/data/test_field.py``
  for examples on how to use this field.
  
  Arguments:
      nesting_field (Field): A field contained in this nested field.
      use_vocab (bool): Whether to use a Vocab object. If False, the data in this
          field should already be numerical. Default: ``True``.
      init_token (str): A token that will be prepended to every example using this
          field, or None for no initial token. Default: ``None``.
      eos_token (str): A token that will be appended to every example using this
          field, or None for no end-of-sentence token. Default: ``None``.
      fix_length (int): A fixed length that all examples using this field will be
          padded to, or ``None`` for flexible sequence lengths. Default: ``None``.
      dtype: The torch.dtype class that represents a batch of examples
          of this kind of data. Default: ``torch.long``.
      preprocessing (Pipeline): The Pipeline that will be applied to examples
          using this field after tokenizing but before numericalizing. Many
          Datasets replace this attribute with a custom preprocessor.
          Default: ``None``.
      postprocessing (Pipeline): A Pipeline that will be applied to examples using
          this field after numericalizing but before the numbers are turned
          into a Tensor. The pipeline function takes the batch as a list, and
          the field's Vocab. Default: ``None``.
      include_lengths: Whether to return a tuple of a padded minibatch and
          a list containing the lengths of each examples, or just a padded
          minibatch. Default: False.
      tokenize: The function used to tokenize strings using this field into
          sequential examples. If "spacy", the SpaCy tokenizer is
          used. If a non-serializable function is passed as an argument,
          the field will not be able to be serialized. Default: string.split.
      tokenizer_language: The language of the tokenizer to be constructed.
          Various languages currently supported only in SpaCy.
      pad_token (str): The string token used as padding. If ``nesting_field`` is
          sequential, this will be set to its ``pad_token``. Default: ``"<pad>"``.
      pad_first (bool): Do the padding of the sequence at the beginning. Default:
          ``False``.
class_docstr_tok: ["A","nested","field",".","A","nested","field","holds","another","field","(","called","*","nesting","field","*",")",",","accepts","an","untokenized","string","or","a","list","string","tokens","and","groups","and","treats","them","as","one","field","as","described","by","the","nesting","field",".","Every","token","will","be","preprocessed",",","padded",",","etc",".","in","the","manner","specified","by","the","nesting","field",".","Note","that","this","means","a","nested","field","always","has","``","sequential=True","``",".","The","two","fields","'","vocabularies","will","be","shared",".","Their","numericalization","results","will","be","stacked","into","a","single","tensor",".","And","NestedField","will","share","the","same","include_lengths","with","nesting_field",",","so","one","should","n't","specify","the","include_lengths","in","the","nesting_field",".","This","field","is","primarily","used","to","implement","character","embeddings",".","See","``","tests\/data\/test_field.py","``","for","examples","on","how","to","use","this","field",".","Arguments",":","nesting_field","(","Field",")",":","A","field","contained","in","this","nested","field",".","use_vocab","(","bool",")",":","Whether","to","use","a","Vocab","object",".","If","False",",","the","data","in","this","field","should","already","be","numerical",".","Default",":","``","True","``",".","init_token","(","str",")",":","A","token","that","will","be","prepended","to","every","example","using","this","field",",","or","None","for","no","initial","token",".","Default",":","``","None","``",".","eos_token","(","str",")",":","A","token","that","will","be","appended","to","every","example","using","this","field",",","or","None","for","no","end-of-sentence","token",".","Default",":","``","None","``",".","fix_length","(","int",")",":","A","fixed","length","that","all","examples","using","this","field","will","be","padded","to",",","or","``","None","``","for","flexible","sequence","lengths",".","Default",":","``","None","``",".","dtype",":","The","torch.dtype","class","that","represents","a","batch","of","examples","of","this","kind","of","data",".","Default",":","``","torch.long","``",".","preprocessing","(","Pipeline",")",":","The","Pipeline","that","will","be","applied","to","examples","using","this","field","after","tokenizing","but","before","numericalizing",".","Many","Datasets","replace","this","attribute","with","a","custom","preprocessor",".","Default",":","``","None","``",".","postprocessing","(","Pipeline",")",":","A","Pipeline","that","will","be","applied","to","examples","using","this","field","after","numericalizing","but","before","the","numbers","are","turned","into","a","Tensor",".","The","pipeline","function","takes","the","batch","as","a","list",",","and","the","field","'s","Vocab",".","Default",":","``","None","``",".","include_lengths",":","Whether","to","return","a","tuple","of","a","padded","minibatch","and","a","list","containing","the","lengths","of","each","examples",",","or","just","a","padded","minibatch",".","Default",":","False",".","tokenize",":","The","function","used","to","tokenize","strings","using","this","field","into","sequential","examples",".","If","``","spacy","''",",","the","SpaCy","tokenizer","is","used",".","If","a","non-serializable","function","is","passed","as","an","argument",",","the","field","will","not","be","able","to","be","serialized",".","Default",":","string.split",".","tokenizer_language",":","The","language","of","the","tokenizer","to","be","constructed",".","Various","languages","currently","supported","only","in","SpaCy",".","pad_token","(","str",")",":","The","string","token","used","as","padding",".","If","``","nesting_field","``","is","sequential",",","this","will","be","set","to","its","``","pad_token","``",".","Default",":","``","``","<","pad",">","''","``",".","pad_first","(","bool",")",":","Do","the","padding","of","the","sequence","at","the","beginning",".","Default",":","``","False","``","."]
code: def __init__(
      self,
      nesting_field,
      use_vocab=True,
      init_token=None,
      eos_token=None,
      fix_length=None,
      dtype=torch.long,
      preprocessing=None,
      postprocessing=None,
      tokenize=None,
      tokenizer_language="en",
      include_lengths=False,
      pad_token="<pad>",
      pad_first=False,
      truncate_first=False,
  ):
      if isinstance(nesting_field, NestedField):
          raise ValueError(
              "nesting field must not be another NestedField"
          )
      if nesting_field.include_lengths:
          raise ValueError(
              "nesting field cannot have include_lengths=True"
          )
  
      if nesting_field.sequential:
          pad_token = nesting_field.pad_token
      super(NestedField, self).__init__(
          use_vocab=use_vocab,
          init_token=init_token,
          eos_token=eos_token,
          fix_length=fix_length,
          dtype=dtype,
          preprocessing=preprocessing,
          postprocessing=postprocessing,
          lower=nesting_field.lower,
          tokenize=tokenize,
          tokenizer_language=tokenizer_language,
          batch_first=True,
          pad_token=pad_token,
          unk_token=nesting_field.unk_token,
          pad_first=pad_first,
          truncate_first=truncate_first,
          include_lengths=include_lengths,
      )
      self.nesting_field = nesting_field
      # in case the user forget to do that
      self.nesting_field.batch_first = True
  
imports: from collections import Counter, OrderedDict
  from itertools import chain
  import torch
  from torchtext.data.utils import dtype_to_attr, get_tokenizer, is_tokenizer_serializable
  from ..vocab import Vocab
  from .dataset import Dataset
  from .pipeline import Pipeline
label_desc: Use image node_id 1 to create a new NestedField object from inherited base classes: Field with example: obj = NestedField(nesting_field, use_vocab, init_token, eos_token, fix_length, dtype, preprocessing, postprocessing, tokenize, tokenizer_language, include_lengths, pad_token, pad_first, truncate_first)