class_docstr: Engine class of Text Robustness.
  
  Support run entrance which automatically finish data loading,
  transformation/subpopulation/attack generation and robustness
  report generation.
  
  Also provide interfaces of each layer to practitioners.
docstr: Generate new samples according to given config,
  save result as json file to out path, and evaluate
  model performance automatically if provide model.
  
  :param textflint.Dataset dataset: container of original samples.
  :param textflint.Config config: config instance to control procedure.
  :param textflint.FlintModel model: model wrapper which implements
      FlintModel abstract methods, not a necessary input.
  :return: save generated samples to json file.
docstr_tok: ["Generate","new","samples","according","to","given","config",",","save","result","as","json","file","to","out","path",",","and","evaluate","model","performance","automatically","if","provide","model",".",":","param","textflint.Dataset","dataset",":","container","of","original","samples",".",":","param","textflint.Config","config",":","config","instance","to","control","procedure",".",":","param","textflint.FlintModel","model",":","model","wrapper","which","implements","FlintModel","abstract","methods",",","not","a","necessary","input",".",":","return",":","save","generated","samples","to","json","file","."]
code: def generate(self, dataset, config, model=None):
      r"""
      Generate new samples according to given config,
      save result as json file to out path, and evaluate
      model performance automatically if provide model.
  
      :param textflint.Dataset dataset: container of original samples.
      :param textflint.Config config: config instance to control procedure.
      :param textflint.FlintModel model: model wrapper which implements
          FlintModel abstract methods, not a necessary input.
      :return: save generated samples to json file.
  
      """
      generator = auto_generator(config)
      out_dir = config.out_dir
  
      if model:
          model = auto_flintmodel(model, config.task)
      evaluate_result = {}
      generate_map = {
          "transformation": generator.generate_by_transformations,
          "subpopulation": generator.generate_by_subpopulations,
          "attack": generator.generate_by_attacks,
      }
  
      for generate_type in generate_map:
          eval_json = {}
          for (
              original_samples,
              trans_samples,
              trans_type,
          ) in generate_map[generate_type](dataset, model=model):
              out_suffix = (
                  "_"
                  + trans_type
                  + "_"
                  + str(len(trans_samples))
                  + ".json"
              )
  
              if original_samples:
                  logger.info(
                      f"{trans_type}, original {len(dataset)} samples, "
                      f"transform {len(original_samples)} samples!"
                  )
                  original_samples.save_json(
                      os.path.join(out_dir, "ori" + out_suffix)
                  )
              else:
                  logger.info(
                      f"{trans_type}, collect {len(trans_samples)} samples"
                  )
  
              if trans_samples:
                  trans_samples.save_json(
                      os.path.join(out_dir, "trans" + out_suffix)
                  )
  
              if model is not None and len(trans_samples):
                  eval_json[trans_type] = {"size": len(trans_samples)}
                  if original_samples:
                      eval_json[trans_type].update(
                          model.evaluate(
                              original_samples.dump(), prefix="ori_"
                          )
                      )
                  eval_json[trans_type].update(
                      model.evaluate(
                          trans_samples.dump(), prefix="trans_"
                      )
                  )
          if eval_json:
              evaluate_result[generate_type] = eval_json
  
      return evaluate_result
  
imports: import os
  from .common import logger
  from .adapter import *
label_desc: Use image node_id 3 for calling the Engine obj's underlying member method code with example usage: obj.generate(dataset, config, model) and returns: evaluate_result