# Sentiment Analysis with LSTMs
This repository contains the iPython notebook and training data to accompany the [O'Reilly tutorial](https://www.oreilly.com/learning/perform-sentiment-analysis-with-lstms-using-tensorflow) on sentiment analysis with LSTMs in Tensorflow. See the original tutorial to run this code in a pre-built environment on O'Reilly's servers with cell-by-cell guidance, or run these files on your own machine. There is also another file called `Pre-Trained LSTM.ipynb` which allows you to input your own text, and see the output of the trained network.
## Downloading Data
Before running the notebook, you'll first need to download all data we'll be using. This data is located in the `models.tar.gz` and `training_data.tar.gz` tarballs. We will extract these into the same directory as `Oriole LSTM.ipynb`. As always, the first step is to clone the repository.
```bash
git clone https://github.com/adeshpande3/LSTM-Sentiment-Analysis.git
```
Next, we will navigate to the newly created directory and run the following commands.
```bash
tar -xvzf models.tar.gz
tar -xvzf training_data.tar.gz
```
## Requirements and Installation
In order to run [the iPython notebook](Oriole-LSTM.ipynb), you'll need the following libraries.
* **[TensorFlow](https://www.tensorflow.org/install/) version 1.1 (See below for later versions)**
* [NumPy](https://docs.scipy.org/doc/numpy/user/install.html)
* [Jupyter](https://jupyter.readthedocs.io/en/latest/install.html)
* [matplotlib](https://matplotlib.org/)
### TensorFlow 1.2 and later
In order to load the models without errors you need to convert the checkpoints using the converter provided by TensorFlow:
```bash
wget https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/contrib/rnn/python/tools/checkpoint_convert.py
python checkpoint_convert.py models/pretrained_lstm.ckpt-90000 converted-checkpoints/pretrained_lstm-90000.ckpt
```
You should also replace the original models folder if you don't want to modify the code:
```bash
rm -rf models
mv converted-checkpoints models
```
### Docker
With Docker, you could just mount the repository and exec it.
1. Install Docker. Follow the [docker guide](https://docs.docker.com/get-started/#prepare-your-docker-environment).
2. Build docker image
``` bash
cd LSTM-Sentiment-Analysis
docker build -t="@yourname/tensorflow_1.1.0_py3" .
```
3. Run the container from the image
``` bash
docker run -p 8888:8888 --name=tensorflow_yourname_py3 -v /@YourDir/LSTM-Sentiment-Analysis:/LSTM-Sentiment-Analysis -it @yourname/tensorflow_1.1.0_py3
```
and visit the URL(http://localhost:8888/)
4. Stop and restart the container
``` bash
docker stop tensorflow_yourname_py3
docker start tensorflow_yourname_py3
docker attach tensorflow_yourname_py3
```
If jupyter is down, relaunch it by using the command below.
``` bash
cd LSTM-Sentiment-Analysis
jupyter notebook --ip=0.0.0.0 --allow-root
```
### Installing Anaconda Python and TensorFlow
The easiest way to install TensorFlow as well as NumPy, Jupyter, and matplotlib is to start with the Anaconda Python distribution.
1. Follow the [installation instructions for Anaconda Python](https://www.continuum.io/downloads). **We recommend using Python 3.6.**
2. Follow the platform-specific [TensorFlow installation instructions](https://www.tensorflow.org/install/). Be sure to follow the "Installing with Anaconda" process, and create a Conda environment named `tensorflow`.
3. If you aren't still inside your Conda TensorFlow environment, enter it by opening your terminal and typing
```bash
source activate tensorflow
```
4. If you haven't done so already, download and unzip [this entire repository from GitHub](https://github.com/adeshpande3/LSTM-Sentiment-Analysis), either interactively, or by entering
```bash
git clone https://github.com/adeshpande3/LSTM-Sentiment-Analysis
```
5. Use `cd` to navigate into the top directory of the repo on your machine
6. Launch Jupyter by entering
```bash
jupyter notebook
```
and, using your browser, navigate to the URL shown in the terminal output (usually http://localhost:8888/)
没有合适的资源?快使用搜索试试~ 我知道了~
基于tensorflow的IMDB文本情感分析完整代码(包含数据和词向量可直接运行)
共26个文件
png:18个
ipynb:2个
gz:2个
4星 · 超过85%的资源 需积分: 34 117 下载量 122 浏览量
2019-03-25
21:15:43
上传
评论 11
收藏 164.63MB ZIP 举报
温馨提示
基于tensorflow的IMDB文本情感分析完整代码(包含数据和词向量可直接运行),网络结构采用双层LSTM。
资源推荐
资源详情
资源评论
收起资源包目录
IMDB文本情感分析.zip (26个子文件)
LSTM-Sentiment-Analysis-master
models.tar.gz 70.21MB
Pre-Trained LSTM.ipynb 7KB
Images
SentimentAnalysis12.png 20KB
SentimentAnalysis14.png 21KB
SentimentAnalysis.png 12KB
SentimentAnalysis17.png 110KB
SentimentAnalysis6.png 147KB
SentimentAnalysis18.png 75KB
SentimentAnalysis9.png 26KB
SentimentAnalysis3.png 42KB
SentimentAnalysis7.png 167KB
SentimentAnalysis10.png 30KB
SentimentAnalysis4.png 13KB
SentimentAnalysis5.png 29KB
SentimentAnalysis15.png 67KB
SentimentAnalysis11.png 33KB
SentimentAnalysis16.png 113KB
SentimentAnalysis8.png 15KB
SentimentAnalysis2.png 25KB
SentimentAnalysis13.png 37KB
Dockerfile 378B
LICENSE 1KB
.gitignore 10B
training_data.tar.gz 93.55MB
README.md 4KB
Oriole LSTM.ipynb 44KB
共 26 条
- 1
资源评论
- Blessy_Zhu2019-10-14我暂时还没下载成功
- qq_457188382020-01-11可以给个源码吗
- 你奈我何啊2019-05-18下载下来再看一遍
一路狂奔的猪
- 粉丝: 203
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功