openai / generating-reviews-discovering-sentiment

Code for "Learning to Generate Reviews and Discovering Sentiment"
https://arxiv.org/abs/1704.01444
MIT License
1.51k stars 379 forks source link

Docker build for CPU and GPU #22

Open loretoparisi opened 7 years ago

loretoparisi commented 7 years ago

I have here added a Docker file for both CPU and GPU builds.

How To Build the Docker image

To build the Docker image for CPU only

git clone https://github.com/loretoparisi/generating-reviews-discovering-sentiment.git
cd generating-reviews-discovering-sentiment
docker build -t sentiment-neuron -f Dockerfile .

or execute ./build.sh

while to build the Docker image for GPU

cd generating-reviews-discovering-sentiment
docker build -t sentiment-neuron -f Dockerfile.gpu .

or you execute ./build.sh GPU

How To Run the Docker image

To run for CPU

cd generating-reviews-discovering-sentiment
docker run --rm -it sentiment-neuron bash

or execute ./run.sh

while to run for GPU you have to attach the nvidia-docker driver and device (here we attach the device 0, that is the first GPU as default):

docker run -it --device=/dev/nvidiactl --device=/dev/nvidia-uvm --device=/dev/nvidia0 --volume-driver nvidia-docker -v nvidia_driver_367.57:/usr/local/nvidia:ro $IMAGE $CMD

or execute ./run.sh GPU

How To Use it

As soon as you run the image you will be in the /sentiment folder. Then you can run the provided examples test_sentiment.py:

root@718644c454d5:/sentiment# python test_sentiment.py 
7.592 seconds to transform 8 examples
it was a nice day 0.012658
it was a great day 0.371533
it was a bad day -0.499269
It was a wonderful day 0.503395
It was an excellent day 0.44557
It was a super excellent day 0.623401
It was such a bad bad day  -0.858701
It was such a bad bad bad day -1.04497

and the test_generative.py example, adapted from this fork.

root@e713b094abb6:/sentiment# python test_generative.py 
'I couldn't figure out'... --> (argmax sampling):
Positive sentiment (1 sentence): 
 I couldn't figure out how to use the stand and the stand but I love it and it is so easy to use.

Negative sentiment (+100 chars):
 I couldn't figure out how to get the product to work and the company would not even try to resolve the problem.  I would ...

'I couldn't figure out'... --> (weighted samples after each word):
Positive sentiment (3 examples, 2 sentences each):
(0) I couldn't figure out what was going on with the characters from page one. I was so engrossed in the story that I read all day.
(1) I couldn't figure out how to install the installation video that came with it but I am so glad I did. My son was so excited to put this together for me.
(2) I couldn't figure out what it was until finding this book by accident.  Every time I encounter a book from this trilogy I enjoy it as much now as I did when I was a child.

Negative sentiment (3 examples, 2 sentences each):
(0) I couldn't figure out how to get the stupid thing to play youtube videos.  I should have never bought this product.
...

Notes

If there will be further info how to train this model, I will add to the Docker image.

loretoparisi commented 7 years ago

Example of session with GPU

Using the GPU the performances will speed up of 3x at least during the generation. Please run with ./run.sh GPU

root@b26bc09607fa:/sentiment# nvidia-smi
Fri Apr 21 18:13:49 2017       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.57                 Driver Version: 367.57                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GRID K520           Off  | 0000:00:03.0     Off |                  N/A |
| N/A   38C    P8    17W / 125W |      0MiB /  4036MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
root@b26bc09607fa:/sentiment# python 
.git/               Dockerfile.gpu      README.md           encoder.py          run.sh              test_sentiment.py   
Dockerfile          LICENSE             build.sh            model/              test_generative.py  utils.py            
root@b26bc09607fa:/sentiment# python test_generative.py 
2017-04-21 18:14:03.451601: I tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0 with properties: 
name: GRID K520
major: 3 minor: 0 memoryClockRate (GHz) 0.797
pciBusID 0000:00:03.0
Total memory: 3.94GiB
Free memory: 3.91GiB
2017-04-21 18:14:03.451662: I tensorflow/core/common_runtime/gpu/gpu_device.cc:908] DMA: 0 
2017-04-21 18:14:03.451697: I tensorflow/core/common_runtime/gpu/gpu_device.cc:918] 0:   Y 
2017-04-21 18:14:03.451731: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GRID K520, pci bus id: 0000:00:03.0)
'I couldn't figure out'... --> (argmax sampling):
Positive sentiment (1 sentence): 
 I couldn't figure out how to use the stand and the stand but I love it and it is so easy to use.

Negative sentiment (+100 chars):
 I couldn't figure out how to get the product to work and the company would not even try to resolve the problem.  I would ...

'I couldn't figure out'... --> (weighted samples after each word):
Positive sentiment (3 examples, 2 sentences each):
(0) I couldn't figure out the controls and controls on the Roku box.  I have used Netflix and the controls are easy to use.
(1) I couldn't figure out what to do and I was glad I found this book.  The book is clear and easy to follow.
(2) I couldn't figure out how to use it properly but it is easy to make my coffee and use it all the time. I would buy another soon.

Negative sentiment (3 examples, 2 sentences each):
(0) I couldn't figure out how to use this  because it is so hard to set up the first time.  Not even the worst thing that was ever to be done to me.
(1) I couldn't figure out how to contact the vendor who is in India and sending the product back to company. What good is it when you get it mailed back to someone that finds it really useful? I am returning this item and looking for a different product.
(2) I couldn't figure out the problem like the rest of the product was good enough to send back but not worth any return and I feel wasted of money.
I have had this thing for exactly 3 weeks and it is still locked up on a different window and still not connected.

'I couldn't figure out'... --> (weighted samples after each character):
Sentiment not influenced (3 sentences):
 I couldn't figure out how to  separate the usb points but it's fine now.Thankfully Amazon.com was able to deal with the error.

Sentiment fixed to 0 (3 sentences):
 I couldn't figure out the plot, but even with that the story still fell flat and silly of Jamie, no offense to J Weller.
was thinking it would be low in calories but its really good.  didnt actually try it though when i tried just a  small amount.

Sligthly negative sentiment (3 sentences):
 I couldn't figure out what it was supposed to do.  I have Comcast. I wanted to do the site fast so they  would see my device.
moscow25 commented 7 years ago

Thanks! I found this very helpful. Hope the Docker file can get merged? Looking like for current code to work, it needs a very specific TF version...

Oh such a perfect day. 0.741055 I'd like to share it with you. 0.109342 You just keep me hanging on. You just keep me hanging on! 0.999466

moscow25 commented 7 years ago

I did noticed that calls to transform need to be of no larger than a batch of 64.

loretoparisi commented 7 years ago

@moscow25 I will send a PR!

vaibhavSOG17 commented 6 years ago

@loretoparisi Thanks a tonne. Very Helpful ..!!

soedr commented 6 years ago

@loretoparisi Thanks a bunch!

loretoparisi commented 6 years ago

You're welcome!