Siamese neural network is a class of neural network architectures that contain two or moreidenticalsubnetworks. identical here means they have the same configuration with the same parameters
and weights. Parameter updating is mirrored across both subnetworks.
It is a keras based implementation of deep siamese Bidirectional LSTM
network to capture phrase/sentence similarity using word embeddings.
Below is the architecture description for the same.
from operator import itemgetterfrom keras.models import load_model
model = load_model(best_model_path)
test_sentence_pairs = [('What can make Physics easy to learn?','How can you make physics easy to learn?'),('How many times a day do a clocks hands overlap?','What does it mean that every time I look at the clock the numbers are the same?')]
test_data_x1, test_data_x2, leaks_test = create_test_data(tokenizer,test_sentence_pairs, siamese_config['MAX_SEQUENCE_LENGTH'])
preds = list(model.predict([test_data_x1, test_data_x2, leaks_test], verbose=1).ravel())
results = [(x, y, z) for (x, y), z in zip(test_sentence_pairs, preds)]
results.sort(key=itemgetter(2), reverse=True)print results