1 Introduction
A relatively less studied problem in machine learning, particularly supervised learning, is the problem of multiset prediction. The goal of this problem is to learn a mapping from an arbitrary input to a multiset
^{1}^{1}1A set that allows multiple instances, e.g. . See Appendix A for a detailed definition. of items. This problem appears in a variety of contexts. For instance, in the context of highenergy physics, one of the important problems in a particle physics data analysis is to count how many physics objects, such as electrons, muons, photons, taus, and jets, are in a collision event [6]. In computer vision, object counting and automatic alttext can be framed as multiset prediction
[30, 14].In multiset prediction, a learner is presented with an arbitrary input and the associated multiset of items. It is assumed that there is no predefined order among the items, and that there are no further annotations containing information about the relationship between the input and each of the items in the multiset. These properties make the problem of multiset prediction unique from other wellstudied problems. It is different from sequence prediction, because there is no known order among the items. It is not a ranking problem, since each item may appear more than once. It cannot be transformed into classification, because the number of possible multisets grows exponentially with respect to the maximum multiset size.
In this paper, we view multiset prediction as a sequential decision making process. Under this view, the problem reduces to finding a policy that sequentially predicts one item at a time, while the outcome is still evaluated based on the aggregate multiset of the predicted items. We first propose an oracle policy that assigns nonzero probabilities only to prediction sequences that result exactly in the target, groundtruth multiset given an input. This oracle is optimal in the sense that its prediction never decreases the precision and recall regardless of previous predictions. That is, its decision is optimal in any state (i.e., prediction prefix). We then propose a novel
multiset loss which minimizes the KL divergence between the oracle policy and a parametrized policy at every point in a decision trajectory of the parametrized policy.We compare the proposed multiset loss against an extensive set of baselines. They include a sequential loss with an arbitrary rank function, sequential loss with an inputdependent rank function, and an aggregated distribution matching loss and its onestep variant. We also test policy gradient, as was done in [30] recently for multiset prediction. Our evaluation is conducted on two sets of datasets with varying difficulties and properties. According to the experiments, we find that the proposed multiset loss outperforms all the other loss functions.
2 Multiset Prediction
A multiset prediction problem is a generalization of classification, where a target is not a single class but a multiset of classes. The goal is to find a mapping from an input to a multiset , where . Some of the core properties of multiset prediction are; (1) the input
is an arbitrary vector, (2) there is no predefined order among the items
in the target multiset , (3) the size of may vary depending on the input , and (4) each item in the class set may appear more than once in . Formally, is a multiset , where gives the number of occurrences of each class in the multiset. See Appendix A for a further review of multisets.As is typical in supervised learning, in multiset prediction a model is trained on a dataset , then evaluated on a separate test set
using evaluation metrics
that compare the predicted and target multisets, i.e. , where denotes a predicted multiset. For evaluation metrics we use exact match , and the score. Refer to Appendix A for multiset definitions of exact match and .3 Related Problems in Supervised Learning
Variants of multiset prediction have been studied earlier. We now discuss a taxonomy of approaches in order to differentiate our proposal from previous work and define strong baselines.
3.1 Set Prediction
Ranking
A ranking problem can be considered as learning a mapping from a pair of input and one of the items to its score . All the items in the class set are then sorted according to the score, and this sorted order determines the rank of each item. Taking the top items from this sorted list results in a predicted set (e.g. [7]). Similarly to multiset prediction, the input is arbitrary, and the target is a set without any prespecific order. However, ranking differs from multiset prediction in that it is unable to handle multiple occurrences of a single item in the target set.
Multilabel Classification via Binary Classification
Multilabel classification consists of learning a mapping from an input to a subset of classes identified as . This problem can be reduced to
binary classification problems by learning a binary classifier for each possible class. Representative approaches include binary relevance, which assumes classes are conditionally independent, and probabilistic classifier chains which decompose the joint probability as
[4, 19, 27, 8]. Since each models binary membership of a particular class, their predictions form a set rather than a multiset .3.2 Parallel Prediction
Power Multiset Classification
A bruteforce approach based on the Combination Method in multilabel classification [27, 19], is to transform the class set into a set of all possible multisets, then train a multiclass classifier that maps an input to one of the elements in . However, the number of all possible multisets grows exponentially in the maximum size of a target multiset,^{2}^{2}2The number of all possible multisets of size is .. rendering this approach infeasible in practice.
One Step Distribution Matching
Instead of considering the target multiset as an actual multiset, one can convert it into a distribution over the class set, using each item’s multiplicity. That is, we consider a target multiset as a set of samples from a single, underlying distribution over the class set
, empirically estimated as
, where is an indicator function. A model then outputs a point in a dimensional simplex and is trained by minimizing a divergence between and . The model also predicts the size of the target multiset, so that each unique has a predicted cardinality . An unnormalized variant could directly regress the cardinality of each class.3.3 Sequential Methods
Sequence prediction
A sequence prediction problem is characterized as finding a mapping from an input to a sequence of classes . It is different from multiset prediction since a sequence has a predetermined order of items, while a multiset is an unordered collection. Multiset prediction can however be treated as sequence prediction by defining an ordering for each multiset. Each target multiset is then transformed into an ordered sequence , a model predicts a sequence , and a perstep loss is minimized using and .
Recently, multilabel classification (i.e. set prediction) was posed as sequence prediction with RNNs [29, 16], improving upon methods that do not model conditional label dependencies. However, these approaches and the approach outlined above require a prespecified rank function which orders output sequences (e.g. class prevalence in [29]).
Because multiset prediction does not come with such a rank function by definition, we must choose a (often adhoc) rank function, and performance can significantly vary based on the choice. Vinyals et al. [28] observed this variation in sequencebased set prediction (also observed in [16, 29]), which we confirm for multisets in section 5.3. This shows the importance of our proposed method, which does not require a fixed label ordering.
Unlike , our multiset loss proposed below is permutation invariant with respect to the order of the target multiset, and is thus not susceptible to performance variations from choosing a rank function, since such a choice is not required. We use as a baseline in Experiment 3, finding that it underperforms the proposed .
Aggregated Distribution Matching
As in onestep distribution matching, a multiset is treated as a distribution over classes. The sequential variant predicts a sequence of classes by sampling from a predicted distribution at each step . The perstep distributions are averaged into an aggregate distribution , and a divergence between and is minimized. We test distance and KLdivergence in the experiments ().
A major issue with this approach is that it may assign nonzero probability to an incorrect sequence of predictions due to the aggregated distribution’s invariance to the order of predictions. This is reflected in an increase in the entropy of over time, discussed in Experiment 3.
Reinforcement Learning
In [30], an approach based on reinforcement learning (RL) was proposed for multiset prediction. In this approach, a policy samples a multiset as a sequential trajectory, and the goal is finding whose trajectories maximize a reward function designed specifically for multiset prediction. REINFORCE [31]
is used to minimize the resulting loss function, which is known to be difficult due to high variance
[18]. We test the RL method in the experiments ().3.4 DomainSpecific Methods
In computer vision, object counting and object detection are instances of multiset prediction. Typical object counting approaches in computer vision, e.g. [14, 33, 17], model the counting problem as density estimation over image space, and assume that each object is annotated with a dot specifying its location. Object detection methods (e.g. [24, 21, 20, 9]) also require object location annotations. Since these approaches exploit the fact the input is an image and rely on additional annotated information, they are not directly comparable to our method which only assumes annotated class labels and is agnostic to the input modality.
4 Multiset Loss Function for Multiset Prediction
In this paper, we propose a novel loss function, called multiset loss, for the problem of multiset prediction. This loss function is best motivated by treating the multiset prediction problem as a sequential decision making process with a model being considered a policy . This policy, parametrized by , takes as input the input and all the previously predicted classes at time , and outputs the distribution over the next class to be predicted. That is, .
We first define a free label multiset at time , which contains all the items that remain to be predicted after predictions by the policy, as
Definition 1 (Free Label Multiset).
where is the prediction made by the policy at time .
We then construct an oracle policy . This oracle policy takes as input a sequence of predicted labels , the input , and the free label multiset with respect to its predictions, . It outputs a distribution whose entire probability (1) is evenly distributed over all the items in the free label multiset . In other words,
Definition 2 (Oracle).
An interesting and important property of this oracle is that it is optimal given any prefix with respect to both precision and recall. This is intuitively clear by noticing that the oracle policy allows only a correct item to be selected. We call this property the optimality of the oracle.
Remark 1.
Given an arbitrary prefix ,
for any .
From the remark above, it follows that the oracle policy is optimal in terms of precision and recall.
Remark 2.
It is trivial to show that sampling from such an oracle policy would never result in an incorrect prediction. That is, this oracle policy assigns zero probability to any sequence of predictions that is not a permutation of the target multiset.
Remark 3.
where multiset equality refers to exact match, as defined in Appendix 1.
In short, this oracle policy tells us at each time step which of all the items in the class set must be selected. By selecting an item according to the oracle, the free label multiset decreases in size. Since the oracle distributes equal probability over items in the free label multiset, the oracle policy’s entropy decreases over time.
Remark 4 (Decreasing Entropy).
where denotes the Shannon entropy of the oracle policy at time , .
Proofs of the remarks above can be found in Appendix B–D.
The oracle’s optimality allows us to consider a stepwise loss between a parametrized policy and the oracle policy , because the oracle policy provides us with an optimal decision regardless of the quality of the prefix generated so far. We thus propose to minimize the KL divergence from the oracle policy to the parametrized policy at each step separately. This divergence is defined as
where is formed using predictions from , and is the entropy of the oracle policy at time step . This entropy term can be safely ignored when learning , since it is constant with respect to . We then define a perstep loss function as . The KL divergence may be replaced with another divergence.
It is intractable to minimize this perstep loss for every possible state , since the size of the state space grows exponentially with respect to the size of a target multiset. We thus propose here to minimize the perstep loss only for the state, defined as a pair of the input and the prefix , visited by the parametrized policy . That is, we generate an entire trajectory by executing the parametrized policy until either all the items in the target multiset have been predicted or the predefined maximum number of steps have passed. Then, we compute the loss function at each time based on , for all . The final loss function is the sum of all these perstep loss functions:
Definition 3 (Multiset Loss Function).
where is the smaller of the smallest for which and the predefined maximum value.
By Remarks 2 and 3, minimizing this loss function maximizes F1 and exact match.
Execution Strategies
As was shown in [22], the use of the parametrized policy instead of the oracle policy allows the upper bound on the learned policy’s error to be linear with respect to the size of the target multiset. If the oracle policy had been used, the upper bound would have grown quadratically with respect to the size of the target multiset. To confirm this empirically, we test the following three alternative strategies for executing the parametrized policy : (1) Greedy search: , (2) Stochastic sampling: , and (3) Oracle sampling: . After training, the learned policy is evaluated by greedily selecting each item from the policy.
VariableSized Multisets
In order to predict variablesized multisets with the proposed loss functions, we introduce a termination policy , which outputs a stop distribution given the predicted sequence of items and the input . Because the size of the target multiset is known during training, we simply train this termination policy in a supervised way using a binary crossentropy loss. At evaluation time, we simply threshold the predicted stop probability at a predefined threshold (0.5). An alternative method for supporting variablesized multisets is discussed in Appendix E.
Relation to Learning to Search
Our framing of multiset prediction as a sequential task based on learning to imitate an oracle policy is inspired by the Learning to Search (L2S) approach to structured prediction [3, 2]. Recently, Leblond et al. [12] proposed SeaRNN, adapting L2S to modern recurrent models. Our proposal can be seen as designing an oracle and loss with favorable properties for multiset prediction, using a learned rollin , and directly setting a cost vector equal to the oracle’s distribution, avoiding the expensive perstep rollout in SeaRNN. We believe that applying the general L2S framework to novel problem settings is an important research direction.
5 Experiments and Analysis
5.1 Datasets
MNIST Multi
MNIST Multi is a class of synthetic datasets. Each dataset consists of multiple 100x100 images, each of which contains a varying number of digits from the original MNIST [13]. We vary the size of each digit and also add clutter. In the experiments, we consider the following variants of MNIST Multi:

MNIST Multi (4): ; 2050 px digits

MNIST Multi (14): ; 2050 px digits

MNIST Multi (10): ; 20 px digits
Each dataset has a training set with 70,000 examples and a test set with 10,000 examples. We randomly sample 7,000 examples from the training set to use as a validation set, and train with the remaining 63,000 examples.
Ms Coco
As a realworld dataset, we use Microsoft COCO [15] which includes natural images with multiple objects. Compared to MNIST Multi, each image in MS COCO has objects of more varying sizes and shapes, and there is a large variation in the number of object instances per image which spans from 1 to 91. The problem is made even more challenging with many overlapping and occluded objects. To better control the difficulty, we create the following two variants:

COCO Easy: ; 10,230 examples, 24 classes

COCO Medium: ; 44,121 training examples, 23 classes
In both of the variants, we only include images whose objects are large and of common classes. An object is defined to be large if the object’s area is above the 40th percentile across the training set of MS COCO. After reducing the dataset to have large objects per image, we remove images containing only objects of rare classes. A class is considered rare if its frequency is less than , where is the class set. These two stages ensure that only images with a proper number of large objects are kept. We do not use finegrained annotation (pixellevel segmentation and bounding boxes) except for creating inputdependent rank functions for the baseline (see Appendix F.2).
For each variant, we hold out a randomly sampled 15% of the training examples as a validation set. We form separate test sets by applying the same filters to the COCO validation set. The test set sizes are 5,107 for COCO Easy and 21,944 for COCO Medium.
MNIST Multi (4)  COCO Easy  

EM  F1  EM  F1  
Random  0.920  0.977  0.721  0.779 
Area  0.529  0.830  0.700  0.763 
Spatial  0.917  0.976  0.675  0.738 
COCO Medium  

EM  F1  
Greedy  0.475 0.006  0.645 0.016 
Stochastic  0.475 0.004  0.649 0.009 
Oracle  0.469 0.002  0.616 0.009 
5.2 Models
MNIST Multi
We use three convolutional layers of channel sizes 10, 10 and 32, followed by a convolutional long shortterm memory (LSTM) layer
[32]. At each step, the feature map from the convolutional LSTM layer is averagepooled spatially and fed to a softmax classifier. In the case of the onestep variant of aggregate distribution matching, the LSTM layer is skipped.Ms Coco
We use a ResNet34 [10]
pretrained on ImageNet
[5] as a feature extractor. The final feature map from this ResNet34 is fed to a convolutional LSTM layer, as described for MNIST Multi above. We do not finetune the ResNet34 based feature extractor.In all experiments, for predicting variablesized multisets we use the termination policy approach since it is easily applicable to all of the baselines, thus ensuring a fair comparison. Conversely, it is unclear how to extend the special class approach to the distribution matching baselines.
Training and evaluation
For each loss, a model was trained for 200 epochs (350 for MNIST Multi 10). After each epoch, exact match was computed on the validation set. The model with the highest validation exact match was used for evaluation on the test set. See Appendix E for more details.
When evaluating a trained policy, we use greedy decoding. Each predicted multiset is compared against the groundtruth target multiset, and we report both the exact match accuracy (EM) and F1 score (F1), as defined in Appendix 1.
5.3 Experiment 1: Influence of a Rank Function on Sequence Prediction
First, we investigate the sequence loss function from Sec. 3.3, while varying a rank function. We test three alternatives: a random rank function^{3}^{3}3The random rank function is generated before training and held fixed. We verified that generating a new random rank function for each batch significantly decreased performance. and two inputdependent rank functions and . orders labels in lefttoright, toptobottom order, and orders labels by decreasing object area; see Appendix F for more detail. We compare these rank functions on MNIST Multi (4) and COCO Easy validation sets.
We present the results in Table 2. It is clear from the results that the performance of the sequence prediction loss function is dependent on the choice of a rank function. In the case of MNIST Multi, the areabased rank function was far worse than the other choices. However, this was not true on COCO Easy, where the spatial rank function was worst among the three. In both cases, we have observed that the random rank function performed best, and from here on, we use the random rank function in the remaining experiments. This set of experiments firmly suggests the need of an orderinvariant multiset loss function, such as the proposed multiset loss function.
5.4 Experiment 2: Execution Strategies for the Multiset Loss Function
In this set of experiments, we compare the three execution strategies for the proposed multiset loss function, illustrated in Sec. 3. They are greedy decoding, stochastic sampling and oracle
sampling. We test them on the most challenging dataset, COCO Medium, and report the mean and standard deviation for the evaluation metrics across 5 runs.
As shown in Table 2, greedy decoding and stochastic sampling, both of which consider states that are likely to be visited by the parametrized policy, outperform the oracle sampling, which only considers states on optimal trajectories. This is particularly apparent in the F1 score, which can be increased even after visiting a state that is not on an optimal trajectory. The results are consistent with the theory from [22, 2]. The performance difference between the first two strategies was not significant, so from here on we choose the simpler method, greedy decoding, when training a model with the proposed multiset loss function.
5.5 Experiment 3: Loss Function Comparison
We now compare the proposed multiset loss function against the five baseline loss functions: reinforcement learning , aggregate distribution matching– and –, its onestep variant , and sequence prediction , introduced in Section 3. Refer to Appendix F for additional details.
MNIST Multi
We present the results on the MNIST Multi variants in Table 3 (a). On all three variants and according to both metrics, the proposed multiset loss function outperforms all the others. The reinforcement learning based approach closely follows behind. Its performance, however, drops as the number of items in a target multiset increases. This is understandable, as the variance of policy gradient grows as the length of an episode grows. A similar behaviour was observed with sequence prediction as well as aggregate distribution matching. We were not able to train any decent models with the onestep variant of aggregate distribution matching. This was true especially in terms of exact match (EM), which we attribute to the onestep variant not being capable of modelling dependencies among the predicted items.
Ms Coco
Similar to the results on the variants of MNIST Multi, the proposed multiset loss function matches or outperforms all the others on the two variants of MS COCO, as presented in Table 3 (b). On COCO Easy, with only two objects to predict per example, both aggregated distribution matching (with KL divergence) and the sequence loss functions are as competitive as the proposed multiset loss. The other loss functions significantly underperform these three loss functions, as they did on MNIST Multi. The performance gap between the proposed loss and the others, however, grows substantially on the more challenging COCO Medium, which has more objects per example. The proposed multiset loss outperforms the aggregated distribution matching with KL divergence by 3.7 percentage points on exact match and 4.8 on F1. This is analogous to the experiments on MNIST Multi, where the performance gap increased when moving from four to ten digits.
5.6 Analysis: Entropy Evolution
Recall from Remark 4 that the entropy of the oracle policy’s predictive distribution strictly decreases over time, i.e., . This naturally follows from the fact that there is no prespecified rank function, because the oracle policy cannot prefer any item from the others in a free label multiset. Hence, we examine here how the policy learned based on each loss function compares to the oracle policy in terms of perstep entropy. We consider the policies trained on MNIST Multi (10), where the differences among them were most clear. As shown in Fig. 1, the policy trained on MNIST Multi (10) using the proposed multiset loss closely follows the oracle policy. The entropy decreases as the predictions are made. The decreases can be interpreted as concentrating probability mass on progressively smaller free labels sets. The variance is quite small, indicating that this strategy is uniformly applied for any input.
The policy trained with reinforcement learning retains a relatively low entropy across steps, with a decreasing trend in the second half. We carefully suspect the low entropy in the earlier steps is due to the greedy nature of policy gradient. The policy receives a high reward more easily by choosing one of many possible choices in an earlier step than in a later step. This effectively discourages the policy from exploring all possible trajectories during training.
On the other hand, the policy found by aggregated distribution matching () has the opposite behaviour. The entropy in general grows as more predictions are made. To see why this is suboptimal, consider the final step. Assuming the first nine predictions were correct, there is only one correct class left for the final prediction . The high entropy, however, indicates that the model is placing a significant amount of probability on incorrect sequences. Such a policy may result because cannot properly distinguish between policies with increasing and decreasing entropies. The increasing entropy also indicates that the policy has learned a rank function implicitly and is fully relying on it. We conjecture this reliance on an inferred rank function, which is by definition suboptimal, resulted in lower performance of aggregate distribution matching.
6 Conclusion
We have extensively investigated the problem of multiset prediction in this paper. We rigorously defined the problem, and proposed to approach it from the perspective of sequential decision making. In doing so, an oracle policy was defined and shown to be optimal, and a new loss function, called multiset loss, was introduced as a means to train a parametrized policy for multiset prediction. The experiments on two families of datasets, MNIST Multi variants and MS COCO variants, have revealed the effectiveness of the proposed loss function over other loss functions including reinforcement learning, sequence, and aggregated distribution matching loss functions. This success brings in new opportunities of applying machine learning to various new domains, including highenergy physics.
Acknowledgments
KC thanks support by eBay, TenCent, NVIDIA and CIFAR. This work was supported by Samsung Electronics (Improving Deep Learning using Latent Structure).
References
 [1] Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:1409.0473, 2014.
 [2] KaiWei Chang, Akshay Krishnamurthy, Alekh Agarwal, Hal Daumé, III, and John Langford. Learning to search better than your teacher. In Proceedings of the 32Nd International Conference on International Conference on Machine Learning  Volume 37, ICML’15, pages 2058–2066. JMLR.org, 2015.
 [3] Hal Daumé, John Langford, and Daniel Marcu. Searchbased structured prediction. Machine Learning, 75(3):297–325, Jun 2009.
 [4] Krzysztof Dembczyński, Weiwei Cheng, and Eyke Hüllermeier. Bayes optimal multilabel classification via probabilistic classifier chains. In Proceedings of the 27th International Conference on International Conference on Machine Learning, ICML’10, pages 279–286, USA, 2010. Omnipress.

[5]
Jia Deng, Wei Dong, Richard Socher, LiJia Li, Kai Li, and Li FeiFei.
Imagenet: A largescale hierarchical image database.
In
Computer Vision and Pattern Recognition, 2009. CVPR 2009. IEEE Conference on
, pages 248–255. IEEE, 2009.  [6] W Ehrenfeld, R Buckingham, J Cranshaw, T Cuhadar Donszelmann, T Doherty, E Gallas, J Hrivnac, D Malon, M Nowak, M Slater, F Viegas, E Vinek, Q Zhang, and the ATLAS Collaboration. Using tags to speed up the atlas analysis process. Journal of Physics: Conference Series, 331(3):032007, 2011.
 [7] Yunchao Gong, Yangqing Jia, Thomas Leung, Alexander Toshev, and Sergey Ioffe. Deep convolutional ranking for multilabel image annotation. arXiv preprint arXiv:1312.4894, 2013.

[8]
S. Hamid Rezatofighi, Vijay Kumar B G, Anton Milan, Ehsan Abbasnejad, Anthony
Dick, and Ian Reid.
Deepsetnet: Predicting sets with deep neural networks.
In The IEEE International Conference on Computer Vision (ICCV), Oct 2017.  [9] Kaiming He, Georgia Gkioxari, Piotr Dollár, and Ross Girshick. Mask RCNN. arXiv preprint arXiv:1703.06870, 2017.
 [10] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 770–778, 2016.
 [11] Diederik Kingma and Jimmy Ba. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980, 2014.
 [12] Rémi Leblond, JeanBaptiste Alayrac, Anton Osokin, and Simon LacosteJulien. Searnn: Training rnns with globallocal losses, 2017.
 [13] Yann LeCun, Léon Bottou, Yoshua Bengio, and Patrick Haffner. Gradientbased learning applied to document recognition. Proceedings of the IEEE, 86(11):2278–2324, 1998.
 [14] V. Lempitsky and A. Zisserman. Learning to count objects in images. In Advances in Neural Information Processing Systems, 2010.
 [15] TsungYi Lin, Michael Maire, Serge Belongie, James Hays, Pietro Perona, Deva Ramanan, Piotr Dollár, and C Lawrence Zitnick. Microsoft coco: Common objects in context. In European conference on computer vision, pages 740–755. Springer, 2014.

[16]
Jinseok Nam, Eneldo Loza Mencía, Hyunwoo J Kim, and Johannes
Fürnkranz.
Maximizing subset accuracy with recurrent neural networks in multilabel classification.
In I. Guyon, U. V. Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett, editors, Advances in Neural Information Processing Systems 30, pages 5419–5429. Curran Associates, Inc., 2017.  [17] Daniel OñoroRubio and Roberto J. LópezSastre. Towards perspectivefree object counting with deep learning. In Bastian Leibe, Jiri Matas, Nicu Sebe, and Max Welling, editors, Computer Vision – ECCV 2016, pages 615–629, Cham, 2016. Springer International Publishing.
 [18] J. Peters and S. Schaal. Reinforcement learning of motor skills with policy gradients. Neural Networks, 21(4):682–697, May 2008.
 [19] Jesse Read, Bernhard Pfahringer, Geoff Holmes, and Eibe Frank. Classifier chains for multilabel classification. Machine Learning, 85(3):333, Jun 2011.
 [20] Mengye Ren and Richard S. Zemel. Endtoend instance segmentation with recurrent attention. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), July 2017.
 [21] Bernardino RomeraParedes and Philip H. S. Torr. Recurrent instance segmentation. arXiv preprint arXiv:1511.08250, 2015.

[22]
Stéphane Ross, Geoffrey J Gordon, and Drew Bagnell.
A reduction of imitation learning and structured prediction to noregret online learning.
InInternational Conference on Artificial Intelligence and Statistics
, pages 627–635, 2011.  [23] D. Singh, A. M. Ibrahim, T. Yohanna, and J.N Singh. An overview of the applications of multisets. Novi Sad Journal of Mathematics, 37(3):73–92, 2007.
 [24] Russell Stewart, Mykhaylo Andriluka, and Andrew Y. Ng. Endtoend people detection in crowded scenes. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2016.
 [25] Ilya Sutskever, Oriol Vinyals, and Quoc V Le. Sequence to sequence learning with neural networks. In Advances in neural information processing systems, pages 3104–3112, 2014.
 [26] Apostolos Syropoulos. Mathematics of Multisets, pages 347–358. Springer, Berlin, Heidelberg, 2001.
 [27] Grigorios Tsoumakas and Ioannis Katakis. Multilabel classification: An overview. Int J Data Warehousing and Mining, 2007:1–13, 2007.
 [28] Oriol Vinyals, Samy Bengio, and Manjunath Kudlur. Order matters: Sequence to sequence for sets, 2015.
 [29] Jiang Wang, Yi Yang, Junhua Mao, Zhiheng Huang, Chang Huang, and Wei Xu. Cnnrnn: A unified framework for multilabel image classification. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2016.
 [30] Sean Welleck, Kyunghyun Cho, and Zheng Zhang. Saliencybased sequential image attention with multiset prediction. In Advances in neural information processing systems, 2017.
 [31] Ronald J Williams. Simple statistical gradientfollowing algorithms for connectionist reinforcement learning. Machine learning, 8(34):229–256, 1992.
 [32] SHI Xingjian, Zhourong Chen, Hao Wang, DitYan Yeung, WaiKin Wong, and Wangchun Woo. Convolutional lstm network: A machine learning approach for precipitation nowcasting. In Advances in neural information processing systems, pages 802–810, 2015.

[33]
Y. Zhang, D. Zhou, S. Chen, S. Gao, and Y. Ma.
Singleimage crowd counting via multicolumn convolutional neural network.
In 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pages 589–597, June 2016.
Appendix A Definitions
We review definitions of multiset and exact match, and present multiset versions of precision, recall, and F1. For a comprehensive overview of multisets, refer to [26, 23].
Multiset
A multiset is a set that allows for multiple instances of elements. Multisets are unordered, i.e. and are equal. We now introduce the formal definition and convenient ways of representing a multiset.
Formally, a multiset is a pair , where is a ground set, and is a multiplicity function that maps each to the number of times it occurs in the multiset. The multiset cardinality is defined as .
A multiset can be enumerated by numbering each element instance and representing the multiset as a size set: . This allows for notation such as .
An additional compact notation is , where each is an auxiliary variable referring to an underlying element of the ground set.
For instance, the multiset can be defined as , where , , and can be written as or .
Exact Match (EM)
Two multisets exactly match when their elements and multiplicities are the same. For example, exactly matches , while does not exactly match or .
Formally, let , be multisets over a common ground set . Then and exactly match if and only if for all . The evaluation metric is 1 when and exactly match, and 0 otherwise.
Note that exact match is the same as multiset equality, i.e. , as defined in [23].
Precision
Precision gives the ratio of correctly predicted elements to the number of predicted elements. Specifically, let , be multisets. Then
The summation and membership are done by enumerating the multiset. For example, the multisets and are enumerated as and , respectively. Then clearly but .
Formally, precision can be defined as
where the summation is now over the ground set . Intuitively, precision decreases by each time an extra class label is predicted.
Recall
Recall gives the ratio of correctly predicted elements to the number of groundtruth elements. Recall is defined analogously to precision, as:
Formally,
Intuitively, recall decreases by each time an element of is not predicted.
F1
The F1 score is the harmonic mean of precision and recall:
Appendix B Proof of Remark 1
Proof.
Note that the precision with is defined as
Because ,
Then,
because and . The equality holds when .
Similarly, we start with the definition of the recall:
Because ,
Since the denominator is identical,
∎
Appendix C Proof of Remark 2
Proof.
When ,
because . From Remark 1, we know that
when . By induction, .
From the proof of Remark 1, we know that the recall increases by each time, and we also know that
when . After steps of executing the oracle policy, the recall becomes
∎
Appendix D Proof of Remark 4
Proof.
Given a multiset with , define , where is interpreted as the ’th instance of class . Writing in enumerated form it is clear that . Let range from 1 to and define as in Definition 1.
Now, define the oracle policy as a distribution over C, according to Definition 2:
Therefore,
where is defined as 0 in the first step.
Now, observe that since is in with probability 1 and by definition. Hence
∎
Appendix E Model Descriptions
Model
An input is first processed by a tower of convolutional layers, resulting in a feature volume of size with feature maps, i.e., . At each time step , we resize the previous prediction’s embedding to be a tensor and concatenate it with , resulting in . This feature volume is then fed into a stack of convolutional LSTM layers. The output from the final convolutional LSTM layer is spatially averagepooled, i.e., . This feature vector is then turned into a conditional distribution over the next item after affine transformation followed by a softmax function. When the onestep variant of aggregated distribution matching is used, we skip the convolutional LSTM layers, i.e., .
Preprocessing
For MNIST Multi, we do not preprocess the input at all. In the case of MS COCO, input images are of different sizes. Each image is first resized so that its larger dimension has 600 pixels, then along its other dimension is zeropadded to 600 pixels and centered, resulting in a 600x600 image.
Training
The model is trained endtoend, except ResNet34 which remains fixed after being pretrained on ImageNet. For all the experiments, we train a neural network using Adam [11] with a fixed learning rate of 0.001, of (0.9, 0.999) and of 1e8. The learning rate was selected based on the validation performance during the preliminary experiments, and the other parameters are the default values. For MNIST Multi, the batch size was 64, and for COCO was 32. For the selection strategy experiments, 5 runs with different random seeds were used.
Data  MNIST Multi  MS COCO 

CNN  conv feat  ResNet34 
maxpool  
conv feat  
maxpool  
conv feat  
maxpool  
81  361  
ConvLSTM  conv feat  conv feat 
conv feat  conv feat 
Feedforward Alternative
While we use a recurrent model in the experiments, the multiset loss can be used with a feedforward model as follows. A key use of the recurrent hidden state is to retain the previously predicted labels, i.e. to remember the full conditioning set in . Therefore, the proposed loss can be used in a feedforward model by encoding in the input , and running the feedforward model for steps, where is determined using a termination policy or the Special Class method detailed below. Note that compared to the recurrent model, this approach involves additional feature engineering.
Termination Policy Alternative: Special Class
An alternative strategy to support predicting variablesized multisets is to introduce a special item to the class set, called , and add it to the final free label multiset . Thus, the parametrized policy is trained to predict this special item once all the items in the target multiset have been predicted. This is analogous to NLP sequence models which predict an end of sentence token [25, 1], and was used in [30] to predict variablesized multisets.
Appendix F Additional Experimental Details
f.1 Baseline Loss Functions
f.1.1
The corresponding loss function for the onestep distribution matching baseline introduced in 3.1.1, , is:
where is a coefficient for balancing the contributions from the two terms.
f.1.2
First define a rank function that maps from one of the unique items in the class set to a unique integer. That is, . This function assigns the rank of each item and is used to order items in a target multiset . This results in a sequence , where for all , and .
With this target sequence created from using the rank function , the sequence loss function is defined as
Minimizing this loss function is equivalent to maximizing the conditional logprobability of the sequence given .
f.1.3
In distribution matching, we consider the target multiset as a set of samples from a single, underlying distribution over the class set . This underlying distribution can be empirically estimated by counting the number of occurrences of each item in . That is,
where is the indicator function.
Similarly, we can construct an aggregated distribution computed by the parametrized policy, here denoted as . To do so, the policy predicts by sampling from a predicted distribution at each step . The perstep distributions are then averaged to form the aggregate distribution .
Learning is equivalent to minimizing a divergence between and . The baseline uses
where and are the vectors representing the corresponding categorical distributions, and in the experiments. The baseline uses KL divergence:
f.1.4
Instead of assuming the existence of an oracle policy, this approach solely relies on a reward function designed specifically for multiset prediction. The reward function is defined as
The goal is then to maximize the sum of rewards over a trajectory of predictions from a parametrized policy . The final loss function is
(1) 
where the second term inside the expectation is the negative entropy multiplied with a regularization coefficient . The second term encourages exploration during training. As in [30], we use REINFORCE [31] to stochastically minimize the loss function above with respect to . This loss function is optimal in that the return, i.e., the sum of the stepwise rewards, is maximized when both the precision and recall are maximal ().
f.2 InputDependent Rank Function
For the baseline, a domainspecific, inputdependent rank function can be defined to transform the target multiset into a sequence. A representative example is an image input with bounding box annotations. Here, we present two inputdependent rank functions in such a case.
First, a spatial rank function assigns an integer rank to each item in a given target multiset such that
where and are the objects corresponding to the items and .
Second, an area rank function decides the rank of each label in a target multiset according to the size of the corresponding object inside the input image:
The area may be determined based on the size of a bounding box or the number of pixels, depending on the level of annotation.