Created
June 8, 2020 04:40
-
-
Save eustin/f568c7157b54fecd623f1ada5e8e101a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExpandBatchLayer(tf.keras.layers.Layer): | |
def __init__(self, **kwargs): | |
super(ExpandBatchLayer, self).__init__(**kwargs) | |
def call(self, input): | |
queries, docs = input | |
batch, num_docs, embedding_dims = tf.unstack(tf.shape(docs)) | |
expanded_queries = tf.gather(queries, tf.zeros([num_docs], tf.int32), axis=1) | |
return tf.concat([expanded_queries, docs], axis=-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment