# Buggy code
def _prepare_sparse_dense_layers(
    self,
    feature_signatures: List[FeatureSignature],
    name: Text,
    reg_lambda: float,
    dense_dim: int,
) -> None:
    sparse = False
    dense = False
    for is_sparse, shape in feature_signatures:
        if is_sparse:
            sparse = True
        else:
            dense = True
            # if dense features are present
            # use the feature dimension of the dense features
            dense_dim = shape[-1]

    if sparse:
        self._tf_layers[f"sparse_to_dense.{name}"] = layers.DenseForSparse(
            units=dense_dim, reg_lambda=reg_lambda, name=name
        )
        if not dense:
            # create dense labels for the input to use in negative sampling
            self._tf_layers[f"sparse_to_dense_ids.{name}"] = layers.DenseForSparse(
                units=2, trainable=False, name=f"sparse_to_dense_ids.{name}"
            )


# Traceback (ValueError)
Traceback (most recent call last):
File "/Users/tabergma/Repositories/rasa/rasa/__main__.py", line 119, in <module>
main()
File "/Users/tabergma/Repositories/rasa/rasa/__main__.py", line 108, in main
cmdline_arguments.func(cmdline_arguments)
File "/Users/tabergma/Repositories/rasa/rasa/cli/train.py", line 142, in train_nlu
additional_arguments=extract_nlu_additional_arguments(args),
File "/Users/tabergma/Repositories/rasa/rasa/train.py", line 431, in train_nlu
additional_arguments,
File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
File "/Users/tabergma/Repositories/rasa/rasa/train.py", line 472, in _train_nlu_async
additional_arguments=additional_arguments,
File "/Users/tabergma/Repositories/rasa/rasa/train.py", line 506, in _train_nlu_with_validated_data
**additional_arguments,
File "/Users/tabergma/Repositories/rasa/rasa/nlu/train.py", line 90, in train
interpreter = trainer.train(training_data, **kwargs)
File "/Users/tabergma/Repositories/rasa/rasa/nlu/model.py", line 191, in train
updates = component.train(working_data, self.config, **context)
File "/Users/tabergma/Repositories/rasa/rasa/nlu/classifiers/diet_classifier.py", line 716, in train
config=self.component_config,
File "/Users/tabergma/Repositories/rasa/rasa/nlu/classifiers/diet_classifier.py", line 1032, in __init__
self._check_data()
File "/Users/tabergma/Repositories/rasa/rasa/nlu/classifiers/diet_classifier.py", line 1099, in _check_data
"If hidden layer weights are shared, data signatures "
ValueError: If hidden layer weights are shared, data signatures for text_features and label_features must coincide.

# Fixed code
def _prepare_sparse_dense_layers(
    self,
    feature_signatures: List[FeatureSignature],
    name: Text,
    reg_lambda: float,
    dense_dim: int,
) -> None:
    sparse = False
    dense = False
    for is_sparse, feature_dimension in feature_signatures:
        if is_sparse:
            sparse = True
        else:
            dense = True
            # if dense features are present
            # use the feature dimension of the dense features
            dense_dim = feature_dimension

    if sparse:
        self._tf_layers[f"sparse_to_dense.{name}"] = layers.DenseForSparse(
            units=dense_dim, reg_lambda=reg_lambda, name=name
        )
        if not dense:
            # create dense labels for the input to use in negative sampling
            self._tf_layers[f"sparse_to_dense_ids.{name}"] = layers.DenseForSparse(
                units=2, trainable=False, name=f"sparse_to_dense_ids.{name}"
            )