-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.py
179 lines (150 loc) · 5.29 KB
/
hello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import tensorflow as tf
from utils import *
from load_word2vec import *
import random
import re
from second_hand_house.toolbox import *
def test_tf(embedding, input_x, sequence_length):
input_x = tf.placeholder(tf.string, [None, sequence_length], name="input_x")
#
# word2vec = tf.Variable(tf.constant(0.0, shape=[vocab_size, embedding_dim]), trainable=False, name="word2vec")
# word_placeholder = tf.placeholder(tf.float32, [vocab_size, embedding_dim], name="word_placeholder")
# word2vec.assign(word_placeholder)
emb = tf.nn.embedding_lookup(embedding, input_x)
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
# sess.run(init_op, feed_dict={input_x: input_x, word_placeholder: embedding})
print(sess.run(emb))
def index_vocab(word, vocab):
index = 0
for w in vocab:
index += 1
if w == word:
return index
def sample2index(samples, vocab):
inner_index_list = []
outer_index_list = []
for sample in samples:
print(sample)
for word in sample:
index = np.where(vocab == word)
if len(index[0]) != 0:
i = index[0][0]
else:
i = 0
inner_index_list.append(i)
outer_index_list.append(inner_index_list)
inner_index_list = []
return outer_index_list
def test1():
# x_raw = ["Optimizing Event Pattern Matching Using Business Process Models",
# "Binbin Gu",
# "Zhixu Li",
# "Frequent Closed Sequence Mining without Candidate Maintenance",
# "Chen Yang",
# "Yelena Yesha"]
# y_test = [0, 1, 1, 0, 1, 1]
#
# input_list = [x.split() for x in x_raw]
# for i in input_list:
# print(i)
# input_pad = makePaddedList(36, input_list)
# for i in input_pad:
# print(i)
#
# # # load word2vec array
# print("loading word2vec:")
# path = "/home/himon/Jobs/nlps/word2vec/resized_dblp_vectors.bin"
# vocab, embedding = load_from_binary(path)
# vocab_size, embedding_dim = embedding.shape
# print(index_vocab('Sequence', vocab))
# print(np.where(vocab == 'Sequence')[0][0])
# index = np.where(vocab == '<pad>')
# if len(index[0]) == 0:
# index = 0
# print(index)
#
# index_list = sample2index_matrix(input_pad, vocab, 36)
# print(index_list)
# test_tf(embedding, index_list, 36)
# sample = ['Agents-based', 'design', 'for', 'fault', 'management', 'systems', 'in', 'industrial', 'processes', '<p>']
# l = sample2index(sample, vocab)
# print(l)
loss = [[-7.81613398, 12.59275246, -9.82943439],
[-8.21374607, 11.90228271, -7.99127913],
[-8.09581947, 11.60901165, -7.79938269],
[-6.60628796, 13.57494068, -11.94314194],
[-8.11062527, 12.61278534, -9.55984306],
[-11.80429077, 18.12654686, -14.37622833],
[-12.34054852, 17.99167442, -13.79800224],
[-8.32250309, 12.67250538, -9.48696995],
[21.00398254, -13.31361675, -11.81652069],
[20.87360764, -14.28156853, -9.39016056]]
index = [i for i in range(len(loss))]
print(index)
loss_dict = dict(zip(index, loss))
print(loss_dict)
predictions = np.array([1, 1, 1, 1, 1, 1, 1, 1, 0, 0])
# predictions = [1, 1, 1, 1, 1, 1, 1, 1, 0, 0]
t_index = np.where(predictions == 0)
print(t_index)
t_num = len(t_index[0])
title_index = 0
max_temp = -1000
max_index = 0
for i in t_index[0]:
if max_temp < loss[i][0]:
max_temp = loss[i][0]
max_index = i
print(i)
print(loss[i])
print(max_index)
def build_date_data(date_size):
dates = []
date = []
for s in range(date_size):
p = random.sample([i for i in range(500)], 2)
date.append(str(p[0]))
date.append('_')
date.append(str(p[1]))
dates.append(date)
date = []
return dates
if __name__ == '__main__':
print('main')
vocab = load_dict('second_hand_house/second_hand_house_complete_dict.pickle')
# str = ' 1-42'
# # print(match_regex('1-42'))
# page_regex0 = r'.*([0-9]+\-[0-9]+$)'
# print(re.match(page_regex0, str))
# dates = build_date_data(20)
# print(dates)
# n = np.zeros([2, 2])
# print(n)
# s1 = "Spatio-temporal Event Modeling and Ranking, Xuefei Li, Hongyun Cai, Zi Huang, Yang Yang and Xiaofang Zhou, " \
# "14th International Conference on Web Information System Engineering,2013"
# s2 = "[0,1,1,1,1,1,2,3]"
# s3 = 'pages 12-35'
# s31 = 'pp 13-89'
# s32 = '45-56'
# s4 = '(2015)'
# s41 = '2016'
#
# page_regex1 = r'.*(^[0-9]+\-[0-9]+$)'
# page_regex2 = r'.*(page.[0-9]+\-[0-9]+$)'
# page_regex2 = r'.*(pp.[0-9]+\-[0-9]+$)'
# print(re.match(page_regex2, s31))
# matchObj = re.match(r'[0-9]', s2)
# print(matchObj)
# l = [x for x in eval(s2)]
# print(l)
# year_regex1 = r'.*([1-2][0-9]{3})' # '2014
# year_regex2 = r'.*(\([1-2][0-9]{3}\))' # '(2014)'
# year_regex = "|".join([year_regex2, year_regex1])
# reobj1 = re.compile(year_regex1)
# print(reobj1.findall(s4))
# reobj2 = re.compile(year_regex2)
# print(reobj2.findall(s4))
#
# result = re.match(year_regex, s41)
# print(result)