neural network for nlp

Neural Storyteller 基于图片讲故事

2018-06-28  本文已影响0人  临渊不羡

neural-storyteller是一个循环神经网络文本生成算法,它可以通过图像生成文本小故事。

代码地址:
https://github.com/ryankiros/neural-storyteller

生成的最终效果:
上传图片:


ex1.jpg

生成结果:
We were barely able to catch the breeze at the beach , and it felt as if someone stepped out of my mind . She was in love with him for the first time in months , so she had no intention of escaping . The sun had risen from the ocean , making her feel more alive than normal . She 's beautiful , but the truth is that I do n't know what to do . The sun was just starting to fade away , leaving people scattered around the Atlantic Ocean . I d seen the men in his life , who guided me at the beach once more .

以下是安装笔记:

基于代码地址安装要注意几个问题

1、第一是python package

这个代码依赖python2 Theano 0.7,如果没有gpu的话还需要安装caffe。为了避免麻烦,我们这里选择Theano 1.0.1,GPU版本,因为pygpu在原生python安装比较复杂,我们这里选择anaconda py2版本。
只需要
conda install pygpu
conda install Theano
另外还需要安装一些其他的包
pip install nltk
pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip
pip install scikit-image
nltk资源如果联网下载不了,自行搜索解决

2、是代码所需的资源

这里有3类资源,
a、neural_storyteller 自己的资源,readme.md上有写,直接下载,解压后备用
b、VGG-19 ConvNet ,readme.md也上有写,最好自备梯子(caffe的资源不必下载)
c、Skip-Thought Vectors的资源,这里readme.md没有说明,需要到https://github.com/ryankiros/skip-thoughts找readme.md
有如下几个资源
dictionary.txt
utable.npy
btable.npy
uni_skip.npz
uni_skip.npz.pkl
bi_skip.npz
bi_skip.npz.pkl

下载好后(比较大),放在一个文件夹内。

3、config.py配置

从master分支下载代码后,修改config.py文件

首先改为非cpu模式,

FLAG_CPU_MODE = False

配置Skip-thoughts的资源
neural_storyteller的资源
vgg等路径,除了caffe的都配置到对应路径上

配置完成后
在python界面上输入

import generate
z = generate.load_all()
generate.story(z, './images/ex1.jpg')

运行时间可能较长,
运行结果:

*[图片上传中...(image.png-8fda70-1530151009090-0)]
**

如果资源下载有问题的,可以在下面留言,我提供给你一份下载好的数据

上一篇下一篇

猜你喜欢

热点阅读