code: def test_lm_stopwords_punctuation(
      lang_model,
      punctuation,
      stopwords,
      filling,
      movie_sentiment_data,
      sample_proba,
      nlp,
  ):
      """
      Checks if the sampling procedure affect the stopwords and the
      punctuation when is not supposed to.
      """
      # unpack test data
      X_test = movie_sentiment_data["X_test"]
  
      # select 10 samples
      n = 10
      np.random.seed(0)
      idx = np.random.choice(len(X_test), size=n, replace=False)
  
      # update test dat
      X_test = [X_test[i] for i in idx]
      assert len(X_test) == n
  
      # define perturb opts
      perturb_opts = {
          "sample_proba": sample_proba,
          "punctuation": punctuation,
          "stopwords": stopwords,
          "frac_mask_templates": 0.1,
      }
  
      # initialize sampler
      sampler = LanguageModelSampler(
          model=lang_model, perturb_opts=perturb_opts
      )
  
      for i in range(n):
          text = X_test[i]
  
          # process test
          processed = nlp(text)
          words = [w.text.lower() for w in processed]
          words = {w: words.count(w) for w in words}
  
          # set sampler perturb opts
          sampler.set_text(text)
  
          # get masks samples
          raw, data = sampler.create_mask(
              (), num_samples=10, filling=filling, **perturb_opts
          )
  
          for j in range(len(raw)):
              mask_counts = str(raw[j]).count(lang_model.mask)
              raw[j] = str(raw[j]).replace(
                  lang_model.mask, "", mask_counts
              )
  
              preprocessed = nlp(str(raw[j]))
              words_masks = [w.text.lower() for w in preprocessed]
              words_masks = {
                  w: words_masks.count(w) for w in words_masks
              }
  
              # check if the stopwords were perturbed and they were not supposed to
              for sw in stopwords:
                  if sw in words:
                      assert words[sw] == words_masks[sw]
  
              # check if the punctuation was perturbed and it was not supposed to
              for p in punctuation:
                  if (p in text) and (
                      p != "'"
                  ):  # ' is a tricky one as in words don't for which don' is a token
                      assert text.count(p) == str(raw[j]).count(p)
  
imports: import pytest
  from pytest_lazyfixture import lazy_fixture
  import string
  import numpy
  from typing import List
  from alibi.api.defaults import DEFAULT_META_ANCHOR, DEFAULT_DATA_ANCHOR
  from alibi.exceptions import PredictorCallError, PredictorReturnTypeError
  from alibi.explainers import AnchorText
  from alibi.explainers.anchors.text_samplers import Neighbors, load_spacy_lexeme_prob
  from alibi.explainers.anchors.language_model_text_sampler import LanguageModelSampler
  from alibi.explainers.tests.utils import predict_fcn
label_desc: Use image node_id 7 for calling a global function with example usage: test_lm_stopwords_punctuation(lang_model, punctuation, stopwords, filling, movie_sentiment_data, sample_proba, nlp) without return types