-
Notifications
You must be signed in to change notification settings - Fork 425
Open
Description
这个代码的主要目的是预测下一个char。
def sample(self, n_samples, prime, vocab_size):
samples = [c for c in prime]
sess = self.session
new_state = sess.run(self.initial_state)
preds = np.ones((vocab_size, )) # for prime=[]
for c in prime:
x = np.zeros((1, 1))
# 输入单个字符
x[0, 0] = c
feed = {self.inputs: x,
self.keep_prob: 1.,
self.initial_state: new_state}
preds, new_state = sess.run([self.proba_prediction, self.final_state],
feed_dict=feed)
c = pick_top_n(preds, vocab_size)
# 添加字符到samples中
samples.append(c)
但是在这里,直接将c值赋给x[0,0]可以么?x开始初始化是int,但是c是str。我建立了个小程序跑这一段,
import numpy as np
prime = "beauty"
for c in prime:
x = np.zeros((1,1))
#x[0,0] = vocab_to_int[c]
x[0,0] = c
print("c",c)
print("x",x)
报错说ValueError: could not convert string to float: 'b'。
请问您是怎么解决这个问题的?
Metadata
Metadata
Assignees
Labels
No labels