Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit 9f267c3

Browse files
kyoheikoyamaafrozenator
authored andcommitted
Feature/new model for scalar regression. In the models/transformer.py, a model called Transformer Regressor was created. (#1332)
* A model called Transformer Encoder was created in the model. * solved an inheriting issue.
1 parent dbab44c commit 9f267c3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tensor2tensor/models/transformer.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,22 @@ def body(self, features):
11211121

11221122
return encoder_output
11231123

1124+
@registry.register_model
1125+
class TransformerRegressor(TransformerEncoder):
1126+
"""Transformer inheriting from Encoder, for the regression problem.
1127+
Final res is a tensor that has a shape of (?, 1, 1, 1)
1128+
"""
1129+
1130+
def top(self, body_output, features):
1131+
"""Computes single scalar value from body_output
1132+
"""
1133+
with tf.variable_scope("reg_top_ffn"):
1134+
# scalar = common_layers.dense(body_output,hparams)
1135+
x = body_output
1136+
x = tf.reduce_mean(x, axis=[1, 2], keepdims=True)
1137+
res = tf.layers.dense(x, 1, name="model_top")
1138+
return res
1139+
11241140

11251141
def features_to_nonpadding(features, inputs_or_targets="inputs"):
11261142
key = inputs_or_targets + "_segmentation"

0 commit comments

Comments
 (0)