Question about net structuring in functional api model

My dataset is a collection of three sub-dataset:Feature,T,Label,batch size=100
and now I build a net model though functional api,6 layers
If I want (layer3, layer4) and (layer5, layer6) be parallel, both get input from layer2 but only sample with T=1 for (layer3, layer4), and sample with T=0 for (layer5, layer6),how should I code?
Could I just find some api to split sample in model depend on conditions I set?Or I should split dataset before model setting?
thx for help

Hey @zhenlinhe,
A very interesting question indeed. I have used functional API to make branched models, each branch predicting different outputs, with some shared architecture, but I never needed to filter the data for the branches. All of my samples in the dataset were simply fed to the shared network, followed by the individual networks.

Now, this is indeed the easiest way to go. You can define a model consisting of Layers 1 and 2, pass the entire dataset through this model to get their representations, and then filter them out based on the T values in the original dataset, and then pass the T = 0 representations and the T = 1 representation, through 2 different models. If later down the line, you want to pass the output of these 2 models through some shared layers, you can define yet another model.

However, the real fun lies in how to make a single model. In my opinion, if we use a single model, the outputs of all the branches could differ in dimensions and even in their formats, but the number of output from each branches should be same, otherwise Tensorflow might throw some errors. So, I guess blocking some data completely from either of the branches is not something Tensorflow might allow. One possible way out here is to use a custom Tensorflow layer after Layer 2 in your model. You can read more about them here. If we perform some form of filtering based on the T values in the original dataset, and then apply the Masking layer of tensorflow, you might be able to achieve your objective. You can read more about masking layers here. Now, in most of the tutorials and documentation, masking layer has been used with sequence models, but I think, it should work in your scenario as well. Do let me know if this helps.


thx,I will try both solutions you suggested, and reply when the outcome of the second one coming out