Giter VIP home page Giter VIP logo

text-summarization-with-amazon-reviews's Introduction

Text-Summarization-with-Amazon-Reviews

The objective of this project is to build a seq2seq model that can create relevant summaries for reviews written about fine foods sold on Amazon. This dataset contains above 500,000 reviews, and is hosted on Kaggle. It's too large to host here, it's over 300MB.

To build our model we will use a two-layered bidirectional RNN with LSTMs on the input data and two layers, each with an LSTM using bahdanau attention on the target data. Jaemin Cho's tutorial for seq2seq was really helpful to get the code in working order because this is my first project with TensorFlow 1.1; some of the functions are very different from 1.0. The architecture for this model is similar to Xin Pan's and Peter Liu's, here's their GitHub page.

This model uses Conceptnet Numberbatch's pre-trained word vectors.

Here are some examples of reviews and their generated summaries:

  • Description(1): The coffee tasted great and was at such a good price! I highly recommend this to everyone!

  • Summary(1): great coffee

  • Description(2): This is the worst cheese that I have ever bought! I will never buy it again and I hope you won’t either!

  • Summary(2): omg gross gross

  • Description(3): love individual oatmeal cups found years ago sam quit selling sound big lots quit selling found target expensive buy individually trilled get entire case time go anywhere need water microwave spoon know quaker flavor packets

  • Summary(3): love it

I wrote an article about this project that explains parts of it in detail.

text-summarization-with-amazon-reviews's People

Contributors

currie32 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

text-summarization-with-amazon-reviews's Issues

Are the output layers concatenated properly ?

Here is the encoding_layer for ease:

def encoding_layer(rnn_size, sequence_length, num_layers, rnn_inputs, keep_prob):
    '''Create the encoding layer'''
    
    for layer in range(num_layers):
        with tf.variable_scope('encoder_{}'.format(layer)):
            cell_fw = tf.contrib.rnn.LSTMCell(rnn_size,
                                              initializer=tf.random_uniform_initializer(-0.1, 0.1, seed=2))
            cell_fw = tf.contrib.rnn.DropoutWrapper(cell_fw, 
                                                    input_keep_prob = keep_prob)

            cell_bw = tf.contrib.rnn.LSTMCell(rnn_size,
                                              initializer=tf.random_uniform_initializer(-0.1, 0.1, seed=2))
            cell_bw = tf.contrib.rnn.DropoutWrapper(cell_bw, 
                                                    input_keep_prob = keep_prob)

            enc_output, enc_state = tf.nn.bidirectional_dynamic_rnn(cell_fw, 
                                                                    cell_bw, 
                                                                    rnn_inputs,
                                                                    sequence_length,
                                                                    dtype=tf.float32)
    # Join outputs since we are using a bidirectional RNN
    enc_output = tf.concat(enc_output,2)
    
    return enc_output, enc_state

I'm new to tensorflow, so here's my understanding:
Based on num_layers, it'll create that many tf.nn.bidirectional_dynamic_rnns. So shouldn't the line enc_output = tf.concat(enc_output,2) be inside the for loop ? Will the return statement returns all the enc_output. If so how ?

And how to find accuracy, can you suggest briefly ?

Restoring Session

Hi,
I'm trying to restore the session for the last checkpoint saved. I do this uncommenting this two lines of the code:

loader = tf.train.import_meta_graph("./" + checkpoint + '.meta')
loader.restore(sess, checkpoint)

But I'm getting this error:
ValueError: cannot add op with name encoder_0/bidirectional_rnn/fw/lstm_cell/kernel/Adam as that name is already used

Am I doing something wrong or is this an issue?

how to make only one bidirectional layer, and other regular rnn layers

Thank you very much your tutorial. it really helped me a lot.
I am wondering if you can help me with this. In you set up, it seems that you are making every encoding layer as bidirectional. But i think it is also very common that we only make 1 bidirectional layer and making other layers as regular rnn layers.(like google's translation model).

I am not sure how to connect a bidirectional layer with a regular rnn layer?

Trained model making random predictions when loaded

The model made some good predictions when I tested it immediately after training was finished. But when I loaded the model after opening the notebook next day, it makes some random meaningless predictions.
Any reason for this?

accuracy for trained model

Hi, I have trained with Fine Food Reviews data with 100 epochs. After that I have changed dataset. downloaded dataset from amazon reviews dataset. There I have taken Home and Kitchen dataset in that dataset I have taken Review Text and Summary. And trained with 100 epochs.

After completion of training I have tested the model. getting same summary for distinct reviews. I have trained so many times getting the same summary while I am testing

Single Layer Encoder

In your code it seems like you are trying to create a multilayer encoder, however what is actually happening is that multiple single layer decoders are being created. As you can see in this graph image created by tensorflow http://imgur.com/a/jqAn5 the rnn inputs are feed into each bidirectional rnn rather than one feeding into the other. I created this image by running your encoding_layer function and passing in some placeholders and then using the tf.summary.FileWriter to draw the graph.

To create a multilayer encoder you would want something like this

def encoding_layer(rnn_size, sequence_length, num_layers, rnn_inputs, keep_prob):
    '''Create the encoding layer'''
    layer_input = rnn_inputs
    for layer in range(num_layers):
        with tf.variable_scope('encoder_{}'.format(layer)):
            cell_fw = tf.contrib.rnn.LSTMCell(rnn_size,
                                              initializer=tf.random_uniform_initializer(-0.1, 0.1, seed=2))
            cell_fw = tf.contrib.rnn.DropoutWrapper(cell_fw, 
                                                    input_keep_prob = keep_prob)

            cell_bw = tf.contrib.rnn.LSTMCell(rnn_size,
                                              initializer=tf.random_uniform_initializer(-0.1, 0.1, seed=2))
            cell_bw = tf.contrib.rnn.DropoutWrapper(cell_bw, 
                                                    input_keep_prob = keep_prob)

            enc_output, enc_state = tf.nn.bidirectional_dynamic_rnn(cell_fw, 
                                                                    cell_bw, 
                                                                    layer_input,
                                                                    sequence_length,
                                                                    dtype=tf.float32)
            layer_input = tf.concat(enc_output, 2)
    # Join outputs since we are using a bidirectional RNN
    enc_output = tf.concat(enc_output,2)
    return enc_output, enc_state

You can see in this graph image http://imgur.com/a/bJANa That this creates the multi layer structure I assume you are going for. (The caveat is that in this function your rnn size must be half of the embedding size so if you want them to be different just move the first birnn out of the loop and have the layers after the first have the same size)

Giving same summary for all reviews

  Hi ,i trained the model but when i tested with different reviews its giving same summary for all whatever we got when i executed  first review ,i didnt understand whats  the problem, can i know what is the reason for that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.