docstr: Creates character vocabulary and saves it to file ``save_path``. You should provide one of parameters ``text``
  and ``text_file_name``. The format of created character vocabulary file is following:
  ```
  {['mask_token': "ANY NON EMPTY STRING", ]['bos_token': "ANY NON EMPTY STRING", ] and so on}
  ' '
  'e'
  ...
  ```
  The first line is a JSON which contains special tokens. This special token are set using parameters
  ``mas_token``, ``bos_token``, ``eos_token``, ``pad_token``, ``sep_token``, ``cls_token``, ``unk_token``.
  Other lines in created vocabulary file are Python string literals containing one character each.
  
  Args:
      save_path: path to the output text file. If ``save_path`` parent directory does not exist it will be created
      text: string which characters are used for vocabulary creation.
      text_file_name: path to a file which characters are used for vocabulary creation. Use this parameter if
          the text in file is too large to be loaded in memory.
      characters_to_exclude: a list of characters which will not be added to vocabulary.
      vocab_size: vocabulary size. If this parameter is set only most frequent ``vocab_size`` characters are added
          to vocabulary.
      mask_token: mask token
      bos_token: the beginning of sequence token
      eos_token: the end of sequence token. Usually equal to sep_token.
      pad_token: token to use for padding.
      sep_token: token used for separating sequences.
      cls_token: class token. Usually equal to bos_token.
      unk_token: token to use for unknown tokens. If the parameter ``unk_token`` is set and there is a character
          in the input of ``text_to_ids`` of ``text_to_tokens`` methods which is not in the vocabulary, then
          such an unknown character is tokenized into ``unk_token``. If the parameter ``unk_token`` is ``False``,
          then unknown tokens are discarded.
code: def build_vocab(
      cls,
      save_path: Union[str, bytes, os.PathLike],
      text: Optional[str] = None,
      text_file_name: Optional[Union[str, bytes, os.PathLike]] = None,
      characters_to_exclude: Optional[List[str]] = None,
      vocab_size: int = None,
      mask_token: Optional[str] = None,
      bos_token: Optional[str] = None,
      eos_token: Optional[str] = None,
      pad_token: Optional[str] = None,
      sep_token: Optional[str] = None,
      cls_token: Optional[str] = None,
      unk_token: Optional[str] = None,
  ):
      """
      Creates character vocabulary and saves it to file ``save_path``. You should provide one of parameters ``text``
      and ``text_file_name``. The format of created character vocabulary file is following:
      ```
      {['mask_token': "ANY NON EMPTY STRING", ]['bos_token': "ANY NON EMPTY STRING", ] and so on}
      ' '
      'e'
      ...
      ```
      The first line is a JSON which contains special tokens. This special token are set using parameters
      ``mas_token``, ``bos_token``, ``eos_token``, ``pad_token``, ``sep_token``, ``cls_token``, ``unk_token``.
      Other lines in created vocabulary file are Python string literals containing one character each.
  
      Args:
          save_path: path to the output text file. If ``save_path`` parent directory does not exist it will be created
          text: string which characters are used for vocabulary creation.
          text_file_name: path to a file which characters are used for vocabulary creation. Use this parameter if
              the text in file is too large to be loaded in memory.
          characters_to_exclude: a list of characters which will not be added to vocabulary.
          vocab_size: vocabulary size. If this parameter is set only most frequent ``vocab_size`` characters are added
              to vocabulary.
          mask_token: mask token
          bos_token: the beginning of sequence token
          eos_token: the end of sequence token. Usually equal to sep_token.
          pad_token: token to use for padding.
          sep_token: token used for separating sequences.
          cls_token: class token. Usually equal to bos_token.
          unk_token: token to use for unknown tokens. If the parameter ``unk_token`` is set and there is a character
              in the input of ``text_to_ids`` of ``text_to_tokens`` methods which is not in the vocabulary, then
              such an unknown character is tokenized into ``unk_token``. If the parameter ``unk_token`` is ``False``,
              then unknown tokens are discarded.
      """
      special_tokens_dict = cls.create_special_tokens_dict(
          mask_token,
          bos_token,
          eos_token,
          pad_token,
          sep_token,
          cls_token,
          unk_token,
      )
      if characters_to_exclude is None:
          characters_to_exclude = []
      else:
          cls.check_characters_to_exclude_from_vocabulary(
              characters_to_exclude
          )
      cls.check_text_and_text_file_name(text, text_file_name)
      if text is not None:
          counter = Counter(text)
      else:
          assert text_file_name is not None
          text_file_name = Path(text_file_name).expanduser()
          counter = Counter()
          with text_file_name.open(encoding="utf-8") as f:
              while True:
                  segment = f.read(
                      NUMBER_OF_CHARACTERS_READ_BUFFER_SIZE
                  )
                  if not segment:
                      break
                  counter.update(segment)
      for char in characters_to_exclude:
          if char in counter:
              del counter[char]
      save_path = Path(save_path).expanduser()
      save_path.parent.mkdir(exist_ok=True, parents=True)
      with save_path.open("w", encoding="utf-8") as f:
          f.write(json.dumps(special_tokens_dict) + "\n")
          if vocab_size is None:
              for c, _ in sorted(counter.items(), key=lambda x: -x[1]):
                  f.write(repr(c) + "\n")
          else:
              vocab_size -= len(special_tokens_dict)
              for i, (c, _) in enumerate(
                  sorted(counter.items(), key=lambda x: -x[1])
              ):
                  if i < vocab_size:
                      f.write(repr(c) + "\n")
                  else:
                      break
  
imports: import json
  import os
  import warnings
  from collections import Counter
  from enum import Enum
  from pathlib import Path
  from typing import Dict, List, NewType, Optional, Union
  from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec
label_desc: Use image node_id 26 for calling the CharTokenizer obj's underlying member method code with example usage: obj.build_vocab(cls, save_path, text, text_file_name, characters_to_exclude, vocab_size, mask_token, bos_token, eos_token, pad_token, sep_token, cls_token, unk_token) without return types