class_docstr: Abstract custom Keras model.
  
   This model overwrites the following methods:
  - train_step
  - test_step
  - predict_step
  - save
  - load
  Cannot be used as tf.keras.Model.
class_docstr_tok: ["Abstract","custom","Keras","model",".","This","model","overwrites","the","following","methods",":","-","train_step","-","test_step","-","predict_step","-","save","-","load","Can","not","be","used","as","tf.keras.Model","."]
docstr: Loads a model from the given weights.
  
  Args:
      model_file_name: Path to file containing model weights.
      model_data_example: Example data point to construct the model architecture.
      predict_data_example: Example data point to speed up prediction during
        inference.
      finetune_mode: Indicates whether to load the model for further finetuning.
      *args: Any other non key-worded arguments.
      **kwargs: Any other key-worded arguments.
  
  Returns:
      Loaded model with weights appropriately set.
docstr_tok: ["Loads","a","model","from","the","given","weights",".","Args",":","model_file_name",":","Path","to","file","containing","model","weights",".","model_data_example",":","Example","data","point","to","construct","the","model","architecture",".","predict_data_example",":","Example","data","point","to","speed","up","prediction","during","inference",".","finetune_mode",":","Indicates","whether","to","load","the","model","for","further","finetuning",".","*","args",":","Any","other","non","key-worded","arguments",".","*","*","kwargs",":","Any","other","key-worded","arguments",".","Returns",":","Loaded","model","with","weights","appropriately","set","."]
code: def load(
      cls,
      model_file_name: Text,
      model_data_example: RasaModelData,
      predict_data_example: Optional[RasaModelData] = None,
      finetune_mode: bool = False,
      *args: Any,
      **kwargs: Any,
  ) -> "RasaModel":
      """Loads a model from the given weights.
  
      Args:
          model_file_name: Path to file containing model weights.
          model_data_example: Example data point to construct the model architecture.
          predict_data_example: Example data point to speed up prediction during
            inference.
          finetune_mode: Indicates whether to load the model for further finetuning.
          *args: Any other non key-worded arguments.
          **kwargs: Any other key-worded arguments.
  
      Returns:
          Loaded model with weights appropriately set.
      """
      logger.debug(
          f"Loading the model from {model_file_name} "
          f"with finetune_mode={finetune_mode}..."
      )
      # create empty model
      model = cls(*args, **kwargs)
      learning_rate = kwargs.get("config", {}).get(LEARNING_RATE, 0.001)
      run_eagerly = kwargs.get("config", {}).get(RUN_EAGERLY)
  
      # need to train on 1 example to build weights of the correct size
      model.compile(
          optimizer=tf.keras.optimizers.Adam(learning_rate),
          run_eagerly=run_eagerly,
      )
      data_generator = RasaBatchDataGenerator(
          model_data_example, batch_size=1
      )
      model.fit(data_generator, verbose=False)
      # load trained weights
      model.load_weights(model_file_name)
  
      # predict on one data example to speed up prediction during inference
      # the first prediction always takes a bit longer to trace tf function
      if not finetune_mode and predict_data_example:
          model.run_inference(predict_data_example)
  
      logger.debug("Finished loading the model.")
      return model
  
imports: import time
  import random
  import tensorflow
  import numpy
  import logging
  import os
  from collections import defaultdict
  from typing import List, Text, Dict, Tuple, Union, Optional, Any, TYPE_CHECKING
  from keras.utils import tf_utils
  from keras import Model
  from rasa.shared.constants import DIAGNOSTIC_DATA
  from rasa.utils.tensorflow.constants import LABEL, IDS, INTENT_CLASSIFICATION, SENTENCE, SEQUENCE_LENGTH, RANDOM_SEED, EMBEDDING_DIMENSION, REGULARIZATION_CONSTANT, SIMILARITY_TYPE, CONNECTION_DENSITY, NUM_NEG, LOSS_TYPE, MAX_POS_SIM, MAX_NEG_SIM, USE_MAX_NEG_SIM, NEGATIVE_MARGIN_SCALE, SCALE_LOSS, LEARNING_RATE, CONSTRAIN_SIMILARITIES, MODEL_CONFIDENCE, RUN_EAGERLY
  from rasa.utils.tensorflow.model_data import RasaModelData, FeatureSignature, FeatureArray
  import rasa.utils.train_utils
  from rasa.utils.tensorflow import layers
  from rasa.utils.tensorflow import rasa_layers
  from rasa.utils.tensorflow.data_generator import RasaDataGenerator, RasaBatchDataGenerator
  from rasa.shared.nlu.constants import TEXT
  from rasa.shared.exceptions import RasaException
  from rasa.utils.tensorflow.types import BatchData, MaybeNestedBatchData
label_desc: Use image node_id 16 for calling the RasaModel obj's underlying member method code with example usage: obj.load(cls, model_file_name, model_data_example, predict_data_example, finetune_mode) and returns: model