MCPcopy Create free account
hub / github.com/apache/singa / get_train_raw

Function get_train_raw

examples/qabot/qabot_data.py:86–111  ·  view source on GitHub ↗

deserialize training data file args: data_dir: dir of data file return: train_raw: list of QnA pair, length of list == number of samples, each pair has 3 fields: 0 is question sentence idx encoded, use idx2word to decode,

(data_dir, data_filename)

Source from the content-addressed store, hash-verified

84
85
86def get_train_raw(data_dir, data_filename):
87 ''' deserialize training data file
88 args:
89 data_dir: dir of data file
90 return:
91 train_raw: list of QnA pair, length of list == number of samples,
92 each pair has 3 fields:
93 0 is question sentence idx encoded, use idx2word to decode,
94 idx2vec to get embedding.
95 1 is ans labels, each label corresponds to a ans sentence,
96 use label2answer to decode.
97 2 is top K candidate ans, these are negative ans for
98 training.
99 '''
100 train_raw = []
101 import gzip
102 with gzip.open(data_dir + data_filename) as fin:
103 for line in fin:
104 tpl = line.decode().strip().split("\t")
105 question = [
106 int(idx.replace("idx_", "")) for idx in tpl[1].split(" ")
107 ]
108 ans = [int(label) for label in tpl[2].split(" ")]
109 candis = [int(label) for label in tpl[3].split(" ")]
110 train_raw.append((question, ans, candis))
111 return train_raw
112
113
114def limit_encode_train(train_raw, label2answer, idx2word, q_seq_limit,

Callers 1

prepare_dataFunction · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected