# Buggy code
def _create_model_data(
    self,
    training_data: List[Message],
    label_id_dict: Optional[Dict[Text, int]] = None,
    label_attribute: Optional[Text] = None,
    training: bool = True,
) -> RasaModelData:
    """Prepare data for training and create a RasaModelData object."""
    from rasa.utils.tensorflow import model_data_utils

    attributes_to_consider = [TEXT]
    if training and self.component_config[INTENT_CLASSIFICATION]:
        # we don't have any intent labels during prediction, just add them during
        # training
        attributes_to_consider.append(label_attribute)
    if training and self.component_config[ENTITY_RECOGNITION]:
        # we don't have any entity tags during prediction, just add them during
        # training
        attributes_to_consider.append(ENTITIES)

    if training and label_attribute is not None:
        # only use those training examples that have the label_attribute set
        # during training
        training_data = [
            example for example in training_data if label_attribute in example.data
        ]

    if not training_data:
        # no training data are present to train
        return RasaModelData()

    features_for_examples = model_data_utils.featurize_training_examples(
        training_data,
        attributes_to_consider,
        entity_tag_specs=self._entity_tag_specs,
        featurizers=self.component_config[FEATURIZERS],
        bilou_tagging=self.component_config[BILOU_FLAG],
    )
    attribute_data, _ = model_data_utils.convert_to_data_format(
        features_for_examples, consider_dialogue_dimension=False
    )

    model_data = RasaModelData(
        label_key=self.label_key, label_sub_key=self.label_sub_key
    )
    model_data.add_data(attribute_data)
    model_data.add_lengths(TEXT, SEQUENCE_LENGTH, TEXT, SEQUENCE)

    self._add_label_features(
        model_data, training_data, label_attribute, label_id_dict, training
    )

    # make sure all keys are in the same order during training and prediction
    # as we rely on the order of key and sub-key when constructing the actual
    # tensors from the model data
    model_data.sort()

    return model_data


# Traceback (ValueError)
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/__main__.py", line 134, in <module>
main()
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/__main__.py", line 116, in main
cmdline_arguments.func(cmdline_arguments)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/cli/train.py", line 205, in train_nlu
finetuning_epoch_fraction=args.epoch_fraction,
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/train.py", line 711, in train_nlu
finetuning_epoch_fraction=finetuning_epoch_fraction,
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/utils/common.py", line 308, in run_in_loop
result = loop.run_until_complete(f)
File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/train.py", line 757, in _train_nlu_async
finetuning_epoch_fraction=finetuning_epoch_fraction,
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/train.py", line 818, in _train_nlu_with_validated_data
**additional_arguments,
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/nlu/train.py", line 116, in train
interpreter = trainer.train(training_data, **kwargs)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/nlu/model.py", line 209, in train
updates = component.train(working_data, self.config, **context)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/nlu/classifiers/diet_classifier.py", line 818, in train
self.component_config[BATCH_STRATEGY],
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/utils/tensorflow/models.py", line 220, in fit
) = self._get_tf_train_functions(eager, model_data, batch_strategy)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/utils/tensorflow/models.py", line 482, in _get_tf_train_functions
train_dataset_function, self.train_on_batch, eager, "train"
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/utils/tensorflow/models.py", line 464, in _get_tf_call_model_function
tf_call_model_function(next(iter(init_dataset)))
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 780, in __call__
result = self._call(*args, **kwds)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 823, in _call
self._initialize(args, kwds, add_initializers_to=initializers)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 697, in _initialize
*args, **kwds))
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 2855, in _get_concrete_function_internal_garbage_collected
graph_function, _, _ = self._maybe_define_function(args, kwargs)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3213, in _maybe_define_function
graph_function = self._create_graph_function(args, kwargs)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3075, in _create_graph_function
capture_by_value=self._capture_by_value),
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py", line 986, in func_graph_from_py_func
func_outputs = python_func(*func_args, **func_kwargs)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 600, in wrapped_fn
return weak_wrapped_fn().__wrapped__(*args, **kwds)
File "/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py", line 973, in wrapper
raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:

/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/utils/tensorflow/models.py:293 train_on_batch  *
prediction_loss = self.batch_loss(batch_in)
/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/nlu/classifiers/diet_classifier.py:1409 batch_loss  *
tf_batch_data = self.batch_to_model_data_format(batch_in, self.data_signature)
/home/stefan.vantchev/.local/lib/python3.7/site-packages/rasa/utils/tensorflow/models.py:592 batch_to_model_data_format  *
batch_data[key][sub_key].append(
/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/framework/sparse_tensor.py:130 __init__  **
indices, name="indices", dtype=dtypes.int64)
/home/stefan.vantchev/.local/lib/python3.7/site-packages/tensorflow/python/framework/ops.py:1475 convert_to_tensor
(dtype.name, value.dtype.name, value))

ValueError: Tensor conversion requested dtype int64 for Tensor with dtype float32: <tf.Tensor 'batch_in_3:0' shape=(None,) dtype=float32>

# Fixed code
def _create_model_data(
    self,
    training_data: List[Message],
    label_id_dict: Optional[Dict[Text, int]] = None,
    label_attribute: Optional[Text] = None,
    training: bool = True,
) -> RasaModelData:
    """Prepare data for training and create a RasaModelData object."""
    from rasa.utils.tensorflow import model_data_utils

    attributes_to_consider = [TEXT]
    if training and self.component_config[INTENT_CLASSIFICATION]:
        # we don't have any intent labels during prediction, just add them during
        # training
        attributes_to_consider.append(label_attribute)
    if (
        training
        and self.component_config[ENTITY_RECOGNITION]
        and self._entity_tag_specs
    ):
        # Add entities as labels only during training and only if there was
        # training data added for entities with DIET configured to predict entities.
        attributes_to_consider.append(ENTITIES)

    if training and label_attribute is not None:
        # only use those training examples that have the label_attribute set
        # during training
        training_data = [
            example for example in training_data if label_attribute in example.data
        ]

    if not training_data:
        # no training data are present to train
        return RasaModelData()

    features_for_examples = model_data_utils.featurize_training_examples(
        training_data,
        attributes_to_consider,
        entity_tag_specs=self._entity_tag_specs,
        featurizers=self.component_config[FEATURIZERS],
        bilou_tagging=self.component_config[BILOU_FLAG],
    )
    attribute_data, _ = model_data_utils.convert_to_data_format(
        features_for_examples, consider_dialogue_dimension=False
    )

    model_data = RasaModelData(
        label_key=self.label_key, label_sub_key=self.label_sub_key
    )
    model_data.add_data(attribute_data)
    model_data.add_lengths(TEXT, SEQUENCE_LENGTH, TEXT, SEQUENCE)

    self._add_label_features(
        model_data, training_data, label_attribute, label_id_dict, training
    )

    # make sure all keys are in the same order during training and prediction
    # as we rely on the order of key and sub-key when constructing the actual
    # tensors from the model data
    model_data.sort()

    return model_data