Constrain both source inputs length in DualSourceTransformer
@@ -6,8 +6,13 @@ See for example https://arxiv.org/pdf/1809.00188.pdf.
import opennmt as onmt
-def model():
- return onmt.models.Transformer(
+from opennmt.utils import misc
+
+
+class DualSourceTransformer(onmt.models.Transformer):
+
+ def __init__(self):
+ super(DualSourceTransformer, self).__init__(
source_inputter=onmt.inputters.ParallelInputter([
onmt.inputters.WordEmbedder(
vocabulary_file_key="source_vocabulary_1",
@@ -26,3 +31,15 @@ def model():
attention_dropout=0.1,
relu_dropout=0.1,
share_encoders=True)
+
+ def auto_config(self, num_devices=1):
+ config = super(DualSourceTransformer, self).auto_config(num_devices=num_devices)
+ max_length = config["train"]["maximum_features_length"]
+ return misc.merge_dict(config, {
+ "train": {
+ "maximum_features_length": [max_length, max_length]
+ }
+ })
+
+
+model = DualSourceTransformer
