hzy46 / char-rnn-tensorflow Goto Github PK
View Code? Open in Web Editor NEWMulti-language Char RNN for TensorFlow >= 1.2.
Multi-language Char RNN for TensorFlow >= 1.2.
\read_utils.py", line 26, in batch_generator
y[:, :-1], y[:, -1] = x[:, 1:], x[:, 0]
TypeError: 'NoneType' object does not support item assignment
ValueError: Cannot feed value of shape (1, 1) for Tensor 'inputs:0', which has shape '(64, 50)'
看报错的意思是在训练时输入大小为(64, 50),在测试时大小为(1,1)。大小不一致所以报错了
这个代码的主要目的是预测下一个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'。
请问您是怎么解决这个问题的?
File "C:/Users/HP/PycharmProjects/CharRnn/sample.py", line 20, in main
FLAGS.start_string = FLAGS.start_string.decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'
你好!首先非常感谢你在百忙之中看我的issue,我现在的最大难题是电脑内存太小,训练语料(中文)太大,无法一次性加载,我希望能够分批增量训练,就是在原来模型基础上再次使用新文章进行补充训练,需要怎么改好那?好像字典字符映射也要修改?我多次尝试好像失败了。谢谢!
如题,报错找不到data/**.txt文件路径,怎么解决
你好,我的模型能够在训练集上拟合较好,但是在采样时却得不到这样通顺的句子,采样的方式也是采用了np.random.choice()方法,只训练了1000个epoch因为在当训练到几百次时即使用来学习率衰减loss也没有下降了。请问有关这个问题有什么解决思路吗
Char-RNN-TensorFlow/read_utils.py
Line 19 in 7d23f2f
新手,看不太懂,请教一下,谢谢
您好,在参考着您的思路自己搭建RNN时候,在训练时输出结果总是预测'\n'或者'\r',请问您当初在训练时有没有碰到这个问题(用的是周杰伦的歌词那个数据)。统计了一下,这两个字符出现的频次都大约在5000/70000远高于其他词的词频,请问有没有什么解决思路呢
embedding = tf.get_variable('embedding', [self.num_classes, self.embedding_size])
self.lstm_inputs = tf.nn.embedding_lookup(embedding, self.inputs)
这样就直接变成了中文的embedding表示吗?不是很明白这两句的意思
请问,我训练模型的时候,英文输入没问题,中文输入多了个embwdding层,就会loss为nan,用tfdbg调试,发现第一次出现nan是Adam/update_embedding/sqrt,这应该是梯度爆炸了吗?模型里用了梯度截断了,还是不行,把梯度截断最大值设置到1.1都不行,请问大神知道什么原因吗
您好,看完您的代码之后,我有一些不太能够理解的地方,希望您能帮我解决一下。
听说是随机词汇,我没找到具体的代码位置。
多谢@hzy46
你好,想请教个问题。
我的运行下来,报错在
y_reshaped = tf.reshape(y_one_hot, self.logits.get_shape())
因为y_one_hot和self.logits的总元素数量不同,所以不能reshape。
我推算了一下:
inputs的shape是(num_seqs, num_steps),经过tf.one_hot以后,lstm_inputs的shape变成(num_seqs, num_steps, num_classes)
我用的是cell是一层的lstm,lstm_inputs经过tf.nn.dynamic(cell, lstm_inputs, initial_state=self.initial_state)后,lstm_outputs的shape是(num_seqs, num_steps, lstm_size)
lstm_outputs经过tf.concat(lstm_outputs, 1)以后,shape没有任何变化,再经过一些列运算后,shape就会有问题。
所以想问一下tf.concat(lstm_outputs, 1)这一步是做什么的?
感谢~
Traceback (most recent call last):
File "train.py", line 7, in
FLAGS = tf.flags.FLAGS
AttributeError: module 'tensorflow' has no attribute 'flags'
请问这个问题怎么解决? 谢谢!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.