What is the difference between a stacked restricted Boltzmann machine and deep belief network?

For what it's worth, Wikipedia says that

  deep belief networks can be formed by "stacking" RBMs.

Hinton writes in Scholarpedia:

  A deep belief net can be viewed as a composition of simple learning modules each of which is a restricted type of Boltzmann machine.

So, a deep belief network is definitely a stacked RBM.

I have never heard of different stacked RBMs, but it is easy to imagine something like convolutional stacked RBMs, where some RBMs are used as filters that slide over the input data or something. Whether that would still be called a deep belief network, is probably up to the guy who publishes it first.


What do they mean by "contradictory loss"?

The contradictory loss is the same loss function that the discriminator would normally use, except with deliberately incorrect labels. That is, when you train the generator, the output of the generator is fed to the discriminator, but instead of the correct label (typically $0$ for a false image), the opposite label is applied (e.g. $1$ for a real image).
This label is condractictory in that it is incorrect and the opposite of the ground truth. However, this is useful, because reducing the loss of this signal represents the goal of the generator. It is important to note that during this phase of the training, you should not update any parameters of the discriminator. The process is followed in order to find gradients for improving the generator only.


Why does my neural network to predict $x$ given $\sin(x)$ not generalize?

The labels are not unique for the input domain [0,20]. Think about sin(x)=0, x could be 0, pi, 2*pi, 3*pi, ..., n*pi, all are correct from a mathematical point of view, but this is not reflected in your MSE loss. At this point your NN has to guess the correct label from your input data. Predicting the mean of your input data is the safest bet for the network.
In essence you're trying to build a arcsin function with a NN. If only consider x values in [-0.5*pi,0.5*pi], the labels are unique and your network should work.


Is recursion used in practice to improve performance of AI systems?

To my knowledge, recursion does not play a strong role in the definition of modern AI techniques, although it does feature used in Lovasz's definition of 'Local Search' and Kurzweil is certainly an advocate.

Recursion can be seen as an elegant 'architectural factorization' - building complexity by combining the results of smaller, similar patterns previously encountered. Computationally, recursion can always be converted into iteration so this form of elegance is really mainly of use in helping to make designs more comprehensible.

GOFAI algorithms that were traditionally defined using recursion include depth- and breath- first search and means-ends analysis (used in Newell and Simon's General Problem Solver).

With respect to performance, while many functions can be very economically defined using recursion, the naive version of such definitions can be inefficient.

This page gives an example in which recursive version of the Fibonacci function, which has asymptotic execution time $n^{1.6}$, which is reduced to $n$ by the use of memoization.


How to go about classifying 1000 classes?

If you are asking for arbitrary ML task dealing with 1000+ classes the most straigtforward thing that comes to mind is the ImageNet - https://en.wikipedia.org/wiki/ImageNet#cite_note-nytimes_2012-2. It has more the 20k categories in the present time.
In order to perform such classification task you need

A large enough dataset, such that each class occurs frequently enough or efficient data augmentation
A powerful model, such that can adapt to variety of different problems

The first neural network to tackle this problem was AlexNet and since then plethora of architectures : VGG's, ResNet's, EfficientNet got better and better quality.
They have a lot of filters that react on different patterns.


Why don't we perform classification of crowd density?

For example, if I have the crowd images labeled based on their crowd density (low, moderate, high), and I'm not interested in the count, but the density class (low, moderate, high), can't I train the network to classify the data based on these classes as a classification network?

Yes you can, all you need is enough correctly labelled training data.

A good rule of thumb is if a human expert can assign the correct label from an image (and purely from the image, not using extra information) then it is a realistic goal to train a CNN to perform the same labelling.

  why there hasn't been attempts to tackle this type of task as a classification problem.

Probably because there are no natural, and likely no widely accepted, classes in this case (I may be wrong, maybe some international society has defined classes you could use). If you use a regression, you can map it to a particular problem case - e.g. sending an alert to someone responsible for traffic and safety when crowd density hits some threshold - by setting numerical boundaries to your classes. Using classification and mapping back the other way is harder.


Using ML to encypher data for production

It sounds like you are trying to compress data, and then recover the same data later.

The most common tool for this task is an autoencoder. This model accepts data as input, and then learns to compress it and decompress it to produce something as close as possible to the original data. By making the middle layer of an autoencoder narrower, you can make the compression more lossy. By making it wider, you can make it less lossy.


What is the difference between the study of evolutionary algorithms and optimization?

Optimization problems are formally defined by two things:

Optimization objective: $$\min_{x \in \mathbb{R}} f(x)$$
List of constraints: $\text{s.t. } x > 0$; $\text{s.t. } x^2 < 100$, ...

Optimization theory as a field deals with variations of such problems. The algorithms that are part of optimization include gradient descent and variants, the simplex algorithm, simulated annealing and many more. I would also include evolutionary algorithms as one of the algorithms in this field.

I am confused. Is he actually teaching optimization? If yes, why is the name of the course not "Optimization"?

Evolutionary algorithms are a subfield of optimization. The name of the course is evolutionary algorithms as you likely don't deal with the other aspects of optimization theory (e.g. the algorithms mentioned above).


How can I prove that all the a-cuts of any fuzzy set A defined on $R^n$ are convex?

We can assume without loss of generality that
\begin{equation}
\min\{\mu_A(r), \mu_A(s)\} = \mu_A(r) = \alpha.
\end{equation}
$\implies$

a-cut of fuzzy set $A$ is on $R^n$ is convex. A-cut can be defined as
\begin{equation}
A = \{x \in R^n| \mu_A(x) \geq \alpha\}
\end{equation}
If we take two elements $r$ and $s$, by the definition of convex set, number $\lambda r + (1 + \lambda)s$ is also an element of that set. Since it's an element of that set that means
\begin{equation}
\mu_A(\lambda r + (1 + \lambda)s) \geq \alpha
\end{equation}

$\impliedby$

$\mu_A(\lambda r + (1 + \lambda)s) \geq \alpha$.

We know from $\min\{\mu_A(r), \mu_A(s)\} = \mu_A(r) = \alpha$ that $\mu_A(s) > \alpha$. We have an affine combination $\lambda r + (1 + \lambda)s$ for which also $\mu_A(\lambda r + (1 + \lambda)s) \geq \alpha$ so we know that all numbers $\lambda r + (1 + \lambda)s$ satisfy inequality $\mu_A(\cdot) \geq \alpha$ (belong to the same set as $r$ and $s$) which means this is a convex set again by the definition of a convex set.


What is the fundamental difference between neural networks for classifying and generating data

The formal name for this difference is "generative" vs "discriminative" models.
By default, a supervised learning process using a simple feed-forward neural network and a set of training data with expected answers will produce a discriminative model. It is hard to use such a model to generate content directly.
Differences between discriminative and generative models tend to be at the architecture level or deeper, although a few generative techniques are simple variants or re-purposing of discriminative networks. There is no single "fundamental" difference in terms of NN design. About the only common theme is that generative models are more complex and harder to work with than discriminative ones.
Images

Probably the most popular currently for image generation are Generative Adversarial Networks or GANs. These train a Generator to create an image from random inputs, alongside a Discriminator that tries to spot fakes compared to real images. Training them together results in a generator network that gets progressively better at creating fake data.

Also suitable for image generation are Variational Autoencoders (VAEs) which learn essentially by compressing a set of images down into a small representation, and as a result become able to "uncompress" similar representations.

There are also VAEGANs, which combine VAEs and GANs

There are other models which generate examples from a dataset. For example, Restricted Boltzmann Machines (RBMs) are similar to neural networks, but the neurons fire randomly, and RBMs require a different training process to NNs.

GANs, VAEs, VAEGANs, RBMs can be used to generate data in any simple non-sequential datasets, they are not restricted to just images, but recent work with GANs for example has excelled there.

For a different kind of generator, you can look at how Deep Dream works. The interesting thing here is that it is a modification of a feed forward network that has been trained by supervised learning. Essentially to run Deep Dream, you take an existing image and change it so that it maximises some internal part(s) of the existing neural network, "training" the image as if it were a set of weights.

The difference between Deep Dream and other generative techniques is that it does not generate content that could be in the training set - it is no good for creating "realistic" images.

Text

Recurrent Neural Networks, and specifically Long Short-Term Memory (LSTM) networks can be used to model word sequences by training them to predict the next word. Because the resulting model is probabilistic (e.g. chance of next work being "Hello" is ~0.001%) then a simple method to make this generative is to sample from the predictions randomly, and then feeding them back into the sequence to see what it will predict next. There is a great blog post about this technique by Andrei Karpathy.

Audio and Music

DeepMind's WaveNet architecture is similar to a CNN predicting the next samples of audio from a given input. It can be used in speech or music generation.

LSTMs are a popular choice here, as well as for language models.

One important caveat. Nearly all these models are hard to understand, work with and train, compared to simpler supervised techniques. Probably the easiest to get to grips with if you want to understand them well enough to implement your own versions, are Deep Dream, VAEs and LSTMs.
It is also worth noting that there are many other ways to generate content than neural networks. For instance, sound and music generation has a long history completely independent of recent AI developments.


Use cross-validation to train after model selection

You are quite correct. If you have properly followed the Cross Validation procedure and selected the best model indeed, then you can use the CV set as the training set for the final model. And no it will not cause your hypothesis to worsen (for that set maybe, but not for new examples) if you have selected the model correctly. In-fact you may use the entire 100% of the data-set.

Justin Johnson a TA at Stanford University answered a similar type of question on training CNN's using 100% of the data-set. He said that if you had enough computational resources and want to squeeze that extra 1% or 2% accuracy from your model you can use the entire data-set after model selection.

NOTE: As @NeilSlater pointed out, if you need the model for reporting purposes you should only use 80% of the data-set, otherwise you'll lose your only source for unbiased model verification. But if you are looking to deploy the model on field you can use 100% of the data-set.


What is the representational capacity of a learning algorithm?

Learning algorithms (some others too, like search) aim at generating functions that get as close as possible to the "shape" of the training data (so we can then feed values to the generated functions and get outputs like, say, a prediction).
In 2D, the "shape" may be easy to visualize. If the data in 2D seems to line up, learning algorithms generating linear/affine functions (e.g. y = ax + b), should fit fairly well. Their representational capacity extends to lines. If the data seems to form a parabola, a representational capacity bound to lines will do poorly. We then need more "capable" representations, which can cope with the quadratic terms.
So this should be what the "family of functions" Goodfellow's book refers to. The "training objective" should not be in the definition (to me), as a line fitting solution is unable to represent, say, a parabola, whatever the training objective is. However the book definition may mean a line can be fit to a parabola, strictly speaking, although it will do so very poorly.
The hypothesis space resembles the definition, perhaps (I have not checked it), but what matters is the "mindset". I would draw a parallel with prior and posterior distributions in Statistics, where we usually make some hypothesis on the shape of the distribution.
Concrete examples like linear regressions generate linear functions, as hinted by their names. Decision trees generate sets of linear functions, thus more complex and "capable". SVM generates functions depending on its kernel. The RBF kernel, for example, allows generating functions that can map quite complex, non-linear data "shapes". And arbitrary neural networks can map "arbitrary" data "shape" (easier written than actually done).


What are the different types of goals for an AI system called?

Do you mean weak AI and strong AI?
The former is roughly about pretending to be intelligent, ie do intelligent things, but without trying to work the same way an actually intelligent system would work. The latter attempts to replicate how an intelligent system works, so would require us to understand a lot more about cognition than if we just mocked up a quick little chatbot to try and compete the Turing Test.


How can I develop a reinforcement learning agent that plays memory cards game?

The main thing to keep in mind when designing a reinforcement learning agent is that you need to develop an interactive environment in which the agent can learn and define the possible moves the agent can make. In your case, the environment is the memory cards.

Next you need to define how the agent can interact with the environment, that is choosing a card or flipping a card etc. Also how the environment will behave when the agent chooses a move.

Finally you need to define the fitness function, in this case the score (number of pairs created) should be fine. You should have a look at some online RL competitions to get a better understanding of the architecture. AWS DeepRacer


Connection between the Bellman equation for the action value function $q_\pi(s,a)$ and expressing $q_\pi(s,a) = q_\pi(s, a,v_\pi(s'))$

Your understanding of the Bellman equation is not quite right. The state-action value function is defined as the expected (discounted) returns when taking action $a$ in state $s$. Now, in your equation (2) you have conditioned on taking action $a'$ in the inner expectation - this is not what happens in the state-action value function, you do not condition on knowing $A_{t+1}$, it is chosen according to the policy $\pi$ as per the definition of a bellman equation.
If you want to see a 'recursion' between state action value functions, note that
$$v_\pi(s) = \sum_a \pi(a|s)q_\pi(s,a)\;,$$
Your equation (5) is incorrect -- you need to drop the outter sum over $a$ as we have conditioned on knowing $a$. I will drop the $\pi$ subscripts for ease on notation, and we can see a 'recursion' for state-action value functions as:
$$q(s,a) = \sum_{s',r}p(s',r|s,a)\left(r + \gamma \left[\sum_{a'} \pi(a'|s')q(s',a')\right]\right)\;.$$


Real time image processing for object recognition using security cameras

Here is some general info on how NNs work in relation to this specific problem. Hopefully it will provide some insight:

To identify target object, you can just train an NN to perform classification of images. Now, you will run into potential problems where this image can be located anywhere in given frame of input from the camera.

Let's say; you train a human NN that's able to act on 60px x 120px (so you will have 10800 input in your NN for the input layer). Under the assumption you can train the NN to identify whether or not the target object is showing in the image provided, you can use this trained NN to locate the object on the input frame.

Let's say the input frame from the camera is 640px x 480px. You will run into several potential problems
1) The object that's closer to the camera will be larger while the object that's further away from the camera will be smaller
2) The object may be located anywhere in the frame.

To overcome this problem with your already trained NN, I would start with a different mask size, for example, the first one I will probably have my first mask convolute all pixels with 240px x 480px. The first step is, scale it to 60px x 120px (which you can tell it is pretty much 4x) and capture the subset of pixels from pixels located in the area of (0,0) and (240, 480) and run it through the NN, If it yields true, then I will typically draw a box around the region to indicate the target object has been found.

Next, you shift over to 1-3 pixel and rerun it. For example, if we choose to move by 3px, then the region we are testing will be (3, 0) and (243, 480).

Once you finish this scale, you will want to choose a smaller mask, maybe something like 200px x 400px and do the same thing. When finished, go even smaller until you believe there's no point to search for an even smaller region because it is not going to be sufficient resolution for NN.

That's just my thought; maybe there's an even more efficient algorithm. Ultimately, I am sure there's a lot more can be optimized than what I've mentioned above!


What are some techniques/method that can be used to train and detect objects like cars and humans?

The terms you are looking for are deeplearning and convolutional neural networks for object detection. Google responds well to these terms.
From academical point of view you can start from:
Single shot multibox detector: https://arxiv.org/pdf/1512.02325v5.pdf
Or Faster-RCNN:
https://arxiv.org/pdf/1506.01497.pdf
These are not simple architectures and there are many improvements to them but these give you an idea of the current state of the art methods.
There are many implementations of both of these networks in deeplearning libraries for python (eg in Tensorflow, PyTorch).


Similarity score between 2 words using Pre-trained BERT using Pytorch

1. Does BERT have any such models?
If you mean the pretrained model, then the answer is YES.
BERT has Cased and Uncased models and also models for other language (BERT-Base, Multilingual Cased and BERT-Base, Multilingual Uncased, trained in 104 languages). You can check those models here.
2. Is it possible to check similarity between two words using BERT?
Refer to this Google Colab Notebook, it is not appopriate with BERT Embeddings for Word-Level similarity comparisons.
However, doing sentence embedding similarity comparisons are still valid with BERT.
That's it, hope it helps you :)


Are artificial neural networks based on human neural networks?

Artificial neural networks (ANNs) are loosely based on human neural networks. However, there are many aspects of the human brain that are not modelled in ANNs.
First of all, ANNs have an input, which is followed by an output. Our brain doesn't work like this. We have many inputs, many outputs, and many cycles that loop in our brain. There's no simple input-output - end of the program. We think even if there is no 'input' (e.g. sleep). In current technology, such a thing is not ready. If you look at the Robot Sophia as another example - she acts like Siri: input-output. You speak, she responds. When in the future it will be possible, that robots will get a pulse, and start a process without an end, then we can call it 'thinking like a human' in a philosophical meaning.
The second point is the size and processing power of our brain. Billions, if not more, neurons, and trillions, and more connections are in our brain. On YouTube you find neuronal networks with 6 neurons, some have 100. Maybe there's a secret military agency that has a network with million networks - we can't say. Entire rooms are hosted to simulate our brain which fits in just one head.
But - to end this respond philosophically: In theory, humans are also machines. Advanced, but still machines. Software that runs on a biological hardware. So any intelligence may be comparable. But since you are mentioning the human part - the answer would be probably no.


Semantic segmentation CNN outputs all zeroes

Similar to other answers, I don't know Matlab that well but you could try the following steps to debug your problem.
Make sure you can overfit to a single instance
from your dataset, pull out a single image with a good amount of true positives in it. Duplicate that images B times (where B = Batch Size) and then try to train your network with only that small dataset. If you can't overfit to a single instance, then something is really wrong and you should validate all functional aspects of your network. If you can overfit, then it's probably more of an algorithmic or data imbalance issue.
Validate Functional Aspects of the Network
Make sure your input data and labels are correct.
Validate that your images are being correclty inputted into the network. You can do this by printing out any images right before they go into the training function. For the labels, make sure to manually inspect a few labels to be sure that the labels correctly match up the images.
Make sure that your loss function is correct.
Add a unit test or two to your loss function to validate that it is doing what it should be doing. Create a simiple example that you can easily validate.
Validate the rest of the non-algorithmic functionality
Anything that isn't a design choice should be validated. Make sure that the weights are the correct sizes, each layer has the correct number of weights, the intermediate features have the correct shape, etc.
Data Imbalance
If you were able to overfit to a single image, and validated the functional aspects of your network then you may be facing a data imbalance issue. Look at your dataset and see what % of your instances are true positives vs. true negatives. If you have an exteme imbalance (like 10% 90%) or something like that, then build a dataset that is more balanced and see if you can fit your data. If you fit the data with that more balanced dataset, then there's plenty of ways to fix your data imbalance issue. Google around for data imbalance and you should get a few good ideas. Some include focal loss, upsampling, etc...
Check your receptive field
The receptive field on a network is basically the area that can be looked at by the network for a specific region. This is controlled by the size of the convolution filters, stride, etc. If the data that you are segmenting doesn't fit within the receptive field of the model, then you might be saturating the loss function. tldr try playing around with kernel sizes.


How to identify if 2 faces contain the same person?

The topic of your problem is person re-identification. You can check here.


How to perform PCA in the validation/test set?

for the first point I'm very sorry that I cannot give you any literature on this, but I might be able to explain you, why you don't take PCA on both datasets independently.

Principal components analysis is simply a transformation of your data into another (less dimensional) coordinate system. The axis for your new coordinate system are defined by the principal components (i.e. eigen-vectors) of your covariance matrix.

Since you will train your machine learning algorithm in the domain that is generated by the PCA, your test data must be exactly in the same domain. So as you said, you use exactly the same transformation for the test data as for the training data, i.e.
$y_{newdim} = y \phi $.
Of course if you applied standardization to your training data, you have to apply the same standardization to your test data. So you need to store the mean $\mu_x$ and the standard deviation $S_x$ and also standardize your test data y to
\begin{equation}
y_{standardized} = \dfrac{y_i - \mu_x}{S_x}
\end{equation}

Note here that you have an error in your standardization formula (you do not need to divide by $M$).

The point is that the principal components of your test data $\phi_{y}$ would not match the principal components of your training data $\phi_{x}$. Thus the transformations from original space into PCA-space $\Phi_x(u)$ and $\Phi_y(u)$ would diverge and similar data points in the original space might be far away in the PCA-representation and vice versa. This is why you generate the mapping $x_{newdim} = \Phi_x(x) = x\phi$ and apply it also on the test data.

I hope I could make it clear to you.

Best


Is it possible to apply the associative property of the convolution operation when it is followed by a non-linearity?

Yes, when you have non-linearity it is not possible to combine your convolution steps.
However, you can approximate the two layers network with one layer net according to the Universal Approximation Theorem. You will probably need to use something like a knowledge distillation technique to do it. Note that, the theorem doesn't say anything about the number of neurons required or if the learning techniques that we usually use will work well.
Also, $ReLU(x)$ is a linear mapping when $x \geq 0$, so if your input, weight, and biases are $\geq 0$, the net can be exactly modeled with a single layer network.


Is Intelligence a naturally occurring function of Information Technology?

Maybe, but it depends to a very large degree on the choice of definition.

One of the biggest challenges for AI researchers, neuroscientists, philosophers, and psychologists, has been that the layperson's understanding of intelligence does not appear to correspond to a well-defined concept. This point was most famously exploited by John R. Searle in his paper Minds Brains and Programs.

Consider your definition again carefully, and notice that decision is unbound. Does a rock rolling down a hill make a decision when it 'decides' to roll to the left? If not, Searle and his ilk would argue that a computer isn't making a decision when it decides to execute the next instruction. It is simply obeying deterministic laws of physics.

To escape this problem and still claim that machines are intelligent, you can either chose to believe that rocks make decisions (a view called panpsychism), or that we should behave as though rocks make decisions because doing so gives us a lot of explanatory power (the intentional stance), or claim that humans are no different from the rock or the computer (eliminative materialism). The last option leaves you with the problem of explaining subjective experiences though.

An excellent book that covers the mainstream arguments in this vein is Haugeland's Mind Design II. All the arguments I've outlined here are covered in great detail within. Among modern AI researchers, I'd say there is a split between those who embrace something like the intentional stance and those who embrace eliminative materialism.


Are there communities dealing with costs-vs-accuracy tradeoffs in Machine Learning?

Welcome to AI.SE ks.and1.

What you're describing could be related to several areas, but since you are looking only for some keywords, I'll suggest some:

You might be interested in anytime learning, which might better be called 'learning that can stop at any time'. A good example of this approach in machine learning is anytime learning for decision trees, as summarized in Esmeir & Markovitch's 2007 JMLR paper
Apart from this, it sounds like you are just describing the regular process of retraining a model when you get more data. For most algorithms, this just amounts to changing the input to your program so that it points at a larger file, containing more records than last time, and maybe buying a faster GPU or CPU to train the model with if it's taking too long with the extra data.

Hopefully, this can help you get started. If you have some more details about your problem, I might be able to suggest some more specific resources.


Does it make sense to include constant states into reinforcement learning formulation?

It is, I suppose, a philosophical question whether data that describes a whole episode and does not respond to events within it is part of the state, or is part of some other structure.
However, the practical response is to view such descriptive data as defining an instance of a class of related environments, and to include it in the state features. This may be done for two main reasons:

The static data is a relevant parameter of the environment, affecting state transitions and rewards.

It is possible to generalise over the population of all values that the parameters can take.

In simple environments, generalisation might only be that the same agent can learn about all variations in a single combined training session. You could use a tabular RL method, starting randomly with one of the possible variations until all were sufficiently covered.
In more complex environments, generalisation may also occur through functon approximation, in a similar manner to contextual bandits. In your personalisation example, you are not expecting to train the agent for all possible user descriptions, but hope that people with similar age, gender etc descriptions will respond similarly to an agent that personalises content.
Philosophically, the contextual data is either part of a larger state space (with a restriction that transitions between different contexts do not happen within an episode), or it is metadata that impacts the "real" state transitions and rewards. Pragmatically, to allow the data to influence value functions and policies, it is necessary to use it in the arguments of those functions. Whether you then view it as part of the state feature vector or as something that is concatenated to state features is a personal choice. Most of the literature I have seen assumes without comment that it is part of the state.


Who manufactures Google's Tensor Processing Units?

Google has not released the manufacturing details for their TPUs. However, it's suspected that they're produced by either Taiwan Semiconductor Manufacturing or GlobalFoundries, as these are some of the largest companies in the industry.

Source


Splitting audio consisting of male / female speaker into segments

Edit: It's not clear what exactly you're trying to accomplish...  My answer assumes you wanted to split the man and the woman's audio, but re-reading your question make me think otherwise.

Note:  Don't expect this to be a perfect answer.  I'm not an expert in the field, just an interested student.  I can't comment on this site yet, so I'm submitting this as an answer.

This sounds less like a problem suited for machine learning and more of a... statistical analysis(terminology?) problem.  Why? You have an extremely small sample space to train on, and the natural cost function would require you to go through the entire recording and manually classify the track anyway.

Your problem is almost well suited for an Independent Component Analysis approach, except for the fact that you only have one audio source.  ICA requires one source for each feature you want to extract.  It might be a good start though to familiarize yourself with the techniques and terminology.  See the Wikipedia page for ICA, an article called "ICA for dummies" by Arnaud Delorme, and this paper: ICA: a tutorial.  I would link the first two, but apparently I need more site rep.

I also found a paper which seems to perfectly match your problem, from Mitsubishi Electrical Research Labs: Separation of Mixed Sources by Independent Subspace Analysis.  It's a bit a of a heavy read, to say the least, but that might be your best shot.  I'll quote the abstract, emphasis mine:

  We propose the method of independent subspace analysis (ISA) for separating individual audio
  sources from a single-channel mixture. ISA is based on independent component analysis (ICA)
  but relaxes the constraint that requires at least as many mixture observation signals as sources. A
  second extension to ICA is the use of dynamic components to represent non-stationary signals.
  Sources are tracked by similarity of dynamic components over small time steps. We propose
  a method for grouping components by partitioning a matrix of independent component crossentropies
  that we call an ixegram. The ixegram measures the mutual similarities of components
  in an audio segment and clustering the ixegram yields the source subspaces and time trajectories.
  To demonstrate the techniques we give examples of ISA applied to separation of musical and
  speech sources from single-channel mixtures.

Good luck!


Maximizing or Minimizing in Trust Region Policy Optimization?

The differences you have observed between the two different versions of the TRPO paper are due to different formalizations of the problem and the objective.

In the first version of the paper you linked, they start out in Section 2 by defining Markov Decision Processes (MDPs) as tuples that, among other things, have a cost function $c : \mathcal{S} \rightarrow \mathbb{R}$. They define $\eta(\pi)$ as the expected discounted cost of a policy $\pi$, and subsequently also define state-action value functions $Q_{\pi}(s_t, a_t)$, value functions $V_{\pi}(s_t)$, and advantage functions $A_{\pi}(s, a)$ in terms of costs. Ultimately, in Equation 15, they write the following:

\begin{aligned}
\underset{\theta}{\text{minimize }} & \mathbb{E}_{s \sim \rho_{\theta_{\text{old}}}, a \sim q} \left[ \frac{\pi_{\theta}(a \vert s)}{q(a \vert s)} Q_{\theta_{\text{old}}}(s, a) \right] \\
\text{subject to } & \mathbb{E}_{s \sim \rho_{\theta_{\text{old}}}} \left[ D_{KL}(\pi_{\theta_{\text{old}}}(\cdot \vert s) ~ \vert \vert ~ \pi_{\theta}(\cdot \vert s)) \right] \leq \delta
\end{aligned}

Now, there's a lot going on there, but we can very informally "simplify" it to only the parts that are relevant for this question, as follows:

$$\underset{\theta}{\text{minimize }} \mathbb{E} \left[ Q(s, a) \right]$$

When we look at just that, we see that we're pretty much trying to minimize $Q$-values, which are costs; that makes sense, typically costs are things we want to minimize.

In the second version of the paper you linked, they have changed the Preliminaries in Section 2. Now they no longer have a cost function $c$ in their definition of an MDP; they have replaced it by a reward function $r : \mathcal{S} \rightarrow \mathbb{R}$. Then they move on to define $\eta(\pi)$ as the expected discounted reward (rather than expected discounted cost), and also define $Q$, $V$ and $A$ in terms of rewards rather than costs. This now all matches the standard, common terminology in Reinforcement Learning.

Ultimately, Equation 14 looks identical to what we saw above, it's again about an expectation of $Q$-values. But, now $Q$-values are rewards rather than costs. Rewards are generally things we want to maximize, rather than minimize, so that's why the objective swapped around.


How are certain machine learning models able to produce variable-length outputs given variable-length inputs?

In short, repetition with feedback.
You are correct that machine learning (ML) models such as neural networks work with fixed dimensions for input and output. There are a few different ways to work around this when desired input and output is more variable. The most common approaches are:

Padding: Give the ML model capacity to cope with the largest expected dimensions then pad inputs and filter outputs as necessary to match logical requirements. For example, this might be used for an image classifier where the input image varies in size and shape.

Recurrent models: Add an internal state to the ML model and use it to pass data along with each input, in order to work with sequences of identical, related inputs or outputs. This is a preferred architecture for natural language processing (NLP) tasks, where LSTMs, GRUs and transformer networks are common choices.

A recurrent model relies on the fact that each input and output is the same kind of thing, at a different point in the sequence. The internal state of the model is used to combine information between points in the sequence so that for example a word in position three in the input has an impact on the choice of the word at position seven of the output.
Generative recurrent models often use their own output (or a sample based on the probabilities expressed in the output) as the next step's input.
It is well worth reading this blog for an introduction and some examples: The Unreasonable Effectiveness of Recurrent Neural Networks by Andrej Karpathy


What algorithm would you advise me to use for my task?

Assuming that the image is blank everywhere but where the face is drawn...
The first step is to scale the image to the mask.  That doesn't require a detailed explanation here as it is too trivial a problem.
Second, rotate the image by 90 degrees three times and save each one.
Third, for the four versions of the image (the original and three rotations), do the image addition.  The only one with information will be the one that is rotationally aligned with the mask.


Why does nobody use decision trees for visual question answering?

For vision tasks, neural network models almost always include a number of layers that pool and convolute. The convolutions, in particular, are very useful - they can make the model generalize better to inputs and maintain performance when inputs have undergone certain linear transformations (e.g. some scaling or a translation along the x-axis). These properties, along with the robust frameworks that exist for developing and deploying neural nets, and the fact that they have been shown to widely produce very good results, are some of the reasons they’re used.

In terms of being a black box, while this is true for a lot of applications it’s actually less true for image-based tasks. The layers of a well designed and trained convolutional neural network model can actually be visualized and made quite interpretable; from these visualizations, it’s often clear how the representation roughly works. In contrast, I’d argue that while a decision tree is theoretically easier to interpret for some tasks (say medical decision making), this is less the case for vision tasks because we don’t interpret images one pixel at a time. People are almost always interested in the higher level representation within an image (say, a cat, a leaf, or a face). Decision trees tend to have trouble capturing these higher level representations.

Distill.pub has a nice explanation of feature visualization that may be of interest.


Why does the error of my LSTM not decrease after 10 epochs?

I think there are some problems with your approach.
Firstly, looking at the Keras documentation, LSTM expects an input of shape (batch_size, timesteps, input_dim). You're passing an input of shape (1000, 1, 1), which means that you're having "sequences" of 1 timestep.
RNNs have been proposed to capture temporal dependencies, but it's impossible to capture such dependencies when the length of each series is 1, and the numbers are randomly generated. If you want to create a more realistic scenario, I would suggest you generate a sine wave, since it has a smooth periodic oscillation. Afterward, increase the timesteps from 1, and you can test on the following timestamps (to make predictions).
For the second part, if you think about a normal RNN (I will explain for a simple RNN but you can imagine a similar flow for LSTM) and a Dense layer when applied to 1 timestamp, there are not so many many differences. The dense layer will have $Y=f(XW + b)$, where $X$ is the input, $W$ is the weight matrix, $b$ is the bias and $f$ is the activation function. Whereas RNN will have $Y=f(XW_1 + W_2h_0 + b)$, since is the first timestamp $h_0$ is $0$, so we can reduce it to $Y=f(XW_1 +b)$, which is identical with the Dense layer. I suspect that the results differences are caused by the activation functions, by default Dense layer has no activation function, and LSTM has tanh and sigmoid.


Sequential programming would not be suitable for this kind of problem, but an algorithm could be implemented in a declarative programming language. I would suggest using Answer Set Programming, a language that is designed for logic axioms.


How would one disambiguate between two meanings of the same word in a sentence?

I'd suggest BERT for this. It is essentially a word-embedding model that uses at local context to determine the appropriate embedding for each word. This means it would assign "bat" a different embedding in a sentence containing "hit the ball" vs. a sentence containing "flies and eats bugs". On top of that, Google has released a number of pre-trained versions of BERT, which can be used directly without additional training (depending on your task of course). BERT as a service is great if you just want embeddings. The Python transformers library makes it exceedingly simple to incorporate BERT into your task-specific model.


Are there any microchips specifically designed to run ANNs?

In May 2016 Google announced a custom ASIC which was is specifically built for machine learningwiki and tailored for TensorFlow. It is using tensor processing unit (TPU) which is a programmable microprocessor designed to accelerate artificial neural networks.

NeuroCores, 12x14 sq-mm chips which can be interconnected in a binary tree, see: Neurogrid, a supercomputer which can provide an option for brain simulations.

TrueNorth, a neuromorphic CMOS chip produced by IBM, which has 4096 cores in the current chip, each can simulate 256 programmable silicon "neurons", giving a total of over a million neurons.

Further readings: Neuromorphic engineering, Vision processing unit, AI accelerators

As a side note, you can always use an FPGA based piece of hardware which you can implement selected genetic algorithm (GA) directly in hardware. For example the CoDi model was implemented in the FPGA based CAM-Brain Machine (CBM)2001.


If Deep Learning is non convex, then why use convex loss?

Well, you are definitely mixing two different things. Here are those bits:

The function that deep learning approximates is basically a function that best fits the INPUT DATA points. You should not think about its differentiability or optimization aspects. We don't care what type of function it is; we just want the best fit of input data (ofcourse overfitting is not desired though). So, the space in which this fucntion lies has dimensions equal to the dimensions of input data (or number of input features). For every function fit we get some loss which basically is the distance from actual data point from the one predicted by the function fitted.
Loss function is the one which is defined in terms weights and biases. You can think the space in which loss function lies has dimensions equal to the number of PARAMETERS to tune (weights and biases). So, this space is very different from the one described in the first point. Now, here we do care about the differentiability of the function because we want a point where the function outputs least value (minimize the loss) given some particular values of inputs (weights and biases in this case) and by differentiating we can traverse to that "optimal" point in the function.

Hope this clears your doubt.


Existing programs that find out words with same meanings

Let us simplify case 1 of the question: assume two files, first one with numbers written in indo-arabic numeral system (i.e. 123, 9, 186754, ...), second one in roman numeral system (XX, LCVI, IX, ...). How do you match pairs of symbols with same meaning ?

Without external information or assumptions, you can not. You could made the hypothesis that probability of one specific number is the same in both examples, and base your pairing on it. But then you need to find two input files that fulfills this condition.


Why don't we use auto-encoders instead of GANs?

In fact, autoencoders are used for generative tasks. Have a look at Tutorial on Variational Autoencoders (VAEs).
The coolest thing about VAE is that abstract features can be easily amplified or suppressed based on extracted vectors from the latent space. Let's imagine a model trained on MNIST to generate digits. If you take two images of the same digit which only vary in thickness, encode both of them and subtract the two vectors, the resulting vector will be a description of thickness in the latent space. Now you can generate an arbitrary digit and incrementally adjust its thickness based on that vector.


Can Reinforcement Learning be used to generate sequences?

One renowned example for the specified case is SeqGAN

Modeling the data generator as a stochastic policy in reinforcement learning (RL), SeqGAN bypasses the generator differentiation problem by directly performing gradient policy update. The RL reward signal comes from the GAN discriminator judged on a complete sequence, and is passed back to the intermediate state-action steps using Monte Carlo search. Extensive experiments on synthetic data and real-world tasks demonstrate significant improvements over strong baselines.


Should I call the error "validation error" or "test error" during cross validation?

The expression "validation error vs training error" is likely more appropriate because the data you use during cross validation that is not the training data is often considered the validation data.

The test data is the data you use to test your model after having performed e.g. cross-validation. The test dataset should be independent of both the training and validation datasets.

This is just a convention, and some people use the terms "validation data" and "test data" interchangeably, because, in a way, during cross-validation you are also "testing" (or, to disambiguate, "validating") the model.

See also this answer: https://stats.stackexchange.com/a/401702/82135.


How does the initialization of the value function and definition of the reward function affect the performance of the RL agent?

There seem to be two different ideas in this question here:

What's the impact / importance of our choice for reward values?
What's the impact / importance of our choice for initial value estimates (how do we initialise our table of $Q(s, a)$ values in the case of a simple, tabular RL algorithm like Sarsa or $Q$-learning)?

The reward values are typically assumed to be a part of the problem definition - something we shouldn't modify if we're using an existing problem definition as a benchmark. But if we're in charge of defining the problem ourselves, we can of course also pick the reward values. Modifying them may indeed have a huge impact on the speed with which RL algorithms are able to learn a task - but it may also intrinsically changes the task, it changes the objective of the problem, it may change which policies are optimal.

As for initialisation of our table of value approximations: by default, we normally assume an all-$0$ initialisation. However, it is a fairly common trick (in tabular RL algorithms, without function approximation) to initialise value estimates optimistically; pick higher initial $Q(s, a)$ value estimates than are likely (or even pick values higher than a known upper bound on what the true value possibly could be). This is often beneficial - also in large gridworlds with sparse rewards (e.g. a single distant goal somewhere) and negative rewards (i.e. costs) incurred for every step taken - because it incentivises exploration of state-action pairs that have not yet been tried.

Suppose you have your gridworld with negative rewards associated with every time step, and the optimal policy being one that takes you to a distant goal as soon as possible. If all $Q(s, a)$ are initialised to $0$ (or worse, to negative values), your agent may quickly learn that everything it does is equally bad anyway, and get stuck near the starting position. If all $Q(s, a)$ values are initialised optimistically (to large, positive values), your agent during the learning process will still have optimistic expectations of what it can achieve if it just tries to navigate to unexplored parts of the state-action space.


Can two admissable heuristics not dominate each other?

This is possible. Admissibility only asserts that the heuristic will never overestimate the true cost. With that being said, it is possible for one heuristic in some cases to do better than another and vice-versa. Think of it as a game of rock paper scissors.

Specifically, you may find that sometimes $h_1 < h_2$ and in other times $h_2 < h_1$, where $h_1$ and $h_2$ are admissible heuristics. Thus, by definition, neither strictly dominates the other.

In fact, there is a way to "combine" the two admissible heuristics to get the best of both using:

$$h_3 = \max(h_1, h_2)$$


How to compute the action probabilities with Thompson sampling in deep Q-learning?

So, how can I calculate $\mu(a)$ when using Thompson Sampling based on dropout?

The only way I could see this being calculated is if you iterate over all possible dropout combinations, or as an approximation sample say 100 or 1000 actions with different dropout, to get a rough distribution.
I don't think this is feasible for practical reasons (the agent will learn so much more slowly due to these calculations, you may as well abandon Thompson Sampling and use epsilon-greedy), and you will have to avoid using importance sampling if you also want to use action-selection techniques where there is no easy way to calculate a distribution.
Many forms of Q-learning do not use importance sampling. These typically just reset eligibility traces if the selected action is different from maximising action.


What are the rules behind vector product in gradient?

It helps to think of each output dimension separately.
You have $X$ which is an $(2 \times 1)$ vector, and $W_1$ is a $(1 \times 2 )$ vector. Their product is a scalar, of which we then take the sigmoid to get our output $Y_1$.
The gradient of this w.r.t. $W_1$ will be $f(WX) (1 - f(WX)) X^T$, which has the appropriate dimensions.
Then, you just stack these for all your outputs, giving you the shape you got.


Should batch-normalization/dropout/activation-function layers be used after the last fully connected layer?

No, the activation of the output layer should instead be tailored to the labels you're trying to predict. The network prediction can be seen as a distribution, for example a categorical for classification or a Gaussian (or something more flexible) for regression. The output of your network should predict the sufficient statistics of this distribution. For example, a softmax activation on the last layer ensures that the outputs are positive and sum up to one, as you would expect for a categorical distribution. When you predict a Gaussian with mean and variance, you don't need an activation for the mean but the variance has to be positive, so you could use exp as activation for that part of the output.


Can fully connected layers be used for feature detection?

First of all, (FC) Neural Networks (NN) are universal function approximators. This means, that, in theory, there must exist some NN of appropriate size that is capable of doing what a CNN can do as well. The only difference is that the standard NN would have to be considerably larger than a corresponding CNN with the same capabilities. Each input pixel would probably have to map to a few dozens to hundreds of input nodes that are trained each on detecting some part of a distinct feature in their respective input image location. Consecutive, hidden layers than have to combine the parts extracted by the input layer for any given location and finally act as the true feature detectors, detecting features as compositions of values in the first layer.
So, for each position in the input image separately, all the filters have to be learned separately. This absence of weight sharing (since filters are not shared across input locations, but have to be trained for each separate input location) makes using a standard NN for feature extraction so inefficient.
However, in theory, also a standard NN could be trained on solving an image classification task, thereby learning to extract features. Actually, I would not be surprised if someone had tested that already on the MNIST dataset.


How to shape the weights or nodes during gradient training of neural network? Training with constraints?

I have a somewhat similar problem, there's this paper that I was supposed to extend (I can explain how): https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-017-1984-2
What they do is that they have a connection network between input and second layer (giving some biological context to training) I don't know how you can maintain the zero edges during back propagation though.


Zilberstein's "LP-dominate" pruning explained?

I think I found the solution. When in PR(W), D=∅, the weight is:

b[i] = 0          for { i | w[i]<max(w) },

and

b[i] = 1.0/max(w) for { i | w[i]==max(w) }.


What is the difference between game theory and machine learning?

These are big areas, so here is a brief description of the differences:

Game theory is concerned with studying solutions for 'games', which are basically a set of decisions leading to certain outcomes. In game theory you look at strategies to achieve the best outcome for a given participant. One classic example (which isn't really a game in the traditional sense) is the Prisoner's Dilemma: you and your friend have been arrested, and if only one of you testifies against the other, that person gets a reduced sentence, and the other one a much longer one. If you both testify against each other, you both get a medium sentence, and if you both keep quiet, you both go free. You don't know what your partner in crime does, so do you a) testify, or b) keep quiet? If you keep quiet, you might go free if your partner also keeps quiet, but if he testifies, you are in it for a long time. So it's risky to keep quiet, even though you get the better outcome. If you testify you might avoid a longer sentence, but also will not go free. What is your best choice?

Game theory is often used in economics to model behaviour, as a rational agent would try to optimise gains.

Machine Learning, on the other hand, is a way of training a statistical classifier. You feed features into an algorithm, and the algorithm then gives you a certain output, depending on the data you have trained it with. This hasn't got anything to do with game theory per se, but I guess you could use machine learning to train an algorithm to choose moves in a game situation and then compare how that matches the optimal choices according to game theory.

As I said, this is a very brief comparison. For more details I suggest you follow the links to read up on those two fields.

UPDATE: Now that the papers are accessible — game theory is indeed used as a benchmark. In the first paper, the rational agent assumption from game theory is being modeled, but without a human expert telling the algorithm what that means. So you learn (using deep learning) what it means to be rational. In the second paper the authors attempt to learn a better algorithm than tit-for-tat, and indeed use game theory as a theoretical framework for comparison/evaluation.


Could AI be used to generate questions from a database input?

One simple approach to consider would be storing each statement as a template made in advance.

Will there be less/more than x goals scored in the match?
Will player score a goal during the match?
...

The system will pick a random statement and will fill the variable fields with some statistically generated data between teamA and teamB; here you have your question.

Example: Will there be less/more than x goals scored in the match?

less/more fragment may be random
x may be the mean of the goals scored considering all the matches between teamA and teamB

Example: Will player score a goal during the match?

player may be a random choice between the top-goalscorer of teamA or teamB


What is a high dimensional state in reinforcement learning?

Usually when people write about having a high-dimensional state space, they are referring to the state space actually used by the algorithm.

  Suppose my state is a high dimensional vector of $N$ length where $N$ is a huge number. Let's say I solve this task using $Q$-learning and I fix my state space to $10$ vectors each of $N$ dimensions. $Q$-learning can easily work with these settings as we need only a table of dimensions $10$ x number of actions.

In this case, I'd argue that the "feature vectors" of length $N$ are quite useless. If there are effectively only $10$ unique states (which may each have a very long feature vector of length $N$)... well, it seems like a bad idea to make use of those long feature vectors, just using the states as identity (i.e. a tabular RL algorithm) is much more efficient. If you end up using a tabular approach, I wouldn't call that a high-dimensional space. If you end up using function approximation with the feature vectors instead, that would be a high-dimensional space (for large $N$).

  Let's also say I have a state space of infinite vectors but each vector is now of length $2$ i.e. very small dimensional vectors. Would it make sense to use DQN in these settings ? Should this state-space be called high dimensional or low dimensional ?

This would typically be referred to as having a low-dimensional state space. Note that I'm saying low-dimensional. The dimensionality of your state space / input space is low, because it's $2$ and that's typically considered to be a low value when talking about dimensionality of input spaces. The state space may still have a large size (that's a different word from dimensionality).

As for whether DQN would make sense in such a setting.. maybe. With such low dimensionality, I'd guess that a linear function approximator would often work just as well (and be much less of a pain to train). But yes, you can use DQN with just 2 input nodes.


What ensemble methods are used in the state-of-the-art models?

In my opinion, it is not because ensemble methods are not good, just the state-of-the-art and Kaggle competitions are two different fields.
Kaggle competitions can be understood as an industry project where the target (accuracy, distance value, etc) is the most important, and they can select some computationally expensive way such as ensemble methods to reach it.
The state-of-the-art models in other ways belong to the research area, where the most important is the contribution for science, you can not just combine a lot of models then call it is the research (and so unfair with some small researcher groups). If you want to contribute something depend on ensemble idea, it should be like this paper.


What kind of neural network architecture do I use to classify images into one hundred thousand classes?

Classification tasks with a large number of classes are usually handled with hierarchical softmax to reduce the complexity of the final layer. This is useful, for example, in applications such as word embedding where you have hundreds of thousands of classes (words), like in your case.


How can a reinforcement learning agent generalize if it is trained against only one opponent?

Reinforcement Learning (RL) at its core does not have anything directly to say about adversarial environments, such as board games. That means in a purely RL set up, it is not really possible to talk about the "strength" of a player.

Instead, RL is about solving consistent environments, and that consistency requirement extends to any opponents or adversarial components. Note that consistency is not the same as determinism - RL theory copes well with opponents that effectively make random decisions, provided the distribution of those decisions does not change based on something the RL agent cannot know.

Provided an opponent plays consistently, RL can learn to optimise against that opponent. This does not directly relate to the "strength" of an opponent, although usually strong opponents present a more challenging environment to learn overall.

  Wouldn't the agent (after learning) be able to play only with that opponent and win? since it estimated the value function of this specific behavior only.

If the RL has enough practice and time to optimise against the opponent, then yes the value function (and any policy based on it) would be specific to that opponent. Assuming, the opponent did not play flawlessly, then the RL would learn to play such it would win as often as possible against the opponent.

When playing against other opponents, the success of the RL agent will depend on how similar the new opponent was to the original that it trained against.

  would it be able to play as good with weaker players?

As stated above, there is not really a concept of "stronger" or "weaker" in RL. It depends on the game, and how general the knowledge is that strong players require in order to win.

In theory you could construct a game, or deliberately play strongly, but with certain flaws, so that RL would play very much to counter one play style, and would fail against another player that did not have the same flaws.

It is difficult to measure this effect, because human players learn from their mistakes too, and are unlikely to repeat the exact same game time after time, but with small variations at key stages. Humans do not make consistent enough opponents, and individual humans do not play enough games at each stage of their ability to study fine-grained statistics of their effective policies.

In practice it seems likely that the effect of weakening against new players would be there in RL, due to sampling error if nothing else. However, it seems that the "strength" of players as we measure them in any game of skill such as chess or go, does correlate with a generalised ability. In part this is backed up by consistent results with human players and Elo ratings.

Any game where you can form "rings" of winning players:

Player B consistently beats Player A
Player C consistently beats Player B
Player A consistently beats Player C

Could cause issues of the type you are concerned about when applying RL to optimise an artificial agent.

  How do you develop an agent that can estimate a value function that generalizes against any behavior and win?

If is possible to play perfectly, then a value function which estimated for perfect play would work. No player could beat it. Think of Tic Tac Toe - it is relatively easy to construct perfect play value functions for it.

This is not achievable in practice in more complex games. To address this, and improve the quality of its decisions, what AlphaGo does is common to many game-playing systems, using RL or not. It performs a look-ahead search of positions. The value function is used to guide this. The end result of the search is essentially a more accurate value function, but only for the current set of choices - the search focuses lots of computation on a tiny subset of all possible game states.

One important detail here is that this focus applies at run time whilst playing against any new opponent. This does not 100% address your concerns about differing opponents (it could still miss a future move by a different enough opponent when searching). But it does help mitigate smaller statistical differences between different opponents.

This search tree is such a powerful technique that for many successful game playing algorithms, it is possible to start with an inaccurate value function, or expert heuristics instead, which are fixed and general against all players equally. IBM's Deep Blue is an example of using heuristics.

  self-play?  if yes, how does that work?

Self-play appears to help. Especially in games which have theoretical optimal play, value functions will progress towards assessing this optimal policy, forming better estimates of state value with enough training. This can give a better starting point than expert heuristics when searching.


What is the difference between applying shallow-learning methods repeatedly and deep learning?

Quite surprising to find someone reading this same book. I read this part a week ago and the explanation is quite clear in the book :

If you use successive shallow learning methods, you first train one model, then you train another model with the outputs of your first model, and then a third with the outputs of your 2nd model. The problem with that is that each model is trained to get good results at his task, not to send information, so there can be an increase when adding successive models, but it is a very weak increase.
If you use deep learning, all the layers are trained at the same time, so each layer learns how to efficiently transfer important information to the next layer of the model. This is why it is much more efficient.

Hope I made it clearer


Can intelligent agents have personalities and emotions?

It can depend on how you define "emotion" and "personality":

Personality

Wikipedia defines personality as "the characteristic set of behaviors, cognitions, and emotional patterns that evolve from biological and environmental factors."  (This is a serviceable definition we can use.)
Since intelligent agents make decisions (take actions), it is safe to say they have a set of behaviors.  Cognition is easy here as well--regardless of the structure of the algorithm, we can say it utilizes a logical process that serves the function of cognition.
Emotion is more difficult.

Emotions

How exactly human emotions work is still partly obscure, and it seems to be a safe bet that chemicals are involved.  But, in a reductionist sense, going back to Ancient Greek Philosophy, we can use a binary "love/hate" (attraction/repulsion) and apply it generally, where these feelings are the prime motivators of natural forces:

And Hesiod says, “First of all things was Chaos made, and then/Broad-bosomed Earth . . . and Love, the foremost of immortal beings,” thus implying that there must be in the world some cause to move things and combine them.
Aristotle (Metaphysics 1.984b)

The real issue comes with interpretations of emotion that involve consciousness, such as on Wikipedia, but even the wiki immediately issues the disclaimer: "Scientific discourse has drifted to other meanings and there is no consensus on a definition," so it may be more useful to look to definitions rooted in cognition and the presumed utility of emotions from an evolutionary standpoint.
If reinforcement learning is being used, an automata can be said to like/dislike (love/hate) certain outcomes, which can be expressed via methods such as reward functions.
Certainly this is not emotion as we humans understand it, but it can be seen as an analog. (Regarding humans chemical response to entities/objects and events/outcomes as reinforce future decisions.)
ANSWER:
In no way do contemporary bots and agents have personalities and emotions in the sense of humans--we are probably still very from this and don't know if it's even possible. It may never be possible validate artificial consciousness, regardless of how conscious a system appears to be.
But, depending on how we define these terms "personality" and "emotion", we can choose to regard automata as having some reduced form of analogous qualities and functions.
Example: If I engineer a game AI to have certain tendencies and behaviors (high-risk-tolerance, partisan, aggressive) that are distinct from other agents (low-risk-tolerance, cooperative, defensive), such agents are commonly referred to as having personalities.
Example: We actually do use terms like "goodness/badness" and informally refer to the automata as "liking" or "not liking" nodes in a graph.  This is a function of anthropomorphization.  (Whether you consider these more than analogies depends on the definitions of feelings, but, generally, there needs to be something to feel. So you also need to reduce consciousness/awareness to the most basic requirement of simply "receiving of input".)


Deep Ranking/Best way to classify book covers?

I read some papers talked about it you can take a look on them maybe help you.

Deep Neural Network Learns to Judge Books by Their Covers

Classification of Book Genres By Cover and Title


What is the next state for a two-player board game?

If your opponent has fixed knowledge (it doesn't learn), then the next state after your agent did an action is the state when your turn is back. So the actions of other players are considered as an environment reaction to your actions.

But if your opponent can learn, you may create a Multi-agent Reinforcement Learning


Unable to understand the second iteration update in value iteration algorithm for solving MDP

First thing to know is that, in this case, values for the gridworld in new iteration are completely calculated with respect to the old values from the previous iteration. Value of $0.78$ is got like this:

$0.9 \cdot (0.8 \cdot 1 + 0.1 \cdot 0.72 + 0.1 \cdot 0) = 0.7848 \approx 0.78$

term $0.8 \cdot 1$ is for going to the right with probability of $0.8$ and getting reward of $1$.

term $0.1 \cdot 0.72$ is for going up with probability of $0.1$, we hit the wall and stay in the same field which value is $0.72$ (from previous iteration)

term $0.1 \cdot 0$ is for going down with probability of $0.1$, even though value of that field in the image is $0.43$ we take the value from previous iteration which is $0$.


How does one prove comprehension in machines?

This is one of the most important issues in the philosophy of artificial intelligence.

The most famous philosophical argument that attempts to address this issue is the Chinese Room argument published by the philosopher John Searle in 1980.

The argument is quite simple. Suppose that you are inside a room and you need to communicate (in a written form) with people outside the room in a certain language that you do not understand (in the particular example given by Searle, Chinese), but you are given the rules to manipulate the characters of this language (for a given input, you have the rules to produce the correct output). If you follow these rules, to the people outside the room, it will seem as if you understand this language, but you don't.

To be more concrete, when I say "apple", you understand that it refers to a specific fruit because you have eaten apples and you have a model of the world. That's understanding, according to Searle.

The most famous mathematical model of computers, the Turing machine, is essentially a system that manipulates symbols, so the Chinese Room argument directly applies to computers.

Many replies or counterarguments to the CR argument have been discussed, such as

the system reply (the symbol manipulator is only a part of the larger system).
the robot reply (the symbol manipulator does not understand the meaning of the symbols because it has not experienced the associated real-world objects, so it suggests that understanding requires a body with sensors and controllers)
the brain simulator reply (the symbol manipulator can actually simulate the activity in the brain of a person that understands the unknown language)

So, can we prove that machines really understand? Even before Searle, Turing had already asked the question "Can machines think?". To prove this, you need a rigorous definition of understanding and thinking that people agree on. However, many people do not want to agree on a definition of intelligence and understanding (hence the many counterarguments to the CR argument). So, if you want to prove that machines understand, you need to provide a proof with respect to a specific definition of understanding. For example, if you think that understanding is just a side effect of symbol manipulation, you can easily prove that machines understand many concepts (it just follows from the definition of a Turing machine). However, even if understanding was just a side effect (what does a side effect actually mean in this case?) of symbol manipulation, would a machine be able to understand the same concepts and in the same way that humans understand? It's harder to answer this question because we really do not know if humans only manipulate symbols in our brains.


Is the Turing test still relevant, as of 2019?

The Turing test is a good test for AI applications like Siri and Alexa (or, in general, intelligent personal assistants), but it doesn't test a lot of features (e.g. vision) that an artificial general intelligence requires. There are several arguments against the Turing test (and it is definitely not flawless), but is it a necessary (but insufficient) test for AGI. The Turing test is still quite relevant: e.g. if IPAs passed the test, people would use them more often and they would be a lot more useful.


Ambiguity in Terms

You are correct that there is something like overloading occurring in tensor terminology in posts and in software libraries. Confusing jargon often appears when those without the mathematical background use mathematical terms. You rarely find this confusion when reading NASA, Cambridge, MIT, or Cal-tech materials.

Tensors, Rank, Dimensions, and Channels

A tensor is a grouping of dimensions. The grouping typically represents a relation between quantities describing a system. The order (or rank) of the tensor is the number of dimensions in the grouping.

When this mathematical idea is applied formally to electrical engineering, chemical systems, biological systems, or computing systems, we can say a tensor is the grouping of the inputs and outputs of that system, abstracting the relation between them. The order (or rank) of the tensor is the total number of signal channels going to or from the system. The rank is simply the number of inputs plus the number of outputs.

That original conception was lost a little when the term tensor began to be applied to grouping inputs in one tensor and grouping outputs in another tensor, without any connection with their relationship, which is not formally correct. Those are simply vectors in mathematics, represented by arrays in computer programs.

A labelled data set prepared for machine learning is a discrete tensor formally, however it does not have a mathematical model applied to it yet. When convergence occurs in an artificial network, the result of training is a set of parameters that, if later applied to new inputs, will predict the outputs based on the net and its trained parameters. The configuration of the network cells had become the model and the trained network had become a tensor expression approximating the phenomenon that the training data represents.

The Specific Example in the Question

A third order tensor cannot have only two dimensions, width and height. It must have three dimensions, possibly width, height, and instantaneous value. Width and height are the independent variables, and instantaneous value is the dependent variable. So we have a rank of $1 + 2 = 3$.

There is no clear and formal definition of what dimensionality means, so it would be useful to discontinue its use until academic textbooks contain a consistent definition, but that's unlikely to occur. It will likely continue to be used by non-mathematicians somewhat arbitrarily. Therefore, stating that two tensors are of equal dimensionality remains ambiguous.

Domain and Range

The correct terms are domain and range. These terms unambiguously describe the variability of the independent and dependent variables of a relation respectively. In the case of an array of samples describing a tensor relationship between horizontal position, vertical position, and brightness, the horizontal domain corresponds to the width and the vertical domain corresponds to the height.

Consequently, one would not say, "Width and height are the spacial dimensions," or, "width and height are the channel dimensions."

It could unambiguously be stated, "Width in this article shall refer to the maximum horizontal pixel position minus its minimum plus one." Without saying something that complex, albeit accurate, this would be a clear statement.

  The fourth convolution layer in the network has a domain of 1280, 768 and a range of IEEE 32 bit floats.

It is easily understood and close enough to technically correct to not cause readers with mathematical training to dismiss the writer as uneducated.

The equality question is now solved. The equality of domains could be stated clearly and unambiguously. Whether it sounds unusual is not particularly relevant.

  The horizontal and vertical domains of network layers two and three are equal, both being [1280, 768].

(The reason [1280, 768] is often seen is because compilers of many languages, starting with FORTRAN or maybe even earlier, interpret that as a two dimensional domain for a two dimensional array. So that can be used among software people, although [768, 1280] is more likely used in programs since it is a video tradition to traverse left to right and then top to bottom.)

Misuse of the Term Tensor

It is incorrect to say that adding two arrays is an example of tensors manipulated in software. Tensors are more abstract than arrays. If one were to ...

Make symbolic manipulations to reduce a complex tensor equation to a simple one,
Show that two tensor expressions are equal for given domains, or
Determine the correlation of a set of discrete points to a model represented as a tensor equation,

... then one would be performing tensor mathematics.

There are many pieces of software that perform such symbolic manipulations, but assigning a tensor to an input sample in machine learning is not tensor math. Tensor object classes that are not part of a system of symbolic manipulation are simply an abstraction of the typical programming language's array structure, parameterizing rank in the constructor. Such a trivial abstraction is not nearly as deep as symbolic manipulation of tensor expressions.


Would convolutional NN recognize patterns in encoded images?

First you should give it a try, because anyone's guess could be off, as there isn't really a complete high level analytic model of how neural networks behave on real data. Most results with neural networks are informed by theory, but involve a whole lot of experimental testing.

I suspect your network might at least learn something from the new images, but would struggle to get anything like the same accuracy as without the noise, because the CNN filters rely on being able to detect similar features at different positions. In your scrambled image, there will not be any meaningful and consistent edges/corners etc that a single learned feature detector could learn to match (and therefore present to the next layer).

A fully-connected network would not have this limitation, and would learn just as well on a set of binary features that have been xor'd identically in each position for each example, as it did on the original copy (i.e. only if the picture was 1 bit depth). It would learn less well if each feature was a scaled 8-bit pixel value that was xor'd with the same 8 bit random number in each pixel position, because that would introduce many more non-linear mappings between input and output. Of course a fully-connected network will generally not learn image tasks as well as CNNs in the first place . . . but if it could learn anything useful at all for your image problem, then it will probably out-perform CNNs after the scrambling effect.

As a CNN usually has a few fully-connected layers, then it may be possible to get something from your scrambled images.

  Thinking logically, the features still exist in the same relation to each other, just in a different form (encoded)

In terms of being recognisable in the way that a CNN filter extracts them, then the features do not exist. That is a problem.


Is a good evaluation function as good as any of the extensions of alpha-beta pruning?

To build on Neil's answer a bit, you're right that the better your evaluation function gets, the less work your optimization function will need to perform. If your evaluation function gets good enough, you won't need to search at all.

This is not just an academic idea though! It's actually fairly widely used, and has been key to solving several games.

The first example I'm aware of is Tesauro's TD-Gammon player, from 1995. Tesauro used the ideas of reinforcement learning and self-play to train a Neural Network to act as an evaluation function. TD-Gammon played with just a 2-move lookahead using the best evaluation function that was found, and was deemed better than most (all?) human expert players at the time.

More recently, AlphaGo Zero used similar techniques to solve Go, but learning both an evaluation function and (separately) a function to randomize over possible moves.


Should I apply image processing techniques to the inputs of convolution networks?

The whole interest of using deep learning-based solutions is that you don't have to do all those pre-processings, i.e. binarization, segmentation of background. CNNs, such as YOLO or FasterRCNN, can learn how to retrieve that information by themselves.


How are kernel's input values initialized in a CNN network?

The kernels are usually initialized at a seemingly arbitrary value and then you would use a gradient descent optimizer to optimize the values so that the kernels solve your problem.

There are many different initialization strategies.

Set all values to 1 or 0 or another constant
Sample from a distribution, such as a normal or uniform distribution
There are also some heuristic methods that seem to work very well in practice, a popular one is the so-called glorot initializer named after Xavier Glorot who introduced them here. Glorot initializers also sample from a distribution but truncate the values based on the kernel complexity.
For specific types of kernels, there are other defaults that seem to perform well. See for example this paper.

Exploring initialization strategies is something I do when my model is not able to converge (gradient problems) or when the training seems to be stuck for a long time before the loss function starts to decrease. These are signs that there might be a better initialization strategy to look for.


Why the cost/loss starts to increase for some iterations during the training phase?

In general, there's nothing wrong with training loss to increase from time-to-time during training.
This is because GD with minibatch is a stochastic process and doesn't guarantee that the loss will decrease at each step.


Is there a way that helps me to architect my CNN fundamentally before training?

See Analysis and Optimization of Convolutional Neural Network Architectures (my master's thesis).

  Is there a way that helps me to architect my model fundamentally before training?

Yes, but the architecture learning approaches are computationally intensive. When I wrote my masters thesis it was ~250,000 USD to run the Google experiment. Meanwhile, there seem to be more efficient methods, e.g. https://autokeras.com/

See Chapter 3.

  Once I train model how do I know which among these variables (number of filters, size, number of convolutional layers, FC layers) should be changed - increased or decreased?

See Chapter 2.5 for some approaches. But there is no silver bullet / no clear answer to this question.


Can we code rules for an agent in python language other than predicate calculus?

You could formulate the problem of predicting disease severity as a classification one, you give the algorithm those 900 attributes and their corresponding labels (severe/not severe) after training, you give it a new data point with just the 900 attributes, it returns the correct label severe or not.

There is an enormous number of algorithms in the ML literature for classification, some of them formulate the problem explicitly as learnable rules, i.e. let the machine figure out the rules given the attributes.

Classification and Regression Trees by Breiman et al (1984)
Random forest by Ho in 1995
XGBoost


How do I convert table-based to neural network-based Q-learning?

A neural network (NN) is a "function approximator", that is, it is a model that can be used to approximate functions. In fact, a neural network with at least one hidden layer is a "universal" function approximator (that is, it can approximate any function).

In mathematics, a function $f$ is usually represented as a mapping of the form $f: D \rightarrow C$, where $D$ and $C$ are respectively the domain (inputs) and codomain (outputs) of $f$, and $\rightarrow$ means that $f$ "maps" $D$ to $C$. A NN (with at least one hidden layer) can thus approximate any function $f$ of this form.

In your context, the $Q$ table is a function: it is a mapping between states and actions (inputs) and Q values (outputs), which are the "expected future cumulative reward" (that you will obtain if you take a certain action from a certain state and then continue to follow the same policy). The Q function can thus more formally be denoted by $Q: (S, A) \rightarrow \mathcal{R}$, where $S$ is the "space of states" and $A$ is the "space of actions" in your problem. Initially, your Q table does not contain the correct (optimal) values. However, after training (or learning), hopefully, your Q table will be an approximation to the optimal Q function for your specific problem.

How do you then represent this table using a NN? What should be the inputs and outputs of the NN?

Let's suppose that your $Q$ table is implemented as matrix $M$. Then $M[s, a]$ is the $Q$ value for the state $s$ and action $a$. So, in this case, the combination of $s$ and $a$ is the input, whereas $M[s, a]$ is the output of your $Q$ function.

To represent this table as a NN, you can thus have as input of the NN the state and action, and as output the $Q$ value. You will then train the NN (using e.g. back-propagation) to learn the $Q(s, a)$, given a state $s$ and an action $a$ as input, for all $s \in \mathcal{S}$ and $a \in \mathcal{A}$. So, during your $Q$-learning algorithm, instead of using $M[s, a]$ to represent $Q(s, a)$, you will simply use the current output of your neural network.

Note that, in practice, I think, you will likely encounter problems while training the NN, if you update the weights of your NN at every time step (because e.g. NNs do not cope well with correlated data, and, in general, the "experience" data you will obtain from time step to time step will be highly correlated). Anyway, this is the basic idea of how to use a NN to represent a $Q$ function. There are other ways, but this is the simplest one, at least, conceptually.


What is the best measurement for how good an action of a reinforcement learning agent really is?

Are there ways to more precisely approximate how good a single action really is considering its short and long term effects?

To understand the short-term effects of an action, just take each of the available actions from the current state and observe the reward for each of them. The action that gives you the highest immediate reward is the best action. However, note that the reward function may change or could be stochastic. In those cases, you may need to estimate the best action e.g. by executing it multiple times.

If you want to know the action that gives you the highest amount of reward in the long run (i.e. that gives you the highest return), then you can use one of the available RL algorithms, which were invented exactly to solve this problem. Basically, you're asking us what is the best RL algorithm. It depends on the problem, as usual.

If you want to know the effects of an action in e.g. $n$ steps ahead, then you can probably formulate this problem as a truncated version of the typical reinforcement learning problem. In practice, you probably can achieve this by changing the discount factor so that the next $n$ rewards are more valuable (or are the only ones considered) than the rewards after $n$ steps. If you aren't familiar with discount factors, I encourage you to have a look at this concept from a reference book.

Note that, in this answer, I am just trying to give you the idea and intuition behind a possible answer to your question (also because your question isn't really suited to provide more detailed or rigorous answers).


If $\alpha$ decreases over time, why is Q-learning guaranteed to converge?

Why is this a convergence criterion?

It is because $R$ and $S'$ are stochastic. A large learning rate applied when these values have variance would not converge to mean, but would wander around typically within some value proportional to $\alpha\sigma$ of the true value, where $\sigma$ is the standard deviation of the term $R + \gamma\text{max}_aQ(S',a)$. If you reduce $\alpha$ towards zero, then this expected error will also reduce to zero.
For deterministic environments, it should be possible to prove convergence with large $\alpha$.

In the special case of static policy, tabular learning and $\alpha = \frac{1}{N(s,a)}$ where $N(s,a)$ is number of visits to state $s$, action $a$, then the expected error for each Q value is the MSE from basic stats i.e. $\frac{\sigma_{TD}}{\sqrt{N(s,a)}}$


Would YOLO be able to detect objects in "different" positions?

As you said, a CNN would be able to detect objects in different positions if the dataset contains enough examples of such cases, though the network is able to generalize and should be able to detect objects in slightly changed positions and orientations.
The term "translation invariance" does not mean that translating an object in the image would yield the same output for this object, but that translating the whole image would yield the same result. So the relative position of object IS important, modern CNN's takes decisions on the whole image (with strong local cues, of course).
To maximize the ability of your CNN to detect multiple orientation, you can train with data augmentation that rotate the images.
the same reasoning can be applied to partial occlusions: if there are enough samples with occlusion in the training set the network should be able to detect those ones. The network ability to generalize should also help a little when occlusions are small, and still be able to detect the object.
Some papers tried different experiment to demonstrate the robustness to occlusion and translation, for instance by looking at the network activation when artificially occluding a portion of the image with a gray rectangle, though I do not have a paper name in mind.


What are the differences between Q-Learning and A*?

Q-learning and A* can both be viewed as search algorithms, but, apart from that, they are not very similar.
Q-learning is a reinforcement learning algorithm, i.e. an algorithm that attempts to find a policy or, more precisely, value function (from which the policy can be derived) by taking stochastic moves (or actions) with some policy (which is different from the policy you want to learn), such as the $\epsilon$-greedy policy, given the current estimate of the value function. Q-learning is a numerical (and stochastic optimization) algorithm that can be shown to converge to the optimal solution in the tabular case (but it does not necessarily converge when you use a function approximator, such as a neural network, to represent the value function). Q-learning can be viewed as a search algorithm, where the solutions are value functions (or policies) and the search space is some space of value functions (or policies).
On the other hand, A* is a general search algorithm that can be applied to any search problem where the search space can be represented as a graph, where nodes are positions (or locations) and the edges are the weights (or costs) between these positions. A* is an informed search algorithm, given that you can use an (informed) heuristic to guide the search, i.e. you can use domain knowledge to guide the search. A* is a best-first search (BFS) algorithm, which is a family of search algorithms that explore the search space by following the next best location according to some objective function, which varies depending on the specific BFS algorithm. For example, in the case of A*, the objective function is $f(n) = h(n) + g(n)$, where $n$ is a node, $h$ the heuristic function and $g$ the function that calculates the cost of the path from the starting node to $n$. A* is also known to be optimal (provided that the heuristic function is admissible)


Context of the question
This is a link to the text cited in the question.
It refers to the usage of SeparableConv2D (tf, keras name). A related question on StackOverflow is "What is the difference between SeparableConv2D and Conv2D layers". This answer points to this excellent article by Chi-Feng Wang:
A Basic Introduction to Separable Convolutions
Answer to the question
In image processing, a separable convolution converts a NxM convolution to two convolutions with kernels Nx1 and 1xM. Using this idea, in NN a SeparableConv2D converts a WxHxD convolution (width x height x depth, where depth means number of incoming features ) to two convolutions with kernels WxHx1 and 1x1xD.
Note the first kernel doesn't handles information across features, thus, it is "learning of spatial features". The 1x1xD kernel doesn't handles different points, it is "learning of channel-wise features".
About the phrase "spatial locations in the input are highly correlated", my understanding of what the author means is: Assume we have a channel (feature) image that each pixel measures the "distance to the background". When we pass from one pixel to a neighbors one, it is expected some continuity in the value (except for edge pixels): correlation. Instead, if we have a channel that measures "brightness" and another one that measures "distance to background" the two values for one specific pixel has little correlation.
Finally, about title question "When should we use separable convolution?" : if the final output must depend of some features of one pixel and some other features of neighbors pixels in a very unpredictable way, a complete WxHxD convolution must be used. However if, as is more usual, you can handle first spatial dependencies (neighborhood) to extract pixel features and next handle pixel-by-pixel these features to get the output, better use a WxHx1 followed by 1x1xD, saving lots of network parameters, thus, saving training time.


Transformers: How to use the target mask properly?

The main issue during training is that you haven't right-shifted the input of the decoder, which is probably why you set the diagonals of mask to -inf (when it should be $0$).
Also, just an FYI, although you haven't focused on evaluation/prediction yet, I will explain the evaluation/prediction here as well for completeness, since it works so differently than training, and also since you will need it when generating the graphs for debugging.
Training
Both tgt and tgt_mask should be changed to simulate auto-regressive properties.
You are feeding in tgt as the input to the decoder, where tgt is the ground truth target sequence to predict. tgt should have dimension length(sequence) x batchSize x $\|dict\|$. Additionally, you are feeding in mask where the diagonals are -inf.
Instead, you should do the following:

Add 2 new special tokens to your vocabulary that signals the start and end of decoding, i.e. <START> and <END>. So your vocabulary will need to be extended to 16 events.
Every input to the decoder (training, evaluation, prediciton) should have <START> as the first token. So during training, when you want to feed in tgt to the decoder, you should right-shift tgt by adding in the <START> token at the beginning.

tgt_shifted will now be of dimension length(sequence)+1 x batchSize x $\| dict \|$
tgt_shifted_mask will now be of dimension length(sequence)+1 x length(sequence)+1. Diagonal should be all $0$
the inputs to the decoder should be tgt_shifted, tgt_shifted_mask, and memory
the output of the decoder will have dimension length(sequence)+1 x batchSize x $\| dict\|$, and will not be right-shifted because it will not have <START> as the first word. But it should have <END> as the last word.
Append <END> to the ground truth tgt, and turn it into one-hot encoding, so tgt should have dimension length(sequence)+1 x batchSize x $\|dict\|$. Your loss operator should be some sort of element-wise comparison between tgt and the output of the decoder.

Note that you only run the decoder once per training batch during training, i.e. the decoder simultaneously predicts the logits of all length(sequence) tokens at the same time. On the other hand, during evaluation/prediction, you must run the decoder length(sequence) times, since you can only use the decoder to predict one token at a time.
Evaluation/Prediction
During evaluation/prediction, the model should generate its own sentence entirely from scratch, one word at a time:

out should be initialized as a single token, <START>, and have dimensions $1$  x batchSize x $\|dict\|$.
Do the following in a loop until termination or max output length is reached:

Generate a out_mask for the current version of out. out_mask should be a matrix with dimension length(out) x length(out). Diagonal should be all $0$
Pass out, out_mask, and memory into the decoder layer. The output of the decoder will be a length(out) x batchSize x $d_{model}$ tensor (note that in your case, $d_{model} = \|dict\|$), which indicates tokenIdx x batchIdx x vocabularyIdx
Convert the last time step (e.g. decoderOutput[-1,:,:] if all sequences in your batch have the same length) into probabilities, and take all the events that surpasses some probability threshold and set them to $1$. Set all other events to $0$. This is the new time step that the decoder layer predicts. So add this time step to out to append it's length by $1$.
Repeat the previous 3 steps in a loop until you reach the <END> token, which signals the end of decoding, or until the max output length is reached.

During evaluation, you can calculate the validation loss by using the logits of only the final iteration of the decoder (which should have dimension length(sequence)+1 x batchSize x $\|dict\|$), and compare those logits with the ground truth with the <END> token added at the end (resulting in dimensions length(sequence)+1 x batchSize x $\|dict\|$).