# Buggy code
def _create_sequence(
    self, attribute: Text, all_tokens: List[List[Text]]
) -> List[scipy.sparse.coo_matrix]:
    X = []

    for i, tokens in enumerate(all_tokens):
        # vectorizer.transform returns a sparse matrix of size
        # [n_samples, n_features]
        # set input to list of tokens if sequence should be returned
        # otherwise join all tokens to a single string and pass that as a list
        tokens_without_cls = tokens
        if attribute in [TEXT_ATTRIBUTE, RESPONSE_ATTRIBUTE]:
            tokens_without_cls = tokens[:-1]

        seq_vec = self.vectorizers[attribute].transform(tokens_without_cls)
        seq_vec.sort_indices()

        if attribute in [TEXT_ATTRIBUTE, RESPONSE_ATTRIBUTE]:
            tokens_text = [" ".join(tokens_without_cls)]
            cls_vec = self.vectorizers[attribute].transform(tokens_text)
            cls_vec.sort_indices()

            x = scipy.sparse.vstack([seq_vec, cls_vec])
        else:
            x = seq_vec

        X.append(x.tocoo())

    return X


# Traceback (ValueError)
Traceback (most recent call last):
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\saurabhd\AppData\Local\Programs\Python\Python36\Scripts\rasa.exe\__main__.py", line 7, in <module>
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\__main__.py", line 76, in main
cmdline_arguments.func(cmdline_arguments)
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\cli\train.py", line 76, in train
kwargs=extract_additional_arguments(args),
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\train.py", line 46, in train
kwargs=kwargs,
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\asyncio\base_events.py", line 484, in run_until_complete
return future.result()
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\train.py", line 97, in train_async
kwargs,
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\train.py", line 184, in _train_async_internal
kwargs=kwargs,
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\train.py", line 241, in _do_training
persist_nlu_training_data=persist_nlu_training_data,
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\train.py", line 470, in _train_nlu_with_validated_data
persist_nlu_training_data=persist_nlu_training_data,
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\nlu\train.py", line 86, in train
interpreter = trainer.train(training_data, **kwargs)
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\nlu\model.py", line 191, in train
updates = component.train(working_data, self.config, **context)
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\nlu\featurizers\sparse_featurizer\regex_featurizer.py", line 67, in train
self._text_features_with_regex(example, attribute)
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\nlu\featurizers\sparse_featurizer\regex_featurizer.py", line 76, in _text_features_with_regex
message, extras, feature_name=SPARSE_FEATURE_NAMES[attribute]
File "c:\users\saurabhd\appdata\local\programs\python\python36\lib\site-packages\rasa\nlu\featurizers\featurizer.py", line 67, in _combine_with_existing_sparse_features
f"Cannot concatenate sparse features as sequence dimension does not "
ValueError: Cannot concatenate sparse features as sequence dimension does not match: 7 != 1. Make sure to set 'return_sequence' to the same value for all your featurizers.

# Fixed code
def _create_sequence(
    self, attribute: Text, all_tokens: List[List[Text]]
) -> List[scipy.sparse.coo_matrix]:
    X = []

    for i, tokens in enumerate(all_tokens):
        # vectorizer.transform returns a sparse matrix of size
        # [n_samples, n_features]
        # set input to list of tokens if sequence should be returned
        # otherwise join all tokens to a single string and pass that as a list
        tokens_without_cls = tokens
        if attribute in [TEXT_ATTRIBUTE, RESPONSE_ATTRIBUTE]:
            tokens_without_cls = tokens[:-1]

        if not tokens_without_cls:
            # attribute is not set (e.g. response not present)
            X.append(None)
            continue

        seq_vec = self.vectorizers[attribute].transform(tokens_without_cls)
        seq_vec.sort_indices()

        if attribute in [TEXT_ATTRIBUTE, RESPONSE_ATTRIBUTE]:
            tokens_text = [" ".join(tokens_without_cls)]
            cls_vec = self.vectorizers[attribute].transform(tokens_text)
            cls_vec.sort_indices()

            x = scipy.sparse.vstack([seq_vec, cls_vec])
        else:
            x = seq_vec

        X.append(x.tocoo())

    return X