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

Add a token and position embedding layer #85

Closed
mattdangerw opened this issue Apr 4, 2022 · 3 comments · Fixed by #91
Closed

Add a token and position embedding layer #85

mattdangerw opened this issue Apr 4, 2022 · 3 comments · Fixed by #91
Assignees
Labels
good first issue Good for newcomers type:feature New feature or request

Comments

@mattdangerw
Copy link
Member

For simplicity of our examples, we should add a layer that combines keras.layers.Embedding and keras_nlp.layers.PositionEmbedding into a single offering. Initial take for an API signature...

keras_nlp.layers.TokenAndPositionEmbedding(
    vocabulary_size,
    max_length,
    embedding_dim,
    embeddings_initializer="glorot_uniform",
    embeddings_regularizer=None,
    mask_zero=False,
    **kwargs
)

Internally, this will combine the layers as follows...

# in __init__
self.token_embeddings = layers.Embedding(
    input_dim=vocab_size, output_dim=embedding_dim
)
self.position_embeddings = keras_nlp.layers.PositionEmbedding(
    max_length=max_length
)

# in call
embedded_tokens = self.token_embeddings(inputs)
embedded_positions = self.position_embeddings(embedded_tokens)
outputs = embedded_tokens + embedded_positions
@mattdangerw mattdangerw added type:feature New feature or request good first issue Good for newcomers labels Apr 4, 2022
@mattdangerw
Copy link
Member Author

Note that we will do this only for the learned positional embedding (not the sinusoidal encoding). We believe that the learned embedding will be the most common usage for adding position info, so it's the only one we will provide the extra "glue" layer for.

@adhadse
Copy link
Contributor

adhadse commented Apr 5, 2022

Can I try to work on this issue? Please assign me.

@mattdangerw
Copy link
Member Author

Please do. Thanks!

@chenmoneygithub chenmoneygithub moved this from In progress to To do in Keras NLP 0.2 release Apr 15, 2022
@mattdangerw mattdangerw moved this from To do to In progress in Keras NLP 0.2 release Apr 15, 2022
Keras NLP 0.2 release automation moved this from In progress to Done Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type:feature New feature or request
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants