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
query_embeddings = np.row_stack([query_1_embeddings, query_2_embeddings_avg]) |
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(query_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_sequences = [] | |
for docs_list in [bing_search_results, google_search_results]: | |
docs_sequences.append(tokeniser.texts_to_sequences(docs_list)) | |
docs_embeddings = [] | |
for docs_set in docs_sequences: | |
this_docs_set = [] | |
for doc in docs_set: | |
this_doc_embeddings = np.array([embeddings[idx] for idx in doc]) | |
this_docs_set.append(this_doc_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[0]: | |
print() | |
print(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) |
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
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
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
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
dense_1 = tf.keras.layers.Dense(units=3, activation='relu') | |
dense_1_out = dense_1(expanded_batch) | |
print(dense_1_out) |