Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_validation_data(input_texts, target_texts, vocab2id, maxlen=400):
# 数据生成器
X, Y = [], []
for i in range(len(input_texts)):
X.append(str2id(input_texts[i], vocab2id, maxlen))
Y.append([vocab2id[GO_TOKEN]] + str2id(target_texts[i], vocab2id, maxlen) + [vocab2id[EOS_TOKEN]])
X = np.array(padding(X, vocab2id))
Y = np.array(padding(Y, vocab2id))
return [X, Y], None
def data_generator(input_texts, target_texts, vocab2id, batch_size, maxlen=400):
# 数据生成器
while True:
X, Y = [], []
for i in range(len(input_texts)):
X.append(str2id(input_texts[i], vocab2id, maxlen))
Y.append([vocab2id[GO_TOKEN]] + str2id(target_texts[i], vocab2id, maxlen) + [vocab2id[EOS_TOKEN]])
if len(X) == batch_size:
X = np.array(padding(X, vocab2id))
Y = np.array(padding(Y, vocab2id))
yield [X, Y], None
X, Y = [], []
def data_generator(input_texts, target_texts, vocab2id, batch_size, maxlen=400):
# 数据生成器
while True:
X, Y = [], []
for i in range(len(input_texts)):
X.append(str2id(input_texts[i], vocab2id, maxlen))
Y.append([vocab2id[GO_TOKEN]] + str2id(target_texts[i], vocab2id, maxlen) + [vocab2id[EOS_TOKEN]])
if len(X) == batch_size:
X = np.array(padding(X, vocab2id))
Y = np.array(padding(Y, vocab2id))
yield [X, Y], None
X, Y = [], []
def get_validation_data(input_texts, target_texts, vocab2id, maxlen=400):
# 数据生成器
X, Y = [], []
for i in range(len(input_texts)):
X.append(str2id(input_texts[i], vocab2id, maxlen))
Y.append([vocab2id[GO_TOKEN]] + str2id(target_texts[i], vocab2id, maxlen) + [vocab2id[EOS_TOKEN]])
X = np.array(padding(X, vocab2id))
Y = np.array(padding(Y, vocab2id))
return [X, Y], None