(patterns, param_overrides)
return hparams
Params for TransformerEncoderDecoderMLModel.

  Args:
    patterns: a dict include train_pattern, dev_pattern, test_pattern
    param_overrides: a string, comma separated list of name=value

  Returns:
    A instance of HParams
Params for TransformerEncoderDecoderMLModel.
Params for TransformerEncoderDecoderMLModel .
def transformer_params(patterns, param_overrides):
  """Params for TransformerEncoderDecoderMLModel.

  Args:
    patterns: a dict include train_pattern, dev_pattern, test_pattern
    param_overrides: a string, comma separated list of name=value

  Returns:
    A instance of HParams
  """

  hparams = contrib_training.HParams(
      train_pattern=patterns["train_pattern"],
      dev_pattern=patterns["dev_pattern"],
      test_pattern=patterns["test_pattern"],
      vocab_filename="pegasus/ops/testdata/sp_test.model",
      encoder_type="sentencepiece_newline",
      length_bucket_size=0,
      add_task_id=False,
      batch_size=patterns["batch_size"],
      max_input_len=patterns["max_input_len"],
      max_target_len=patterns["max_output_len"],
      max_decode_len=patterns["max_output_len"],
      hidden_size=1024,
      filter_size=4096,
      num_heads=16,
      num_encoder_layers=16,
      num_decoder_layers=16,
      beam_size=1,
      beam_start=5,
      beam_alpha=0.8,
      beam_min=0,
      beam_max=-1,
      temperature=0.0,
      top_k=0,
      top_p=0.0,
      optimizer_name="adafactor",
      train_steps=patterns["train_steps"],
      learning_rate=patterns["learning_rate"],
      label_smoothing=0.1,
      dropout=0.1,
      eval_max_predictions=patterns.get("eval_steps", 1000),
      use_bfloat16=False,
      model=None,
      parser=None,
      encoder=None,
      estimator_prediction_fn=None,
      eval=None,
      estimator_eval_metrics_fn=estimator_metrics.gen_eval_metrics_fn,
  )

  if param_overrides:
    hparams.parse(param_overrides)

  hparams.parser = functools.partial(
      parsers.supervised_strings_parser,
      hparams.vocab_filename,
      hparams.encoder_type,
      hparams.max_input_len,
      hparams.max_target_len,
      length_bucket_size=hparams.length_bucket_size,
      length_bucket_start_id=pegasus_params.LENGTH_BUCKET_START_ID,
      length_bucket_max_id=pegasus_params.TASK_START_ID - 1,
      add_task_id=hparams.add_task_id,
      task_start_id=pegasus_params.TASK_START_ID)

  hparams.encoder = public_parsing_ops.create_text_encoder(
      hparams.encoder_type, hparams.vocab_filename)

  hparams.model = functools.partial(
      transformer.TransformerEncoderDecoderModel, hparams.encoder.vocab_size,
      hparams.hidden_size, hparams.filter_size, hparams.num_heads,
      hparams.num_encoder_layers, hparams.num_decoder_layers,
      hparams.label_smoothing, hparams.dropout)

  beam_keys = ("beam_start", "beam_alpha", "beam_min", "beam_max",
               "temperature", "top_k", "top_p")
  beam_kwargs = {k: hparams.get(k) for k in beam_keys if k in hparams.values()}

  def decode_fn(features):
    return hparams.model().predict(features, hparams.max_decode_len,
                                   hparams.beam_size, **beam_kwargs)

  hparams.estimator_prediction_fn = decode_fn
  hparams.eval = functools.partial(
      text_eval.text_eval,
      hparams.encoder,
      num_reserved=pegasus_params.NUM_RESERVED_TOKENS)

  return hparams
def transformer_params ( patterns , param_overrides ) : hparams = contrib_training . HParams ( train_pattern = patterns [ "train_pattern" ] , dev_pattern = patterns [ "dev_pattern" ] , test_pattern = patterns [ "test_pattern" ] , vocab_filename = "pegasus/ops/testdata/sp_test.model" , encoder_type = "sentencepiece_newline" , length_bucket_size = 0 , add_task_id = False , batch_size = patterns [ "batch_size" ] , max_input_len = patterns [ "max_input_len" ] , max_target_len = patterns [ "max_output_len" ] , max_decode_len = patterns [ "max_output_len" ] , hidden_size = 1024 , filter_size = 4096 , num_heads = 16 , num_encoder_layers = 16 , num_decoder_layers = 16 , beam_size = 1 , beam_start = 5 , beam_alpha = 0.8 , beam_min = 0 , beam_max = - 1 , temperature = 0.0 , top_k = 0 , top_p = 0.0 , optimizer_name = "adafactor" , train_steps = patterns [ "train_steps" ] , learning_rate = patterns [ "learning_rate" ] , label_smoothing = 0.1 , dropout = 0.1 , eval_max_predictions = patterns . get ( "eval_steps" , 1000 ) , use_bfloat16 = False , model = None , parser = None , encoder = None , estimator_prediction_fn = None , eval = None , estimator_eval_metrics_fn = estimator_metrics . gen_eval_metrics_fn , ) if param_overrides : hparams . parse ( param_overrides ) hparams . parser = functools . partial ( parsers . supervised_strings_parser , hparams . vocab_filename , hparams . encoder_type , hparams . max_input_len , hparams . max_target_len , length_bucket_size = hparams . length_bucket_size , length_bucket_start_id = pegasus_params . LENGTH_BUCKET_START_ID , length_bucket_max_id = pegasus_params . TASK_START_ID - 1 , add_task_id = hparams . add_task_id , task_start_id = pegasus_params . TASK_START_ID ) hparams . encoder = public_parsing_ops . create_text_encoder ( hparams . encoder_type , hparams . vocab_filename ) hparams . model = functools . partial ( transformer . TransformerEncoderDecoderModel , hparams . encoder . vocab_size , hparams . hidden_size , hparams . filter_size , hparams . num_heads , hparams . num_encoder_layers , hparams . num_decoder_layers , hparams . label_smoothing , hparams . dropout ) beam_keys = ( "beam_start" , "beam_alpha" , "beam_min" , "beam_max" , "temperature" , "top_k" , "top_p" ) beam_kwargs = { k : hparams . get ( k ) for k in beam_keys if k in hparams . values ( ) } def decode_fn ( features ) : return hparams . model ( ) . predict ( features , hparams . max_decode_len , hparams . beam_size , * * beam_kwargs ) hparams . estimator_prediction_fn = decode_fn hparams . eval = functools . partial ( text_eval . text_eval , hparams . encoder , num_reserved = pegasus_params . NUM_RESERVED_TOKENS ) return hparams