class_docstr: Defines a datatype together with instructions for converting to :class:`~torch.Tensor`.
  :class:`Field` models common text processing datatypes that can be represented by tensors.
  It holds a :class:`Vocab` object that defines the set of possible values
  for elements of the field and their corresponding numerical representations.
  The :class:`Field` object also holds other parameters relating to how a datatype
  should be numericalized, such as a tokenization method.
  
  Args:
      name (str):
          The name of the field.
      pad_token (str):
          The string token used as padding. Default: ``None``.
      unk_token (str):
          The string token used to represent OOV words. Default: ``None``.
      bos_token (str):
          A token that will be prepended to every example using this field, or ``None`` for no `bos_token`.
          Default: ``None``.
      eos_token (str):
          A token that will be appended to every example using this field, or ``None`` for no `eos_token`.
      lower (bool):
          Whether to lowercase the text in this field. Default: ``False``.
      use_vocab (bool):
          Whether to use a :class:`Vocab` object. If ``False``, the data in this field should already be numerical.
          Default: ``True``.
      tokenize (function):
          The function used to tokenize strings using this field into sequential examples. Default: ``None``.
      fn (function):
          The function used for preprocessing the examples. Default: ``None``.
class_docstr_tok: ["Defines","a","datatype","together","with","instructions","for","converting","to",":","class",":","`","~torch.Tensor","`",".",":","class",":","`","Field","`","models","common","text","processing","datatypes","that","can","be","represented","by","tensors",".","It","holds","a",":","class",":","`","Vocab","`","object","that","defines","the","set","of","possible","values","for","elements","of","the","field","and","their","corresponding","numerical","representations",".","The",":","class",":","`","Field","`","object","also","holds","other","parameters","relating","to","how","a","datatype","should","be","numericalized",",","such","as","a","tokenization","method",".","Args",":","name","(","str",")",":","The","name","of","the","field",".","pad_token","(","str",")",":","The","string","token","used","as","padding",".","Default",":","``","None","``",".","unk_token","(","str",")",":","The","string","token","used","to","represent","OOV","words",".","Default",":","``","None","``",".","bos_token","(","str",")",":","A","token","that","will","be","prepended","to","every","example","using","this","field",",","or","``","None","``","for","no","`","bos_token","`",".","Default",":","``","None","``",".","eos_token","(","str",")",":","A","token","that","will","be","appended","to","every","example","using","this","field",",","or","``","None","``","for","no","`","eos_token","`",".","lower","(","bool",")",":","Whether","to","lowercase","the","text","in","this","field",".","Default",":","``","False","``",".","use_vocab","(","bool",")",":","Whether","to","use","a",":","class",":","`","Vocab","`","object",".","If","``","False","``",",","the","data","in","this","field","should","already","be","numerical",".","Default",":","``","True","``",".","tokenize","(","function",")",":","The","function","used","to","tokenize","strings","using","this","field","into","sequential","examples",".","Default",":","``","None","``",".","fn","(","function",")",":","The","function","used","for","preprocessing","the","examples",".","Default",":","``","None","``","."]
docstr: Constructs a :class:`Vocab` object for this field from the dataset.
  If the vocabulary has already existed, this function will have no effect.
  
  Args:
      dataset (Dataset):
          A :class:`Dataset` object. One of the attributes should be named after the name of this field.
      min_freq (int):
          The minimum frequency needed to include a token in the vocabulary. Default: 1.
      embed (Embedding):
          An Embedding object, words in which will be extended to the vocabulary. Default: ``None``.
docstr_tok: ["Constructs","a",":","class",":","`","Vocab","`","object","for","this","field","from","the","dataset",".","If","the","vocabulary","has","already","existed",",","this","function","will","have","no","effect",".","Args",":","dataset","(","Dataset",")",":","A",":","class",":","`","Dataset","`","object",".","One","of","the","attributes","should","be","named","after","the","name","of","this","field",".","min_freq","(","int",")",":","The","minimum","frequency","needed","to","include","a","token","in","the","vocabulary",".","Default",":","1.","embed","(","Embedding",")",":","An","Embedding","object",",","words","in","which","will","be","extended","to","the","vocabulary",".","Default",":","``","None","``","."]
code: def build(self, dataset, min_freq=1, embed=None):
      r"""
      Constructs a :class:`Vocab` object for this field from the dataset.
      If the vocabulary has already existed, this function will have no effect.
  
      Args:
          dataset (Dataset):
              A :class:`Dataset` object. One of the attributes should be named after the name of this field.
          min_freq (int):
              The minimum frequency needed to include a token in the vocabulary. Default: 1.
          embed (Embedding):
              An Embedding object, words in which will be extended to the vocabulary. Default: ``None``.
      """
  
      if hasattr(self, "vocab"):
          return
      sequences = getattr(dataset, self.name)
      counter = Counter(
          token for seq in sequences for token in self.preprocess(seq)
      )
      self.vocab = Vocab(
          counter, min_freq, self.specials, self.unk_index
      )
  
      if not embed:
          self.embed = None
      else:
          tokens = self.preprocess(embed.tokens)
          # if the `unk` token has existed in the pretrained,
          # then replace it with a self-defined one
          if embed.unk:
              tokens[embed.unk_index] = self.unk
  
          self.vocab.extend(tokens)
          self.embed = torch.zeros(len(self.vocab), embed.dim)
          self.embed[self.vocab[tokens]] = embed.vectors
          self.embed /= torch.std(self.embed)
  
imports: from collections import Counter
  import torch
  from underthesea.utils.sp_fn import pad
  from underthesea.utils.sp_vocab import Vocab
label_desc: Use image node_id 10 for calling the Field obj's underlying member method code with example usage: obj.build(dataset, min_freq, embed) without return types