Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Working version #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .coveragerc

This file was deleted.

156 changes: 0 additions & 156 deletions .gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions .style.yapf

This file was deleted.

17 changes: 9 additions & 8 deletions bin/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from tensorflow import gfile

from seq2seq import models
from seq2seq.contrib.experiment import Experiment as PatchedExperiment
from seq2seq.configurable import _maybe_load_yaml, _create_from_dict
from seq2seq.configurable import _deep_merge_dict
from seq2seq.data import input_pipeline
Expand Down Expand Up @@ -79,7 +78,7 @@
to. If None, a local temporary directory is created.""")

# Training parameters
tf.flags.DEFINE_string("schedule", "continuous_train_and_eval",
tf.flags.DEFINE_string("schedule", None,
"""Estimator function to call, defaults to
continuous_train_and_eval for local run""")
tf.flags.DEFINE_integer("train_steps", None,
Expand All @@ -106,13 +105,13 @@
"""In addition to keeping the most recent checkpoint
files, keep one checkpoint file for every N hours of
training.""")
tf.flags.DEFINE_float("gpu_memory_fraction", 1.0,
tf.flags.DEFINE_float("gpu_memory_fraction", 0.6,
"""Fraction of GPU memory used by the process on
each GPU uniformly on the same machine.""")
tf.flags.DEFINE_boolean("gpu_allow_growth", False,
tf.flags.DEFINE_boolean("gpu_allow_growth", True,
"""Allow GPU memory allocation to grow
dynamically.""")
tf.flags.DEFINE_boolean("log_device_placement", False,
tf.flags.DEFINE_boolean("log_device_placement", True,
"""Log the op placement to devices""")


Expand All @@ -126,14 +125,16 @@ def create_experiment(output_dir):
output_dir: Output directory for model checkpoints and summaries.
"""

session_config = tf.ConfigProto()
session_config.gpu_options.allow_growth = FLAGS.gpu_allow_growth
session_config.gpu_options.per_process_gpu_memory_fraction = FLAGS.gpu_memory_fraction
config = run_config.RunConfig(
tf_random_seed=FLAGS.tf_random_seed,
save_checkpoints_secs=FLAGS.save_checkpoints_secs,
save_checkpoints_steps=FLAGS.save_checkpoints_steps,
keep_checkpoint_max=FLAGS.keep_checkpoint_max,
keep_checkpoint_every_n_hours=FLAGS.keep_checkpoint_every_n_hours,
gpu_memory_fraction=FLAGS.gpu_memory_fraction)
config.tf_config.gpu_options.allow_growth = FLAGS.gpu_allow_growth
session_config=session_config)
config.tf_config.log_device_placement = FLAGS.log_device_placement

train_options = training_utils.TrainOptions(
Expand Down Expand Up @@ -203,7 +204,7 @@ def model_fn(features, labels, params, mode):
metric = _create_from_dict(dict_, metric_specs)
eval_metrics[metric.name] = metric

experiment = PatchedExperiment(
experiment = tf.contrib.learn.Experiment(
estimator=estimator,
train_input_fn=train_input_fn,
eval_input_fn=eval_input_fn,
Expand Down
2 changes: 1 addition & 1 deletion example_configs/nmt_large.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ model_params:
optimizer.name: Adam
optimizer.params:
epsilon: 0.0000008
optimizer.learning_rate: 0.0001
optimizer.learning_rate: 0.001
source.max_seq_len: 50
source.reverse: false
target.max_seq_len: 50
4 changes: 1 addition & 3 deletions example_configs/nmt_medium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ model_params:
dropout_output_keep_prob: 1.0
num_layers: 2
optimizer.name: Adam
optimizer.params:
epsilon: 0.0000008
optimizer.learning_rate: 0.0001
optimizer.learning_rate: 0.001
source.max_seq_len: 50
source.reverse: false
target.max_seq_len: 50
2 changes: 1 addition & 1 deletion example_configs/nmt_small.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ model_params:
optimizer.name: Adam
optimizer.params:
epsilon: 0.0000008
optimizer.learning_rate: 0.0001
optimizer.learning_rate: 0.001
source.max_seq_len: 50
source.reverse: false
target.max_seq_len: 50
28 changes: 0 additions & 28 deletions example_configs/text_metrics_bpe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,3 @@ metrics:
- class: BleuMetricSpec
params:
<<: *default_params
- class: RougeMetricSpec
params:
<<: *default_params
rouge_type: rouge_1/f_score
- class: RougeMetricSpec
params:
<<: *default_params
rouge_type: rouge_1/r_score
- class: RougeMetricSpec
params:
<<: *default_params
rouge_type: rouge_1/p_score
- class: RougeMetricSpec
params:
<<: *default_params
rouge_type: rouge_2/f_score
- class: RougeMetricSpec
params:
<<: *default_params
rouge_type: rouge_2/r_score
- class: RougeMetricSpec
params:
<<: *default_params
rouge_type: rouge_2/p_score
- class: RougeMetricSpec
params:
<<: *default_params
rouge_type: rouge_l/f_score
16 changes: 8 additions & 8 deletions example_configs/train_seq2seq.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
buckets: 10,20,30,40
hooks:
- class: PrintModelAnalysisHook
- class: MetadataCaptureHook
- class: SyncReplicasOptimizerHook
- class: TrainSampleHook
params:
every_n_steps: 1000
buckets: 10,20,30,40
hooks:
- class: PrintModelAnalysisHook
- class: MetadataCaptureHook
- class: SyncReplicasOptimizerHook
- class: TrainSampleHook
params:
every_n_steps: 1000
10 changes: 5 additions & 5 deletions seq2seq/contrib/seq2seq/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

import six

from tensorflow.contrib.distributions.python.ops import bernoulli
from tensorflow.contrib.distributions.python.ops import categorical
from tensorflow.contrib.distributions import Bernoulli
from tensorflow.contrib.distributions import Categorical
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.layers import base as layers_base
Expand Down Expand Up @@ -264,7 +264,7 @@ def sample(self, time, outputs, state, name=None):
select_sample_noise = random_ops.random_uniform(
[self.batch_size], seed=self._scheduling_seed)
select_sample = (self._sampling_probability > select_sample_noise)
sample_id_sampler = categorical.Categorical(logits=outputs)
sample_id_sampler = Categorical(logits=outputs)
return array_ops.where(
select_sample,
sample_id_sampler.sample(seed=self._seed),
Expand Down Expand Up @@ -384,8 +384,8 @@ def initialize(self, name=None):
def sample(self, time, outputs, state, name=None):
with ops.name_scope(name, "ScheduledOutputTrainingHelperSample",
[time, outputs, state]):
sampler = bernoulli.Bernoulli(probs=self._sampling_probability)
return math_ops.cast(
sampler = Bernoulli(probs=self._sampling_probability)
return math_ops.cast(
sampler.sample(sample_shape=self.batch_size, seed=self._seed),
dtypes.bool)

Expand Down
10 changes: 6 additions & 4 deletions seq2seq/test/pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@


def _clear_flags():
"""Resets Tensorflow's FLAG values"""
#pylint: disable=W0212
tf.app.flags.FLAGS = tf.app.flags._FlagValues()
tf.app.flags._global_parser = argparse.ArgumentParser()
"""Resets Tensorflow's FLAG values"""
#pylint: disable=W0212
for flag_key in dir(tf.app.flags.FLAGS):
delattr(tf.app.flags.FLAGS, flag_key)
#tf.app.flags.FLAGS = tf.app.flags._FlagValues()
tf.app.flags._global_parser = argparse.ArgumentParser()


class PipelineTest(tf.test.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion seq2seq/training/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def cell_from_spec(cell_classname, cell_params):
cell_class = locate(cell_classname) or getattr(rnn_cell, cell_classname)

# Make sure additional arguments are valid
cell_args = set(inspect.getargspec(cell_class.__init__).args[1:])
cell_args = set(inspect.signature(cell_class.__init__).parameters)
for key in cell_params.keys():
if key not in cell_args:
raise ValueError(
Expand Down