- paddle.fluid.layers.nn. filter_by_instag ( ins, ins_tag, filter_tag, is_lod, out_val_if_empty=0 ) [source]
Filter By Instag Layer
This function filter a batch of ins by instag, There are multiple ins, and every ins belongs to some tags. We can specify some tags we want. So the ins which belongs to that tags remains in the output, and others removed.
For example, one batch has 4 ins. Every ins has its tag list.Ins | Ins_Tag |
|:-----:|:——:| | 0 | 0, 1 | | 1 | 1, 3 | | 2 | 0, 3 | | 3 | 2, 6 |
And Lod is [1,1,1,1]
And the filter tags 
From the definition above, ins which has tag 1 can pass the filter So Ins 0 and Ins 1 can pass and be seen in the output, Ins 2 and 3 cannot pass because they do not has tag 1.
Actually, if is_lod is false, it is normal tensor that equals to lod_tensor with all 1, similar to the example above.
ins (Variable) – Input Variable (LoDTensor), usually it is 2D tensor And first dimension can have lod info or not.
ins_tag (Variable) – Input Variable (LoDTensor), usually it is 1D list And split them by lod info
filter_tag (Variable) – Input Variable (1D Tensor/List), usually it is list that holds the tags.
is_lod (Bool) – Boolean value to indicate ins is lod tensor or not.
out_val_if_empty (Int64) – If the output after filter is empty, this value will be set to Output tensor.
filtered ins (LoDTensor) and loss weight (Tensor)
- Return type
import paddle.fluid.layers as layers ins = layers.data(name='Ins', shape=[-1,32], lod_level=0, dtype='float64') ins_tag = layers.data(name='Ins_tag', shape=[-1,16], lod_level=0, dtype='int64') filter_tag = layers.data(name='Filter_tag', shape=[-1,16], dtype='int64') out, loss_weight = layers.filter_by_instag(ins, ins_tag, filter_tag, True)