docstr: Instantiates the SROIE corpus with perfect ocr boxes.
  
  :param base_path: the path to store the dataset or load it from
  :param label_type: the label_type to add the ocr labels to
  :param encoding: the encoding to load the .json files with
  :param load_images: if True, the pillow images will be added as metadata
  :param normalize_coords_to_thousands: if True, the coordinates will be ranged from 0 to 1000
  :param in_memory: If set to True, the dataset is kept in memory as Sentence objects, otherwise does disk reads
  :param label_name_map: Optionally map tag names to different schema.
  :return: a Corpus with Sentences that contain OCR information
docstr_tok: ["Instantiates","the","SROIE","corpus","with","perfect","ocr","boxes",".",":","param","base_path",":","the","path","to","store","the","dataset","or","load","it","from",":","param","label_type",":","the","label_type","to","add","the","ocr","labels","to",":","param","encoding",":","the","encoding","to","load","the",".json","files","with",":","param","load_images",":","if","True",",","the","pillow","images","will","be","added","as","metadata",":","param","normalize_coords_to_thousands",":","if","True",",","the","coordinates","will","be","ranged","from","0","to","1000",":","param","in_memory",":","If","set","to","True",",","the","dataset","is","kept","in","memory","as","Sentence","objects",",","otherwise","does","disk","reads",":","param","label_name_map",":","Optionally","map","tag","names","to","different","schema",".",":","return",":","a","Corpus","with","Sentences","that","contain","OCR","information"]
code: def __init__(
      self,
      base_path: Optional[Union[str, Path]] = None,
      encoding: str = "utf-8",
      label_type: str = "ner",
      in_memory: bool = True,
      load_images: bool = False,
      normalize_coords_to_thousands: bool = True,
      label_name_map: Optional[Dict[str, str]] = None,
      **corpusargs,
  ) -> None:
      """Instantiates the SROIE corpus with perfect ocr boxes.
  
      :param base_path: the path to store the dataset or load it from
      :param label_type: the label_type to add the ocr labels to
      :param encoding: the encoding to load the .json files with
      :param load_images: if True, the pillow images will be added as metadata
      :param normalize_coords_to_thousands: if True, the coordinates will be ranged from 0 to 1000
      :param in_memory: If set to True, the dataset is kept in memory as Sentence objects, otherwise does disk reads
      :param label_name_map: Optionally map tag names to different schema.
      :return: a Corpus with Sentences that contain OCR information
      """
      base_path = (
          flair.cache_root / "datasets"
          if not base_path
          else Path(base_path)
      )
  
      dataset_name = self.__class__.__name__.lower()
      data_folder = base_path / dataset_name
  
      if not data_folder.exists():
          # the url is copied from https://huggingface.co/datasets/darentang/sroie/blob/main/sroie.py#L44
          url = "https://drive.google.com/uc?id=1ZyxAw1d-9UvhgNLGRvsJK4gBCMf0VpGD"
          zip_path = base_path / "sroie.zip"
          gdown.cached_download(
              url, str(zip_path), postprocess=gdown.extractall
          )
          zip_path.unlink()
      dev_path, test_path, train_path = find_train_dev_test_files(
          data_folder, None, None, None
      )
      super().__init__(
          train_path,
          dev_path,
          test_path,
          encoding=encoding,
          label_type=label_type,
          in_memory=in_memory,
          load_images=load_images,
          label_name_map=label_name_map,
          normalize_coords_to_thousands=normalize_coords_to_thousands,
          **corpusargs,
      )
  
imports: import json
  from pathlib import Path
  from typing import Dict, Optional, Union
  import gdown.download_folder
  import PIL
  from torch.utils.data import Dataset
  import flair
  from flair.data import BoundingBox, Corpus, FlairDataset, Sentence, get_spans_from_bio
  from flair.datasets.base import find_train_dev_test_files
label_desc: Use image node_id 1 to create a new SROIE object from inherited base classes: OcrCorpus with example: obj = SROIE(base_path, encoding, label_type, in_memory, load_images, normalize_coords_to_thousands, label_name_map)