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
loss = tf.keras.losses.KLDivergence() | |
batch_loss = loss(relevance_grades_prob_dist, scores_prob_dist) | |
print(batch_loss) |
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
relevance_grades_prob_dist = tf.nn.softmax(relevance_grades, axis=-1) | |
print(relevance_grades_prob_dist) |
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
scores_for_softmax = tf.squeeze(scores_out, axis=-1) | |
scores_prob_dist = tf.nn.softmax(scores_for_softmax, axis=-1) | |
print(scores_prob_dist) |
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
scores = tf.keras.layers.Dense(units=1, activation='linear') | |
scores_out = scores(dense_1_out) | |
print(scores_out) |
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
dense_1 = tf.keras.layers.Dense(units=3, activation='relu') | |
dense_1_out = dense_1(expanded_batch) | |
print(dense_1_out) |
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
expanded_batch = np.concatenate([expanded_queries, docs_averaged_embeddings], axis=-1) | |
print(expanded_batch) |
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
NUM_DOCS_PER_QUERY = 5 | |
expanded_queries = tf.gather(query_embeddings, [0 for x in range(NUM_DOCS_PER_QUERY)], axis=1).numpy() | |
print(expanded_queries) |
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
print(docs_averaged_embeddings.shape) |
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
docs_averaged_embeddings = [] | |
for docs_set in docs_embeddings: | |
this_docs_set = [] | |
for doc in docs_set: | |
this_docs_set.append(tf.reduce_mean(doc, axis=0, keepdims=True)) | |
concatenated_docs_set = tf.concat(this_docs_set, axis=0).numpy() | |
docs_averaged_embeddings.append(concatenated_docs_set) | |
docs_averaged_embeddings = np.array(docs_averaged_embeddings) |
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
for embeddings in docs_embeddings[1]: | |
print() | |
print(embeddings) |