title: Efficient way to get best matching pairs given a similarity-outputting neural network?
body: <p>I am trying to come up with a neural network that ranks two short pairs of text (for example, stackexchange title and body).  Following the deep learning cookbook's example, the network would look basically like this:</p>
  
  <p><a href="https://i.stack.imgur.com/UDr0N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UDr0N.png" alt="enter image description here"></a> </p>
  
  <p>So we have our two inputs (title and body), embed them, then calculate the cosine similarity between embeddings.  The inputs of the model would be [title,body], the output is [sim].</p>
  
  <p>Now I'd like the closest matching body for a given title.  I am wondering if there's a more efficient way of doing this that doesn't involve iterating over every possible pair of (title,body) and calculating the corresponding similarity?  Because for very large datasets this is just not feasible.  </p>
  
  <p>Any help is much appreciated!</p>