I am new to DNN still learning, have a need to build item-to-item content based recommendation using DNN. For example, say I have a column of strings where each row represents a document I need to compute the cosine similarity of this column and recommend similar documents.

id   document

1     "hi this document is about science"

2     "hi this document is about wars"  
3     "This document is about peace"

now need to train based on document and column and recommend all the documents similar to a given document. I have solved this problem by using cosine similarity in ML now wanted to achieve the same in DNN (Deep Neural Nets). I have spent a lot of time on the net they all talk about movie rating where userId, rating, title is used. The problem I only have one column document how can I achieve this in DNN?


To be able to compare strings / Words or documents the data needs to be converted to a format the computer understand, vectors.

Google has a nice guide on Universal Sentence Encoder for sentence similarity that you can follow which explains how to generate a vector from the neural network that they have already trained.

What they do and what you can try is to use cosine similarity to compare the vectors. Compare one sentence vector with all other vectors and find the closest.

I am adding Annoy here, because I find it quite intuitive to use and you can get the n closest items.

  • $\begingroup$ Thanks much, it helped me a lot this solves the problem! $\endgroup$ – Raj Oct 21 '20 at 2:28
  • $\begingroup$ Glad I could help :) $\endgroup$ – Bjornar Remmen Oct 21 '20 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.