Let’s assume I have “abbcab”-> {“Apple”,”Banana”}, “Bibb”-> {“Carrot”} so the output is a sequence of various length, but I can pad it to be the same length. My problem, how do I create a simple LSTM model that takes a string of characters of varying length and map it to a vector? What should be the last layer to return the vector?
1
-
$\begingroup$ Look up "Association" in the Help $\endgroup$ – Daniel Huber Jan 25 at 10:24
Add a comment
|
$\begingroup$
$\endgroup$
2
This is a multilabel classification.
classes = Length@{"Apple", "Banana", "Carrot"};
net = NetChain[
{
EmbeddingLayer[8],
LongShortTermMemoryLayer[16],
SequenceLastLayer[],
LinearLayer[classes],
ElementwiseLayer[LogisticSigmoid]
},
"Input" -> NetEncoder[{"Characters"}]
];
netT = NetTrain[net, {"abbcab" -> {1, 1, 0}, "Bibb" -> {0, 0, 1}}, MaxTrainingRounds -> 100]
netT@"abbcab"
{0.822325, 0.864362, 0.163531}
netT@"Bibb"
{0.219002, 0.200206, 0.798121}
You should do your own post-processing to select top-n classes.