<jupyter_start><jupyter_text>Embed data with joint LSTMEmbed downstream data using the joint LSTM trained on all signals simultaneously.<jupyter_code>import os
os.environ["CUDA_VISIBLE_DEVICES"] = "3"
from phase.embedding import *

PATH = os.path.expanduser("~/phase/upstream_embedding/")

lookback = 60
DEBUG = False

label_type_eta_currfeat_lst = [("desat_bool92_5_nodesat",0.02,"SAO2"),
                               ("nibpm60",0.1,"NIBPM"), 
                               ("etco235",0.1,"ETCO2")]

for label_type, _, curr_feat in label_type_eta_currfeat_lst:
    print("\n[Progress] label_type: {}, eta: {}, curr_feat {}".format(label_type, "NA", curr_feat))

    for hosp_model in [0,1]:

        # This is the order of features that the big LSTM uses
        top15 = ["SAO2","FIO2","ECGRATE","ETCO2","RESPRATE","PEEP","TV","PEAK",
                 "PIP","ETSEVO","ETSEV","TEMP1","NIBPM","NIBPS","NIBPD"]

        MODDIR = "/homes/gws/hughchen/phase/upstream_embedding/models/"
        MODDIR += "multivariate_biglstmdropout_hd{}_nextfivetask_".format(hosp_model)
        MODDIR += "200n_200n_200ep_rmspropopt_0.001lr_0.5drop_1000bs_epochsize"
        min_mod = load_min_model_helper(MODDIR)
        min_mod_weights = min_mod.get_weights()

        for hosp_data in [0,1]:
            print("\n[Progress] hosp_data {}".format(hosp_data))

            data_type = "proc[top15]+nonsignal"
            # Load train validation data and split it
            (X_trval_lst,y_trval) = load_data(PATH,data_type,label_type,True,hosp_data,curr_feat,DEBUG=DEBUG)
            X_trval_lst = [X[:,:,np.newaxis] if X.shape[1] == 60 else X for X in X_trval_lst]
            
            # Load test data
            (X_test1_lst,y_test1) = load_data(PATH,data_type,label_type,False,hosp_data,curr_feat,DEBUG=DEBUG)
            X_test1_lst = [X[:,:,np.newaxis] if X.shape[1] == 60 else X for X in X_test1_lst]
            
            # Create and save embeddings for top15 features
            task   = "nextfivemulti"
            suffix = "embedding_data{}_model{}.npy".format(hosp_data,hosp_model)
            final_task = label_type
            SPATH  = PATH+"data/{}/hospital_{}/".format(final_task,hosp_data)
            SPATH += "hidden200/{}/model_{}/".format(task,hosp_model)
            if not os.path.exists(SPATH): os.makedirs(SPATH)

            for i in range(0,len(top15)):
                feat = top15[i] # Current feature being embedded
                
                # Create model
                h1 = 200; h2 = 200; lookback = 60
                model = Sequential()
                model.add(LSTM(h1, recurrent_dropout=0.5, return_sequences=True, 
                               input_shape=(lookback,1), 
                               weights=min_mod_weights[(i*3):((i+1)*3)]))
                model.add(LSTM(h2, recurrent_dropout=0.5,dropout=0.5,
                               weights=min_mod_weights[(45+(i*3)):(45+((i+1)*3))]))

                # Create embeddings and names
                trval_pred = model.predict(X_trval_lst[i])
                test1_pred = model.predict(X_test1_lst[i])
                trval_pred_name = "task:{}_feat:{}_trval_{}".format(task,feat,suffix)
                test1_pred_name = "task:{}_feat:{}_test1_{}".format(task,feat,suffix)

                # Save embeddings
                np.save(SPATH+trval_pred_name,trval_pred)
                np.save(SPATH+test1_pred_name,test1_pred)<jupyter_output>[Progress] label_type: etco235, eta: NA, curr_feat ETCO2
[PROGRESS] Starting load_min_model_helper()
[DEBUG] MPATH /homes/gws/hughchen/phase/upstream_embedding/models/multivariate_biglstmdropout_hd1_nextfivetask_200n_200n_200ep_rmspropopt_0.001lr_0.5drop_1000bs_epochsize
{'fraction_non_alphanumeric': 0.12526881720430108, 'fraction_numerical': 0.03494623655913978, 'mean_word_length': 2.6409001956947162, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '32662', 'license': 'MIT', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1269, 'n_words': 194, 'path': 'experiments/upstream/Embed joint LSTM.ipynb', 'repo_name': 'suinleelab/PHASE', 'size': '3720'}