Siamese Q Neural Networks

Hello!

I would like to build a siamese quantum neural network (as inputs I would like to start with MNIST dataset). My main problem is the Differencing layer (see picture). In the differencing layer we calculate the difference of these two dense layers and output the result to a single neuron with sigmoid activation function(0 to 1).

Any ideas on how to implement that? Thank you in advance! (any ideas on the general architecture would be appreciated)

p.s. for more information on siamese neural networks: Siamese Networks. Line by line explanation for beginners | by Krishna Prasad | Towards Data Science

Hi @NikSchet,

In the link that you shared there is a code example for this siamese layer. My suggestion would be that you first test the code as it is and then start changing aspects of it.

If you want to add a quantum layer you can follow the example of our demo on turning quantum nodes into Keras layers. You would create a qnode, turn it into a Keras layer using qml.qnn.KerasLayer, and then add it to the sequential model.

Once you get this working then I would suggest exploring a dataset change if that’s your goal. We have an example using the MNIST dataset here, although using this dataset is probably not ideal if you’re trying to measure performance. This blog post by Maria Schuld has a great explanation on why always using MNIST may not be the best path forward.

I hope this helps you and let me know if you have any questions while building this neural network!

1 Like