# Buggy code
def _set_spacy_features(self, message: Message, attribute: Text = TEXT):
    """Adds the spacy word vectors to the messages features."""

    message_attribute_doc = self.get_doc(message, attribute)

    if message_attribute_doc is not None:
        features = self._features_for_doc(message_attribute_doc)

        cls_token_vec = self._calculate_cls_vector(features, self.pooling_operation)
        features = np.concatenate([features, cls_token_vec])

        features = self._combine_with_existing_dense_features(
            message, features, DENSE_FEATURE_NAMES[attribute]
        )
        message.set(DENSE_FEATURE_NAMES[attribute], features)


# Traceback (ValueError)
rasa train; rasa shell nlu
Nothing changed. You can use the old model stored at '/Users/vincent/Development/rasa-spacy-integration/models/20200415-161323.tar.gz'.
2020-04-15 16:15:26 INFO     rasa.nlu.components  - Added 'SpacyNLP' to component cache. Key 'SpacyNLP-spacy-trained-model'.
NLU model loaded. Type a message and press enter to parse it.
Next message:
yo
Traceback (most recent call last):
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2227, in _convert_inputs_to_signature
expand_composites=True)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/util/nest.py", line 883, in flatten_up_to
expand_composites=expand_composites)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/util/nest.py", line 802, in assert_shallow_structure
expand_composites=expand_composites)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/util/nest.py", line 786, in assert_shallow_structure
input_length=len(input_tree), shallow_length=len(shallow_tree)))
ValueError: The two structures don't have the same sequence length. Input structure has length 4, while shallow structure has length 5.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/vincent/Development/rasa-spacy-integration/venv/bin/rasa", line 11, in <module>
sys.exit(main())
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/rasa/__main__.py", line 91, in main
cmdline_arguments.func(cmdline_arguments)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/rasa/cli/shell.py", line 83, in shell_nlu
rasa.nlu.run.run_cmdline(nlu_model)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/rasa/nlu/run.py", line 31, in run_cmdline
result = interpreter.parse(message)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/rasa/nlu/model.py", line 376, in parse
component.process(message, **self.context)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/rasa/nlu/classifiers/diet_classifier.py", line 783, in process
out = self._predict(message)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/rasa/nlu/classifiers/diet_classifier.py", line 671, in _predict
return self.model.predict(model_data)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/rasa/utils/tensorflow/models.py", line 213, in predict
return self._predict_function(batch_in)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 568, in __call__
result = self._call(*args, **kwds)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 606, in _call
results = self._stateful_fn(*args, **kwds)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2362, in __call__
graph_function, args, kwargs = self._maybe_define_function(args, kwargs)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2661, in _maybe_define_function
*args, **kwargs)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2185, in canonicalize_function_inputs
self._flat_input_signature)
File "/Users/vincent/Development/rasa-spacy-integration/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2231, in _convert_inputs_to_signature
format_error_message(inputs, input_signature))
ValueError: Structure of Python function inputs does not match input_signature:
inputs: (
(array([[  0,   0,   0],
[  0,   0,  35],
[  0,   0, 228],
[  0,   0, 229],
[  0,   0, 338],
[  0,   1,   0],
[  0,   1,  35],
[  0,   1, 228],
[  0,   1, 229],
[  0,   1, 338]]), array([2., 1., 1., 1., 1., 2., 1., 1., 1., 1.], dtype=float32), array([  1,   2, 346]), array([2.], dtype=float32)))
input_signature: (
(TensorSpec(shape=(None, 3), dtype=tf.int64, name=None), TensorSpec(shape=(None,), dtype=tf.float32, name=None), TensorSpec(shape=(3,), dtype=tf.int64, name=None), TensorSpec(shape=(None, None, 300), dtype=tf.float32, name=None), TensorSpec(shape=(None,), dtype=tf.float32, name=None)))

# Fixed code
def _set_spacy_features(self, message: Message, attribute: Text = TEXT) -> None:
    """Adds the spacy word vectors to the messages features."""
    doc = self.get_doc(message, attribute)

    if doc is None:
        return

    # in case an empty spaCy model was used, no vectors are present
    if doc.vocab.vectors_length == 0:
        logger.debug("No features present. You are using an empty spaCy model.")
        return

    features = self._features_for_doc(doc)

    cls_token_vec = self._calculate_cls_vector(features, self.pooling_operation)
    features = np.concatenate([features, cls_token_vec])

    features = self._combine_with_existing_dense_features(
        message, features, DENSE_FEATURE_NAMES[attribute]
    )
    message.set(DENSE_FEATURE_NAMES[attribute], features)