资源简介
我是“小诗姬”,全唐诗作为训练数据。可以写押韵自由诗、藏头诗、给定若干字作为主题的诗
代码片段和文件信息
import logging
import time
from enum import Enum
import heapq
import numpy as np
import tensorflow as tf
from rhyme_helper import RhymeWords
logging.getLogger(‘tensorflow‘).setLevel(logging.WARNING)
SampleType = Enum(‘SampleType‘(‘max_prob‘ ‘weighted_sample‘ ‘rhyme‘‘select_given‘))
class CharRNNLM(object):
def __init__(self is_training batch_size num_unrollings vocab_sizew2v_model
hidden_size max_grad_norm embedding_size num_layers
learning_rate cell_type dropout=0.0 input_dropout=0.0 infer=False):
self.batch_size = batch_size
self.num_unrollings = num_unrollings
if infer:
self.batch_size = 1
self.num_unrollings = 1
self.hidden_size = hidden_size
self.vocab_size = vocab_size
self.max_grad_norm = max_grad_norm
self.num_layers = num_layers
self.embedding_size = embedding_size
self.cell_type = cell_type
self.dropout = dropout
self.input_dropout = input_dropout
self.w2v_model = w2v_model
if embedding_size <= 0:
self.input_size = vocab_size
self.input_dropout = 0.0
else:
self.input_size = embedding_size
self.input_data = tf.placeholder(tf.int64 [self.batch_size self.num_unrollings] name=‘inputs‘)
self.targets = tf.placeholder(tf.int64 [self.batch_size self.num_unrollings] name=‘targets‘)
if self.cell_type == ‘rnn‘:
cell_fn = tf.nn.rnn_cell.BasicRNNCell
elif self.cell_type == ‘lstm‘:
cell_fn = tf.nn.rnn_cell.BasicLSTMCell
elif self.cell_type == ‘gru‘:
cell_fn = tf.nn.rnn_cell.GRUCell
params = dict()
#params = {‘input_size‘: self.input_size}
if self.cell_type == ‘lstm‘:
params[‘forget_bias‘] = 1.0 # 1.0 is default value
cell = cell_fn(self.hidden_size **params)
cells = [cell]
#params[‘input_size‘] = self.hidden_size
for i in range(self.num_layers-1):
higher_layer_cell = cell_fn(self.hidden_size **params)
cells.append(higher_layer_cell)
if is_training and self.dropout > 0:
cells = [tf.nn.rnn_cell.DropoutWrapper(cell output_keep_prob=1.0-self.dropout) for cell in cells]
multi_cell = tf.nn.rnn_cell.MultiRNNCell(cells)
with tf.name_scope(‘initial_state‘):
self.zero_state = multi_cell.zero_state(self.batch_size tf.float32)
if self.cell_type == ‘rnn‘ or self.cell_type == ‘gru‘:
self.initial_state = tuple(
[tf.placeholder(tf.float32
[self.batch_size multi_cell.state_size[idx]]
‘initial_state_‘+str(idx+1)) for idx in range(self.num_layers)])
elif self.cell_type == ‘lstm‘:
self.initial_state = tuple(
[tf.nn.rnn_cell.LSTMStateTuple(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-08-25 06:01 poet-master\
文件 666 2017-08-25 06:01 poet-master\README.md
文件 12877 2017-08-25 06:01 poet-master\char_rnn_model.py
文件 6216 2017-08-25 06:01 poet-master\config_poem.py
目录 0 2017-08-25 06:01 poet-master\data\
目录 0 2017-08-25 06:01 poet-master\data\poem\
文件 8399779 2017-08-25 06:01 poet-master\data\poem\poem_ids.txt
文件 9458157 2017-08-25 06:01 poet-master\data\poem\poems_edge_split.txt
文件 11310 2017-08-25 06:01 poet-master\data\poem\rhyme_words.txt
文件 2832643 2017-08-25 06:01 poet-master\data\poem\vectors_poem.bin
文件 9342 2017-08-25 06:01 poet-master\data_loader.py
目录 0 2017-08-25 06:01 poet-master\doc\
文件 48580 2017-08-25 06:01 poet-master\doc\client.png
文件 55386 2017-08-25 06:01 poet-master\doc\train.png
文件 1104 2017-08-25 06:01 poet-master\poem_server.py
文件 875 2017-08-25 06:01 poet-master\rhyme_helper.py
文件 8515 2017-08-25 06:01 poet-master\train.py
文件 1282 2017-08-25 06:01 poet-master\word2vec_helper.py
文件 6342 2017-08-25 06:01 poet-master\write_poem.py
相关资源
- Python-用于物体跟踪的全卷积连体网络
- Python-数学建模竞赛中所使用的相关算
- Python-MonoDepthPyTorchPyTorch无监督单目深
- Python-用Tensorflowjs实现的可回收非可回
- Python-利用TensorFlow中的深度学习进行图
- Python-TensorFlow快速入门与实战课件与参
- Python-FCN完全卷积网络中最简单最容易
- Python-匈牙利算法卡尔曼滤波器多目标
- Python-mathAI一个拍照做题程序输入一张
- Python-Tensorflow实现SpatialAsDeepSpatialCNN
- Python-图像分类目标检测姿态估计分割
- Python-用python3opencv3做的中国车牌识别
- Python-各种对抗神经网络GAN大合集
- Python-Intel开源增强学习框架Coach
- Python-CENet用于2D医学图像分割的上下文
- Python-基于深度神经网络和蒙特卡罗树
- Python-SPNLearningAffinityviaSpatialPropagatio
- Python-效果超赞的图片自动增强GANs非成
- Python-VoiceactivitydetectionVAD语音端点检测
- Python-TensorFlow实现的人脸性别年龄识别
- Python-waifu2x利用卷积神经网络放大图片
- Python-TheElementsofStatisticalLearningESL的中
- Python-基于Tensorflow和Keras实现端到端的
- Python-MuseGAN用于乐曲生成的AI
- Python-简单快速实时可定制的机器学习
- Python-PySceneDetect基于PythonOpenCV实现的视
- Python-输入输出隐马尔可夫模型IOHMM的
- Python-基于OpenCVKerasTensorFlow实现深度换
- Python-在PyTorch中关注神经机器翻译的最
- Python-PointSIFT一种类似SIFT的网络模块用
评论
共有 条评论