rasa/core/policies/embedding_policy.py
def load(cls, path: Text) -> 'EmbeddingPolicy':
        """Loads a policy from the storage.

            **Needs to load its featurizer**"""

        if not os.path.exists(path):
            raise Exception("Failed to load dialogue model. Path {} "
                            "doesn't exist".format(os.path.abspath(path)))

        featurizer = TrackerFeaturizer.load(path)

        file_name = 'tensorflow_embedding.ckpt'
        checkpoint = os.path.join(path, file_name)

        if not os.path.exists(checkpoint + '.meta'):
            return cls(featurizer=featurizer)

        meta_file = os.path.join(path, "embedding_policy.json")
        meta = json.loads(utils.read_file(meta_file))

        tf_config_file = os.path.join(
            path, "{}.tf_config.pkl".format(file_name))

        with open(tf_config_file, 'rb') as f:
            _tf_config = pickle.load(f)

        graph = tf.Graph()
        with graph.as_default():
            sess = tf.Session(config=_tf_config)
            saver = tf.train.import_meta_graph(checkpoint + '.meta')

            saver.restore(sess, checkpoint)

            a_in = cls.load_tensor('intent_placeholder')
            b_in = cls.load_tensor('action_placeholder')
            c_in = cls.load_tensor('slots_placeholder')
            b_prev_in = cls.load_tensor('prev_act_placeholder')
            dialogue_len = cls.load_tensor('dialogue_len')
            x_for_no_intent = cls.load_tensor('x_for_no_intent')
            y_for_no_action = cls.load_tensor('y_for_no_action')
            y_for_action_listen = cls.load_tensor('y_for_action_listen')

            sim_op = cls.load_tensor('similarity_op')

            alignment_history = cls.load_tensor('alignment_history')

            user_embed = cls.load_tensor('user_embed')
            bot_embed = cls.load_tensor('bot_embed')
            slot_embed = cls.load_tensor('slot_embed')
            dial_embed = cls.load_tensor('dial_embed')

            rnn_embed = cls.load_tensor('rnn_embed')
            attn_embed = cls.load_tensor('attn_embed')
            copy_attn_debug = cls.load_tensor('copy_attn_debug')

            all_time_masks = cls.load_tensor('all_time_masks')

        encoded_actions_file = os.path.join(
            path, "{}.encoded_all_actions.pkl".format(file_name))

        with open(encoded_actions_file, 'rb') as f:
            encoded_all_actions = pickle.load(f)

        return cls(featurizer=featurizer,
                   priority=meta["priority"],
                   encoded_all_actions=encoded_all_actions,
                   graph=graph,
                   session=sess,
                   intent_placeholder=a_in,
                   action_placeholder=b_in,
                   slots_placeholder=c_in,
                   prev_act_placeholder=b_prev_in,
                   dialogue_len=dialogue_len,
                   x_for_no_intent=x_for_no_intent,
                   y_for_no_action=y_for_no_action,
                   y_for_action_listen=y_for_action_listen,
                   similarity_op=sim_op,
                   alignment_history=alignment_history,
                   user_embed=user_embed,
                   bot_embed=bot_embed,
                   slot_embed=slot_embed,
                   dial_embed=dial_embed,
                   rnn_embed=rnn_embed,
                   attn_embed=attn_embed,
                   copy_attn_debug=copy_attn_debug,
                   all_time_masks=all_time_masks)
Loads a policy from the storage.

            **Needs to load its featurizer**
Loads a policy from the storage.
Needs to load its featurizer
Loads a policy from the storage . Needs to load its featurizer
def load(cls, path: Text) -> 'EmbeddingPolicy':
        if not os.path.exists(path):
            raise Exception("Failed to load dialogue model. Path {} "
                            "doesn't exist".format(os.path.abspath(path)))
        featurizer = TrackerFeaturizer.load(path)
        file_name = 'tensorflow_embedding.ckpt'
        checkpoint = os.path.join(path, file_name)
        if not os.path.exists(checkpoint + '.meta'):
            return cls(featurizer=featurizer)
        meta_file = os.path.join(path, "embedding_policy.json")
        meta = json.loads(utils.read_file(meta_file))
        tf_config_file = os.path.join(
            path, "{}.tf_config.pkl".format(file_name))
        with open(tf_config_file, 'rb') as f:
            _tf_config = pickle.load(f)
        graph = tf.Graph()
        with graph.as_default():
            sess = tf.Session(config=_tf_config)
            saver = tf.train.import_meta_graph(checkpoint + '.meta')
            saver.restore(sess, checkpoint)
            a_in = cls.load_tensor('intent_placeholder')
            b_in = cls.load_tensor('action_placeholder')
            c_in = cls.load_tensor('slots_placeholder')
            b_prev_in = cls.load_tensor('prev_act_placeholder')
            dialogue_len = cls.load_tensor('dialogue_len')
            x_for_no_intent = cls.load_tensor('x_for_no_intent')
            y_for_no_action = cls.load_tensor('y_for_no_action')
            y_for_action_listen = cls.load_tensor('y_for_action_listen')
            sim_op = cls.load_tensor('similarity_op')
            alignment_history = cls.load_tensor('alignment_history')
            user_embed = cls.load_tensor('user_embed')
            bot_embed = cls.load_tensor('bot_embed')
            slot_embed = cls.load_tensor('slot_embed')
            dial_embed = cls.load_tensor('dial_embed')
            rnn_embed = cls.load_tensor('rnn_embed')
            attn_embed = cls.load_tensor('attn_embed')
            copy_attn_debug = cls.load_tensor('copy_attn_debug')
            all_time_masks = cls.load_tensor('all_time_masks')
        encoded_actions_file = os.path.join(
            path, "{}.encoded_all_actions.pkl".format(file_name))
        with open(encoded_actions_file, 'rb') as f:
            encoded_all_actions = pickle.load(f)
        return cls(featurizer=featurizer,
                   priority=meta["priority"],
                   encoded_all_actions=encoded_all_actions,
                   graph=graph,
                   session=sess,
                   intent_placeholder=a_in,
                   action_placeholder=b_in,
                   slots_placeholder=c_in,
                   prev_act_placeholder=b_prev_in,
                   dialogue_len=dialogue_len,
                   x_for_no_intent=x_for_no_intent,
                   y_for_no_action=y_for_no_action,
                   y_for_action_listen=y_for_action_listen,
                   similarity_op=sim_op,
                   alignment_history=alignment_history,
                   user_embed=user_embed,
                   bot_embed=bot_embed,
                   slot_embed=slot_embed,
                   dial_embed=dial_embed,
                   rnn_embed=rnn_embed,
                   attn_embed=attn_embed,
                   copy_attn_debug=copy_attn_debug,
                   all_time_masks=all_time_masks)
def load ( cls , path : Text ) -> 'EmbeddingPolicy' : if not os . path . exists ( path ) : raise Exception ( "Failed to load dialogue model. Path {} " "doesn't exist" . format ( os . path . abspath ( path ) ) ) featurizer = TrackerFeaturizer . load ( path ) file_name = 'tensorflow_embedding.ckpt' checkpoint = os . path . join ( path , file_name ) if not os . path . exists ( checkpoint + '.meta' ) : return cls ( featurizer = featurizer ) meta_file = os . path . join ( path , "embedding_policy.json" ) meta = json . loads ( utils . read_file ( meta_file ) ) tf_config_file = os . path . join ( path , "{}.tf_config.pkl" . format ( file_name ) ) with open ( tf_config_file , 'rb' ) as f : _tf_config = pickle . load ( f ) graph = tf . Graph ( ) with graph . as_default ( ) : sess = tf . Session ( config = _tf_config ) saver = tf . train . import_meta_graph ( checkpoint + '.meta' ) saver . restore ( sess , checkpoint ) a_in = cls . load_tensor ( 'intent_placeholder' ) b_in = cls . load_tensor ( 'action_placeholder' ) c_in = cls . load_tensor ( 'slots_placeholder' ) b_prev_in = cls . load_tensor ( 'prev_act_placeholder' ) dialogue_len = cls . load_tensor ( 'dialogue_len' ) x_for_no_intent = cls . load_tensor ( 'x_for_no_intent' ) y_for_no_action = cls . load_tensor ( 'y_for_no_action' ) y_for_action_listen = cls . load_tensor ( 'y_for_action_listen' ) sim_op = cls . load_tensor ( 'similarity_op' ) alignment_history = cls . load_tensor ( 'alignment_history' ) user_embed = cls . load_tensor ( 'user_embed' ) bot_embed = cls . load_tensor ( 'bot_embed' ) slot_embed = cls . load_tensor ( 'slot_embed' ) dial_embed = cls . load_tensor ( 'dial_embed' ) rnn_embed = cls . load_tensor ( 'rnn_embed' ) attn_embed = cls . load_tensor ( 'attn_embed' ) copy_attn_debug = cls . load_tensor ( 'copy_attn_debug' ) all_time_masks = cls . load_tensor ( 'all_time_masks' ) encoded_actions_file = os . path . join ( path , "{}.encoded_all_actions.pkl" . format ( file_name ) ) with open ( encoded_actions_file , 'rb' ) as f : encoded_all_actions = pickle . load ( f ) return cls ( featurizer = featurizer , priority = meta [ "priority" ] , encoded_all_actions = encoded_all_actions , graph = graph , session = sess , intent_placeholder = a_in , action_placeholder = b_in , slots_placeholder = c_in , prev_act_placeholder = b_prev_in , dialogue_len = dialogue_len , x_for_no_intent = x_for_no_intent , y_for_no_action = y_for_no_action , y_for_action_listen = y_for_action_listen , similarity_op = sim_op , alignment_history = alignment_history , user_embed = user_embed , bot_embed = bot_embed , slot_embed = slot_embed , dial_embed = dial_embed , rnn_embed = rnn_embed , attn_embed = attn_embed , copy_attn_debug = copy_attn_debug , all_time_masks = all_time_masks )
Loads a policy from the storage.
Loads a policy from the storage .
"""Loads a policy from the storage.

            **Needs to load its featurizer**"""
cls
path
Text