Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the transformer instead of a simple LSTM layer #22

Open
basma-b opened this issue Feb 20, 2019 · 2 comments
Open

Using the transformer instead of a simple LSTM layer #22

basma-b opened this issue Feb 20, 2019 · 2 comments

Comments

@basma-b
Copy link

basma-b commented Feb 20, 2019

@lsdefine please can you tell me how can I use the transformer instead of an LSTM layer in a simple encoder ? as in this small example.

model = Sequential()
model.add(Embedding(top_words, 100, input_length=max_words, trainable=True))
model.add(LSTM(32))
model.add(Dense(1, activation='sigmoid'))
@fazlekarim
Copy link

@basma-b Did you figure it out?

@lsdefine
Copy link
Owner

from transformer import QANet_Encoder

inp = Input(shape=(max_len,), dtype='int32')
x = Embedding(words.num(), 64)(inp)
x = Dropout(0.5)(x)
mask = Lambda(lambda x:K.cast(K.greater(x, 0), 'float32'))(inp)
x = QANet_Encoder(64, n_head=4, n_conv=2, n_block=3, kernel_size=5, dropout=0.5, add_pos=False)(x, mask)

Or using Encoder instead of the QANet_Encoder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants