# Buggy code
def decoder_teacher_forcing(self, encoder_output, target=None, encoder_end_state=None):
    # ================ Setup ================
    batch_size = encoder_output.shape[0]

    # Prepare target for decoding
    target_sequence_length = sequence_length_2D(target)
    start_tokens = tf.tile([self.GO_SYMBOL], [batch_size])
    end_tokens = tf.tile([self.END_SYMBOL], [batch_size])
    if self.is_timeseries:
        start_tokens = tf.cast(start_tokens, tf.float32)
        end_tokens = tf.cast(end_tokens, tf.float32)
    targets_with_go_and_eos = tf.concat(
        [
            tf.expand_dims(start_tokens, 1),
            target,  # right now cast to tf.int32, fails if tf.int64
            tf.expand_dims(end_tokens, 1),
        ],
        1,
    )
    target_sequence_length_with_eos = target_sequence_length + 1

    # Decoder Embeddings
    decoder_emb_inp = self.decoder_embedding(targets_with_go_and_eos)

    # Setting up decoder memory from encoder output
    if self.attention_mechanism is not None:
        encoder_sequence_length = sequence_length_3D(encoder_output)
        self.attention_mechanism.setup_memory(
            encoder_output, memory_sequence_length=encoder_sequence_length
        )

    decoder_initial_state = self.build_decoder_initial_state(
        batch_size, encoder_state=encoder_end_state, dtype=tf.float32
    )

    decoder = tfa.seq2seq.BasicDecoder(
        self.decoder_rnncell, sampler=self.sampler, output_layer=self.dense_layer
    )

    # BasicDecoderOutput
    outputs, final_state, generated_sequence_lengths = decoder(
        decoder_emb_inp,
        initial_state=decoder_initial_state,
        sequence_length=target_sequence_length_with_eos,
    )

    logits = outputs.rnn_output
    # mask = tf.sequence_mask(
    #    generated_sequence_lengths,
    #    maxlen=tf.shape(logits)[1],
    #    dtype=tf.float32
    # )
    # logits = logits * mask[:, :, tf.newaxis]

    # append a trailing 0, useful for
    # those datapoints that reach maximum length
    # and don't have a eos at the end
    logits = tf.pad(logits, [[0, 0], [0, 1], [0, 0]])

    return logits  # , outputs, final_state, generated_sequence_lengths


# Traceback (AttributeError)
2020-10-19 03:06:47.001119: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
File "train.py", line 78, in <module>
train(args)
File "train.py", line 41, in train
ludwig_model.save_savedmodel(args.model_dir)
File "/usr/local/lib/python3.6/dist-packages/ludwig/api.py", line 1445, in save_savedmodel
self.model.save_savedmodel(save_path)
File "/usr/local/lib/python3.6/dist-packages/ludwig/models/ecd.py", line 82, in save_savedmodel
keras_model = self.get_connected_model(training=False)
File "/usr/local/lib/python3.6/dist-packages/ludwig/models/ecd.py", line 77, in get_connected_model
inputs = inputs or self.get_model_inputs(training)
File "/usr/local/lib/python3.6/dist-packages/ludwig/models/ecd.py", line 63, in get_model_inputs
self.input_features.items()
File "/usr/local/lib/python3.6/dist-packages/ludwig/models/ecd.py", line 62, in <dictcomp>
for input_feature_name, input_feature in
File "/usr/local/lib/python3.6/dist-packages/ludwig/features/base_feature.py", line 70, in create_input
return tf.keras.Input(shape=self.get_input_shape(),
File "/usr/local/lib/python3.6/dist-packages/ludwig/features/set_feature.py", line 127, in get_input_shape
return len(self.vocab),
AttributeError: 'SetInputFeature' object has no attribute 'vocab'

# Fixed code
def decoder_teacher_forcing(self, encoder_output, target=None, encoder_end_state=None):
    # ================ Setup ================
    batch_size = tf.shape(encoder_output)[0]

    # Prepare target for decoding
    target_sequence_length = sequence_length_2D(target)
    start_tokens = tf.tile([self.GO_SYMBOL], [batch_size])
    end_tokens = tf.tile([self.END_SYMBOL], [batch_size])
    if self.is_timeseries:
        start_tokens = tf.cast(start_tokens, tf.float32)
        end_tokens = tf.cast(end_tokens, tf.float32)
    targets_with_go_and_eos = tf.concat(
        [
            tf.expand_dims(start_tokens, 1),
            target,  # right now cast to tf.int32, fails if tf.int64
            tf.expand_dims(end_tokens, 1),
        ],
        1,
    )
    target_sequence_length_with_eos = target_sequence_length + 1

    # Decoder Embeddings
    decoder_emb_inp = self.decoder_embedding(targets_with_go_and_eos)

    # Setting up decoder memory from encoder output
    if self.attention_mechanism is not None:
        encoder_sequence_length = sequence_length_3D(encoder_output)
        self.attention_mechanism.setup_memory(
            encoder_output, memory_sequence_length=encoder_sequence_length
        )

    decoder_initial_state = self.build_decoder_initial_state(
        batch_size, encoder_state=encoder_end_state, dtype=tf.float32
    )

    decoder = tfa.seq2seq.BasicDecoder(
        self.decoder_rnncell, sampler=self.sampler, output_layer=self.dense_layer
    )

    # BasicDecoderOutput
    outputs, final_state, generated_sequence_lengths = decoder(
        decoder_emb_inp,
        initial_state=decoder_initial_state,
        sequence_length=target_sequence_length_with_eos,
    )

    logits = outputs.rnn_output
    # mask = tf.sequence_mask(
    #    generated_sequence_lengths,
    #    maxlen=tf.shape(logits)[1],
    #    dtype=tf.float32
    # )
    # logits = logits * mask[:, :, tf.newaxis]

    # append a trailing 0, useful for
    # those datapoints that reach maximum length
    # and don't have a eos at the end
    logits = tf.pad(logits, [[0, 0], [0, 1], [0, 0]])

    return logits  # , outputs, final_state, generated_sequence_lengths