code: def test_feature_computation(
      create_lexical_syntactic_featurizer: Callable[
          [Dict[Text, Any]], LexicalSyntacticFeaturizer
      ],
      sentence: Text,
      part_of_speech: Optional[List[Text]],
      feature_config: List[List[Text]],
      expected_features: List[Union[int, List[int]]],
  ):
      featurizer = create_lexical_syntactic_featurizer(
          {"alias": "lsf", "features": feature_config}
      )
  
      # build the message
      tokens = [
          Token(text=match[0], start=match.start())
          for match in re.finditer(r"\w+", sentence)
      ]
      # ... and add part of speech tags (str) to tokens (if specified)
      if part_of_speech:
          assert len(tokens) == len(part_of_speech)
          for token, pos in zip(tokens, part_of_speech):
              token.data = {POS_TAG_KEY: pos}
      message = Message(data={TOKENS_NAMES[TEXT]: tokens})
  
      # train
      featurizer.train(TrainingData([message]))
      assert not message.features
  
      # process
      featurizer.process([message])
      assert len(message.features) == 1
      feature = message.features[0]
      assert feature.attribute == TEXT
      assert feature.is_sparse()
      assert feature.type == FEATURE_TYPE_SEQUENCE
      assert feature.features.shape[0] == len(tokens)
  
      if isinstance(expected_features[0], List):
          assert len(expected_features) == feature.features.shape[0]
          # we specified the full matrix
          assert np.all(feature.features.todense() == expected_features)
      else:
          assert len(expected_features) == feature.features.shape[1]
          # just check features for the first token
          assert np.all(
              feature.features.todense()[0] == expected_features
          )
  
imports: import numpy
  import pytest
  import re
  from typing import Text, Dict, Any, Callable, List, Optional, Union
  from rasa.engine.graph import ExecutionContext
  from rasa.engine.storage.storage import ModelStorage
  from rasa.engine.storage.resource import Resource
  from rasa.nlu.constants import DENSE_FEATURIZABLE_ATTRIBUTES, MESSAGE_ATTRIBUTES, TOKENS_NAMES
  from rasa.nlu.tokenizers.spacy_tokenizer import POS_TAG_KEY
  from rasa.nlu.featurizers.sparse_featurizer.lexical_syntactic_featurizer import LexicalSyntacticFeaturizer, FEATURES
  from rasa.shared.nlu.training_data.training_data import TrainingData
  from rasa.shared.nlu.training_data.message import Message
  from rasa.shared.nlu.constants import FEATURE_TYPE_SEQUENCE, TEXT
  from rasa.shared.exceptions import InvalidConfigException
  from rasa.nlu.tokenizers.tokenizer import Token
label_desc: Use image node_id 3 for calling a global function with example usage: test_feature_computation(create_lexical_syntactic_featurizer, sentence, part_of_speech, feature_config, expected_features) without return types