3
$\begingroup$

Is there a natural way, in terms of structure of the layers of a NN, in order to pass 2 inputs vectors to the NN?

Example: text authorship identification

  • Input #1: sentence1 by unknown author encoded, as list of words from a dictionary

    "The sky is blue" => x1 = [2, 23, 7, 76, 0, 0, 0, ..., 0] (zero-padded to have a length of 1000 items)

  • Input #2: sentence2 by unknown author, idem

    "The cat is sleeping" => x2 = [2, 65, 7, 121, 0, 0, 0, ..., 0]

  • Output: y = a single number in [0, 1].
    0 = different authors
    1 = same author
    0.9 = high probability of same author, etc.

Of course I could build the layers like this:

  Input-size: None, 1000, 2    (x1, x2 stacked into a 1000x2 matrix)
  CNN ...
  ...
  Dense: None, 1

Then I could train with a dataset with 10,000 pairs of sentences of the same author (desired output: 1), and 10,000 pairs of sentences with different authors (desired output: 0).

But I don't know if it would work by just stacking x1 and x2 as a 1000x2 matrix.

TL;DR: What is the classical approach to build a NN taking 2 inputs and a single number as output which is a similarity index from 0% to 100%? (if possible with Sequential structure)

$\endgroup$
3
$\begingroup$

Sure! There's all sorts of ways you can pass in two inputs. Your idea of stacking the inputs like a 2-channel image is one idea.

Another possibly simpler idea would be something like this:

enter image description here

The intuition is that the network learns intermediate representations for the two sentences, then compares the representations.

Of course, you have an enormous amount of flexibility in how you configure the network connections. There are endless variations that allow you to have two (or more) separate inputs. For another example, check out DeepMind's pysc2 paper. On page 10 you can find diagrams for networks that deal with three different inputs. There's a flat vector of non-spatial features along with two different spatial inputs.

enter image description here

$\endgroup$

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.