MCPcopy Create free account
hub / github.com/chinawithfrank/ChatBotCourse / next_batch

Method next_batch

tf_classify_demo/sample_data.py:176–200  ·  view source on GitHub ↗

获取一批样本数据

(self, count)

Source from the content-addressed store, hash-verified

174
175
176 def next_batch(self, count):
177 """
178 获取一批样本数据
179 """
180 x_s = []
181 y_s = []
182 if self.pos >= len(self.data):
183 print("error")
184 sys.exit(1)
185 while count > 0:
186 item = self.data[self.pos]
187 vectors = item['vectors']
188 local_group_id = item['local_group_id']
189 x_array = np.zeros([self.dim_info.x_dim], dtype=np.float)
190 y_array = np.zeros(self.maps.group_id_size(), dtype=np.float)
191 y_array[local_group_id] = 1
192 for word_id in vectors:
193 vector = vectors[word_id]
194 for index, weight in enumerate(vector):
195 x_array[word_id*self.dim_info.vec_dim+index] = weight
196 x_s.append(x_array)
197 y_s.append(y_array)
198 self.pos = (self.pos + 1) % len(self.data)
199 count = count - 1
200 return x_s, y_s
201
202 def test_sets(self):
203 """

Callers 4

sample_data.pyFile · 0.45
trainFunction · 0.45

Calls 2

group_id_sizeMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected