没有合适的资源?快使用搜索试试~ 我知道了~
首页笔记:机器人写唐诗(tensorflow)
1.准备数据 1.1数据下载 数据集1:https://github.com/todototry/AncientChinesePoemsDB this repo is a DB for Ancient Chinese Poems and Ancient Chinese Pronunciation. 数据集2:https://github.com/jackeyGao/chinese-poetry 最全的中华古典文集数据库,包含 5.5 万首唐诗、26 万首宋诗、2.1 万首宋词和其他古典文集。诗人包括唐宋两朝近 1.4 万古诗人,和两宋时期 1.5 千古词人。数据来源于互联网。 数据集1是每首诗
资源详情
资源评论
资源推荐

笔记:机器人写唐诗笔记:机器人写唐诗(tensorflow)
1.准备数据准备数据
1.1数据下载数据下载
数据集数据集1::https://github.com/todototry/AncientChinesePoemsDB
this repo is a DB for Ancient Chinese Poems and Ancient Chinese Pronunciation.
数据集数据集2::https://github.com/jackeyGao/chinese-poetry
最全的中华古典文集数据库,包含 5.5 万首唐诗、26 万首宋诗、2.1 万首宋词和其他古典文集。诗人包括唐宋两朝近 1.4 万古
诗人,和两宋时期 1.5 千古词人。数据来源于互联网。
数据集1是每首诗一个txt文件,数据集2是每一千首诗词一个json文件
1.2整理数据整理数据
数据集1处理起来比较方便,所以这里选用数据集1来建立模型
import os
import codecs
def write_txt_to_one_file(file_dir):
"""
将诗集集中在一个文件中,一行就是一首诗
@param file_dir: 诗集所在的文件夹
@return:
"""
error = [] wf = codecs.open("./data/tangshi.txt", 'w', encoding='utf-8')
i = 0
j = 0
length = 0
for root, dirs, files in os.walk(file_dir):
# root当前目录路径
# dirs当前路径下所有子目录
# files当前路径下所有非目录子文件
length = len(files)
print("一共有 %d 个文件" % (length, ))
for file in files:
file_path = root+"/"+file
i += 1
with open(file_path, 'r') as f:
line = f.readline()
while line:
line = line.strip()
print("Loading...[%.2f%%] %d" % (i/len(files)*100, i), end="")
if '_' in line or '(' in line or ')' in line or '《' in line or '》' in line:
error.append(file)
line = f.readline()
continue
if len(line) < 16:
error.append(file)
line = f.readline()
continue
if len(line) != 0:
j += 1
wf.writelines(line)
wf.write('')
else:
error.append(file)
line = f.readline()
wf.close()
print()
print("finish!!!")
print("已写入文件:%d" % (j, ))
print("错误文件:%d" % (len(error), ))
print("空白文件:%d" % (length-j-len(error)))
return None
2.训练模型训练模型
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0