code: def get_news20(base_dir="./data/20news-18828"):
      """
      Parse 20 Newsgroup dataset and return a list of (tokens, label).
      The dataset will be downloaded automatically if not found in the target base_dir.
      """
      news20_dir = base_dir + "/20news-18828/"
      if not os.path.isdir(news20_dir):
          download_news20(base_dir)
      texts = []
      label_id = 0
      for category in sorted(os.listdir(news20_dir)):
          category_dir = os.path.join(news20_dir, category)
          if os.path.isdir(category_dir):
              for text_file in sorted(os.listdir(category_dir)):
                  if text_file.isdigit():
                      text_file_path = os.path.join(
                          category_dir, text_file
                      )
                      if sys.version_info < (3,):
                          f = open(text_file_path)
                      else:
                          f = open(text_file_path, encoding="latin-1")
                      content = f.read()
                      texts.append((content, label_id))
                      f.close()
          label_id += 1
      class_num = label_id
      print("Found %s texts." % len(texts))
      return texts, class_num
  
file_path: analytics-zoo/pyzoo/zoo/examples/textclassification/news20.py
imports: import tarfile
  import zipfile
  from bigdl.dataset import base
  from bigdl.util.common import *
label_desc: Use image node_id 1 for calling a global function with example usage: get_news20(base_dir) and returns: texts,  class_num