Giter Site home page Giter Site logo

arunarn2 / hierarchicalattentionnetworks Goto Github PK

View Code? Open in Web Editor NEW
73.0 3.0 29.0 1.25 MB

Hierarchical Attention Networks for Document Classification in Keras

Python 100.00%
sentiment-classification keras-tensorflow hierarchical-models hierarchical-attention-networks imdb-sentiment-analysis

hierarchicalattentionnetworks's People

Contributors

arunarn2 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

Watchers

 avatar  avatar  avatar

hierarchicalattentionnetworks's Issues

Masking error

Trying to run the network in Google Colab, throws an error due to the mask dimensions:

Bildschirmfoto 2020-01-24 um 09 52 10

Running it on the computer returns
ValueError: Dimensions must be equal, but are 15 and 100 for 'hierarchical_attention_network_2/mul' (op: 'Mul') with input shapes: [?,15], [?,15,100].

Any help on how to fix this much appreciated,
Cheers!

Model not learning

I'm trying your HiarchicalAttentionNetworks in keras and no matter what I do, it predicts 1. I'm running on tf.keras on the amazon fine food reviews. (I replaced self.trainable_weights by self._trainable_weights to make it compile)

Here's a code sample

#Input
word_input = Input(shape=(max_senten_len,), dtype="float32")
#Embeddings
word_sequences = Embedding(input_dim=vocab_length, output_dim=EMBEDDING_DIM, 
                           weights=[embedding_matrix], input_length=max_senten_len, 
                           trainable=False)(word_input)
#Words GRU
word_gru=GRU(units = 100, return_sequences=True,  
             kernel_regularizer=l2_reg)(word_sequences)
#Words attention
word_att = HierarchicalAttention(100)(word_gru)
wordEncoder = Model(word_input, word_att)

#Sentences part
sent_input = Input(shape=(max_senten_num, max_senten_len), dtype='float32')
#Sentence Input
sent_encoder = TimeDistributed(wordEncoder)(sent_input)
#Sentence GRU
sent_gru=GRU(units = 100, return_sequences=True, 
             kernel_regularizer=l2_reg)(sent_encoder)

#Sentences attention
sent_att = Dropout(0.4)(HierarchicalAttention(100)(sent_gru))
#Prediction
preds = Dense(1, activation='sigmoid')(sent_att)
#Model
model_HAN = Model(sent_input, preds)
model_HAN.compile(loss='binary_crossentropy', optimizer="adam", metrics=['acc'])
model_HAN.summary()```

Visualization for keras version?

I tried to return the alphas (the attentions) in the class AttLayer(Layer), but Keras gets the error "you must feed value to sentence_input", Can you help me fix this problem?

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.