I came across the following expression in python. I believe the expression itself is legit and how it constructs actually makes sense. But still, from strongly typed background, I am wondering if people typically do that in python ... i.e. using the same class expressing two quite different concept (data vs data size meta data)
class AttentionDecoderOutput(
namedtuple("DecoderOutput", [
"logits", "predicted_ids", "cell_output", "attention_scores",
"attention_context"
])):
"""Augmented decoder output that also includes the attention scores.
"""
pass
AttentionDecoderOutput defines a data structure. The output_size below defines the size of each element in the namedtuple.
def output_size(self):
return AttentionDecoderOutput(
logits=self.vocab_size,
predicted_ids=tf.TensorShape([]),
cell_output=self.cell.output_size,
attention_scores=tf.shape(self.attention_values)[1:-1],
attention_context=self.attention_values.get_shape()[-1])