code: def test_action_unlikely_intent_prediction(
      self,
      trained_policy: UnexpecTEDIntentPolicy,
      model_storage: ModelStorage,
      resource: Resource,
      execution_context: ExecutionContext,
      default_domain: Domain,
      predicted_similarity: float,
      threshold_value: float,
      is_unlikely: bool,
      monkeypatch: MonkeyPatch,
      tmp_path: Path,
  ):
      loaded_policy = self.persist_and_load_policy(
          trained_policy, model_storage, resource, execution_context
      )
  
      similarities = np.array([[[0.0] * len(default_domain.intents)]])
  
      dummy_intent_index = 4
      similarities[0, 0, dummy_intent_index] = predicted_similarity
      query_intent = default_domain.intents[dummy_intent_index]
  
      loaded_policy.label_thresholds[
          dummy_intent_index
      ] = threshold_value
  
      precomputations = None
      tracker = DialogueStateTracker(
          sender_id="init", slots=default_domain.slots
      )
  
      tracker.update_with_events(
          [UserUttered(text="hello", intent={"name": query_intent})],
          default_domain,
      )
  
      # Preset the model predictions to the similarity values
      # so that we don't need to hardcode for particular model predictions.
      monkeypatch.setattr(
          loaded_policy.model,
          "run_inference",
          lambda data: {"similarities": similarities},
      )
  
      prediction = loaded_policy.predict_action_probabilities(
          tracker, default_domain, precomputations
      )
  
      if not is_unlikely:
          assert (
              prediction.probabilities
              == [0.0] * default_domain.num_actions
          )
      else:
          assert (
              prediction.probabilities[
                  default_domain.index_for_action(
                      ACTION_UNLIKELY_INTENT_NAME
                  )
              ]
              == 1.0
          )
  
          # Make sure metadata is set. The exact structure
          # of the metadata is tested separately and
          # not as part of this test.
          assert prediction.action_metadata is not None
          # Assert metadata is serializable
          assert json.dumps(prediction.action_metadata)
  
imports: import json
  from pathlib import Path
  from typing import Optional, List, Dict, Type
  import tensorflow
  import numpy
  import pytest
  from _pytest.monkeypatch import MonkeyPatch
  from _pytest.logging import LogCaptureFixture
  import logging
  from rasa.core.featurizers.single_state_featurizer import IntentTokenizerSingleStateFeaturizer
  from rasa.core.featurizers.tracker_featurizers import TrackerFeaturizer
  from rasa.core.featurizers.tracker_featurizers import IntentMaxHistoryTrackerFeaturizer
  from rasa.nlu.classifiers import LABEL_RANKING_LENGTH
  from rasa.shared.constants import LATEST_TRAINING_DATA_FORMAT_VERSION
  from rasa.shared.core.generator import TrackerWithCachedStates
  from rasa.core.policies.ted_policy import PREDICTION_FEATURES
  from rasa.core.policies.unexpected_intent_policy import UnexpecTEDIntentPolicy, RankingCandidateMetadata
  from rasa.engine.graph import ExecutionContext
  from rasa.engine.storage.resource import Resource
  from rasa.engine.storage.storage import ModelStorage
  from rasa.shared.core.constants import ACTION_UNLIKELY_INTENT_NAME, ACTION_LISTEN_NAME
  from rasa.shared.core.domain import Domain
  from rasa.shared.core.events import ActionExecuted, UserUttered, EntitiesAdded, SlotSet, ActionExecutionRejected, ActiveLoop
  from rasa.shared.core.trackers import DialogueStateTracker
  from rasa.utils.tensorflow.constants import IGNORE_INTENTS_LIST, LABEL, MASK, SENTENCE, IDS, POSITIVE_SCORES_KEY, NEGATIVE_SCORES_KEY, RANKING_KEY, RANKING_LENGTH
  from rasa.shared.nlu.constants import INTENT
  from rasa.shared.core.events import Event
  from rasa.utils.tensorflow import model_data_utils
  from tests.core.test_policies import train_trackers
  from tests.core.policies.test_ted_policy import TestTEDPolicy
label_desc: Use image node_id 16 for calling the TestUnexpecTEDIntentPolicy obj's underlying member method code with example usage: obj.test_action_unlikely_intent_prediction(trained_policy, model_storage, resource, execution_context, default_domain, predicted_similarity, threshold_value, is_unlikely, monkeypatch, tmp_path) without return types