code: def test_lm_sample_punctuation(
      lang_model,
      punctuation,
      filling,
      movie_sentiment_data,
      sample_proba,
  ):
      """
      Check if the punctuation is not sampled when flag is set.
      """
      # 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": [],
          "filling": filling,
          "sample_punctuation": False,
      }
  
      # initialize sampler
      sampler = LanguageModelSampler(
          model=lang_model, perturb_opts=perturb_opts
      )
  
      for i in range(n):
          text = X_test[i]
          tokens = lang_model.tokenizer.tokenize(text)
          tokens = [
              t
              if not lang_model.is_punctuation(
                  t, perturb_opts["punctuation"]
              )
              else " "
              for t in tokens
          ]
          text = lang_model.tokenizer.decoder.decode(tokens)
  
          # set sampler perturb opts
          sampler.set_text(text)
  
          # get masks samples
          raw, data = sampler.perturb_sentence(
              (), num_samples=10, **perturb_opts
          )
  
          for j in range(len(raw)):
              tokens = lang_model.tokenizer.tokenize(raw[j])
              assert all(
                  [
                      not lang_model.is_punctuation(
                          t, perturb_opts["punctuation"]
                      )
                      for t in tokens
                  ]
              )
  
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 10 for calling a global function with example usage: test_lm_sample_punctuation(lang_model, punctuation, filling, movie_sentiment_data, sample_proba) without return types