# Deep Learning for Audio Event Detection and Tagging on Low-Resource Datasets
## 2 Task Factorisation
### Audio Event Detection (WHEN)
#### 2.2.2 Multi Instance Learning
On the other hand, we propose a couple simpler assumptions about these characteristics that can achieve a similar effect. One assumption is to consider the mean of the instance predictions of a bag. If a bag is negative, the mean should be zero, while if it is positive it should be greater than zero. The true mean is unknown in weakly labelled data. A naive assumption is to presume that approximately half of the time a specific event will be present in a recording. Even though this is not true all of the time, it takes into consideration the predictions for all instances, and also inserts a bias to the loss that will keep producing gradient for training even after the max term has reached its perfect accuracy. However, this is indeed a naive assumption that will guide the network to predict a balanced amount of positives and negatives that may make it more sensitive to all kinds of audio events, even when they are not the ones in question. Another simple yet accurate assumption is that on both negative and positive recordings the minimum predictions at an instance-level should be zero. It is possible for a positive recording to have no negative frames; however, it is extremely rare in practice. This assumption could be used in synergy with max and mean to enforce the prediction of negative instances even on positive recordings and manage a certain level of the bias that is introduced with considering mean in the computation of the loss. We train a network on a loss function that takes into account all the above-mentioned assumptions and compute the max, mean and min from the predictions of a recording and depending on whether a recording is positive or negative we predict their divergence from different conditions. Our proposed loss function is computed as:  
\[Loss=\frac{1}{3}\big{(}bin\_cr(max_{j}(o_{ij}),Y_{i})+bin\_cr(mean_{j}(o_{ij}),\frac{Y_{i}}{2})+bin\_cr(min_{j}(o_{ij}),0)\big{)}, \tag{5}\]  
where \(bin\_cr(x,y)\) is a function that computes the binary cross-entropy between \(x\) and \(y\), \(o_{ij}\) are all the predicted strong labels of bag \(B_{i}\), where \(j=1...M_{i}\) with \(M_{i}\) being the total number of instances in a bag, and \(Y_{i}\) is the label of the bag. We refer to this as an MIL setting using max, mean and min (MMM). For negative recordings, Equation (5) will compute the binary cross-entropy between the max, mean and min of the predictions of the instances of a bag \(B_{i}\) and zero. This denotes that the predictions for all instances of a negative recording should be zero. On the other hand, for positive recordings, the predictions should span the full dynamic range from zero to one, biased towards a similar amount of positive and negative instances. Our proposed loss function is designed to balance the positive and negative predictions in a bag resulting in a network that has the flexibility of learning from harder-to-predict positive instances even after many epochs. This is due to the fact that there are no obvious local minima to get stuck in as in the max case. Some examples of the difference between the predictions produced by MIL using max and MIL using MMM when our proposed WHEN network is trained for birdsong detection are depicted in Figure 2. It becomes apparent that MIL using MMM can correctly classify harder to predict instances, especially when studying the difference between Figure 2a,c. In Figure 2c, one can notice that the network is able to correctly classify the harder to predict instances between the three main audio events.