arunarn2 / hierarchicalattentionnetworks Goto Github PK
View Code? Open in Web Editor NEWHierarchical Attention Networks for Document Classification in Keras
Hierarchical Attention Networks for Document Classification in Keras
Trying to run the network in Google Colab, throws an error due to the mask dimensions:
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!
Looking at the tensorflow code, it seems to me that tf version has only one bilstm encoder ( only for words).
Is that correct implementation?
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()```
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.