def test2(): token_id, _ = load_dict() get_sentIDs(accident_train_sents_root, token_id, accident_train_sents_pkl2) get_sentIDs(accident_test_sents_root, token_id, accident_test_sents_pkl2) get_sentIDs(earthquake_train_sents_root, token_id, earthquake_train_sents_pkl2) get_sentIDs(earthquake_test_sents_root, token_id, earthquake_test_sents_pkl2)
def test123(): #below is a function test; if you use this for text classifiction, you need to tranform sentence to indices of vocabulary first. then feed data to the graph. num_classes = 6 learning_rate = 0.01 batch_size = 8 decay_steps = 1000 decay_rate = 0.9 # sequence_length=5 vocab_size = 40000 embed_size = 300 rnn_size = 64 is_training = True dropout_keep_prob = 1 #0.5 textRNN = TextRNN(num_classes, learning_rate, batch_size, decay_steps, decay_rate, vocab_size, embed_size, rnn_size, is_training) word2idx, idx2word = load_dict() data_path = '../data/test_data/train_new_data_idx.pkl' trainingSamples = loadDataset(data_path) # test_path = '../data/test_data/test_data_idx.pkl' # testingSamples = loadDataset(test_path) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) for i in range(5): batches = getBatches(trainingSamples, 64) for e in batches: # print("emo_cat_len",len(e.emo_cat)) # print(batches) feed_dict = { textRNN.input_x: e.inputs_sentence, textRNN.input_length: e.inputs_sentence_length, textRNN.input_y: e.post_cat, textRNN.dropout_keep_prob: dropout_keep_prob } # input_x=np.zeros((batch_size,sequence_length)) #[None, self.sequence_length] # input_y=np.array([1,0,1,1,1,2,1,1]) #np.zeros((batch_size),dtype=np.int32) #[None, self.sequence_length] # loss,acc,predict,_=sess.run([textRNN.loss_val,textRNN.accuracy,textRNN.predictions,textRNN.train_op],feed_dict={textRNN.input_x:input_x,textRNN.input_y:input_y,textRNN.dropout_keep_prob:dropout_keep_prob}) learning_rate, loss, acc, predict, _ = sess.run( [ textRNN.learning_rate, textRNN.loss_val, textRNN.accuracy, textRNN.predictions, textRNN.train_op ], feed_dict=feed_dict) print("learing rate:", learning_rate, "loss:", loss, "acc:", acc)
def test3(): token_id, _ = load_dict() pid2pos_pos2pid_dict_pkl = '../preprocessed/pid2pos_pos2pid_dict.pkl' with open(pid2pos_pos2pid_dict_pkl, 'rb') as f: _, pos_pid = cPickle.load(f) role_rid = {'S': 0, 'O': 1, 'X': '2', 'B': 3, 'V': 4, '?': 5} get_sentIDs_pids_rids(accident_train_sents_root, token_id, accident_train_sents_pkl3, pos_pid, role_rid) get_sentIDs_pids_rids(accident_test_sents_root, token_id, accident_test_sents_pkl3, pos_pid, role_rid) get_sentIDs_pids_rids(earthquake_train_sents_root, token_id, earthquake_train_sents_pkl3, pos_pid, role_rid) get_sentIDs_pids_rids(earthquake_test_sents_root, token_id, earthquake_test_sents_pkl3, pos_pid, role_rid)
dataset [https://zenodo.org/record/2872624#.X5s-G4hKiUk] and the cammoun parcellation of 1000 nodes, as described in the manuscript. If some of the data is missing, you will still be able to generate the figures that do not require the data. For example, panels a and b of Figure 1 can be created in the absence of the freesurfer annotation files. @author: Vincent Bazinet """ import numpy as np import os # Load the example data import load_data LAU1000 = load_data.load_dict("data/LAU1000") ''' RESULT 1: Compute the random walker transition probabilities. ''' # Choose time points at which the transition probabilities will be evaluated. LAU1000['t_points'] = np.logspace(-0.5, 1.5, 100) # Compute transition probabilities for every time points. from multiscale_functions import transition_probabilities LAU1000['pr'] = transition_probabilities(LAU1000['sc'], LAU1000['t_points'], method='rwL') ''' RESULT 2:
tf.app.flags.DEFINE_integer( "batch_size", 32, "Batch size for training/evaluating.") #批处理的大小 32-->128 tf.app.flags.DEFINE_integer( "validate_every", 50, "Validate every validate_every epochs.") #每10轮做一次验证 tf.app.flags.DEFINE_integer("dropout_keep_prob", 0.5, " the value of dropout_keep_prob") tf.app.flags.DEFINE_boolean("use_embedding", True, "whether to use embedding or not.") # tf.app.flags.DEFINE_string("traning_data_path","train-zhihu4-only-title-all.txt","path of traning data.") #train-zhihu4-only-title-all.txt===>training-data/test-zhihu4-only-title.txt--->'training-data/train-zhihu5-only-title-multilabel.txt' tf.app.flags.DEFINE_string("word2vec_model_path", "zhihu-word2vec.bin-100", "word2vec's vocabulary and vectors") tf.app.flags.DEFINE_string('model_dir', 'test_1/', 'Path to save model checkpoints') FLAGS = tf.app.flags.FLAGS word2idx, idx2word = load_dict() data_path = '../data/test_data/train_new_data_idx.pkl' trainingSamples = loadDataset(data_path) # test_path = '../data/test_data_ids.pkl' # testingSamples = loadDataset(test_path) model = TextRNN(FLAGS.num_classes, FLAGS.learning_rate, FLAGS.batch_size, FLAGS.decay_steps, FLAGS.decay_rate, FLAGS.vocab_size, FLAGS.embed_size, FLAGS.rnn_size, FLAGS.is_training) config = tf.ConfigProto() config.gpu_options.allow_growth = True sess = tf.Session(config=config) ckpt = tf.train.get_checkpoint_state(FLAGS.model_dir)
# Load file path constants file_path_dict = constants['db_file_paths'] DATABASE_FILE_PATH = file_path_dict['database'] DICT_FILE_PATH = file_path_dict['dict'] USER_GOALS_FILE_PATH = file_path_dict['user_goals'] run_dict = constants['run'] USE_USERSIM = run_dict['usersim'] WARMUP_MEM = run_dict['warmup_mem'] NUM_EP_TRAIN = run_dict['num_ep_run'] TRAIN_FREQ = run_dict['train_freq'] MAX_ROUND_NUM = run_dict['max_round_num'] SUCCESS_RATE_THRESHOLD = run_dict['success_rate_threshold'] print("In train") database = load_dict() db_dict = load_orgdict() user_goals = load_goals() emc = ErrorModelController(db_dict, constants) state_tracker = StateTracker(database, constants) dqn_agent = DQNAgent(state_tracker.get_state_size(), constants) user = UserSimulator(user_goals, constants, database) print("In train1") def run_round(state, warmup=False): # 1) Agent takes action given state tracker's representation of dialogue (state) agent_action_index, agent_action = dqn_agent.get_action(state, use_rule=warmup) # 2) Update state tracker with the agent's action