class_docstr: BPE Helper for GPT2 Models.
  
  Original source:
      https://github.com/openai/gpt-2/blob/main/src/encoder.py
  
  Original license: MIT
  
  This is a modified implementation from that of fairseq:
      https://github.com/pytorch/fairseq/blob/main/fairseq/data/encoders/gpt2_bpe_utils.py
  
  Fairseq license: MIT
class_docstr_tok: ["BPE","Helper","for","GPT2","Models",".","Original","source",":","https",":","\/\/github.com\/openai\/gpt-2\/blob\/main\/src\/encoder.py","Original","license",":","MIT","This","is","a","modified","implementation","from","that","of","fairseq",":","https",":","\/\/github.com\/pytorch\/fairseq\/blob\/main\/fairseq\/data\/encoders\/gpt2_bpe_utils.py","Fairseq","license",":","MIT"]
docstr: Override init to build the data.
docstr_tok: ["Override","init","to","build","the","data","."]
code: def __init__(self, opt: Opt, shared: TShared = None):
      """
      Override init to build the data.
      """
      super().__init__(opt, shared)
      if self.lower:
          warn_once(
              "Are you sure you want to lower case your BPE dictionary?"
          )
  
      if self.maxtokens > 0 or self.minfreq > 0:
          raise ValueError(
              "You should not filter vocabulary with using --dict-tokenizer bytelevelbpe"
              " (no --dict-minfreq or --dict-maxtokens)."
          )
  
      (
          self.bpe_data,
          self.json_path,
          self.merge_path,
      ) = self._build_data()
  
      # build encoder & decoder
      self.encoder: Dict[str, str] = self._build_encoder(self.json_path)
      self.decoder: Dict[str, str] = {
          v: k for k, v in self.encoder.items()
      }
  
      bpe_merges = [
          tuple(merge_str.split())
          for merge_str in self.bpe_data.split("\n")[1:-1]
      ]
      self.byte_encoder = self.bytes_to_unicode()
      self.byte_decoder = {v: k for k, v in self.byte_encoder.items()}
      self.bpe_ranks = dict(zip(bpe_merges, range(len(bpe_merges))))
  
      if regex is None:
          raise ImportError(
              "Please install regex with: pip install regex"
          )
      # Should haved added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
      self.pat = regex.compile(self.PATTERN)
  
imports: from parlai.core.params import ParlaiParser
  from abc import ABC, abstractmethod
  from functools import lru_cache
  import json
  import os
  import random
  import re
  from typing import Dict, List, Optional, Set, Tuple
  from typing_extensions import final
  from parlai.core.build_data import download, make_dir
  from parlai.core.opt import Opt
  from parlai.utils.misc import warn_once
  from parlai.utils.typing import TShared
  from parlai.utils.io import PathManager
  import parlai.utils.logging
label_desc: Use image node_id 1 to create a new Gpt2BpeHelper object from inherited base classes: BPEHelper with example: obj = Gpt2BpeHelper(opt, shared)