Giter Club home page Giter Club logo

interpretable-han-for-document-classification-with-keras's People

Contributors

charlesdong1991 avatar

Stargazers

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

Watchers

 avatar  avatar

interpretable-han-for-document-classification-with-keras's Issues

input dimension error in han.show_sent_attention()

han.show_sent_attention(x) is supposed to take in an array of size (max_sent_num, max_sent_length) as input. But the return Model(self.model.input, dummy_layer).predict(x) throws a ValueError, saying that the array should have 3 dimensions instead of 2.

Error traceback attached ( data[i] has shape (10, 100) ) :

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-67-285d332a8fb7> in <module>
----> 1 sent_att = han.show_sent_attention(data[i])
      2 sent_tokenized_review = sent_tokenize(all_text[i])
      3 
      4 temp_df = han.sent_att_to_df(sent_tokenized_reviews, sent_att)

~/Privacy_Work/interpretable-han-for-document-classification-with-keras/han/model.py in show_sent_attention(self, x)
    183         )(prev_tensor)
    184 
--> 185         return Model(self.model.input, dummy_layer).predict(x)
    186 
    187     @staticmethod

/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
   1439 
   1440         # Case 2: Symbolic tensors or Numpy array-like.
-> 1441         x, _, _ = self._standardize_user_data(x)
   1442         if self.stateful:
   1443             if x[0].shape[0] > batch_size and x[0].shape[0] % batch_size != 0:

/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
    577             feed_input_shapes,
    578             check_batch_axis=False,  # Don't enforce the batch size.
--> 579             exception_prefix='input')
    580 
    581         if y is not None:

/usr/local/lib/python3.6/dist-packages/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    133                         ': expected ' + names[i] + ' to have ' +
    134                         str(len(shape)) + ' dimensions, but got array '
--> 135                         'with shape ' + str(data_shape))
    136                 if not check_batch_axis:
    137                     data_shape = data_shape[1:]

ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (10, 100)

size error

hello, I called part of your code including build_word_encoder and build_sent_encoder, but something went wrong, can you please help me?
here is my error(your DENSE_SIZE=100, and I use 64 as my DENSE_SIZE ):
tensorflow.python.framework.errors_impl.InvalidArgumentError: Inputs to operation bidirectional_3_1/while/Select of type Select must have the same size and shape. Input 0: [1,32768] != input 1: [1,64]

han.show_word_attention() does add up to 1

I have tried to implement your functions, and i really do like your work. However, i find that when using the han.show_word_attention() function the attention weights does not add up to 1. How i have understood it, it should have because it is just supposed to be the softmax probabilities for the attention for each word. Do you know how i might fix this?
Best Regards
Malte

Tensorflow 2 upgrade

Hi,

I have an issue with the dummy layer you defined as:

dummy_layer = Lambda(
lambda x: att_layer._get_attention_weights(x)
)(prev_tensor)

It is not working in Tensorflow 2. Based on my search, we need to convert it to a subclass layer. Could you please help with this issue? How this subclass layer should be defined inside "show_word_attention(self, x)" function?

Thanks

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.