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

Function get_samples

chatbotv4/demo.py:27–53  ·  view source on GitHub ↗

构造样本数据 :return: encoder_inputs: [array([0, 0], dtype=int32), array([0, 0], dtype=int32), array([1, 3], dtype=int32), array([3, 5], dtype=int32), array([5, 7], dtype=int32)] decoder_inputs: [array([1, 1], dtype=int32), array([7, 9], dtype=int32), array([ 9

()

Source from the content-addressed store, hash-verified

25
26
27def get_samples():
28 """构造样本数据
29
30 :return:
31 encoder_inputs: [array([0, 0], dtype=int32), array([0, 0], dtype=int32), array([1, 3], dtype=int32),
32 array([3, 5], dtype=int32), array([5, 7], dtype=int32)]
33 decoder_inputs: [array([1, 1], dtype=int32), array([7, 9], dtype=int32), array([ 9, 11], dtype=int32),
34 array([11, 13], dtype=int32), array([0, 0], dtype=int32)]
35 """
36 train_set = [[[5, 7, 9], [11, 13, 15, EOS_ID]], [[5, 7, 9], [11, 13, 15, EOS_ID]]]
37 encoder_input_0 = [PAD_ID] * (input_seq_len - len(train_set[0][0])) + train_set[0][0]
38 encoder_input_1 = [PAD_ID] * (input_seq_len - len(train_set[1][0])) + train_set[1][0]
39 decoder_input_0 = [GO_ID] + train_set[0][1] + [PAD_ID] * (output_seq_len - len(train_set[0][1]) - 1)
40 decoder_input_1 = [GO_ID] + train_set[1][1] + [PAD_ID] * (output_seq_len - len(train_set[1][1]) - 1)
41
42 encoder_inputs = []
43 decoder_inputs = []
44 target_weights = []
45 for length_idx in xrange(input_seq_len):
46 encoder_inputs.append(np.array([encoder_input_0[length_idx], encoder_input_1[length_idx]], dtype=np.int32))
47 for length_idx in xrange(output_seq_len):
48 decoder_inputs.append(np.array([decoder_input_0[length_idx], decoder_input_1[length_idx]], dtype=np.int32))
49 target_weights.append(np.array([
50 0.0 if length_idx == output_seq_len - 1 or decoder_input_0[length_idx] == PAD_ID else 1.0,
51 0.0 if length_idx == output_seq_len - 1 or decoder_input_1[length_idx] == PAD_ID else 1.0,
52 ], dtype=np.float32))
53 return encoder_inputs, decoder_inputs, target_weights
54
55
56def get_model(feed_previous=False):

Callers 2

trainFunction · 0.70
predictFunction · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected