资源简介
深度学习算法实践-电子工业出版社-吴岸城-2017年1月-随书源码
代码片段和文件信息
# -*- coding:utf-8 -*-
import os
os.environ[‘KERAS_BACKEND‘] = “theano“
# os.environ[‘THEANO_FLAGS‘] = “device=cpu“
from keras.models import Sequential
from keras.layers.core import Dense Activation
from keras.layers.recurrent import LSTM
from keras.layers.wrappers import TimeDistributed Bidirectional
from keras.layers import FlattenLambdaK
from keras.layers.embeddings import embedding
from keras.layers.pooling import MaxPooling2D GlobalMaxPooling2DMaxPooling1D
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.layers import MergeDropout
from keras.datasets import imdb
import numpy as np
# from keras.utils import plot_model
from keras.utils.visualize_util import plot
from keras.preprocessing import sequence
def text_feature_extract_model1(embedding_size=128 hidden_size=256):
‘‘‘
this is a model use normal Bi-LSTM and maxpooling extract feature
examples:
这个货很好,很流畅 [ 1.62172219e-05]
这个东西真好吃, [ 1.65377696e-05]
服务太糟糕味道差 [ 1.]
这个贴花的款式好看 [ 1.76498161e-05]
看着不错,生产日期也是新的是16年12月份的,就是有点小贵 [ 1.59666997e-05]
一股淡淡的腥味。每次喝完都会吃一口白糖 [ 1.]
还没喝,不过,看着应该不错哟 [ 1.52662833e-05]
用来看电视还是不错的,就是有些大打字不习惯,要是可以换输入法就好了! [ 1.]
嗯,中间出了点小问题已经联系苹果客服解决了,打游戏也没有卡顿,总体来讲还不错吧! [ 1.52281245e-05]
下软件下的多的时候死了一回机,强制重启之后就恢复了。 [ 1.]
东西用着还可以很流畅! [ 1.59881820e-05]
:return:
‘‘‘
model = Sequential()
model.add(embedding(input_dim=max_features
output_dim=embedding_size
input_length=max_seq))
model.add(Bidirectional(LSTM(hidden_size return_sequences=True)))
model.add(TimeDistributed(Dense(embedding_size/2)))
model.add(Activation(‘softplus‘))
model.add(MaxPooling1D(5))
model.add(Flatten())
# model.add(Dense(2048 activation=‘softplus‘))
# model.add(Dropout(0.2))
model.add(Dense(1 activation=‘sigmoid‘))
model.compile(loss=‘binary_crossentropy‘ optimizer=‘adam‘ metrics=[‘accuracy‘])
model.summary()
plot(model to_file=“text_feature_extract_model1.png“ show_shapes=True)
return model
if __name__ == “__main__“:
#prepare y 1 negtive 0 postive
y = []
txt_path = ‘../data/corpus/reviews/‘
with open(txt_path+‘1_point.txt‘ ‘rb‘) as fp:
lines = fp.readlines()
len_temp_lines = len(lines)
for i in range(len(lines)):
y.append(1)
with open(txt_path+‘5_point.txt‘ ‘rb‘) as fp:
lines += fp.readlines()
for i in range(len(lines[len_temp_lines:])):
y.append(0)
def create_dict():
dict = open(txt_path+‘1_point.txt‘ ‘rb‘).read()
# dict += open(txt_path + ‘2_point.txt‘ ‘rb‘).read()
dict += open(txt_path+‘5_point.txt‘ ‘rb‘).read()
dict_list = set(list(dict.decode(‘utf8‘)))
dicts = {}
for i d in enumerate(dict_list):
dicts[d] = i
return dicts
def create_X(lines):
len_seq = []
dicts = create_dict()
sequences = []
for line
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\
文件 7 2017-04-20 11:24 Book_DeepLearning_Practice-master\.gitignore
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\algorithm\
文件 6086 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\algorithm\RNN-CNN_feature_extract.py
文件 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\algorithm\__init__.py
文件 71891 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\algorithm\text_feature_extract_model1.png
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\data\
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\data\corpus\
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\data\corpus\reviews\
文件 16765967 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\data\corpus\reviews\1_point.txt
文件 14183087 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\DeepTextClf\data\corpus\reviews\5_point.txt
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\dialogue\
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\dialogue\提取和选择\
文件 12292 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\dialogue\提取和选择\answer_find_out.py
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\dialogue\爬取\
文件 38276 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\dialogue\爬取\fromSE.py
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\dialogue\相似提取答案\
文件 4433 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\dialogue\相似提取答案\Compress.py
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\dialogue\蕴含\
文件 8415 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\dialogue\蕴含\textual_entailment.py
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\mail\
文件 1789 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\mail\mail_classily.py
文件 4660 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\mail\stopwords.txt
文件 452 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\mail\text_preprocess.py
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\sentiment\
目录 0 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\sentiment\LSTM\
文件 5410 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\sentiment\LSTM\extract_feature.py
文件 931 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\sentiment\LSTM\lstm_model.py
文件 340 2017-04-20 11:24 Book_DeepLearning_Practice-master\2_Chapter\sentiment\LSTM\test_lstm.py
............此处省略64个文件信息
- 上一篇:微信小程序源码-合集3
- 下一篇:k66说明,智能车K66
相关资源
- 李宏毅深度学习ppt
- SSD目标检测算法论文-英文原版
- 台湾李宏毅教授深度学习讲义 pdf
- 基于深度学习实现人脸识别包含模型
- 深度学习与PyTorch-代码和PPT.zip
- 测试工程源码1(一种基于深度学习的
- 深度学习: MNIST的数据集
- 《深度学习》 高清版本中文PDFIan Go
- 今日头条38万条新闻数据标题
- 深度学习算法论文
- TensorFlow Machine Learning Cookbook+无码高清
- Hands-On Machine Learning with Scikit-Learn an
- Neural Networks:Tricks of the Trade+无码高清
- 基于深度学习的图像超分辨率算法论
- 人工智能初步学习总结
- 迁移学习简明手册
- 基于深度学习的软件源码漏洞预测综
- 一天搞懂深度学习 台湾资料科学年会
- 基于深度学习的神经网络算法论文
- 台湾李宏毅教授关于深度学习PPT
- 白话大数据和深度学习_2018最新版
- 深度学习框架下LSTM网络在短期电力负
- 深度学习作业lr_utils和对应数据集
- 深度学习软件平台使用手册.docx
- 基于深度学习的图像检索系统CNN
- 基于tensorflow的深度学习图像分类案例
- 目标跟踪中用到的各种深度学习方法
- 您需要了解的9篇深度学习论文.pdf
- Deep Learning with R.pdf
- 基于深度学习的链路预测
评论
共有 条评论