diff --git a/texar/tf/modules/encoders/hierarchical_encoders.py b/texar/tf/modules/encoders/hierarchical_encoders.py index a3be0f9a..750d5d97 100644 --- a/texar/tf/modules/encoders/hierarchical_encoders.py +++ b/texar/tf/modules/encoders/hierarchical_encoders.py @@ -15,7 +15,7 @@ Various encoders that encode data with hierarchical structure. """ -import collections +import collections.abc import tensorflow as tf from tensorflow.contrib.rnn import LSTMStateTuple @@ -256,7 +256,7 @@ def _kwargs_split(kwargs): if medium is None: states_minor = self.flatten(states_minor) else: - if not isinstance(medium, collections.Sequence): + if not isinstance(medium, collections.abc.Sequence): medium = [medium] for fn in medium: if isinstance(fn, str) and fn == 'flatten': @@ -355,7 +355,7 @@ def flatten(x): """ if isinstance(x, LSTMStateTuple): return x.h - if isinstance(x, collections.Sequence): + if isinstance(x, collections.abc.Sequence): return tf.concat( [HierarchicalRNNEncoder.flatten(v) for v in x], -1) else: diff --git a/texar/tf/utils/utils.py b/texar/tf/utils/utils.py index 1404cc46..565df317 100644 --- a/texar/tf/utils/utils.py +++ b/texar/tf/utils/utils.py @@ -25,6 +25,7 @@ from pydoc import locate import copy import collections +import collections.abc import numpy as np import tensorflow as tf @@ -577,7 +578,7 @@ def flatten_dict(dict_, parent_key="", sep="."): items = [] for key, value in dict_.items(): key_ = parent_key + sep + key if parent_key else key - if isinstance(value, collections.MutableMapping): + if isinstance(value, collections.abc.MutableMapping): items.extend(flatten_dict(value, key_, sep=sep).items()) elif isinstance(value, tuple) and hasattr(value, "_asdict"): dict_items = collections.OrderedDict(zip(value._fields, value))