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: Build and return the encoder.
  
  :param json_path:
      path to encoder json file
  
  :return:
      encoder, mapping tokens to unicode reps
docstr_tok: ["Build","and","return","the","encoder",".",":","param","json_path",":","path","to","encoder","json","file",":","return",":","encoder",",","mapping","tokens","to","unicode","reps"]
code: def _build_encoder(self, json_path: str) -> Dict[str, str]:
      """
      Build and return the encoder.
  
      :param json_path:
          path to encoder json file
  
      :return:
          encoder, mapping tokens to unicode reps
      """
      with PathManager.open(json_path, "r", encoding="utf8") as f:
          encoder = json.load(f)
      for each_token in encoder.keys():
          new_token = "".join(
              # escape nonprintable characters
              "\\" + hex(b).lstrip("0")
              if (b > 127 or b < 32)
              else chr(b)
              for b in each_token.encode("utf-8")
          )
          encoder[each_token] = new_token
  
      return encoder
  
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 3 for calling the Gpt2BpeHelper obj's underlying member method code with example usage: obj._build_encoder(json_path) and returns: encoder