3
$\begingroup$

I've built mixed data NN, but I'm trying to build an NN that only has categorical variables. In my problem, I cannot represent my categorical variables using the commonly used NetEncoder[{"Class", VarLevels, "UnitVector"}], and each of my variables is a sequence of digits. So input1 will be 001, or 020, and Input2 maybe 02435 or 05433

 net = NetGraph[{CatenateLayer[], 2, 
    SoftmaxLayer[]}, {{NetPort["Input1"], NetPort["Input2"]} -> 1, 
    1 -> 2}, 
    "Input1" -> 
    NetEncoder[{"Characters", Automatic, IgnoreCase -> True}], 
    "Input2" -> 
    NetEncoder[{"Characters", Automatic, IgnoreCase -> True}], 
    "Output" -> NetDecoder[{"Class", {"no", "yes"}}]]

I implemented this very simple net but I still get an error

 NetGraph::netinvgport: Output is neither a valid input or output port for the given NetGraph.

However, I don't know how to fix it. Any help will be most appreciated.

$\endgroup$
2
$\begingroup$

It works if you (1) connect the inputs to UnitVectorLayer's and SequenceLastLayers, (CatenateLayer can't take varying-length inputs) and (2) connect the linear layer to the softmax layer, like this:

net = NetInitialize@NetGraph[
   {
    UnitVectorLayer[], SequenceLastLayer[],
    UnitVectorLayer[], SequenceLastLayer[],
    CatenateLayer[],
    2,
    SoftmaxLayer[]},
   {
    NetPort["Input1"] -> 1 -> 2, NetPort["Input2"] -> 3 -> 4,
    {2, 4} -> 5 -> 6 -> 7
    },
   "Input1" -> 
    NetEncoder[{"Characters", Automatic, IgnoreCase -> True}], 
   "Input2" -> 
    NetEncoder[{"Characters", Automatic, IgnoreCase -> True}], 
   "Output" -> NetDecoder[{"Class", {"no", "yes"}}]]

net[<|"Input1" -> "123", "Input2" -> "456"|>]

yes

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you very much for the prompt response! $\endgroup$ – user34018 Aug 24 '18 at 9:53

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.