transliterate.py
def train():
    """
    Train the model:
    1. Create vocab file from dataset if not created
    2. Split dataset into test/eval if not available
    3. Create TFRecord files if not available
    4. Load TFRecord files using tf.data pipeline
    5. Train model using tf.Estimator
    """
    model_dir = get_model_dir(FLAGS.model_name)
    vocab_file = os.path.join(model_dir, FLAGS.vocab_file)

    if not os.path.exists(vocab_file):
        create_vocab([FLAGS.data_file], vocab_file)
    
    vocab, characters = load_vocab(vocab_file)
    
    train_file, eval_file = split_text_file(FLAGS.data_file, model_dir, FLAGS.eval_fraction)
    
    hparams = get_hparams(len(vocab), FLAGS.hparams)
    tf.compat.v1.logging.info('params: %s', str(hparams))

    train_input_fn = make_dataset_fn(train_file, vocab_file, hparams['batch_size'], True)
    eval_input_fn = make_dataset_fn(eval_file, vocab_file, hparams['batch_size'], False)

    estimator = tf.estimator.Estimator(
            model_fn=create_model(),
            model_dir=model_dir,
            params=hparams,
            config=tf.estimator.RunConfig()
    )

    hook = tf.estimator.experimental.make_stop_at_checkpoint_step_hook(estimator, FLAGS.train_steps)

    train_spec = tf.estimator.TrainSpec(input_fn=train_input_fn, hooks=[hook])
    eval_spec = tf.estimator.EvalSpec(input_fn=eval_input_fn, throttle_secs=120, steps=FLAGS.eval_steps)

    tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)

    Train the model:
    1. Create vocab file from dataset if not created
    2. Split dataset into test/eval if not available
    3. Create TFRecord files if not available
    4. Load TFRecord files using tf.data pipeline
    5. Train model using tf.Estimator
    
Train the model:
1. Create vocab file from dataset if not created
2. Split dataset into test/eval if not available
3. Create TFRecord files if not available
4. Load TFRecord files using tf.data pipeline
5.
Train the model : 1 . Create vocab file from dataset if not created 2 . Split dataset into test / eval if not available 3 . Create TFRecord files if not available 4 . Load TFRecord files using tf . data pipeline 5 .
def train():
    model_dir = get_model_dir(FLAGS.model_name)
    vocab_file = os.path.join(model_dir, FLAGS.vocab_file)
    if not os.path.exists(vocab_file):
        create_vocab([FLAGS.data_file], vocab_file)
    vocab, characters = load_vocab(vocab_file)
    train_file, eval_file = split_text_file(FLAGS.data_file, model_dir, FLAGS.eval_fraction)
    hparams = get_hparams(len(vocab), FLAGS.hparams)
    tf.compat.v1.logging.info('params: %s', str(hparams))
    train_input_fn = make_dataset_fn(train_file, vocab_file, hparams['batch_size'], True)
    eval_input_fn = make_dataset_fn(eval_file, vocab_file, hparams['batch_size'], False)
    estimator = tf.estimator.Estimator(
            model_fn=create_model(),
            model_dir=model_dir,
            params=hparams,
            config=tf.estimator.RunConfig()
    )
    hook = tf.estimator.experimental.make_stop_at_checkpoint_step_hook(estimator, FLAGS.train_steps)
    train_spec = tf.estimator.TrainSpec(input_fn=train_input_fn, hooks=[hook])
    eval_spec = tf.estimator.EvalSpec(input_fn=eval_input_fn, throttle_secs=120, steps=FLAGS.eval_steps)
    tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
def train ( ) : model_dir = get_model_dir ( FLAGS . model_name ) vocab_file = os . path . join ( model_dir , FLAGS . vocab_file ) if not os . path . exists ( vocab_file ) : create_vocab ( [ FLAGS . data_file ] , vocab_file ) vocab , characters = load_vocab ( vocab_file ) train_file , eval_file = split_text_file ( FLAGS . data_file , model_dir , FLAGS . eval_fraction ) hparams = get_hparams ( len ( vocab ) , FLAGS . hparams ) tf . compat . v1 . logging . info ( 'params: %s' , str ( hparams ) ) train_input_fn = make_dataset_fn ( train_file , vocab_file , hparams [ 'batch_size' ] , True ) eval_input_fn = make_dataset_fn ( eval_file , vocab_file , hparams [ 'batch_size' ] , False ) estimator = tf . estimator . Estimator ( model_fn = create_model ( ) , model_dir = model_dir , params = hparams , config = tf . estimator . RunConfig ( ) ) hook = tf . estimator . experimental . make_stop_at_checkpoint_step_hook ( estimator , FLAGS . train_steps ) train_spec = tf . estimator . TrainSpec ( input_fn = train_input_fn , hooks = [ hook ] ) eval_spec = tf . estimator . EvalSpec ( input_fn = eval_input_fn , throttle_secs = 120 , steps = FLAGS . eval_steps ) tf . estimator . train_and_evaluate ( estimator , train_spec , eval_spec )
Train the model:
1.
Train the model : 1 .
"""
    Train the model:
    1. Create vocab file from dataset if not created
    2. Split dataset into test/eval if not available
    3. Create TFRecord files if not available
    4. Load TFRecord files using tf.data pipeline
    5. Train model using tf.Estimator
    """