code: def construct_dataset(
      x: DataFrame,
      y: Series,
      location=None,
      reference=None,
      params=None,
      save=False,
      weight=None,
  ):
      try_import_lightgbm()
      import lightgbm as lgb
  
      dataset = lgb.Dataset(
          data=x,
          label=y,
          reference=reference,
          free_raw_data=True,
          params=params,
          weight=weight,
      )
  
      if save:
          assert location is not None
          saving_path = f"{location}.bin"
          if os.path.exists(saving_path):
              os.remove(saving_path)
  
          os.makedirs(os.path.dirname(saving_path), exist_ok=True)
          dataset.save_binary(saving_path)
          # dataset_binary = lgb.Dataset(location + '.bin', reference=reference, free_raw_data=False)# .construct()
  
      return dataset
  
imports: import copy
  import os
  import time
  from typing import List, Optional
  import numpy
  import pandas
  from pandas import DataFrame, Series
  from autogluon.common.utils.try_import import try_import_lightgbm
  from autogluon.core.constants import BINARY, MULTICLASS, QUANTILE, REGRESSION, SOFTCLASS
  from autogluon.core.utils.exceptions import TimeLimitExceeded
label_desc: Use image node_id 4 for calling a global function with example usage: construct_dataset(x, y, location, reference, params, save, weight) and returns: dataset