# Buggy code
def batch_to_model_data_format(
    batch: Union[Tuple[tf.Tensor], Tuple[np.ndarray]],
    data_signature: Dict[Text, List[FeatureSignature]],
) -> Dict[Text, List[tf.Tensor]]:
    """Convert input batch tensors into batch data format.

    Batch contains any number of batch data. The order is equal to the
    key-value pairs in session data. As sparse data were converted into indices,
    data, shape before, this methods converts them into sparse tensors. Dense data
    is kept.
    """

    batch_data = defaultdict(list)

    idx = 0
    for k, signature in data_signature.items():
        for is_sparse, shape in signature:
            if is_sparse:
                # explicitly substitute last dimension in shape with known
                # static value
                batch_data[k].append(
                    tf.SparseTensor(
                        batch[idx],
                        batch[idx + 1],
                        [batch[idx + 2][0], batch[idx + 2][1], shape[-1]],
                    )
                )
                idx += 3
            else:
                if isinstance(batch[idx], tf.Tensor):
                    batch_data[k].append(batch[idx])
                else:
                    # convert to Tensor
                    batch_data[k].append(tf.constant(batch[idx], dtype=tf.float32))
                idx += 1

    return batch_data


# 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 batch_to_model_data_format(
    batch: Union[Tuple[tf.Tensor], Tuple[np.ndarray]],
    data_signature: Dict[Text, List[FeatureSignature]],
) -> Dict[Text, List[tf.Tensor]]:
    """Convert input batch tensors into batch data format.

    Batch contains any number of batch data. The order is equal to the
    key-value pairs in session data. As sparse data were converted into indices,
    data, shape before, this methods converts them into sparse tensors. Dense data
    is kept.
    """

    batch_data = defaultdict(list)

    idx = 0
    for k, signature in data_signature.items():
        for is_sparse, feature_dimension in signature:
            if is_sparse:
                # explicitly substitute last dimension in shape with known
                # static value
                batch_data[k].append(
                    tf.SparseTensor(
                        batch[idx],
                        batch[idx + 1],
                        [batch[idx + 2][0], batch[idx + 2][1], feature_dimension],
                    )
                )
                idx += 3
            else:
                if isinstance(batch[idx], tf.Tensor):
                    batch_data[k].append(batch[idx])
                else:
                    # convert to Tensor
                    batch_data[k].append(tf.constant(batch[idx], dtype=tf.float32))
                idx += 1

    return batch_data