text:
YOLO - are the anchor boxes used only in training?
another question in YOLO.
I've red about how YOLO adjusts anchor boxes by offsets to create the final bounding boxes.
What I do not understand, is when YOLO does it.
Is it being done only during the training process, or also during the common use of already trained model?

Object detection models behave the same during both, training and test phase, i.e. they just return thousands and thousands of bounding boxes as predictions, plus a confidence score for each box (important). What change between training and test is what we make out of these bounding boxes.
Trainining:
During training we want to assess how good each bounding box is with respect to our ground truth annotations, so what happen is usually a brutal comparison between each predicted bounding box with each true annotation box. Of course we need to quantify the quality of each predicted box vs true annotation, we can do that using Intersection Over the Union(IOU), i.e. percentage of shared pixels between the total area of the two boxes combined. We don't care during training about the amount of predictions the model return, we just want the model to learn to predict good boxes on overall.
Test:
During test instead we want indeed to have a single box per object, but the model is still returning thousands of them, so we need to find a way to select one ourselves, and this is why the predicted confidence scores are important, otherwise we would have no idea about what boxes are better than others. The most common algorithm used to choose winning boxes depending on their confidence scores is called Non Maximum Suppression.
The picture below shows the algorithm (taken from the linked blog post).

You can see that Non-Max Suppression work iteratively, starting from the box with highest confidence score, and checking the IOU between it and the remaining boxes. In order to work, an initial threshold parameter needs to be set, this threshold is used to determine if one of the remaining boxes should be kept and tested in the next iteration or not. Basically we want to discard boxes that overlap too much. Conceptually, if I have a box with high confidence score in a location, and another box overlapping a lot with it but with a lower confidence score, I want to keep only the first one and discard the second. If instead two boxes are not overlapping, then they might be detecting different objects, and I want to keep both. Notice that in a soft version of Non-Max Suppression the IOU score is used to update the confidence scores of each box as well. After converging, Non-Max Suppression will return the set of best non overlapping boxes.

maybe I missed the point. I understand what you say sir, but it seems to me not exactly an answer to what I have asked. My question is about the ancor boxes. A am sure they are used to train a model on a dataset as they are being apposed to the ground truth boxes (backpropagation process adjustes them untill they fit to the location and size of ground truth boxes).
But I doubt that they are used in a common daily use of already trained yolo model. Am i right?


text:
Claim: Deep Neural Networks "Automatically" Perform Feature Selection and Feature Engineering?
I have often heard that Deep Learning Models (i.e. Deep Neural Networks) are automatically performing feature engineering within the network themselves. This is contrasted with traditional statistical and Machine Learning models where the feature engineering is typically done prior to training the model:

Apparently, the operations that Neural Networks perform during the training phase are equivalent to "searching for meaningful combinations of variables that produce better performance results on the training data". I have heard that this is in some way similar to Principal Component Analysis (PCA) and Kernel Methods, seeing as these methods combine many different existing features into new features that have "more meaningful representation".
For instance, in the "Deep Learning Book" (https://www.deeplearningbook.org/contents/intro.html), I read about this ability of Deep Neural Networks to "automatically perform feature engineering" :
"Deep learning solves this central problem in representation learning by introducing representations that are expressed in terms of other, simpler representations. Deep learning enables the computer to build complex concepts out of simpler concepts."
However, in the end - I still do not understand how Neural Networks during the training phase (i.e. gradient descent, weight update, backpropagation) are "automatically performing (some degree of) feature engineering".
How exactly are Neural Networks doing this "automatically"?
Thanks!
Note: I have heard that NN's are said to be universal function approximators (i.e. universal approximation theorem). Therefore, for a given data set - there should exist a specific neural network architecture (i.e. specific number/value of weights, layers and choice of activation functions) that will result in your target function being approximated sufficiently well - however, the combinatorial search space is massive and recovering that network can be very difficult for large data because of the time required to train the network using gradient descent. So "automatic feature engineering" is something indirect that might or might not happen because of the universal approximation theorem.

Probably the best and most suggestive example of automatic feature extraction comes from Restricted Boltzmann Machines (RBMs). Because of their architecture, composed in its simplest form of one visible layer and one hidden layer of same size, they allow us to visualise the weights learnt during training really easily, i.e. by simply reshaping them in the same size as the input images fed during training.
Below you can see an example of such weight visualisation, learned on the classic MNIST (hand written digits) dataset. An important thing to understand is that dark and bright pixels are associated with respectively small and big weights. Again, I want to stress out that every image is a set of weights that connect each pixel of an input image to a single hidden node (as shown in the second picture).
So each image effectively is showing us what the RBM consider important in an image. When we feed an image to the RBM, the first feature map is applied, and we can see that this feature map recall something like a 9 (in black) and a 2 (in white), so the RBM will respond with high activations to images similar to a 2 and very low activations for images similar to a 9.
How did the RBM decided that these features are important? The answer lies in two main factors:

the training algorithm
the data distribution

In this case the training algorithm is contrastive divergence, an unsupervised energy based algorithm that minimise the energy of the weights when similar training inputs are presented while trying to maximise their energy when different ones are presented. This algorithmic design explain why we see feature maps like the first one. Contrastive divergence is trying to minimise the energy for all inputs images containing 2 while trying also to keep 2 and 9 separated from each other (in terms of nodes activations). Clearly 2 and 9 have similarities like the top curve, so the model need to learn features maps that activate a lot nodes connected to areas belonging to features specific to only one class, like the bottom straight line of 2. Unfortunately, this is almost as far as we can go into the analysis of "why a model is learning something", without falling into models interpretability discussions (for which there are already good threads in this community), and surely we'll never know "how exactly", or if that day will come, then we won't need machine learning anymore.
Last but not least, a well known bias of the MNIST dataset is the centred position of each digit. Nowhere in the data you will find lines on the edges of an image, and indeed the RBM also never learn to pay attention to the edges. So, regardless of the choice of the training algorithm, the training data distribution will also always impact what a model learn (or in this case not learn).

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Graph Neural Networks: Why do papers use very low label rates?
I was recently reading the following paper: "Semi-supervised classification with Graph Convolutional Networks" by Kipf and Welling (here).
Question: When testing on datasets, why are the authors using such a low label rate?
Context: In Table 1 where the authors list the statistics for the datasets they used to benchmark the architecture, the label rates are quite small percentages (5%, 3%, <1%). I don't quite understand why this is the case...
I know this is 'semi-supervised' classification such that we have access to ALL the node features, regardless of whether they are training or testing. However, I don't know why we are using 5% label rate as opposed to, for example, 30% label rate.
Any insight would be appreciated.

a main reason is that it keeps the computational cost down. I’m not aware of any performance degradations by using more labels, the only thing I can think is that if you achieve similar test performance whilst training on fewer labels, this would be better as you’re less likely to be overfitting

@DavidIreland - many thanks for the reply! That makes sense.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Difference between TPU and VPU
There are these two concepts of ASICs for the usage for neural networks.
The one is called Tensor Processing Unit (TPU) and the other one is called a Vision Processing Unit (VPU). How do they differ from each other? I don't want to dig to deep into differences in terms of architecture but more or less application wise. Is it at the end of the day just naming convention, but they can be used for the same stuff?


text:
What techniques exist to increase the learning importance of difficult-to-learn labels over easy ones?
I am training a model to place labels in image data. Some labels are learnt very quickly by the model while others take a long time to perfect. I cannot simply add more labeled data with only the labels I am looking to improve on since most of the image data contains a combination of the easy labels and the more difficult ones.
Are there any smart ways to get the model to focus on the hard labels? I am just looking for some leads. Of course I can just train for longer but that seems inefficient as half the labels are already predicted almost perfectly.

are we talking about low represented classes or balanced classes but some of them are not classified properly for unknown reasons? If it's the latter case it would be helpful to provide more information about the data and some examples.

The label set is balanced. Some labels are harder to place correctly on the image because they are simply more difficult to identify (since some features I am trying to label have more variance in shape/perspective, lighting conditions and motion).

if those are the main issues sounds like you need just some extra prerocessing steps to standardize your images and remove that variance. But again, hard to give suggestions without concrete examples.

Well I am tracking animals frame by frame. Some bodyparts are easy to identify (eg: all the points along spine from head to tail) whereas limbs are harder because they can obscure each other and move quickly. A left front paw and right front paw can look very different depending on where is it seen from whereas the neck or top of the tail is trivial to find.

The easiest approach to give more importance to a group of specific training instances is simply using a weight to increase the error loss computed on those specific instances during training. Libraries like sklearn have implemented off the shelf the sample_weight parameter to perform precisely this. The obvious downside of this approach is that you need to know before hand which training instances are hard to learn for the model, and you need a metric to translate that difficulty level into a loss weight.
More fancy approaches try to boost accuracy for instances hard to tackle by trying to better approximate this "hardness level" and then ranking the training instances from the easiest to the hardest, logic being that this order will facilitate gradient descent convergence. The main two approaches are:

Self-Paced learning, the core idea is to replace the classic loss with an objective function that can learn both, model weights and a parameter (usually indicated with $v$) indicating the difficulty of each training instance.
Hard Examples Mining, similar to active learning, a model is trained on a set of known easy examples, and then used to harvest miss classified data that are used to perform a focused retraining of the same model.

Honestly though, these ideas are pretty old, and the fact that they're not widely used today to me suggests that the benefits are way less than the difficulties they introduce. So an in depth analysis of your data to boost standardization in term of quality (brightness/contrast adjustment, histogram equalization and so on) will probably be less of a rabbit hole and most likely still lead to better performance of your model.

I don't think I can standardize the quality of individual features in the image since I have both the "easy" labels and the "hard" labels in the same image. I can't alter one without the other and at that point I could just use more data augmentation on top of the basic mirroring I currently do, but I don't think this solves the problem of trying to get the model to focus on the hard labels. Will check out your other suggestions, thanks!

you could split the task tough. Use normal rgb for body parts easy to detect and train another model on enhanced images to compensate for dark parts to detect limbs. My point is: machine learning is data driven, if the data is crap, the model will be crap, no debate around it, and no matter what fancy approaches you try to compensate for what the data lack. So personally I live by trying to improve the data first, and leave the rest as final resource. But of curse that's just my philosophy.


text:
How can the input order of pairs into a neural network not matter (i.e. symmetry)?
Let me explain, suppose we are building a neural network that predicts if two items are similar or not. This is a classification task with hard labels (0, 1) of examples of similar and dissimilar items. Suppose we also have access to embeddings for each item.
A naive approach might be to concat the two item embeddings, add a linear layer or two and finally perform a sigmoid (as this is binary classification) for the output probability.
However, that approach would mean that potentially inputing (x, y) to the model could give a different score from inputing (y, x) into it, since concat is not symmetric.
How can we go about overcoming this? What is the common practice in this situation?
So far I have thought about:

Whenever I input (x, y) I can also input (y, x) and always take the average prediction of both of them. But this feels like a hacky way of forcing the network to be symmetric, it doesn't make it learn the same thing despite of the input order.

Replacing concat with some other symmetric tensor operation. But what operation? Addition? Element-wise multiplication? Element-wise max? What's the "default"?

Out of interest, why in the example scenario do you have embeddings where "similar" items have dissimilar embeddings? Are you not in control of the encoder?

I never said that "similar" items have dissimilar embeddings. The embeddings are fixed and extracted from text with pretrained BERT. My problem is in the ordering that I should give each pair of item embeddings. My intuition says that the order shouldn't matter.

If you mean to ask "Why do we need supervision for similarity if we can just calculate the similarity on the embeddings?" then I would say that is a good point that had not occured to me. I guess the fact that the embeddings are fixed is a valid reason.
The final layer can be "correcting actions" or a way to learn a threshold of "how similar is similar enough".

Yes that is why I was asking. One of your solutions here - which sidesteps the symmetry issue - is to train such that the embeddings already solve your problem. This is how face recognition usually works. That could be part of an answer, but whether or not is worth mentioning depends on whether you are asking to solve your original problem (classifying pairs as similar), or whether you want to stay focused on the symmetry issue already presented in the question.

I don't know whether training embeddings for low distance when similar and high distance when different (triplet loss is a standard example) is used much in text systems. Chances are if you are using an embedding, it will be from some pre-trained general language model, which may be very expensive to train or re-train yourself.

It WAS very expensive so I considered it fixed and only ran it once to get the embeddings for all the text in my dataset.

I think what is asked of me is a model that can tell, given two pairs, if they are similar or not based on a labeled dataset provided. As such, I don't think training to find good embeddings (e.g. Siamese networks) and then finding an arbitrary threshold to predict similarity for new data is more sensible than doing classification to begin with. How would I even find that threshold? Another nn? There is a recursion here somewhere...

The problem you're describing is related to (if not a subset of) Shift Invariance. Shift invariance refers to any geometric translation of an input, but concatenation of a pair of tenors in 2 different ways $(x, y) \rightarrow (y, x)$ can be seen as translation with step equal to the shape of the tensors.
How to tackle lack of shift invariance? There is still not unanimous consensus on why deep neural network are not shift invariant, even though some papers pointed out that some convolution operations might be a core issue.

Zhang proposed an alternative variation of pooling tat should enhance anti-aliased feature maps
Chaman & Dokmanic focus instead on analyzing the impact of dawn sampling operations, suggesting a new subsampling operation as well to replace in the conventional down sampling approaches.

Starting from a completely different perspective, other papers analyze the impact of classic euclidean geometry, utilized not only in loss design (l1 and l2 norm for example), but also an underlying assumption of every classic deep learning model (despite non linear activation functions, every hidden layer is still a linear transformation of the form $w*x + b$). So instead of fixing linear operations or enforce good shift invariant feature maps, we change the geometry we're using to ensure that translation and rotations have no impact in the optimization of our objective.

This paper is a good start if you feel brave enough to start experimenting with not euclidean approaches.

On a final note, I think that you first suggestion could be worth a shot if you rethink it this way:

Present the model each time 2 pairs $(x, y)$ & $(y, x)$ and add a custom loss component to enforce the same prediction (could be literally MSE between the two outputs logits). This loss should at least give you a hint if it's possible for the model to become robust to this specific translation operation (if that loss component decrease over training time the answer is yes).

I answered a similar question here. So the goal here is to train a network which can tell whether the inputs $x$ and $y$ are "similar" or not. You can first build a model $f$ which "compresses" the high-dimensional input into a smaller embedding dimension. In the case of Xception this $f$ would be a mapping from a $299 \times 299 \times 3$ RGB image to a $2048$ "feature vector".
Now the classifier model $c(x, y)$ can be built as $c(x, y) = g(f(x) - f(y))$, where $g$ can be a very simple function without any trainable parameters like $g(\overline{d}) = 1 - e^{-\sum_i d_i^2}$ or something more complex. Clearly here $c(x, y) = c(y, x)$ and $c(x, x) = 0$.
With a custom $f$ and $g$ you can train this model end-to-end, or if your embeddings are fixed (or you use a pre-trained network $f$) it is also possible to just train the $g$.

So in your version, I would take the difference between the f(x) and f(y) and then pass them through network g(x) instead of doing g(concat(f(x), f(y))? But does the loss changes? Do I still use binary cross entropy for classification or does my task change?

I thought Siamese Networks that employ ranking losses were used to learn embeddings where similar objects are closer than dissimilar objects not to predict the similarity itself.

Also, the difference is not symmetric either so.. problem not solved.

Yes you still use binary cross entropy since your target is still a 0 / 1 prediction. You can take element-wise absolute value (or square them) to guarantee a symmetric model $c$.


text:
What is a neural network compatibility function?

Typically, a neural network parameterized by weights $\mathbf{W}$ is
a function from an input $x$ to an output $y$. The network has
an associated compatibility function $\Psi(y; x, \mathbf{W}) \rightarrow \mathbb{R}^+$ that
measures how likely an output y is given an input x under
weights $W$.

Source: Gradient-based Inference for Networks with Output Constraints, AAAI 2019 (https://arxiv.org/abs/1707.08608)
What is a compatibility function? What is its utility?
Neural networks are generally deterministic. We are guaranteed to get a specific output for a given input. How do we interpret compatibility function in this context?

What have you understood about it? Have you read the paper that you're citing?


text:
time series analysis: predict number and type of service
I have temporal data regarding the number of customers who requested a specific service in a given period (month and year). Below is a small excerpt from the dataset:

Month-year: month and year when the service has been requested/offered
Service Description: the tipology of the service request by the customer
occurences: how many times the customers in that period requested that service

I have monthly data from 2003 to 2020 and I would like to carry out a predictive analysis to predict the number of events from 2021 to 2023 and also predict the type of services. For the first I know that I have to face the problem using the analysis of the time series, I have doubts about the second part ... how to predict the type of service in addition to the number of requests? Can you give me some suggestions?

You could have one model for each type of service , which would predict the number of events in a given month and year based on history.
You could also jointly model them using a neural network to approximate the distribution or gaussian process.


text:
Are Problems in AI Usually "Ill Posed"?
I was reading the following link (https://en.wikipedia.org/wiki/Well-posed_problem) on "Well Posed Problems". Supposedly, if a problem is "Well Posed", it must meet the following conditions:

a solution exists

the solution is unique

the solution's behavior changes continuously with the initial conditions

I can understand why the first two conditions are desirable for a problem to be "Well Posed", but I am having trouble understanding the last condition.
For instance, if "the solution's behavior changes continuously with the initial conditions" - isn't this a bad thing? Would we not want the "solution's behavior NOT TO CHANGE continuously with the initial conditions"?
If the solution's behavior can change with the initial conditions, would this not result in the problem having the ability to be "chaotic and unpredictable", thus displaying "bad behavior" and as a result - "Ill Posed"?
Thanks!

From a dynamical systems perspective this makes sense because based on where you start, your solution/how the physical system acts should be different.
I would argue that this may be a good thing to have for AI too. I am imagining an RL system (whose continuous versions of control can be formalized with continuous DP principles via pde's) like a robot navigating a room. If the third condition (3) didn't hold, then you would be enacting the same policy regardless of where you start. If it is a stationary setting where a repeat of states could occur (a ground hogs day), then one may argue that they do not want (3). Technically though it could satisfy the third condition if one changes continuously by staying constant with respect to initial conditions.


text:
Was the original perceptron machine really just comparing images to the "average image for each class"?
I've been looking into the history of artificial neural networks, and only recently learned that the original Mark 1 Perceptron was only a single layer network.  It would iteratively modify the weights of connections using weights from the image sensors directly (i.e. pixel weights).
My question is:  Wouldn't this algorithm really just produce connection weights that resemble the "average image" for each class?
I.e. say you used the Mark 1 Perceptron to differentiate between three different classes of image (A, B and C).  Would the connection weights for class A not just produce an "average image" for class A, and likewise the connection weights for class C would just resemble an "average image" for class C?  In this sense, each of the connection groups would resemble the "average image" it's attempting to classify, and the output class is really just the class whose connection weights are most similar to the input image?  I found this intuition a useful way of understanding how the simple perceptron works, but I want to make sure it's a valid interpretation.


text:
Are tabular methods appropriate for this task?
I'm a RL beginner and I have a project in mind: I'm an engineer who works doing CAD projects and there is a time consuming task that I want to automatize. This task it's doing by a person because it requires certain logic.
For example, given a CAD model with several object in it (Circles, rectangles, etc) the objetive is to tag every object following certain rules:

Tags cannot cross between them.
Tags cannot overlap other tags.
If possible, the tags must be aligned.
If possible, the tag must be near the object.
If the tag fits inside the object, it must be placed inside it. If not, the tag must be placed outside the object.

This is how a example model looks:

My idea is the following. I can export the CAD model to a "shp" file and load it in Shapely (a GIS Python library). With this I can create the environment.
Once I have the environment I can start iterating over the states. Every state will be a representation of the environment. In the state zero I won't have any tag, so I can start putting the first tag that will be a rectangle with fixed dimensions. Once the tag is added I can get the reward based on the position, checking if the tag overlap another object, if it's too far from the source object, etc.
The next state will be the environment with the previous tag and so on.
I don't know if this can work. I believe the agent must execute some sort of planning but, correct me if I'm wrong, this is not possible with Q-Learning or another tabular method.
So, the question is...could be possible to do it with a tabular method or I will have a super large table to handle?

It's not the right tool for the problem. The problem of how to represent the objects and how to determine if there is overlap with tags or if tags can fit is nontrivial by itself since you have a bunch of nonconvex objects here. That's actually the hard part, the easy part then is to just iterate through all objects and then put tag for each of them, which is what you wanted to do through RL but it's unnecessary since you can just go through each object.

@Brale I can represent the objects and check if there is overlap and other type of things. My problem is I can't make a standard script to place the tags, because the objects change between projects because the tag placement require certain logic and planning.

Look into book "Planning Algorithms" by LaValle


text:
neat - what is the purpose of looped networks?
So im writing my own implementation of NEAT and i'm wondering how looped
networks (like one shown in the image) can be useful. I'll probably implement
them anyway because i want to fiddle around with as much features and improvements
as i possibly can, but i just cant wrap my head around where they can be
applied. What are the possible tasks that cant be solved (or are less likely to
be solved) without looped networks?
NOTES just in case:
I'm not talking about networks that pass info from the previous timestep output
like those that allow to solve e.g. double pole balancing without velocity info.
(Or are they the same thing? Haven't really figured it out, but either way,
question implies that networks like that are treated as a special case. Hopefully
this remark makes any kind of sense)
Also i know how both looped and feed-forward networks are activated and i have
algorithm in place to identify and separate both of them, im not asking about that.
Also, when i say "activating" the looped network, i mean algorithm like sharpNEAT
has in place: https://github.com/colgreen/sharpneat/tree/master/src/SharpNeatLib/Phenomes/NeuralNets/CyclicNetwork


text:
Comparing Solutions from Saddle Points vs. Local Minimums
Can Saddle Points Provide "Better Solutions" to Machine Learning Models Compared to Local Minimums?
The solution to a Machine Learning model (i.e. the final model parameters) are selected by trying to optimize the Loss Function associated with that Machine Learning model. The "best" solution (i.e. "best" choice of model parameters) are those associated with the "global minimum" of this Loss Function (i.e. the smallest value of the Loss Function) - thus, "relatively better" solutions can be considered as solutions that are located closer to the "Global Minimum". Optimization Algorithms (e.g. Gradient Descent) try to search for the "Global Minimum" of the Loss Function by repeatedly searching in the direction of the derivatives corresponding to this Loss Function.
However, there are different obstacles than can occur during this search process. For instance:

The Optimization Algorithm can get stuck in a "Local Minimum"
The Optimization Algorithm can get stuck in a "Saddle Point"

I have heard "Saddle Points" as being considered "worse" than "Local Minimums" - this is because "Saddle Points" aren't actually a minimum of any sort, whereas "Local Minimums" are at least minimums at the local level. Thus, this would imply that model parameters chosen from a "Saddle Point" should be worse than model parameters chosen from a "Local Minimum". To further illustrate my question, I drew the following graph of a hypothetical Loss Function for some Machine Learning model:

In the above picture, we can see that Loss Function has a smaller loss at the "Saddle Point" compared to the loss at the "Local Minimum". Thus, in this case - (Assuming that we could not reach "P3") if we had to choose a selection of model parameters from "P2" ("Saddle Point") and "P1" ("Local Minimum") - it would clearly make more sense to pick model parameters from "P2".
My Question: In general, do we know if solutions corresponding to "Local Minimums" points on a Loss Function are considered to be "better" corresponding to "Saddle Points" (e.g. perhaps solutions from "Local Minimums" might be more "stable")? Or is this claim incorrect, and solutions corresponding to regions of the Loss Function with lower Loss values are generally "better" - regardless of whether they come from a "Saddle Point" or a "Local Minimum"?
Thanks!

Rather than writing "Comparing Solutions from Saddle Points vs. Local Minimums", put your specific question in the title. Note "Comparing Solutions from Saddle Points vs. Local Minimums" is not a question and it's not specific.

Ok, can you do it then? See https://ai.meta.stackexchange.com/q/1654/2444 in case this request does not make much sense to you.

Your interpretation of the graph is correct, in this simple example weight taken from the saddle point will perform better than the samples taken at the local minima. Said tat, this 1D example is a bit of an outlier compared to what happen in more realistic scenarios.
If we keep in mind the second partial derivative test, used to check if a point of a function is a maximum, minimum or saddle point, then it's easy to see that especially in higher dimensions the probability of a point being a saddle one are higher than being a maximum or a minimum one.
When analyzing a point we first compute the determinant of the Hessian matrix of our loss function (I'm using the 2 variables formulation for convenience):
$H(x, y)=f_{xx}(x, y)f_{yy}(x, y) - (f_{xy}(x,y))^{2}$
if $H(x,y)<0$ then the point is a saddle point. Otherwise if $H(x,y)>0$ it could be a maximum or minimum. Notice that $f_{xx}(x, y)$ tells us the direction of concavity in the x direction, whereas $f_{yy}(x, y)$ tells us the direction of the concavity in the y direction. This makes sense, if the concavities points on different directions for different dimensions we can't have a maximum or a minimum (see picture below, positive direction for y axis, negative for x axis), and indeed the resulting score is negative, indicating a saddle point.
The take home point is that a local minima compared to a saddle point respects the property of sharing the same negative direction across all dimensions of the function. This implies that, as the number of dimensions increases (and with real models we can easily start from thousands of them) the probability of a point being a saddle point increases as well, while the probability of being a local or global minima decreases.
So in a more realistic case, just for a matter of probability, a solution associated with a random local minima has lot of chances to be better than a solution  associated to a random saddle point.


text:
how can a VAE learn to generate a style for Neural Style Transfer?
I have come across this research paper where a Variational Autoencoder is used to map multiple styles from reference images to a linear latent space and then transfer the style to another image like this:

What I don't understand from the paper is how does the Variation module learn the style of the reference images as opposed to the content?
And since VAEs are generative models, is it possible to generalise this to generate styles from the trained variation model by feeding it random noise instead of the encoded reference images?


text:
Can we Consider Regularization as a "Constraint"?
I have the following question on "Regularization vs. Constrained Optimization" :
In the context of statistical modelling, we are often taught about "Regularization" as a method of dealing with the "Bias-Variance Tradeoff" (i.e. stabilizing the inconsistent performance of complicated models). When a L1-Norm or L2-Norm Penalty Term is added to the estimation function (corresponding to the statistical model) being optimized, some of the model parameters will either "shrink" in size towards 0, thus producing a "sparser" model that is more likely to retain its "low bias" but possible reduce its "high variance":

I have often heard of functions containing these L1-Norm and L2-Norm "Penalty Terms" being referred to as "optimization constraints" (i.e. the "feasible region" from which valid choices of model parameters can belong to has now been "altered" due to these "norm penalty constraints"):

My Question: When we estimate some statistical model's parameters and the estimation equation contains some "regularization penalty term," would it be incorrect to refer to this as an example of "constrained optimization"?
Is regularized optimization in Machine Learning and Statistical Modelling fundamentally any different (with the exception of usually being more difficult and solved using approximate stochastic iterative methods) from Constrained Optimization in Linear Programming?

References:

https://en.wikipedia.org/wiki/Regularization_(mathematics)
http://ab-initio.mit.edu/wiki/index.php?title=NLopt_Tutorial

Yes, it can be considered as a type of 'soft' constraint. For example, with these norm regularizations, you bias the learning process towards regions where parameter values are smaller.

Regularization is different than constraints. The problem with an L1 regularization term would be
\begin{align*}
\underset{\theta}{\min} & \quad f(\theta) + c\lVert \theta \rVert_1
\end{align*}
whereas the same problem with an L1 constraint would be
\begin{align*}
\underset{\theta}{\min} & \quad f(\theta)  \\
\text{such that } & \quad \lVert \theta \rVert_1 \leq M \\
& \quad
\end{align*}
where $c$ and $M$ are constants which needs to be specified. These are different problems, with different values of $\theta$ for solutions, and need to be solved differently (in particular, the constrained problem is significantly harder to solve).
Now, these two problems are related, and we would expect them to have similar solutions, provided $c$ and $M$ are chosen appropriately. You might want to also read this answer on stats exchange


text:
Are there any scale invariant activation functions that outputs probability distribution?
Softmax activation function is used to convert any random vector into a probability distribution. So, it is generally used as an activation function in the last layer of deep neural networks that are intended for classification.
But, the softmax() does not satisfy the property of scale invariance i.e., the ratio of inputs and the ratio of outputs does not remain the same.
For example if we give the input [1.4285, 0.3815] to softmax, the function will give [0.7402, 0.2598] as output.We can calculate ratios 1.4285: 0.3815 and 0.7402: 0.2598 and find that they are not the same.
Are there any scale-invariant versions of softmax?

Could you explian why you need a scale-invariant function? Unmodified logits in a neural network can be, and often are negative. They cannot be simply scaled into a discrete probability distribution. However, if you are willing to accept other non-linearities to adjust this, then something may be possible. But it not clear whether what has driven your question, thus whether such a thing would be a good idea.

@NeilSlater The text book I am reading mentioned about this property explicitly. So, I think there might be some significance and hence asked it.

Can you give a reference to where it is mentiioned and in which content? As far as I know there is no function that could turn arbitrary logits into a discrete probability distribution without impacting their ratios. Non-linearity is required to deal with negative inputs.

Can't you just divide the numbers by their sum? If your numbers could be negative, you can clamp them to a probability of zero by passing them through a RELU activation.

I am asking for reputed ones in application.

I don't think there is any other function which preserves the ratios of numbers [0, a, b] and scales them to sum to 1. You explicitly ask if there is such function, and I answered that yes there is and provided an example.


text:
how to detect ouliers in audio dataset?
I'm currently working on an audio classification project using CNNs. The problem is I'm having trouble training my CNN. I doubt if there are outliers in my dataset but I don't know how to detect outliers in an audio dataset. I've searched google and found nothing helpful.

Tell us what you have found so far and why it's not helpful. Explain also exactly what you're looking for.

@nbro almost everything I found on google was about finding outliers in tabular data, therefore, they're not applicable to audio or any kind of time series data.

A first think what comes to mind is to train an autoencoder, then identify abnormal data by these heuristics:

Is the reconstruction error large, for example remove the top 5% of the data?
Are the codes (outputs of the encoder) within a densely populated region, or are they outliers? You could calculate the distance to Nth nearest neighbor.

Interesting idea, do you know any articles that has done that on audio or any kind of time series data?

I haven't read any of these papers, but I found plenty from Google Scolar by searching for "autoencoder outlier detection".


text:
What can be an example other than batch normalization that uses statistics of batches?
Consider the following paragraph, taken from OPTIMIZING BATCHES of the textbook named Deep Learning with PyTorch by Eli Stevens et al., regarding the reasons for processing data into batches

The reason we want to do this batching is multifaceted. One big
motivation is to make sure the computation we’re asking for is big
enough to saturate the computing resources we’re using to perform the
computation. GPUs in particular are highly parallelized, so a single
input on a small model will leave most of the computing units idle. By
providing batches of inputs, the calculation can be spread across the
otherwise-idle units, which means the batched results come back just
as quickly as a single result would. Another benefit is that some
advanced models use statistical information from the entire batch, and
those statistics get better with larger batch sizes.

The bolded portion says a statistical reason for batch processing. I know only batch normalization that satisfies the portion as mean and standard deviation are calculated over the batch of inputs.
Is there any such example that needs statistics of batches that are apt to the description?

Here's some examples:

Group Normalization
Layer Normalization
Switchable Normalization
Attentive Normalization
Spectrl Normalization

Notice how in general different normalization techniques are implemented using as a backbone the same idea of batch normalization, i.e. computing mean and standard deviation, but along a different dimension rather than the batch one, or on a subset of points (image below taken from the switchable normalization paper)

The alternative, as performed by the attentive and spectral normalization authors, is to rethink the normalization as something different from the classic linear transformation $\mu x + \sigma$, or to add extra parameters to learn, to make the normalization more non linear (image taken from the attentive normalization paper).


text:
How to calculate adjusted and normalized fitness when a higher raw fitness is better
I am reading Genetic Programming: On the Programming of Computers by Means of Natural Selection by John R. Koza.

For calculating the "standardized fitness" of an individual, where a lower raw fitness score is better:
$s_i = r_i$
where $s_i$ is the standardized fitness, and $r_i$ is the raw fitness of the individual. Lower standardized fitness scores correspond to fitter individuals.
In problems where an individual with a higher raw fitness score is better, Koza suggests this:
$s_i = r_{max} - r_{i}$

The adjusted fitness of each individual is $0 <= a <= 1$, and it is calculated like this:
$a_i = \frac{1}{1 + s_i}$
Higher adjusted fitness scores correspond to fitter individuals.

The normalized fitness is calculated like this:
$n_i = \frac{a_i}{\sum\limits_{k=1}^{M}{a_k}}$
where $M$ is the number of individuals in the population.
The sum of the normalized fitness of all individuals equals to $1$.

My issue is this: in problems where individuals with a higher raw fitness score are fitter than those with lower raw fitness scores, and $r_{max}$ is not known, how do I calculate the adjusted fitness and normalized fitness?
This is my approach:

Ignore the standardized fitness, and calculate the adjusted fitness scores directly using raw fitness scores.
$a_i = 1 - \frac{1}{1 + r_i}$
$n_i = \frac{a_i}{\sum\limits_{k=1}^{M}{a_k}}$ (same as the textbook).

This seems to works well. However, to my surprise, the textbook is suggesting a different method (section 6.3.2):

If no upper bound $r_{max}$ is known and a bigger value of raw fitness is better, the adjusted fitness and the normalized fitness (both described below) can be computed directly from the raw fitness. If a smaller value of raw fitness is better and no lower bound is known, the sign can be reversed and the adjusted fitness and the normalized fitness can be computed directly from the raw fitness.

This suggestion is most puzzling:

When a bigger value of raw fitness is better, the book is suggesting to use $a_i = \frac{1}{1 + r_i}$, but higher $r$ values will produce lower $a$ values, which is wrong because higher $a$ is supposed to correspond to fitter individuals!
When a smaller value of raw fitness is better, the book suggesting to "reverse the sign". This would make all $a$ values negative. It would also make $n$ wrong because the weakest individuals will end up having the highest normalized fitness values!

So, please help me understand the quote above. How do I calculate the adjusted fitness and normalized fitness when higher raw fitness scores correspond to fitter individuals?


text:
Detecting cheats visually using AI
I really like to play my favorite 3D shooter game online. Unfortunately, it is really old and cheat protection isn't really common there, but cheaters are! It is very frustrating, because it really kills all the fun playing against cheaters.
Currently we rely to an admin that is spectating a person accused as cheater and decides if he gets banned from the server or not. But admins are not available 24/7.
The common cheats are:

Wallhacks: seeing other players through walls
Aimbots: aiming the enemy and shooting automatically when just one pixel of the other player enter the cheaters visible field

I wonder if it is possible to take randomly short video footage (1 min) for each player (spectating him) and score if it is very likely that he plays with a cheat active or not.
I guess for wallhack, it might not be really possible because the player does not behave different as the other players, he is just seeing more (and might look against a wall where a non cheating player might not do so). However, i think is very hard to tell even for a human if a wallhack is enabled or not. I think the error rate is really high here.
But for aimbots i think, it can be possible because for a human it is very obvious:
The cheater moves/looks into one direction and if an enemy appears in back of the cheater he turns immediately (in ~1-2 frame) around and shoots (and mostly hit). A straight player would never see whats going on behind him but might luckily turn around and hit somebody, so one of those hits might not be a 100% guarantee accusing someone being a cheater, but several of those "lucky shots" will definitely.
I would say, for a human it usually takes one to three of those impossible movements to conclude that it is 99% sure that this person is cheating.
Since i only have basic experience with AI (detecting things on images), i don't know what can be suitable from AI "tooling"  to detect something like this, because the content of the video frames itself is not really relevant, but the "change" between the images is crucial i guess ...
However, is this possible to detect cheaters "visually" using AI ?
I googled a bit around and read something about "next frame prediction" using convolutional LSTM. Is it something like "when a frame appears next that was not predicted it might be cheat" ?
Since this seems to be a very complex area i just want to find out the right direction i should look for. Any keywords for me to google here?
I am not really deep into AI but I could also imagine that calculating some kind of a "value" of each video frame can be used here. If the value between the frames does alter too much, it is likely that the person moves "unnatural"

It seems that you're looking for a reference, so you can use the tag [tag:reference-request] and remove one of the existing tags that is less relevant.


text:
How does using complex weights in a neural network affect performance?
If you switch a neural network from real weights to complex weights, you're roughly doubling the size of the network, and increasing the computational load by a factor of 2 to 4. My question is, in general, roughly how does the benefit of using complex weights stack up to those extra costs? E.g. Will a complex neural network with half the weights achieve worse/comparable/better performance than a regular network with real weights?
In audio signal processing, complex numbers make the theory much more elegant, which is why I imagine using complex numbers might be disproportionately beneficial. Though I can also imagine the complexity they introduce might overly hinder things as well.
As far as I know, no one uses complex weights in the NNs (which must be for a reason), but I'd like a more definitive answer.

related: https://ai.stackexchange.com/questions/7247/why-do-we-need-floats-for-using-neural-networks. Also see this paper: https://arxiv.org/abs/1705.09792 And it looks like someone has asked the same question already in dataStackExchange: https://datascience.stackexchange.com/questions/28676/are-there-neural-networks-packages-that-use-complex-numbers

Note that using complex numbers doubles the number of network parameters. In general, we can say that a network with $n$ complex nodes will have a training cost equivalent to a network with $2n$ real nodes.
About audio, it is true that a lot of analytics is done in Fourier/Laplace spaces, where complex numbers are mandatory. However, the incoming signal is real, also filters can be keep on this field. It is not usual, by example, the need of a DFT followed by a complex number NN.
Finally, note one of the main advantages of a NN is their non-linear structure and capabilities. Usual transforms and related tools are restricted to linear. In this point, the NNs are a step after.


text:
References for Nvidia's DLSS
Nvidia's deep learning super-sampling is presented as an application of deep learning techniques to video-rendering in videogames.
Question: I'm asking for a technical reference that explains what is the deep learning architecture that is behind the inner works of the Nvidia's DLSS.
Thanks in advance!


text:
A2C: Why do episode rewards reset?
I am training a model using A2C with stable baselines 2. When I increased the timesteps I noticed that episode rewards seem to reset (see attached plot). I don´t understand where these sudden decays or resets could come from and I am looking for practical experience or pointers to theory what these resets could imply.

could you please add some more information, e.g. what environment are you using, what is the reward space for that env, what exactly is the plot showing?

i've seen this in learning using deep Q network. some tips may help you came over this problem :

use some remembering mechanisms like replay buffer. some times agent forget what it has been learnt. reply buffer remembers the agent what he saw at several episodes ago.
something else that worked for me was changing the optimizer. As DQN article says , using RMSprop is very useful for learning neural network based agents.

if these tips dont help you, please give more information about your agent.

thank you. Indeed trying DQN instead of A2C seems to help. If I use a large replay buffer with DQN I don't get the resets, while with a smaller replay buffer I still get resets.
Could this effect also be related to the very large variance I seem to get in episode rewards? (the individual points in the plot have a wide distribution along they y axis)

this question needs more investigate on the network. But maybe it's right because input-output normalization of a network may affect the network. Besides changing the optimizer may help you too. I suggest test RMSprop too. My intuition says me that RMSprop have too flexibility at the begging and then becomes more stable at the end of learning. this helps RL agent to not forget the first experiences.

A2C is on-policy,  so cannot use a long term replay table. It is common practice to run multiple environments at once instead, and wait until there's enough variety to calculate policy and value updates without too much correlation

I ran into this and learned that not only is observation normalization is as important as reward normalization.
The y-axis is showing this env reward is much higher than 1.0
Try rescaling your env reward such that it always falls within the range -1 to 1.
The reason why reward normalization is required is it affects the policy loss scaling. If you look at your policy loss you will also notice it much higher than 1.0. A policy loss that high makes training the neural network unstable


text:
Focal Loss vs Weighted Cross Entropy Loss
Weighted Focal Loss is defined like so
$FL(p_t) = -\alpha_t log(p_t) (1-p_t)^\gamma $
Whereas weighted Cross Entropy Loss is defined like so
$CE(p_t) = -\alpha_t log(p_t)$
Some blog posts try to explain the core difference, but I still fail to understand why select one over the other?
Compiling some of those blogs, boils down to

Another way, apart from Focal Loss, to deal with class imbalance is to
introduce weights. Give high weights to the rare class and small
weights to the dominating or common class. These weights are referred
to as $\alpha$

Adding these weights does help with class imbalance however, the focal
loss paper reports:

The large class imbalance encountered during the training of dense
detectors overwhelms the cross-entropy loss.
Easily classified negatives comprise the majority of the loss and
dominate the gradient. While balances the importance of
positive/negative examples, it does not differentiate between
easy/hard examples
Even when we add α, while it does add different weights to different
classes, thereby balancing the importance of positive/negative
examples - just doing this in most cases is not enough. What we also
want to do is to reduce the loss of easily-classified examples because
otherwise these easily-classified examples would dominate our
training.

My question
I fail to see why the added multiplicative factor of focal loss handles "how easily samples are classified" moreso than what is already present in the very essence of CrossEntropyLoss.
It seems like with FocalLoss, the (CrossEntropy)loss is simply skewed downwards at the "certain" part, such that loss there becomes insignificant - but that is also the case for CrossEntropy. I simply fail to see the fundamental difference that FocalLoss can solve and CrossEntropyLoss can't.
Their qualitative shape is quite similar, so I don't see why they what problem one can solve that the other can't.


text:
How to compare RL algorithms with different NN sizes?
I wanted to run some tests with some RL algorithms in a continuous control task, namely PPO-clip and SAC.
When comparing their NN structures described in their papers, SAC used 2 layers with 256 neurons, while PPO used 2 layers with 64 neurons each.
Can one compare these algorithms with these different NN sizes, "just like that"? I imagine a larger NN can approximate more complex functions and must be harder to train until convergence, compared to a smaller NN.
And in this case, the width of the NN differs a lot. It seems to me that the NN size is rather ignored when comparing, or am I missing something?


text:
Neural network for an output in the form of a probability distribution
I am not an expert in machine learning. Recently, I want to construct a data-driven model based the neural network. The problem is that I want from my algorithm to learn an output in the form of a probability distribution (maybe to learn the parameters of a predefined probability distribution). This is because the phenomenon I am trying to model is highly uncertain.
In my case, I am dealing with a supervised learning. Hence, the output which is supposedly in form of a probability distribution should be compared with data points to assess the performance. Could you please suggest to me a reference dealing with this issue.
Thank you so much for your valuable help.

Can you be more specific about the distribution that you want to learn? Do you want to learn any distribution? Do you know that regular neural networks for classification produce a probability vector? I don't think that's what you want though.

Thanks for your response. I know that stochasticity is an intrinsic property of my system so I need to model it explicitly (regression rather than classification). I want my system to learn for example the parameters of a normal distribution. Regular neural networks  produce a probability vector but I think perhaps this is not a property of the 'law' govening the data exactly.


text:
Question about true positive and false positive detections in object detection
I am computing true positives, false positives, and false negatives in order to calculate my model's precision and recall. I am using YOLOv5.
According to this source and this one, an IoU overlap between the predicted and ground truth bounding box greater than 50% is a true positive detection (we are assuming we set the IoU threshold at 0.5), and an overlap less than 50% is considered to be a false positive.
Let's say you have multiple objects in your image that you are detecting. You label one object as "class A", but the model predicts it as "class B." Am I correct that this is also a false positive? As I understand it, there are two ways of getting a false positive: Achieving an IoU overlap of less than 50% of the correctly-predicted class, and identifying any overlap of an incorrect class?

Rather than saying "Question about", just put your specific question in the title. thanks.

AFAIK, talking about false/true positive/negatives makes sense in the context of binary classification. I guess you're considering the multi-class classification problem. If A is your "positive" class, then if the model predicts B, then this is a false negative. If B was the "positive" class and the model predicted B and the actual class of the object was A (i.e. negative), then it would be a false positive. Is this your question?

@nbro More along the lines of a two-class object detector being trained to identify two objects. If I drew a bounding box and labeled a "car" during training, and the algorithm identifies a "truck." Would that be a false positive prediction? It is saying that something is there in the bounding box, but the algorithm is just incorrect in its prediction.


text:
Alternatives to using RL to explore an environment
I am looking at some ideas on exploring an environment using Curiosity Driven Exploration and am being a little skeptical about it. The objective here is to just explore without the need to obtain optimal actions for each state. For this purpose, wouldn't it be better to just use some sampling strategy rather than RL?
For instance, given a large grid world, I'd like to efficiently find the locations of fire pits and the exit door. One way to go about it is Curiosity Driven RL, but that would be overkill since I am not concerned with learning the optimal actions for each state.

It is not clear what kind of answer you are looking for - e.g. whether you are concerned about your specific example of exploring a physical space? What information do you as the developer know about the environment and are willing to use to improve efficiency by coding it into the explorer? A typical RL agent won't "know" that going north then south ends up in the same place, and has to learn it. So if you are willing to code that knowledge into your bot it will already be more efficient at exploring a grid space - at the expense of not being able to learn about different kinds of space.

I am looking to explore an arbitrary environment. For now, let's assume its the grid world.
As a developer, I won't specify anything that'll help the agent/search algorithm.
One way RL agents are trained to realize that going north and subsequently south leads to the same place, is by computing a similarity metric. But that is not specifically a RL thing and can be used in other applications.
Thank you for your comment. I realize my question sounds a little open-ended. Please let me know if you have more questions.


text:
Does the number of biases in a Convolutional layer scale with the number of images?
I am convolving 32 grey scale images of size 28 x28 with 16 filters of size 5x5.
Which of the following is the correct way to add biases to the convolution operation output?

add 1 scalar value bias for each of the 16 filters. (Each of the 32 images share the same weights and 16 biases)

For each of the 32 images, add 1 scalar value bias for each of the 16 filters. Each image has its own weights and 16 biases?

something else- Please explain


text:
How to model graph node as priority list over a visual scene in neuro-symbolic AI?
Suppose if we have a visual scene graph and we model each component in the scene as a node of a graph and edges which are relationship between the visual scene components. Some of the nodes are like agent who can move(say human as node can move but not tree in scene graph). However, their movement or action, like who will move first is based on some rules. How to approach the problem of node priority list generation in this case. Like node A will move first, followed by node B and C. Usually graph are modelled as classification problem or link prediction problem. Not able to find a way in which such kind of priority list generation is tackled over graphs (or knowledge graph).
Or suggest any other approach to tackle it without graph network or knowledge graph.


text:
Image-in image-out neural network architectures
With an RGB image of a paper sheet with text, I want to obtain an output image which is cropped and deskewed. Example of input:

I have tried non-AI tools (such as openCV.findContours) to find the 4 corners of the sheet, but it's not very robust in some lighting conditions, or if there are other elements on the photo.
So I see two options:

a NN with input=image, output=image, that does everything (including the deskewing, and even also the brightness adjustment). I'll just train it with thousands of images.

a NN with input=image, output=coordinates_of_4_corners. Then I'll do the cropping + deskewing with a homographic transform, and brightness adjustment with standard non-AI tools

Which approach would you use?
More generally what kind of architecture of neural network would you use in the general case input=image, output=image?
Is approach #2, for which input=image, output=coordinates possible? Or is there another segmentation method you would use here?

have you tried preprocessing the image before applying findcontours? Like contrast boosting, conversion to hsv space, masking with edge detection. A neural net for such task sounds a real overkill to me, and complicate cause of the annotations that it would require.

I agree that a neural net seems like overkill. That being said, this paper seems interesting: "Convolutional Neural Network Architecture for Geometric Matching" Ignacio Rocco, Relja Arandjelovic, Josef Sivic https://openaccess.thecvf.com/content_cvpr_2017/html/Rocco_Convolutional_Neural_Network_CVPR_2017_paper.html

I think the second approach will be the best because it only requires that your training set is annotated with four labels for each of the four corners of the paper sheet.
This is sort of the idea of a Region Proposal Network which is used in Faster R-CNN (section 3.1).
Here is a reference implementation of a Region Proposal Network in PyTorch from the torchvision library. Notice how the network outputs boxes (in the forward() method) which is a tuple (x1, y1, x2, y2). From these four coordinates, you could crop the image to the desired paper sheet region.

You could try U-Net for approach 1.
This is called the image-to-image translation problem in machine learning. You could see more architectures in this paper:
https://arxiv.org/pdf/2101.08629.pdf

A U-net wouldn't help a whole lot if it's being spatially transformed, since the skip connections wouldn't line up correctly between the input and output. That said, I guess a U-net is probably better than an autoencoder-like model without any skip connections, so idk.

@TheGuywithTheHat What kind of neural network would you use as a general tool for the general problem of image=in image=out, and you want the NN the learn transformations of images on thousands of examples? I would be interested in an answer about this, if you have one! Thanks

@logijaz Accurate spatial transformations are something that current neural net architectures are just fundamentally unsuited to solve. U-nets connect pixels that are in the same location in the input and output, but with spatial transformations those pixels don't correspond to one another, so it's pointless. Other architectures can try to transform the image, but will lose a significant amount of detail (e.g. any text will become gibberish or disappear entirely). If you really want to involve a neural net, use it to find the corners, and then use traditional methods to transform the image.


text:
Distinguishing text with opposite meanings in SVM (False Information Detection)
I am currently working on a Binary Text Classification Model (False Information Detection) using Support Vector Machine and used TF-IDF as text vectorizer in Python. I have already tried training the model but upon testing, I have encountered a problem:
For example I have the model predicted an entry saying "COVID-19 is happening today" as "True", but after changing the text into "COVID-19 is not happening today", it is still predicted as "True", in which should be predicted as "False".
Where does the problem lie in this situation?
How can we make the algorithm classify text with opposite meanings like ones mentioned above?
Note:

The text that exists in the dataset I used in modelling is “COVID-19 is happening today.”

I used also predict_proba to know the probability of the text being 0(False), or 1(True). It shows that the two entries I made have the same output in predict_proba which with this I can say that it reads the two entries as the same (maybe as "COVID-19 is happening today").

describe in details the preprocessing you apply and how you generate the TF-IDF features from the text. I know it sounds stupid but if you're using automatic preprocessing tools they might exclude stop words for example, among which "is" and "not". That would turn those two sentences into the same one.

Stop words may be a simple issue to fix, but will only get so far. It would be worth knowing how complex the statements are that you are classifying.

In terms of data preprocessing, I just removed symbols, performed tokenization, stop word removal, and stemming. In terms of what you have said, I have also tried excluding negation words such as 'no', 'not', 'cant', 'dont', etc. on stop word removal but the problem is still present. As with the TF-IDF, I used sklearn's TfidfVectorizer(use_idf=True) to vectorize the text.  @EdoardoGuerriero

Such statements present from my dataset are "The COVID19 vaccine is dangerous because 23 people died in Norway within hours of receiving it."(False information) and "The Pfizer vaccine can be safely administered to children from 5 years of age. Both Moderna and Pfizer vaccines are licensed for use in children from 12 years of age.
" (True). Would it help @NeilSlater if I posted samples from the dataset I am using?

@alexand88r: I think if you used [edit] to add just those two examples it would help get a sense of the problem you are trying to solve. Also the size of your training dataset, because you are going to get suggestions for using more sophisticated sequence-based classifiers, but your options may be limited if you only have a few thousand or less examples.

Going step by step:
Preprocessing
Preprocessing is a big deal in NLP, out there you'll find many tutorials describing the classic steps but few explanations about why and when you should actually perform them. Let's go trough the steps you're performing:

remove symbols: usually symbols don't convey much semantic meaning, and in many cases we don't care about punctuation. Moreover, when using pretrained features like embeddings usually the dictionary don't contain vectors for such characters, hence another reason why we can remove them without loosing any information. BUT, if you're extracting your own features and if you're dealing with short sentences, these symbols might become an important source of information for a model. For example in tweets # and @ are pretty important symbols, useful to distinguish rubbish (tweets with no text but only hashtags and mentions) from good stuff. For all these reasons you might want to consider to skip this step.
tokenization: in its most common form tokenization simply means splitting text at words level. Of course this is useful most of the time, but something worth mentioning is that you don't have to limit yourself to generate features only from single words. And you don't have to limit yourself to just text. For example you might generate also numerical features to concatenate along with the encoded text. An example would be to count for each token how many times it appears in the sentence. The logic being that will be clear in the next steps.
stop words removal: this is what is causing your current issue. After word stop removal many short sentences becomes literally the same. Because stop words are extremely frequent words like "is" "are" "not" "the". Why and when using this step is basically equivalent to symbols removal. Again consider skipping this step.
stemming: reducing words to their common root serve the purpose to reduce the total dictionary size. Most of the times you don't care to have a feature for a word and its plural for example, combining both helps making more robust features. So this is an ok step also for your case.
extra: many times along with preprocessing you perform also feature extraction, meaning not the TF-IDF, which is only the last step that turns words in numbers, but rather extracting n-grams, applying simple sentiment analysis to have a positiveness score per word, and much more. Sentiment analysis in particular might suit your case, since factual sentences are most of the time neutral, while false statements most of the time convey opinions, usually expressed with more non neutral word on the positive or negative extreme of the sentiment spectrum. Long story short, be creative and help your model, artificial intelligence is stupid and it works only if you guide it with good features.

Training
Be sure to not use a linear SVM, otherwise you can be sure it will never perform well in these kind of tasks. What you're trying to learn here are really subtle hints that most likely requires lot of non linear features.
Consider also trying simple deep learning models like a Multichannel CNN for text classification. They are usually much better than SVMs and faster to train. Admittedly you should have a large enough dataset, but I myself trained tweet classification models with small datasets of 1k instances achieving good performances. In this regard leveraging pretrained features like GloVe embeddings will boost a lot the final performance, since those vectors were trained on billions on documents (hence rather than training you're fine tuning a classifier on top of a pretrained language model).


text:
Can the environment change even without the intervention of the agent in Reinforcement Learning?
I'm modeling a problem using Reinforcement Learning (RL). Formally, I have two agents: one of them is the one that I have to program and model, the other one is unpredictable (random). With unpredictable, I mean that I can't even define a set of possible actions for it.
Given that, I thought of modeling the scenario as a single-agent scenario in which the environment changes even without the intervention of my agent. Can I do it?
Reformulating: in RL, should the environment be modified (and then change) only by the agent in a single-agent scenario? Is it possible that even if the agent makes no action the environment changes or should I add some entity (the random agent) to my model?
I tried to find the answer in the book "Reinforcement Learning: An Introduction", 2nd edition, by Sutton and Barto, but I found nothing answering the question in the introductory chapters (1 and 3). With "I found nothing", I mean that the authors neither say that I can do it, nor that I can't.

For the second agent, have you been set any task such as predicting its expected return? How are time steps arranged - do both agents act at once, or take turns, or is it more complicated? If you cannot define the action set of the second agent, can you at least still measure the changes it makes to the environment during training?

@NeilSlater following the order in which you asked:

no task set for the second agent
random time steps (I could see one action of one agent, the n actions of the other, m of the first and so on)
I cannot see all the changes made by the second agent

Thanks for the updaate. When you say "cannot see the changes", does that mean the state includes hidden information (related to what the other agent did) that is important and can affect the success of the first agent? E.g. is it like a poker game where you don't know how many draws the other player has made? Or is everything you need to know for success observable in the state description? E.g. is it like Blackjack where you know your and the dealer's draws, but don't know what any other players have done (so you can generally ignore whatever cards they have drawn)?

Thank you for your interest. The model is about a defender of a network and an attacker of the network, so the attacker may be inside the network and it could have modified something, but the defender may not be aware of it. In other words, the other agent (attacker) could have acted or not - if it made an action, I can't be 100% sure to see that it acted and what it did.

So, to clarify, the observer can see a state that might include network stats, machine stats etc, but has no idea whether any of those stats have been influenced by the attacker, who is in essence invisible? This is more like Poker, unfortunately. Is the first agent supposed to actively defend against adversarial attacks (that it cannot see), or just raise the alarm or simply shut services down?

The agent is supposed to actively defend. One of the goals of the defender is: given the state (network stats, machine stats, etc), which action should I take? Implicitly, it has to understand if this state is influenced by the attacker. Therefore, some actions of the attackers will be visible and some others not, because some actions are noisier than others.


text:
How "Patch Merging" works in SWIN-Transformers?
In the SOTA paper: SWIN-Transformers, the authors have tried their best to explain everything clearly. I have got an idea of how it works except the Patch Merging part. I found some blogs and other things explaining this but still I am not able to comprehend how the shape changes and how come the SHAPE of windows are changed at the time when the only thing thy are doing is Concatenating the neighbouring 2x2 patches. Could someone please explain it in Laymen terms or maybe a video link or something intuitive explanation.

This awesome blog explains every detail clearly
Implementation in Pytorch from scratch with explanation
Keras / Tensorflow Implementation

Below are some intuitive images which I am trying to grasp in bits and pieces

What happens during the patch merging? Concatenationating is only one part of the whole operations. Below, I quote the code from the original implementation and explain step by step what happens.
x = x.view(B, H, W, C)

Firstly, x, the input image, needs to be reshaped to regain the height H and width W.
x0 = x[:, 0::2, 0::2, :]  # B H/2 W/2 C
x1 = x[:, 1::2, 0::2, :]  # B H/2 W/2 C
x2 = x[:, 0::2, 1::2, :]  # B H/2 W/2 C
x3 = x[:, 1::2, 1::2, :]  # B H/2 W/2 C

Then, the input is vectorised. Since Swin merges 4 tokens into 1 patch, one token out of a square of 4 is selected. How does the selection process work? Each vector is specialised in one corner of the square. x0 always consists of the top left corner, x1 of the bottom left corner and so on. So during this prep step, the input is divided into 4 quarters.
x = torch.cat([x0, x1, x2, x3], -1)  # B H/2 W/2 4*C

The next step is the one you already found. The 4 vectors are concatenated. Since each vector is a quarter of the input, they are half the height (H/2) and half the width (W/2) of the input. 4 quarters exists so the channel size quadruples 4*C.
By the end of this step, the desired downsampled shape in the height and width dimension are created BUT there are two many channels. Swin doubles it channels during each patch merging operation, not quadruples it. That means Swin keeps 2 tokens to represent a square of 4 tokens.
How do we get from 4 channels to 2? Via reduction through a linear layer.
x = self.reduction(x)

This operation reduces the channel size from 4 to 2.
How is the reduction defined?
self.reduction = nn.Linear(4 * dim, 2 * dim, bias=False)

As a linear projection from dim 4 to 2.

But why doesn't it use a normal convolution to reduce each dimension by half and double the channels?


text:
How do we reduce the output dimensions of BERT?
The output dimensions of BERT are 768-dimensional, is it possible to reduce them to a lower, custom number? For example, if there is another BERT-based transformer model which has a lower count of ouput dimensions, if it's possible to fine tune BERT on MLM to output lower dimension encodings etc.
And if not, are there any possible workarounds for this issue?

SBERT.net gives an example that does exactly (or very close to) what you requested. The approach is based on PCA that projects high dimensional vectors (768 dim in this case) to lower dimensions with some performance drop. It even mentioned that it's possible to reduce the original vector to dimension as low as 32.
For more details, please refer to Model Distillation


text:
Next Sentence Prediction for 5 sentences using BERT
I am given a dataset in which each instance consisting of 5 sentences. The goal is to predict the sequence of numbers which represent the order of these sentences.

For example, given a story:
He went to the store. He found a lamp he liked. He bought the lamp.
Jan decided to get a new lamp. Jan's lamp broke.
your system needs to provide an answer in the following form:
2   3   4   1   0
where the numbers correspond to the zero-based index of each sentence
in the correctly ordered story. So "2" for "He went to the store."
means that this sentence should come 3rd in the correctly ordered
target story. In This particular example, this order of indices
corresponds to the following target story:
Jan's lamp broke. Jan decided to get a new lamp. He went to the store.
He found a lamp he liked. He bought the lamp.

My initial idea is to extended the NSP algorithm used to train BERT, to 5 sentences somehow. I can't find an efficient way to go about doing so. All suggestions would be appreciated.
Thank you!

Is this a homework problem? If yes, you should tag your post with [tag:homework].

No, its for a personal project. Figured it out though: turns out its just using a custom head on the BERT model

Feel free to write a formal answer below to your own question ;)


text:
What is the difference between multi-label and multi-task classification?
I am working on a data-set that has multiple labels associated with it (not necessarily independent of each other). During my development, I am confused if I should consider it as a multi-class multilabel data or a multi-class MTL kind of an approach. Is there any fundamental difference between the two?

Hello. "MTL" stands for? Multi-task learning?

Is there any fundamental difference between the two?

The difference is in the names:

Multi task means that we are learning more than a single task, i.e. the labels we have will be used to compute different losses
Multi label means that for a single task, more than one label is allowed as correct prediction. but in practice, the different labels will be used to compute a single loss.

You can also visualize the difference: a network trained on multi tasks will have more output layers, one per task,whereas a network trained on multi label classification require only one output layer. Note that in a multi task learning setting one of the tasks could very well be multi label classification.

I am confused if I should consider it as a multi-class multilabel data or a multi-class MTL kind of an approach

That depends on what you're trying to do, and we can't even give suggestions without knowing the data.

Thanks Edoardo for the explanation. To be specific, I have 3 sec speech audio inputs and labels which state if the particular audio input has sound repetition,  prolongation and other types of speech disfluencies. And each disfluency is assigned a number between 0-3. A given sample can be categorized as sound repetition =2 and prolongation=1. So I think with an objective to classify the audio inputs into different classes of disfluency I can either choose a single task learning or multi task, I think.


text:
Is there any reason for giving an index to a token based on its frequency in the text?
In pre-processing of text, we need to assign a number for each token in a text. Then only we can pass it to a model. In pre-processing of text, we need to assign a number for each token in a text. The paragraph  from this section named Text Preprocessing recommended indexing according to the frequency of the token

The string type of the token is inconvenient to be used by models,
which take numerical inputs. Now let us build a dictionary, often
called vocabulary as well, to map string tokens into numerical indices
starting from 0. To do so, we first count the unique tokens in all the
documents from the training set, namely a corpus, and then assign a
numerical index to each unique token according to its frequency.
Rarely appeared tokens are often removed to reduce the complexity. Any
token that does not exist in the corpus or has been removed is mapped
into a special unknown token “”. We optionally add a list of
reserved tokens, such as “” for padding, “” to present the
beginning for a sequence, and “” for the end of a sequence.

I want to know whether it is necessary to index in accordance with the frequency of token or any unique index serves the purpose?

The main reason is given in the next sentence, i.e. after crating a corpus we want to know which words are the most frequent and which one are the most rare.
All together, rare and frequent words are usually referred to as stop words, and they use to preprocess the data, specifically they are usually removed (with some exceptions).
Another reason to keep trace of the frequency of words is that to convert text to numbers all approaches start by computing the probability of a word occuring in the corpus, hence counting unique values and their frequency in one shot will save computational time in later steps.

In NLP, word types (not tokens) are often represented by numbers, as they are easier to process: They all take the same space, so random access is a lot easier than with variable length strings, and comparison is also a lot faster. The actual numerical value used is completely arbitrary.
If you have a static corpus you want to process (ie you know all the words that occur in it, and there won't ever be any new words coming in), then you can kill two birds with one stone and double up the numerical value with their frequency rank (not the actual frequency, as there will be many words which have the same frequency).
I guess one reason with language models is that they often have a fixed number of words that they can handle. If we arbitrarily set that to 1024, we can then make sure that only the most frequent words are used, by simply replacing any index value greater than 1022 by 1023 (assuming a range from 0 to 1023). The word type with the index 1023 then becomes "UNKNOWN". This is an elegant way to make sure that only the least common word types are excluded.
In an open-ended NLP system, you cannot do that (as the vocabulary is not stationary), so you'd usually have maintain a separate frequency list. If you then want to extract the 1023 most common word types, you'd always have to add a frequency-rank lookup each time, which you can save if the index is already the frequency rank.
So it's an efficiency gain in a trade-off for requiring a static vocabulary.
Please note that these are not stop words, as mentioned in another answer: stop words are high-frequency words, usually function words, which have no lexical meaning (but provide the 'glue' between words in a sentence). In days when memory was limited, these words would often be excluded, as they did not contribute much to the 'meaning' of a text (for a very limited definition of meaning). In a "bag-of-words" approach, they can probably be ignored. Rare words are not stop words.


text:
What is the state of the art concerning autoencoder that connect 2 images that are not similar but are physicaly related?
I am currently working on an autoencoder that connect two images. The first one can be seen as the electron flow and the second one is the electrostatic potential seen by the electrons. Long story short, the neural network connects those pairs of images that are very different but related by physical law. I have already something working, but I have a hard time trying to find similar kinds of application of neural networks. Most of the time an autoencoder connect images that are very similar (denoising for example). My two questions are the following:

Are you aware of other similar application of autoencoder?

What methods can I use to explain the working procedure of my neural networks? (In the literature the methods concerne mainly classification tasks.)

It's not really an autoencoder if the output is expected to be different to the input. What you appear to have is an image-to-image function, and I guess the only "auto" part is that you have some other reliable method of calculating the output from the input as opposed to measuring it for a dataset? The architecture can be very similar to an autoencoder of course. Maybe look up image encoder/decoder architectures, because there are many similar applications IMO.

Thank you for your answer. Indeed, I am looking for an image-to-image function. It might be a stupid question, but I don't know the difference the architecture of an autoencoder and an encoder-decoder. Is there a well defined difference between them?

There isn't really a clear architecture difference. The difference is the training process and the eventual role that the network components will take. You may prefer an architecture without a bottleneck in your case, making it less like an autoencoder (because there will not be a compressed "embedding" vector in the middle layer). But that depends on how many degrees of freedom are in the input

I see what mean, thank you for the clear explanation. I will take this difference into account. Are you aware of application of such encoder decoder architecture? Because so far I didn't find any image to image neural network in the case of the input images is very different of the output image

If I understand correctly, you are looking for the image-to-image translation method. For example take a look at pix2pix GAN (pub) - very cool idea of cGAN application. You can also look for U-NET type networks (encoder-decoder). In my opinion autoencoder will not work for this application.

Thank you for your answer. Indeed the pix2pix GAN would be useful for my project and is actually my current project. I've never heard about IMO autoencoder, what is it ?
Are you also aware explainable machine learning methods for this kind of neural network? It would be very useful for my project to see the working procedure of my neural network.

Sorry, IMO = in my opinion :) Just edited the answer. Take a look at this tutorial for tensorflow.


text:
Having the negative cases in the same batch vs. shuffling the dataset
I am working on a model for an NLP task. The model encodes the text and has a regression output layer.
In this task, from each instance (positive), I create several negative cases using a specific technique and I merge them with their positive corresponding ones in a data split (training/val/test). After that, I shuffle the data split.
I was thinking of the following: Isn't better to keep the negative instances with their corresponding positive ones in the same batch instead of shuffling the data?
Is there an answer to this question? does it depend on the task?

Can you explain why wouldn't you use the negative cases and positive cases in the same batch? Why are you separating the cases? Can you provide more details about your specific task?

@nbro I shuffle the data because this helps the training converge fast. It's hard to give details here but the task is to train a model to produce a score. I have instances with 1.0 scores, and with the negative sampling, I created instances that have scores less than 1.0 (0, 0.33, 0.67, etc.). The negative instances are similar to the original ones and share part of the text.

Depending on how you generate the negative cases, you may have a potential for data leakage from your test set. If you have a positive case in your test set, and use some rule to "negate" that case and put it in your training set, you now have a training sample that is not truly independent of your test data. With this approach, you may wind up with a biased performance estimate that is over-optimistic, as the model was trained based on data that was a modification of the test data. The size of this problem will depend on how you generate the synthetic cases from real ones and will be difficult to quantify, so you may be justified in keeping the real positive cases and synthetic negative cases in the same batch to avoid this problem.

Thanks, @Nuclear. The generation of the negative cases is split-based; The negative cases that are in the training part were created from the positive ones in the training part. I don't move them across the splits. My point is, should I shuffle the training part then or keep the negative cases with their positive ones in the same batch?


text:
Is AI able to detect major changes in pairs of images while ignoring minor changes (due to tree crown growth, color and perspectiv disstortions)?
I'm starting to get involved into machine learning but still have some troubles to select the approriate tool or algorithm.
My basic task is to compare remotly sensed images of individual trees at two time steps (e.g. 2012 and 2016). Between images I'd like to determine if any individual tree was cut or not.
Problems that arise are different colors, slightly different shapes (due to lateral growth of tree crowns) and distortions of perspective (due to off-nadir images, meaning that the position of the plane in relation to the tree differs between both time steps).
When I determine by "hand"/eye if trees were cut, I heavily rely on the shadows of trees facing to the upper left corner.
Here are some images to illustrate my problem (left image: 2012, right image: 2016):
The tree in the image below remains, but the colors differs and the shape (perimeter) differs slightly.

Here, the tree in the image below remains as well but due to distortions of persective both images look (from a machine point of view) quite different.

The tree in image below was cut and the area around was converted to urban area/ buildings.

And finally, the tree in the image below was cut but the understorey and accompanying vegetation remains.

I'll have to do this comparison many thousand times - therefor I'd like to train an neural network.
My focus of interest are those trees that were cut between both images. I'd tried to use the NDVI value ("greennes of vegetation") to detect major changes but this approach worked only for some cases.
During my research I found many image change detection papers using CNNs but they seemed to be focussed on more substantial changes like grassland conversion into buildings or deforestation ...
Some additional research lead me to face verification algorithms that in theory might fit:
I have two known images to compare and like human faces there might be minor changes (perspective, haircut ...) but the verification still works.
Is this approach possible or do I miss some important tool or is this kind of tree verification even to difficult???
Thank you for your time and responses!

Do you have already labelled data or are you leading toward an unsupervised methods?

Hi Edoardo! I could generate labeled data easily from a step prior in the processing chain. But it is weak data (not picked by a human) and comes in a ratio of 3:1 (~5000 labeled images to 1700 not-labeled images). Thanks!


text:
How is the output of the Generator in a GAN corrected?
If the Generator in a GAN is taking a matrix of size WxH of noise to generate a WxH sized output image, and the Discriminator classifies the output as fake, how is that information back-propagated through the generator?
How is the error in classification attributed to individual "pixels" of the generators generated image? Is the error divided by the number of pixels?

If you ask this question it means you conceive a generative adversarial network as a combination of 2 separate entities, the discriminator and generator, but this is not really the case.
It is true that for convenience we distinguish between generator and discriminator since they fulfill separate purposes, but by simply looking at a drawing of a whole GAN you'll see that they are not separated at all.
When training the generator we simply backpropagate the gradients coming from the discriminator through the fake generated sample, as it was an intermediate layer between generator and discriminator (see red area in the drawing).
Of course the discriminator can be updated on its own, and even the generator since we can compute loss and backpropagate from the fake generated sample level. This is nothing special, for example it's done also in normal CNN training when using losses computed at the feature maps level (like perceptual loss).

Maybe reference the separate D/G training steps for detail at the end, as you cover how the architecture supports this. I suspect the OP would appreciate a reference to the full algoirithm.

Thanks for the answer @edoardo, but to confirm, the backprop stage goes from the discriminators output back through to its inputs (the generated image) and continues backwards though the generator? So each pixel the generator output is being corrected by the chain-rule back through the discriminator?

@NeomerArcana yes, exactly! And this doesn't require any fancy implementation when using deep learning libraries, as long as both, discriminator and generator are implemented as modules, autograd  automatically recognize that the fake image has gradients coming from the generator, so when backpropagating the discriminator loss you're already updating the generator as well. The only difference required is a different optimizer for the generator weights.

I'm going to keep my answer relatively high-level and avoid details like the actual loss functions or activation functions. But please know these also have an effect on GANs.
The Discriminator (D)
The discriminator in a GAN is a binary classifier. It is given an image and asked to predict whether that image is real or fake. The discriminator reduces the given image down using convolutional layers. Convolutional layers detect features, in the case of images these would be edges, borders, certain shapes and so on.
The discriminator is learning which features correspond to a real image and which features correspond to a fake image.
The Generator (G)
The generator is almost the inverse of the discriminator: Instead of reducing features it uses deconvolutional layers to create features from a random seed. This random seed is a vector (not a matrix) called the latent vector (z).
The generator is learning which features to create to return a real label from the discriminator.
How GAN learns
In each training step the following happens:

Get gen_images from G given z.
Get real_predictions from D by passing real images to D.
Get fake_predictions from D by passing gen_images to D.
Compute loss on G as a function of (real, fake_predictions)
Compute loss on D as a function of (real, real_predictions) + (fake, fake_predictions)
Use backpropagation to update the weights and biases in D and G for the losses.

The big point here is that the generator's loss function directly depends on the output of D. Did G manage to trick D or not? This is computed by comparing the fake_predictions with the real label. G wants those two values to be as close as possible.
This loss does not correspond to individual pixels, but because we are using convolutions/deconvolutions in our models it corresponds to feature selection (in D) and feature creation (in G) with groups of pixels.
In short: the individual pixels are not directly trained in a GAN's generator, instead patterns and features creation are.
If you are still confused: Think about how a child draws.
A child doesn't start drawing by examining things a millimeter at a time, but by using symbolism and feature selection. At the beginning you can really only guess what they are trying to make.
A cat might be a big mess of scribbles, but slowly the child learns to draw pointy ears, or whiskers. At some point the child can draw features that are identifiable as a cat. The child has gotten feedback from you when you ask her, "Oh, what's that supposed to be?" and when you say, "Oh, is that a cat?" and then finally, "That's a nice looking cat!".

How does this work in practice? If the discriminator predicts correctly that the image is a fake, aren't the outputs of the generator (the image pixels) corrected?

Yes! That's what the loss function (for the generator) does. The loss function quantifies how undesired the output was. Since G wants to trick D, we compare the guesses of D (the actual output) on the generated images and compare the guesses to the label real (the desired output). Like in any other network, when the desired output and the actual output don't match there is a loss, which is backpropagated through the network.