text:
How can I stabilise a recurrent neural network used for binary classification?
I’m looking for some help with my neural network. I’m working on a binary classification on a recurrent neural network that predicts stock movements (up and down) Let’s say I’m studying Eur/Usd, I’m using all the data from 2000 to 2017 to train et I’m trying to predict every day of 2018.
The issue I’m dealing with right now is that my program is giving me different answers every time I run it even without changing anything and I don’t understand why?
The accuracy during the train from 2000 to 2017 is around 95% but I’ve noticed another issue. When I train it with 1 new data every day in 2018, I thought 2 epochs was enough, like if it doesn’t find the right answer the first time, then it knows what the answer is since the problem is binary, but apparently that doesn’t work.
Do you guys have any suggestion to stabilize my NN?

do you think stock movements is a mathematical function?

I’m obviously not gonna get 80% of accuracy, and that’s not my goal anyway, I’m just trying to stabilise the prediction for now

Firstly, dealing with the issue that the program gives different answers every time without making any changes can be due to a couple of things.

Assigning random values to weights and bias. This can be solved by setting a seed manually at the start of the program.
Make sure you have set the model to the testing mode after training. For some frameworks, this has to be done manually.

Secondly, regarding your expected results.
To generate a proper accuracy metric, you will have to sample your dataset into training and testing data, making sure there is now overlap between them. This might be an issue as you have stated training on data till 2017 and then again training on data of 2018.
Lastly, don't expect that the model will know that the output is wrong and directly change it because it's binary classification. This is not how neural networks work. The model fits the solution better by gradually updating its weights and biases over a number of iterations. So it will take a number of epochs to learn new trends in the data for 2018.

I thought about the random weights but I don't think that's the problem here, let me explain :
I ran my code 15 times in a row without changing anything with 150 epochs for the big training until 2017, I checked everything on tensorboard and the loss is decreasing going slowly to 0 while the accuracy is increasing going slowly to 1, results are that I get 20% of variation on my correct predictions
Then I ran the same test with only 15 epochs, around 0.55 accuracy and a big loss and I only got around 1% of variation on my correct predictions

I tried 100 epochs for the trainings on 2018's everyday data and still, some of them get 0 accuracy

As you have realized, it's true that the accuracy increases as the model is trained over a number of epochs. This is true till the model starts to overfit.

Regarding the training for 2018 data, the most probable cause of this loss in accuracy is the fact that there is not enough data for the model to train on. In the first case, you have 356 days * 18 years data points, but of 2018 you seem to have only 365 days data points.

Would it be a better idea to train a single NN for every day of 2018 ? So I would have to train « 365 » ?

This may not be directly answering your question, but predicting market movement based on past prices is probably not very sensible.
Assuming that future samples are drawn from the same populations as the past samples basically violates the founations of AIML and statistics quite frankly. See relevant figure below.
As far as accuracy goes, its is all relative. If you have a cpu which is right 0.999 of the time you have a useless piece of silicon, but if you have a 0.501 accuracy on stock market ID then you are the richest man in the world. That said, stock historical data is just not a phenomenon that repeats itself based on its own underlying distribution.

Always remember that when it comes to markets, past performance is not a good predictor of future returns—looking in the rear-view mirror is a bad way to drive. Machine learning, on the other hand, is applicable to datasets where the past is a good predictor of the future.
— Deep learning with python,  Francois Chollet

Rather than an image, can you please copy and paste the relevant section of the book that you want to show or emphasize?

@nbro sorry, unless this is a personal request can you please refer me to relevant SE policy rule on this?

Please, see this, this and this. Essentially, in your case, text is preferable because it improves e.g. the searchability of your post.

Text is preferable to improve the searchability of the post sounds a like a reasonable suggestion for post improvement, will do asap.


text:
How can I use the bottleneck layer of the U-net to calculate the similarity between two images?
I would like to use the bottleneck layer of U-Net (the last layer of the encoder) to calculate the similarity between two images. For that, I have to somehow flatten the last layer of the encoder. In my opinion, there are two approaches:

Take the last layer which in my case is $4 \times 4 \times 16$ and flatten it to 1D
Add a dense before the decoder and then reshape the dense 1D layer into 3D

For the second case, I am not sure how this would affect the network. Arbitrarily reshaping a 1D array into a 3D tensor. Could that introduce weird artifacts? Does someone have experience in a similar problem?

If I understood you correctly it's the same (architecturally). Decoder will reshape dense layer into 3d tensor anyway in U-net

I don't think that's true. In the paper the bottleneck layer is of dimension 30 x 30 x 1024.

Anyway shouldn't be a problem. Dense layer is just 1x1xN convolution layer and however you down/upsample it shouldn't change behavior too much.

I think it only doesn't change things if - when shaped into 3D again - the same pixels  end up in the same spot. Otherwise the spatial information gets lost.

source: Stack Exchange

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

sort: votes


text:
Neural networks when gradient descent is not possible
I am looking for an example in which it is simply impossible to use some sort of gradient descent to train a neural network. Is this available?
I have read quite some papers about gradient-free optimization tools, but they always use it on a network for which you can also use gradient descent. I want to have a situation in which the only option to train the network is by, for example, a genetic algorithm.

What level of example are you looking for? Creating a neural network architecture that cannot be trained using gradient descent is very easy. Describing a problem that requires finding an optimal function, where it is possible to apply a NN, but impossible to use gradients, is a lot harder. It can be the case that using gradients is not as efficient as other methods, but here you are asking for "simply impossible", which is tougher

Ideally I would like to have a neural network design that can be applied to, for example, the MNIST dataset but where gradient descent would not be possible to train the network.

OK, that's easy. Just use a non-linearity somewhere in the network which cannot be usefully differentiated. A step function in the last layer should do it (or in any other layer). It's artificial, and probably lower-performing than the equivalent network with that layer removed. But it should achieve your goals

@DuttaA This is wrong, unless by "basic perceptron learning algorithm" you mean something else. In that case, your terminolgy is at least misleading. The perceptron can and is trained using GD. See e.g. https://stats.stackexchange.com/a/411216/82135.

@DuttaA A perceptron is a neural network with one input layer and one output layer. That's what a perceptron is.

@DuttaA The word perceptron is often used to denote such neural network. If the original paper used a Hebbian rule to learn, it is a different story. There are actually several variants of the perceptron.

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


text:
Will artificial intelligence cause mass unemployment?
Everyone is afraid of losing their job to robots. Will or does artificial intelligence cause mass unemployment?

The nuanced, boring answer is that it depends on your definition of AI. Most people wouldn't say that the rule-based systems designed in the 70's are AI. The amazing leaps in machine learning are almost taken for granted as well (think about how normal speech and facial recognition have become). This is known as the AI effect; when we become accustomed to the technology, it loses it's 'magical aspect' and is thus no longer labelled as AI.
Since AI is so diverse and difficult to define, the question becomes incredibly abstract. Did Siri cause all secretaries to become unemployed? Did TurboTax replace all accountants? Some parts of AI will affect jobs, or even make them redundant yes. On the other hand, it will give rise to new jobs as well. It is therefore impossible to generalize it as 'AI will cause massive unemployment'.
This is not a new phenomenon, however, it has been part of the human economy ever since the industrial revolution (probably even before that, but I am not a historian). The invention of the car crippled the horse-and-wagon industry, but it brought along new jobs as well.

Yes , but you should be happy about it. It is like usage of mashines in industry causes "mass unemployment". Modern tendencies is unfortinatly not like that - industry has not so bit interest in full automatisation cause of huge amout of cheap work force from immigrants - it is a bad factor, not that "ai takes your job".
And further, robot what would take your job must not be realy smart - in could be just some doll without AI just making what is in programm...

Up to a point. Some jobs will IMHO not easily be replaced by robots, others more easily. Some could be, but I hope common sense will prevail and stop that.
Manual jobs: fruit picking, warehouse picking, and cooking are some jobs that need really subtle hand control, and precise handling of fragile items. I think those will be harder to automate than eg car factory robots.
Customer facing roles: receptionists have to do a wide variety of tasks. While some of the tasks might be aided by AI systems, a good PA or receptionist cannot easily be replaced. Also, many people would much rather interact with a fellow human than with a machine, at least in some situations.
Judgments: a lot of jobs require judging a situation, balancing risks, and making 'gut' decisions. While AI systems can do them, I think many would still require human intervention. I for one wouldn't like to be sentenced by a robo-judge, or examined by a robo-doctor. True, humans also make mistakes, but they would hopefully err in less potentially disastrous ways.
Administration: again, many tasks can be assisted, which would lead to a reduction in head count, but a general AI is still off the horizon, so you'd still need humans.
Creative arts: not likely. Would you want to read computer-generated novels, or look at computer-generated paintings?
I could go on... in general: I think AI systems will make a lot of tasks faster and easier, so you need fewer people to do them. Some jobs cannot realistically be done by machines in the near-to-mid future, so overall we need not worry too much.

Yes. Just as the horse lost it's employment as the form of transportation to the car.

When the mechanical loom was invented, people were up in arms. Steam engine, etc. Every new invention makes people think there will be mass-unemployment.


text:
How do I determine whether a truck is inside its lane?
I have a bunch of images from different trucks passing the road. Here is an example.

The truck needs to be at a certain distance from the border of the lane. Some of the trucks are way close to the border (that you can see on the shoulder of the road).
I want to find a way to measure the distance between the truck and the border of the lane and, more importantly, to detect whether a truck is inside its lane.
I would like to solve this problem by training a deep learning-based classifier or image processing techniques. Painting the ground is also possible if I can train a classification algorithm with painted images.

Please, do not remove info from your post that is useful to answer the question. Your last version of the post was missing several details that are needed to understand the problem and provide an answer. I tried to save this question by asking what I think is the most likely question you were asking. Can you please confirm that?

One possible approach will be to use an algorithm which detects lines (Ex. Hough lines or any deep neural net trained to detect lanes) and use some threshold range so that we can get the lane and the edges of truck, then after extracting the lines, you can easily find the distance between them.
Then you need to experiment out on few images to get the threshold distance that you are expecting the truck to maintain as the real distance and the distance calculated using images are not same

If you want to classify using deep learning, you may need to preprocess the images and send them. As it will become very difficult to directly learn to classify
based on image, you may need to first detect the lanes, then apply a mask and then send the masked image to your network to make the network to converge.

thanks for the reply, I tried the Hough lines and circle. HoughCircle detection, for example, it doesn't detect all the wheels and will also detect random circles in the foliage and as you see the wheels projections are ellipses and not circles, what should I do for that? could you pls elaborate on the second method as well?

You can possibly remove the random circles by specifying a threshold area or use contours. I was expecting that hough lines will be able to detect the edges of the truck trailer (which has straight edges) and the lanes, and calculating gap from those.
So, to use deep learning for classification we need lot of data or data which already has some good amount of information that network needs to learn for the task, here the information that network would probably learn is first identifying the lanes and truck, so if we preprocess the image and send those as input the learning process gets easier

where can I find more readings about how to calculate distance? I really need to read about them

I don't think there are direct articles on calculating distances in this kind of situtations. I feel this problem can be solved by applying different concepts. Mostly its about image processing that you need to know after you get the lanes and edges of truck or some boundaries of truck to calculate distances. Book by Richard Szeliski which has almost everything related to computer vision. You may also try out image segmentation and find distances on the output

what programing language do you think would give better results? do you think using image processing would be robust enough for this project? for example, if the truck changes?

Python will be good. Image processing will be used if you want to find distance that to after you get the the lanes and the boundaries of truck. You can use deep learning algorithms to detect the lanes and truck boundaries

If you know the latitude-longitude of the trucks and the center, you can do the following,
Given the latitude-longitude location of the center and the radius in which you want to search the presence of a truck(say R) around center, you can find the latitude-longitude bounds of the space around center within R radius by : Link1
You can find python implementation here:Link2
Once you know the bounds, you can simply check if the truck's location falls within the latitude-longitude bounds.


text:
What is the difference between Knowledge Representation and Automated Reasoning?
Knowledge Representation and Automated Reasoning are two AI subfields which seem to have something to do with reasoning.
However, I can't find any information online about their relationship. Are they synonyms? Is KR a subfield of AR? What's the difference, if any?
To expand further, I believe representing knowledge is an essential part of "reasoning": how can you reason without a proper representation of the concepts you want to manipulate?
At the same time, reasoning seems to be an essential part of KR (we build Knowledge Bases in order to build computer programs which are able to make inferences from them).
So it seems to me that they are the same field, or at least deeply interrelated, but nobody on the internet seems to explicitly say that; furthermore, in this question, they are mentioned separately.
Another point of ambiguity is that the wikipedia page of KRR mentions reasoning and automated reasoning as a part of KR; it even lists "automated theorem proving" (a classical application of AR) as an application of KR.
But at the same time, we have a separate AR page which does not mention KR at all.


text:
Adding BERT embeddings in LSTM embedding layer
I am planning to use BERT embeddings in the LSTM embedding layer instead of the usual Word2vec/Glove Embeddings. What are the possible ways to do that?

do you want the entire bert contextual embedding or just the subword embeddings?

I would need the contextual embeddings.

Instead of using the Embedding() layer directly, you can create a new bertEmbedding() layer and use it instead.
# Sample code
# Model architecture

# Custom BERT layer
bert_output = BertLayer(n_fine_tune_layers=10)(bert_inputs)

# Build the rest of the classifier
dense = tf.keras.layers.Dense(256, activation='relu')(bert_output)
pred = tf.keras.layers.Dense(1, activation='sigmoid')(dense)

model = tf.keras.models.Model(inputs=bert_inputs, outputs=pred)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(...)

This article will walk you through the entire process of creating the custom BERT layer along with example code. Give it a read.


text:
What are the common myths associated with Artificial Intelligence?
What are some interesting myths of Artificial Intelligence and what are the facts behind them?

Hi and welcome to AI Stack Exchange. Sadly this is not a fit to the site format. It would be a great question on a forum, but this is not a forum. If you could re-phrase the question so that it could have an objective single answer, then it would fit. That might work if you asked about a single rumour/myth that you had seen somewhere and wanted to know the truth behind it.

As Artificial Intelligence is rapidly invading in our lives the myths around AI is also fabricating rapidly. Before getting into details one need to get clear off from this myths.
Myth 1: AI will take away our jobs:
Reality: AI is not completely different from other technologies and AI will not take away jobs but AI will change the way we work and helps us to increase the productivity by removing monotonous works.
Myth 2: Artificial intelligence will take over the world:
Reality: AI controlling the world. According to me it will not possible unless we give it that power. AI or robots will assist in our work and helps us to solve some tedious works that are difficult for human to solve easily.
Myth 3: Intelligent machines can learn on their own
Reality: It seems that a Intelligent machine can learn by it own. But the fact is that a AI Engineer or AI specialist should develop the algorithm and feed the machine with datasets and instructions and continuous monitoring should be done and most importantly regular update of software should be done.
Myth 4: Artificial Intelligence, Machine learning and Deep learning all three are same:
Reality: No not at all. To be clear machine learning is a part of AI and deep learning is the subset of ML. All three- AL, ML and DL are different but they are inter related with each other.

unless we give it that power I wonder how many powerful governments or organizations would just love to give an AI the power to control the world on their behalf...

In artificial intelligence, even though not everyone agrees, a common (and maybe the biggest) myth is that of the intelligence explosion, which some people claim will happen (without considering physical limits or knowing anything about thermodynamics).

Comments are not for extended discussion; this conversation has been moved to chat.


text:
What is the difference between GAT and GaAN?
I was looking at two papers

Graph Attention Networks (GAT) by Petar Veličković and
GaAN: Gated Attention Networks for Learning on Large and Spatiotemporal Graphs by Jiani Zhang.

I'm trying to implement the second paper and I'm having some troubles understanding the differences between GAT and GaAN. By looking at equation 1 in GaAN paper I can see only two differences from GAT.

The first difference is that they are doing a dot product with the initial feature map and
Have another fully connected layer to project the result.

Is there something else that I'm missing?

wow the stuff is realy hardcore. About (1), looks like they are implementing it differently but still maintaing the structure, so its basicly the same. And (2) fc-layer is not important.
But did you understand what do thay do further with input? to put a graph of any length they must do some aggregation over variable length and i

Regarding point 1 in the GaAN paper they are stating: "The difference
between our aggregator and that in GAT is that we have adopted the key-value attention mechanism and the dot product attention while GAT does not compute additional value vectors and uses a fully-connected layer". From my understanding those two implementations are quite different. Lets try to break it down. Lets say we have 2 nodes i,j where each have an embedding size of 3. When we are computing the GAT aggregator we combine the two nodes embeddings and feed them to a single ff neural net so we are learning 6 parameters.

When computing the GaAN aggregator we define two weight matrices of size [3,3]. We than multiply node i with the first one and node j with the second one and have two matrices of size [1,3]. Afterwards we can use the dot product between them so that we only have 1 (the attention score). Now looking at the number of parameters GAT uses 6 vs GaAN 18 I think we can say that the two implementations are not similar. Please correct me if I am wrong.

Did you completed the implementation of GaAN? I have found the implementation of GaAN in here https://github.com/jennyzhang0215/GaAN, but environment setup for that implementation is quite hardly, so I haven't been able to run it yet!


text:
It is possible to solve a problem with continuous action spaces and no states with reinforcement learning?
I want to use Reinforcement Learning to optimize the distribution of energy for a peak shaving problem given by a thermodynamical simulation. However, I am not sure how to proceed as the action space is the only thing that really matters, in this sense:

The action space is a $288 \times 66$  matrix of real numbers between $0$ and $1$. The output of the simulation and therefore my reward depend solely on the distribution of this matrix.

The state space is therefore absent, as the only thing that matters is the matrix on which I have total control. At this stage of the simulation, no other variables are taken into consideration.

I am not sure if this problem falls into the tabular RL or it requires approximation. In this case, I was thinking about using a policy gradient algorithm for figuring out the best distribution of the $288 \times 66$ matrix. However, I do not know how to behave with the "absence" of the state space. Instead of a tuple $\langle s,a,r,s' \rangle$, I would just have $\langle a, r \rangle$, is this even an RL-approachable problem? If not, how can I reshape it to make it solvable with RL techniques?

A stateless RL problem can be reduced to a Multiarmed Bandit (MAB) problem. In such a scenario, taking an action will not change the state of the agent.
So, this is the setting of a conventional MAB problem: at each time step, the agent selects an action to either perform an exploration or exploitation move. It then records the reward of the taken action and updates its estimation/expectation of the usefulness of the action. Then, repeats the procedure (selection, observing, updating).
To chose between exploration and exploitation moves, MAB agents adopt a strategy. The simplest one would probably be $\epsilon$-greedy which agent chooses the most rewarding actions most of the time (1-$\epsilon$ probability) or randomly selects an action ($\epsilon$ probability).

This makes sense. However, in the MAB scenario, you have a discrete action-space and the exploration/exploitation dynamics is much clearer and is normally approached (to my knowledge) with simple tabular methods. In my case, I have a very large matrix to be filled with real values, which would definitely require an approximation (a NN?) somewhere. Plus, considering the exploration dilemma: should I reshape the action-space to force the agent to change one entry of the matrix at the time (or one column at the time)? Otherwise, I do not see where and how exploration can happen in my case.


text:
How do I classify an image that contains only polygons?
I have two closed polygons, drawn as connected straight black lines on a white background. I need to classify such images in to three forms

Two separate polygons
One polygon encloses the other
The two polygons overlap each other.

The polygons vary in sizes and location on the image, and the image contains only the polygons and the white background.
Which neural network architecture should I use to solve this problem?

To make it easy take small known CNN network like Alex Net, train like : input  is image, output is [1,0,0,] separate, [0,1,0], encloses, [0,0,1] overlap. Cause you task is easy i guess that will be fine. But it can be done without ML just analysing image with constant algorithm by where are the points of poligons.


text:
Proof of Correctness of Monte Carlo Tree Search
I'm trying to write the proof of correctness of Monte Carlo Tree Search. Any help would be really appreciated.


text:
Why feeding the correct output as input during training of seq2seq models?
I've read about seq2seq for time-series and it seemed really promising, but, when I went to implement it, all the tutorials I've found use the correct output as input to the decoder phase during training, instead of using the actual prediction made by the cell before it. Is there a reason why not do the latter?
I've been using the tutorial from here
But all the other tutorials that I've found followed the same principle.

This is called "teacher forcing". See here: https://en.m.wikipedia.org/wiki/Teacher_forcing

The reason why you would use the ground truth as input to the decoder is to learn the testing distribution. From what I've seen so far, most of the papers are using scheduled sampling (Bengio et al.). Meaning that you will introduce a new term $p$, which will be the probability of the network to feed as input its own prediction. Initially, $p$ will be very small, so that the network will use the ground truth, but later as more iterations pass by, the probability will increase and the network will start using its own predictions.


text:
How do I perform object detection if there is only one type of object?
How do I do object detection (or identify the location of an object) if there is only one kind of object, and they are more of less similar size, but the picture does not look like standard scenes (it is detection of drops on a substrate in microscopic images)?  Which software is good for it?

Object detection and recognition are not exactly the same thing. See: https://dsp.stackexchange.com/q/12940/40095. So, please, edit your question to use the most appropriate expression in all cases.

what ouput do you want to have, meybe you do have some division in sub- categories?

The hardest part is image annotation: here the difference between object recognition and object detection becomes important. If you just want to answer the question "does this image contain object X?", then you just need to provide as many images that contain object X as possible, together with as many images  that don't contain object X (but are otherwise similar). However if you want to answer the question "Where exactly object X is located in this image?" then you will need to manually provide a bounding box for each instance of object X in each image. Obviously, the second scenario is a lot more labor intensive.
After you've done this part, train either a binary image classifier (typically this will be a convolutional neural network) on your annotated images (split them into train and test partitions), or an object detector (googling "custom object detection" produces lots of code examples how to train it (e.g. https://towardsdatascience.com/tutorial-build-an-object-detection-system-using-yolo-9a930513643a start with Step 2B).

That I know.  "A lot of code examples" is a problem, the question is which one to select.

Are you not happy with the one I suggested for some reason?

authors: Ирина Демидова


text:
Which explainable artificial intelligence techniques are there?
Explainable artificial intelligence (XAI) is concerned with the development of techniques that can enhance the interpretability, accountability, and transparency of artificial intelligence and, in particular, machine learning algorithms and models, especially black-box ones, such as artificial neural networks, so that these can also be adopted in areas, like healthcare, where the interpretability and understanding of the results (e.g. classifications) are required.
Which XAI techniques are there?
If there are many, to avoid making this question too broad, you can just provide a few examples (the most famous or effective ones), and, for people interested in more techniques and details, you can also provide one or more references/surveys/books that go into the details of XAI. The idea of this question is that people could easily find one technique that they could study to understand what XAI really is or how it can be approached.

Explainable AI and model interpretability are hyper-active and hyper-hot areas of current research (think of holy grail, or something), which have been brought forward lately not least due to the (often tremendous) success of deep learning models in  various tasks, plus the necessity of algorithmic fairness & accountability.
Here are some state of the art algorithms and approaches, together with implementations and frameworks.

Model-agnostic approaches

LIME: Local Interpretable Model-agnostic Explanations (paper, code, blog post, R port)

SHAP: A Unified Approach to Interpreting Model Predictions (paper, Python package, R package). GPU implementation for tree models by NVIDIA using RAPIDS - GPUTreeShap (paper, code, blog post)

Anchors: High-Precision Model-Agnostic Explanations (paper, authors' Python code, Java implementation)

Diverse Counterfactual Explanations (DiCE) by Microsoft (paper, code, blog post)

Black Box Auditing and Certifying and Removing Disparate Impact (authors' Python code)

FairML: Auditing Black-Box Predictive Models, by Cloudera Fast Forward Labs (blog post, paper, code)

SHAP seems to enjoy high popularity among practitioners; the method has firm theoretical foundations on co-operational game theory (Shapley values), and it has in a great degree integrated the LIME approach under a common framework. Although model-agnostic, specific & efficient implementations are available for neural networks (DeepExplainer) and tree ensembles (TreeExplainer, paper).

Neural network approaches (mostly, but not exclusively, for computer vision models)

The Layer-wise Relevance Propagation (LRP) toolbox for neural networks (2015 paper @ PLoS ONE, 2016 paper @ JMLR, project page, code, TF Slim wrapper)

Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization (paper, authors' Torch code, Tensorflow code, PyTorch code, yet another Pytorch implementation, Keras example notebook, Coursera Guided Project)

Axiom-based Grad-CAM (XGrad-CAM): Towards Accurate Visualization and Explanation of CNNs, a refinement of the existing Grad-CAM method (paper, code)

SVCCA: Singular Vector Canonical Correlation Analysis for Deep Learning Dynamics and Interpretability (paper, code, Google blog post)

TCAV: Testing with Concept Activation Vectors (ICML 2018 paper, Tensorflow code)

Integrated Gradients (paper, code, Tensorflow tutorial, independent implementations)

Network Dissection: Quantifying Interpretability of Deep Visual Representations, by MIT CSAIL (project page, Caffe code, PyTorch port)

GAN Dissection: Visualizing and Understanding Generative Adversarial Networks, by MIT CSAIL (project page, with links to paper & code)

Explain to Fix: A Framework to Interpret and Correct DNN Object Detector Predictions (paper, code)

Transparecy-by-Design (TbD) networks (paper, code, demo)

Distilling a Neural Network Into a Soft Decision Tree, a 2017 paper by Geoff Hinton, with various independent PyTorch implementations

Understanding Deep Networks via Extremal Perturbations and Smooth Masks (paper), implemented in TorchRay (see below)

Understanding the Role of Individual Units in a Deep Neural Network (preprint, 2020 paper @ PNAS, code, project page)

GNNExplainer: Generating Explanations for Graph Neural Networks (paper, code)

Benchmarking Deep Learning Interpretability in Time Series Predictions (paper @ NeurIPS 2020, code utilizing Captum)

Concept Whitening for Interpretable Image Recognition (paper, preprint, code)

Libraries & frameworks
As interpretability moves toward the mainstream, there are already frameworks and toolboxes that incorporate more than one of the algorithms and techniques mentioned and linked above; here is a partial list:

The ELI5 Python library (code, documentation)

DALEX - moDel Agnostic Language for Exploration and eXplanation (homepage, code, JMLR paper), part of the DrWhy.AI project

The What-If tool by Google, a feature of the open-source TensorBoard web application, which let users analyze an ML model without writing code (project page, code, blog post)

The Language Interpretability Tool (LIT) by Google, a visual, interactive model-understanding tool for NLP models (project page, code, blog post)

Lucid, a collection of infrastructure and tools for research in neural network interpretability by Google (code; papers: Feature Visualization, The Building Blocks of Interpretability)

TorchRay by Facebook, a PyTorch package implementing several visualization methods for deep CNNs

iNNvestigate Neural Networks (code, JMLR paper)

tf-explain - interpretability methods as Tensorflow 2.0 callbacks (code, docs, blog post)

InterpretML by Microsoft (homepage, code still in alpha, paper)

Captum by Facebook AI - model interpetability for Pytorch (homepage, code, intro blog post)

Skater, by Oracle (code, docs)

Alibi, by SeldonIO (code, docs)

AI Explainability 360, commenced by IBM and moved to the Linux Foundation (homepage, code, docs, IBM Bluemix, blog post)

Ecco: explaining transformer-based NLP models using interactive visualizations (homepage, code, article).

Recipes for Machine Learning Interpretability in H2O Driverless AI (repo)

Reviews & general papers

A Survey of Methods for Explaining Black Box Models (2018, ACM Computing Surveys)

Definitions, methods, and applications in interpretable machine learning (2019, PNAS)

Stop explaining black box machine learning models for high stakes decisions and use interpretable models instead (2019, Nature Machine Intelligence, preprint)

Machine Learning Interpretability: A Survey on Methods and Metrics (2019, Electronics)

Principles and Practice of Explainable Machine Learning (2020, preprint)

Interpretable Machine Learning -- A Brief History, State-of-the-Art and Challenges (keynote at 2020 ECML XKDD workshop by Christoph Molnar, video & slides)

Explainable Artificial Intelligence (XAI): Concepts, taxonomies, opportunities and challenges toward responsible AI (2020, Information Fusion)

Counterfactual Explanations for Machine Learning: A Review (2020, preprint, critique by Judea Pearl)

Interpretability 2020, an applied research report by Cloudera Fast Forward, updated regularly

Interpreting Predictions of NLP Models (EMNLP 2020 tutorial)

Explainable NLP Datasets (site, preprint, highlights)

Interpretable Machine Learning: Fundamental Principles and 10 Grand Challenges

eBooks (available online)

Interpretable Machine Learning, by Christoph Molnar, with R code available

Explanatory Model Analysis, by DALEX creators Przemyslaw Biecek and Tomasz Burzykowski, with both R & Python code snippets

An Introduction to Machine Learning Interpretability (2nd ed. 2019), by H2O

Online courses & tutorials

Machine Learning Explainability, Kaggle tutorial

Explainable AI: Scene Classification and GradCam Visualization, Coursera guided project

Explainable Machine Learning with LIME and H2O in R, Coursera guided project

Interpretability and Explainability in Machine Learning, Harvard COMPSCI 282BR

Other resources

explained.ai blog

A Twitter thread, linking to several interpretation tools available for R

A whole bunch of resources in the Awesome Machine Learning Interpetability repo

The online comic book (!) The Hitchhiker's Guide to Responsible Machine Learning, by the team behind the textbook Explanatory Model Analysis and the DALEX package mentioned above (blog post and backstage)

Hey.  According to the paper, GNNEXPLAINER may be model-agnostic rather than neural-network-based. I paraphrase from the paper "Here we propose GNNEXPLAINER, the first general, model-agnostic approach for providing interpretable explanations for predictions of any GNN-based model on any graph-based machine learning task."

There are a few XAI techniques that are (partially) agnostic to the model to be interpreted

Layer-wise relevance propagation (LRP), introduced in On Pixel-Wise Explanations for Non-Linear Classifier Decisions by Layer-Wise Relevance Propagation (2015)
Local Interpretable Model-agnostic Explanations (LIME), introduced in "Why Should I Trust You?" Explaining the Predictions of Any Classifier (2016)
Model Agnostic Contrastive Explanations Method (MACEM), introduced in Model Agnostic Contrastive Explanations for Structured Data (2019)

There are also ML models that are not considered black boxes and that are thus more interpretable than black boxes, such as

linear models (e.g. linear regression)
decision trees
naive Bayes (and, in general, Bayesian networks)

For a more complete list of such techniques and models, have a look at the online book Interpretable Machine Learning: A Guide for Making Black Box Models Explainable, by Christoph Molnar, which attempts to categorise and present the main XAI techniques.

Jacques Pitrat's last book  Artificial Beings
The Conscience of a Conscious Machine  has some interesting chapters (§2, §3, §5, §6, §7) related to the questions of explanations and meta-explanations in AI systems.
It describes a reflexive, "expert system" like, meta-knowledge based approach to explainable AI
You could also read his papers
Implementation of a reflective system (1996)
and A Step toward an Artificial AI Scientist online (there could be a typo in it: "pile" is the French word for stack, including the call stack).
You might also look into J.Pitrat's blog and into the ongoing RefPerSys project (it is in November 2020).
PS. J.Pitrat (born in 1934) passed away in October 2019. French readers could see this. His blog might disappear in a few months.


text:
What approach should I take to model forecasting problem in machine learning?
I have a dataset which contains 4000k rows and 6 columns. The goal is to predict travel time demand of a taxi. I have read many articles regarding how to approach the problem. So, every writer tell his own way. The thing which I have concluded from all my readings is that I have to use multiple algorithms and check the accuracy of each one. Then I can ensemble them by averaging or any other approach.
Which algorithms will be best for my problem accuracy-wise? Some links to code will be helpful for me.
I currently only have training set of data. After I work on it, it will be evaluated on any testing set by my professor. So, what should I do now? Either split data I have into my own testing and training set or separately generate dummy data as a testing set?

In general, this type of problem is called a regression problem since the target variable (i.e. travel time) can take any value in a continuous domain. In theory, you can use any regression algorithms (a subset supervised learning techniques) to solve this problem. Some of the most popular ones are linear regression, K-nearest neighbor (regressor), and neural networks.
As you observed already, different algorithms result in (sometimes significantly) different results. Also, the parameter configurations (e.g., number of hidden layers in Neural Networks) can make a big difference. Sometimes, ensembling different models can be helpful, but in general, you should try to avoid overfitting (when your model is more complex than your data such that it memorizes the training set instead of learning it!). That may result in a very good performance on your training set but perform very poorly on your professor's testing set.
What I would do is:

exploring the dataset to see what are the contributing factor in travel time (any correlation between the columns).
cleaning and preprocessing my dataset (duplicates, null values, outliers)
reshaping my dataset if needed (normalizing some columns, merging or splitting columns)
dividing my dataset to training and evaluation subsets (so I train on one part and test on the other part to avoid overfitting)
choosing a simple baseline, applying and measuring the accuracy metrics.
trying to fine tune parameters of my baseline or trying other more advanced techniques.
comparing the results and improving any part of the pipeline when necessary (more/less cleaning, parameter tuning, ensembling).

Yes. LR and ANNs do work on approximation functions and there are some other ML algorithms which use different approach to solve a problem, so, if someone doesn't want to get biased to a single approach then he can use others and then average the effects of all algorithms to get an unbiased result. Although, ML is not accurate enough still it is the only way to solve such problems because such problems don't follow a common pattern plus they don't purely follow some function. So, we have to go with both things to get an unbiased result. The approach is purely a data scientist's choice.


text:
Would an artificial general intelligence have to be Turing complete?
For the purposes of this question, let's suppose that an artificial general intelligence (AGI) is defined as a machine that can successfully perform any intellectual task that a human being can [1].
Would an AGI have to be Turing complete?

That is not a normal definition of a General AI. Arguably a modern PC meets the criteria - there is a large degree of interpretation possible in your use of "capable" and "computational" which you may want to fix (be careful, lest you exclude human intelligences!) Hence AGI is often defined around imagined behaviour of the system, or refers to traits of human cognition such as types of memory, perception and reasoning.

A system is Turing complete if it can be used to simulate any Turing machine.
Given the Church-Turing thesis (which has not yet been proven), a human brain can compute any function that a Turing machine can (given enough time and space), but the reverse is not necessarily true, given that the human brain might be able to compute more functions than a Turing machine. Intuively, humans are thus Turing complete (even though, to prove this, you need a formal model of the human), that is, given enough time and space, a human can compute anything that a Turing machine can.
Hence, an AGI, defined as an AI with human-level intelligence, needs to be Turing complete, otherwise there would be at least one function that a human can calculate but the AGI cannot, which would not make it as general as a human.

My answer is yes, but in a trivial way. The least you would expect from an intelligent agent is that it is able to execute a given Turing machine on a given input. This requires actually no intelligence, just following rules. If however, you are referring to the capability of predicting if the Turing machine will terminate on the given input, that is another matter. I don't think it is reasonable to expect such "undecidable" computational power for an agent to be generally intelligent.


text:
Do I need LSTM units everywhere in the network?
I have recently begun researching LSTM networks, as I have finished my GA and am looking to progress to something more difficult. I believe I am using the classic LSTM (if that makes any sense) and have a few questions.
Do I need LSTM units everywhere in the network? For example, can I only use LSTM units for the first and last layer and use feedforward units everywhere else?
How do I go about implementing bias values into an LSTM?
Assuming I create a network that predicts the next few words of a sentence, does that mean my outputs should be every possible word that the network could conceivably use?

For question 1) I dont understand what you are getting at... LSTM cells will work on a contiguous block of inputs, where it sequentially uses the states from a previous time step and the new input to generate the next ones.
question 2) Please look into the LSTM atchitecture
As you see, biases are already there, is there somewhere specific you want it, that it isnt?
question 3) Generally yes, but the normalization step can be expensive (such as softmax), so if you want to get clever, you can use negative sampling or hierarchial softmax-- but generally, you you predict a probability over all possible words given the previous text

Okay, I'll try to clarify: 1. A LTSM network (I assume) has more than a single cell. Say I had a 2 inputs a single hidden layer with 3 cells and 2 outputs. Would all those cells be of the LSTM variety? Would their vertical outputs connect at random to the vertical inputs? 2. I see from the diagram you included there are two horizontal line, the memory blocks and the outputs. Ommiting the vertical output and input, would the "horizontal output" feed into it's own "output of previous block"? And would the cells own "memory concurrent block" feed into it's own "memory from previous block" essenti

There is only one cell that gets reused every timestep per lstm.... and yes, the output is one of the hidden states of the next layer..... and the memory get fed forward, never backwards

I see, so each cell holds its memory independent from one another, only the vertical output gets fed forward. And a network can have multiple lstm cell layers feeding information to an output layer.

so there is no weights or dot mult in there? how do you backpropagate that?

@user8426627 where ever you see a non-linearity there is a linear operation preceding it... and side note (basic ops like additions and activation fns still have gradients, so youd be able to backprop it regardless, it just wouldnt have learnable params)

i still dont get it . pls, write calculation what are done with backprop. Andi guess it will be BPTT, so i must stove values of all items from previous  times ??


text:
Why should each filter have different weights for each input channel?
From the answers to this question In a CNN, does each new filter have different weights for each input channel, or are the same weights of each filter used across input channels?, I got the fact that each filter has different weights for each input channel. But why should that be the case? What if we apply the same weights to each input channel? Does it work or not?

For simplicitly, let's consider only the first convolutional layer, that is, the one applied to the image. If you consider an RGB image, then there are $3$ channels: the red channel, the green channel and the blue channel. Thus, a kernel that is applied to this image will also have $3$ channels: the red channel, the green channel and the blue channel. In general, the distributions of the intensity of the red, green and blue colors in the image are different, so, in general, the red, green and blue channels of the kernel will also be different because they need to keep track of different information.

Thanks for your answer. I understand what you mean, so do you think it is possible to use the same weight for different channel? Or do you know someone who tried it and got a result?

The weights are the learnable parameters. They are changed by gradient descent and the back-propagation algorithm during training.

@wangxl To test it yourself you could just modify your images to place the red channel at the top, the green channel in the middle and the blue channel at the bottom (so that your 3-channel width * height image becomes a 1-channel width * (3*height) image) and feed that single-channel image into the network. This will contain all the same information as your original image, but only train a single set of filter kernels.


text:
What is the time complexity of an unparellelized Monte Carlo tree search?
I am writing a report where I used a slightly modified version of MCTS (not parallelized). I thought It could be interesting if I could calculate its time complexity. I'd appreciate any help I could get.
Here's the rough idea of how it works:
Instead of tree search, I'm using graph search meaning I keep a list of visited nodes in order to avoid adding duplicate nodes.
So in the expansion phase, I add all child nodes of the current node that aren't present elsewhere in the tree.
For the remaining phases, it's essentially the same as the basic version of MCTS, with a default random policy in the simulation step.

Are you sure it makes sense to talk about time complexity in MCTS? It does not have a end or a certain amount of iterations you should do in each node, it is always relative for the problem you are trying to solve.

I actually agree, my professor suggested it and I wanted to either calculate the complexity or have a good argument justifying why I didn't do it.

You can still quantify the time complexity that depends on some parameter of the problem.

I would like to note that the time complexity of an algorithm actually depends on the implementation. For example, the usage of different data structures can affect the time complexity. So, I would suggest you to link us to or add to your post the algorithm (or its pseudocode) that you implemented. Furthermore, maybe this would be a question better asked on https://cs.stackexchange.com, even though I would say it is on-topic here too.


text:
Validation Loss Fluctuates then Decrease alongside Validation Accuracy Increases
I was working on CNN. I modified the training procedure on runtime.

As we can see from the validation loss and validation accuracy, the yellow curve does not fluctuate much. The green curve and red curve fluctuate suddenly to higher validation loss and lower validation accuracy, then goes to the lower validation loss and the higher validation accuracy, especially for the green curve.
Is it happening because of overfitting or something else?
I am asking it because, after fluctuation, the loss decreases to the lowest point, and also the accuracy increases to the highest point.
Can anyone tell me why is it happening?

I have the same problem with my CNN training, Any ideas?

This question has been asked a year ago when I faced this problem I searched and it hasn't any answers on it, I tried different ways and finally, data augmentation helped me.
I used data augmentation and a very small learning rate. If the fluctuations are big, the batch size should be increased, and the learning rate should be decreased. After all, using more epochs helps you to have an almost smooth plot.

That does not mean something really. While getting closer to the global minimum, your gradients fluctuates only. You just need to check the overall behaviour such if there is any over-fitting etc.


text:
How does one make a neural network learn the training data while also forcing it to represent some known structure?
In general, how does one make a neural network learn the training data while also forcing it to represent some known structure (e.g., representing a family of functions)?
The neural network might find the optimal weights, but those weights might no longer make the layer represent the function I originally intended.
For example, suppose I want to create a convolutional layer in the middle of my neural network that is a low-pass filter. In the context of the entire network, however, the layer might cease to be a low-pass filter at the end of training because the backpropagation algorithm found a better optimum.
How do I allow the weights to be as optimal as possible, while still maintaining the low-pass characteristics I originally wanted?
General tips or pointing to specific literature would be much appreciated.

Two ways to do it - freeze above mentioned layer, don't update it. Another - add regularizer to loss wich force that layer to retain it's properties. Latter could be very non-trivial

Extending @mirror2image's comment, if you have a certain metric that allows you to measure how close the intended layer is to a low pass filter (something that compares its output with what a low pass filter would have produced, for example), the simplest way to achieve what you want would be to add a term in your loss function that calculates the value of this metric. This way, each time you do a training step, the network now is not only made to output the correct predictions but is also forced to do so while also keeping that specific layer's behavior as close to a low-pass filter as possible.
This is the most common way of tweaking the behavior of neural networks and is often encountered in many research papers.

the idea about training that it is allowed for weights (not layer as you wrote) "learn" values what they "want" from general network setting. But actualy i v thinked about that too, and to have weights represent as you want, you can first train a shorter network, while having those weights (1) as very last, so you have maximum control over them, after trained a lot append next layers to those and learning rate for weights (1) make much smaller as for new weights


text:
Why do the inputs and outputs of a convolutional layer usually have the same depth?
Here's the famous VGG-16 model.

Do the inputs and outputs of a convolutional layer, before pooling, usually have the same depth?  What's the reason for that?
Is there a theory or paper trying to explain this kind of setting?

I edited this post in order to save it. It wasn't clear what you meant by "input/output channels". To answer what I think is your question: no, the depth of the inputs and outputs of a convolutional layer are not typically the same.

Keeping the same channel size allows the model to maintain rank but i would say the main reason is convenience. Its easier book keeping.
Also in many model cases output features need some form of alignment with the input (example being all models using residual units -- $\hat{x} = F(x) + x$

What do you mean by "rank" in this context? It is also not clear the question because the depth of the input and output volumes are usually different.

also good point about alignment because GPU and CPU vector ops need this


text:
How to deal with invalid output in a policy network?
I am interested in creating a neural network-based engine for chess. It uses a $8 \times 8 \times 73$ output space for each possible move as proposed in the Alpha Zero paper: Mastering Chess and Shogi by Self-Play with a General Reinforcement Learning Algorithm.
However, when running the network, the first selected move is invalid. How should we deal with this? Basically, I see two options.

Pick the next highest outputted move, until it is a valid move. In this case, the network might automatically over time not put illegal moves on top.
Process the game as a loss for the player who picked the illegal move. This might have the disadvantage that the network might be 'stuck' on only a few legal moves.

What is the preferred solution to this particular problem?

You should have a method to generate a possible moves output based on the board state. Use this as a mask before normalization in the policy head.


text:
Is there a way to break a piece of dialogue into components?
In many chatbots, I've seen a lot of hardcoded responses, but nothing that allows an AI to break a piece of dialogue into components (say that the speaker sounds happy or is trying to be manipulative) and model a response based on this.
I envision a coding scheme for different core components of conversation. This would allow an AI to be more dynamic in its responses, and would be closer to actually being able to hold a conversation.
I'm not looking for AI-generated text, at least not in the sense of some NN or the like being fed a diet of literature and seeing what it spits out - there's nothing dynamic about that.


text:
Does the encoding of a restricted Boltzmann machine improve with more layers?
I'm using a restricted Boltzmann machine (RBM) as an autoencoder. For now, I use a simple architecture of two layers, the input (~100 nodes) and the output (3 nodes) layers.  I'm thinking to add more hidden layers.
Are there some improvements in encoding by adding multiple hidden layers? If yes, how can multiple layers improve the encoding?

It's been too long since I've looked at them for me to feel comfortable writing a proper answer... but you're going to want to look into "Deep Belief Networks"

First of all, when you add hidden layers, or stack RBMs, you get a Deep Belief Network (DBN). Your question then deals with the comparison of DBNs and RBMs.
There are some elements to answer this question in the article Representational Power of Restricted Boltzmann Machines and Deep Belief Networks by Nicolas Le Roux, which can be found summarized in these course slides. The main results are:

Restricted Boltzmann Machines:

Increasing the number of hidden units improves representational ability.
With an unbounded number of units, any distribution over $\{0,1\}^n$ can be approximated arbitrarily well.

Deep Belief Networks:

Adding additional layers using greedy contrastive divergence training does not provide additional benefit.
There remain open questions about the benefits additional layers add.

I emphasized the $4^{th}$ point that covers the most your question. It does not mean that additional layers are useless, but since RBM are universal approximators ($2^{nd}$ point), the benefits of adding layers seem less straightforward. They seem dependent on the first layer, the training procedure... You can see the article for more details and the open questions raised about DBNs. Note that this answer is an entry point on the topic, there might be more recent results following this article which I'm not familiar with...


text:
Understanding the proof that A* search is optimal
I don't understand the proof that $A^*$ is optimal.
The proof is by contradiction:

Assume $A^*$ returns $p$ but there exists a $p'$ that is cheaper. When $p$ is chosen from the frontier, assume $p''$ (Which is part of the path $p'$) is chosen from the frontier. Since $p$ was chosen before $p''$, then we have $\text{cost}(p) + \text{heuristic}(p) \leq \text{cost}(p'') + \text{heuristic}(p'')$. $p$ ends at goal, therefore the $\text{heuristic}(p) = 0$. Therefore $\text{cost}(p) \leq \text{cost}(p'') + \text{heuristic}(p'') \leq \text{cost}(p')$ because heuristics are admissible. Therefore we have a contradiction.

I am confused: can't we also assume there's a cheaper path that's in a frontier closer to the start node than $p$? Or is part of the proof that's not possible because $A^*$ would have examined that path because it is like BFS with lowest cost search, so, if there's a cheaper path, it'll be at a further frontier?

The key phrase here is

because heuristics are admissible

In other words, the heuristics never overestimate the path length:
$$cost(n) + heuristic(n) \le cost(\text{any path going through n})$$
And since the frontier is ordered by $\textbf{cost + heuristic}$, when a completed path $p$ is dequeued from the frontier, we know that it must necessarily be $\le$ any path going through some other frontier node $q$, because
$$cost(p) = cost(p) + heuristic(p)$$
$$\le cost(q) + heuristic(q)$$
$$\le cost(\text{any path going through q})$$

However, $p'$ in the proof is not any path, it is a path assumed to be cheaper than $p$. So, how do you explain the conclusion "Therefore $\text{cost}(p) \leq \text{cost}(p'') + \text{heuristic}(p'') \leq \text{cost}(p')$"? By assumption, $\text{cost}(p') < \text{cost}(p)$. How come that you can conclude the opposite only because you say, in the proof, that you remove $p$ before $p''$ from the frontier? Even if the frontier is ordered, it does not imply that you have not removed $p'$ before $p$. I think this is what is confusing in the provided proof.

@nbro: It is a proof by contradiction.  That is the contradiction.  You can in fact assume that $p'$ has not been dequeued yet, because if it had, the algorithm would have terminated and returned $p'$

I think that's the actual answer to the original question "can't we also assume there's a cheaper path that's in a frontier closer to the start node than $p$?".

I mean, the answer to that question is really the proof given by OP. My answer is simply an alternative proof that more directly answers his question, hopefully in a way that makes more intuitive sense.  Neither of these are the same as your original question, which should technically be a separate question on this site, but is easily answered in a comment.

How is my question different than "can't we also assume there's a cheaper path that's in a frontier closer to the start node than ?", which, I suppose, it means "can't we also assume that $p'$ is dequeued before $p$"? The proof simply tells you, in an intricate way, that you remove $p$ before $p'$, hence $p'$ cannot be cheaper. By the way, how is yours an alternative proof? You just rephrased parts of the proof.


text:
Where could I find information on the learning methods used in Neurogrid?
I have been searching for more than one week which learning methods were used in Neurogrid.
But I only found descriptions of its architecture (chips, circuits, analog and/or digital components, performance results), everything but no clue on how it updates the weights.
In my opinion, I think that it cannot be gradient descent (with back-propagation), as the topology of the neurons in a chip, for example in the neurocore of Neurogrid, is a mesh or grid.
Do you know where I could find this kind of information?

Hey thanks a lot for answering, could you please give me these names or articles ? I looked for those for hours and hours without any result.


text:
What are some neural network models that can use auxiliary info during training for image segmentation?
What are some deep learning models that can use supplementary information other than RGB channels for image segmentation?

For example, imagine a poorly shot image of a river (blue) that shows a gap, and the supplementary information is detailed flow directions (arrows), which helps to show the river's true shape (no gap in reality). To get the river shape, most image segmentation models I see, such as U-Net, only use RGB channels.
Are there any neural network models that can use this kind of auxiliary information along with RGB channels during training for the image segmentation task?


text:
How to voxelize multiple frames at the time and append them together?
I'm trying to implement this approach for object detection and tracking.
In this approach, the first step is voxelize each frame to construct a 3D tensor, the second step is to append multiple voxels at the time along a new axis to create a 4D tensor.
What I want to understand is how to voxelize multiple frames at the time and append them together.

Hi and welcome to this community! Your question is currently too broad. Please, specify which details you have not understood and ask one question.

@nbro thank you for the clarification but the details are linked and couldn't be put in one question as i want to understand the steps? what do you suggest? thank you

I suggest that you ask a question regarding the first thing in the paper that doesn't allow you to proceed. Once this is clarified, you can ask another question (in another post). If you ask someone to explain to you the paper, then it will require maybe an answer which is longer than the paper, which is of course too much.

Agreed with nbro here. The question "Can anyone be kind enough to walk me through it" is a problem. It is too much work for most volunteers to write a tutorial for a whole system implementation, and not at all clear which details you need help with. Ask about the first step where you struggle, and give details in the question. Use [edit] to add them


text:
How do I classify strings with possibly no meaning?
I am quite new to text classification.
Using EAST text detection model, I get multiple strings that aren't words and most often have no meaning. For example, IDs, brand names, etc. I would like to classify them into two groups. Which models work the best and how should I preprocess the strings?  I wanted to use Word2Vec, but I think it only works with real words and not with arbitrary strings.

I would just use a dictionary. A simple list lookup would tell you whether it's a recognised word or not. As an added bonus you can add some basic language processing, eg to identify inflected forms without listing them in your dictionary. Or use regular expressions to recognise ID numbers. ML is not really the right tool here.

What do you mean with dictionary? the problem I have is I got strings such as „526//51“ which would be an ID I want to recognize. But also „A1213“ would be an ID. And unfortunately every ID just occurs once or twice. So I can‘t use stuff like tf-id

A dictionary is basically a word list. For IDs you could use regular expression matching, like /[A-Z][0-9]+/ to recognise a letter followed by one or more digits. You could even do it the other way round: use a regular expression to recognise words (basically /[a-z]+/, possibly with a hyphen included), and treat everything else as a non-word/ID. The matching words you can then check against a dictionary/list, either of words or (in order to exclude them) brand names.

I would like to use the power of labels and train a supervised model. What would be the best way to create embeddings. I read about different embedding methods such as hashing.

It's the wrong tool.


text:
How does FastText support online learning?
I'm using FastText pre-trained-embedding for tackling a classification task, but I saw it supports also online training (incremental training) for adding domain-specific corpus.
How does it work?
As far as I know, starting from the "model.bin" file it retrains the model only on the new corpus updating the old word-vectors, is it right?

Are you referring to https://github.com/facebookresearch/fastText/pull/423 ? It seems the official FastText does not support incremental learning yet.

yeah exactly i saw that link. Probably i misunderstood. Anyway i opted for the pretrained one with Wikipedia corpus. Thanks for your answer, hoping and waiting for the official "incremental" features in Fast Textt as soon as possible :).

The pull request #1327 (https://github.com/facebookresearch/fastText/pull/1327)
Allows for:

test after each epoch
checkpointing
training on large data which does not fit into memory (largest I tested was 1.6TB)
finetuning already trained models

The trained model is indistinguishable from a model that was created by an original tool and can be used for inference by the old code.


text:
What is the point of converting conditional probability to factor for Variable Elimination?

I have this slide from my AI class on using a Bayes network to compute a conditional probability. I don't really understand the point of converting the conditional probabilities to factors (besides the fact that it looks weird to marginalize or multiply variables in a CP). It seems kind of arbitrary. Is there some benefit I'm not noticing?

the benefit is that you are utilizing the distributions factorization to simplify marginalization (which on the joint is extremely expensive!)


text:
Are there any better visual models for transfer rather than ImageNet?
Similar to the recent pushes in Pretrained Language Models (BERT, GPT2, XLNet) I was wondering if such a thrust exists in Computer Vision?
From my understanding, it seems the community has converged and settled for ImageNet trained classifiers as the "Pretrained Visual Model". But relative to the data we have access too, shouldn't there exist something stronger? Also, classification as a sole task has its own constrictions on domain transfer (based on the assumption of how these loss manifolds are).
Are there any better visual models for transfer rather than ImageNet successes? If no, why? Is it because of the domains fluidity in shape, resolution, etc., in comparison to text?

Why is ImageNet so popular for transfer learning?
Models pre-trained on the ImageNet datasets have been the de-facto choice for many years now. Many popular reasons as to why people think that ImageNet is so effective for transfer learning are the following:

ImageNet is a truly large-scale dataset that contains over 1 million images, each of which has a decent resolution.
ImageNet has a wide and diverse set of classes (1000 in total) ranging from animals to humans, cars, trees, etc. Most Computer Vision tasks operate in similar domains, however there are some notable exceptions (e.g. medical images).
For example, an object detection model for autonomous driving would benefit from ImageNet transfer learning, as the pre-trained model has seen images with similar content (e.g. roads, people, cars, street signs), even though it tries to solve a different task (i.e. object detection not classification).
The above two reasons allow models trained on ImageNet to identify and extract very generic features, especially in their initial layers, that can be effectively re-used.
ImageNet has a lot of similar classes. This is an interesting argument because it contradicts the second one. Due to the closeness of some classes (e.g. multiple breeds of cats), networks learn to extract more fine-grained features.

Another overlooked reason I find very important is that:

ImageNet has been the benchmark for performance for image classifiers for years now. When, for example, you are selecting a re-trained ResNet to use, you know that that model is guaranteed to operate at a high level of performance. Other datasets don't have such notable challenges as the ILVRC. That challenge is what make the VGG and ResNet popular in the first case, so it comes natural that people would want to use those weights.

In practice, due to the way in which CNNs identify and extract features from images, they can easily be "transferred" from task to task.
Is it actually better than other datasets?
This question was widely explored by Huh et al., who tried to identify the reasons that made the ImageNet dataset better than other ones for transfer learning.
In short they found out that most of the reasons that people thought made ImageNet so good (i.e. the ones I mentioned above) weren't necessarily correct. Furthermore, the amount and diversity of images and classes required to effectively train a CNN has been highly overestimated. So there is no particular reason people should choose this specific dataset.
Now, to answer your questions:

I was wondering if such a thrust exists in Computer Vision?

No, ImageNet is currently established as the de-facto choice, evident by the fact that all 10 keras.applications models offer weights only for ImageNet.

But relative to the data we have access too, shouldn't there exist something stronger?

This is an interesting question, as the consensus things that deep learning models keep getting better with more data. There is, however, evidence that indicates otherwise (i.e. that CNN models con't have as much capacity as we thought). You can read the aforementioned study for more details. In any case, this is still an open research question.
Even if models could get better, though, with more data, it is possible that it still wouldn't matter because ImageNet pre-trained models are strong enough.

classification as a sole task has its own constrictions on domain transfer

There have been numerous cases where models initialized from pre-trained ImageNet weights have done well in settings other than classification (e.g. regression, object detection). I'd argue that initialization from ImageNet is almost always better than random initialization.

Are there any better visual models for transfer rather than ImageNet successes? If no, why? Is it because of the domains fluidity in shape, resolution, etc., in comparison to text?

Partly, yes. I think that in comparison to text, images have some useful properties that are exploited through CNNs, which makes their knowledge more transferable. This claim, however, is based on intuition; I can't back this up somehow.

Comments are not for extended discussion; this conversation has been moved to chat.


text:
Which online machine learning technique to use for multi-class classification problem with multiple inputs?
I have the following problem. We have $4$ separate discrete inputs, which can take any integer value between $-63$ and $63$. The output is also supposed to be a discrete value between $-63$ and $63$. Another constraint is that the solution should allow for online learning with singular values or mini-batches, as the dataset is too big to load all the training data into memory.
I have tried the following method, but the predictions are not good.
I created an MLP or feedforward network with $4$ inputs and $127$ outputs. The inputs are being fed without normalization. The number of hidden layers is $4$ with $[8,16,32,64]$ units in each (respectively). So, essentially, this treats the problem like a sequence classification problem. For training, we feed the non-normalized input along with a one-hot encoded vector for that specific value as output. The inference is done the same way. Finding the hottest output and returning that as the next number in the sequence.

I suggest using Data Stream algorithms to try on your problems since you are asking for "online learning with singular values or minibatches as the dataset is too big too load all the training data into memory."
MOA is a good choice for these algorithms. Hoeffding Trees is also a good first  choice to try.

If you prefer to use Python (rather than Java, which is used to implement MOA, which is suggested in the other answer), you might want to have a look at the Python's creme library, whose API is described at https://creme-ml.github.io/api.html, which is a library for incremental and online learning. In particular, you might be interested in the class OneVsRestClassifier.

The way I would approach this (and which I already applied in the past for similar a similar task) is based on multiple points. Let's suppose we're working with PyTorch.

I'd start normalizing every input in $[-1, 1]$. Since every feature of the input is in $\mathbb{Z}$ and $\in [-63, +63]$, normalizing it and casting it to fp16 can lower the overall dimension of the batches in the memory, and can allow for automatic mixed precision training. Matter of fact, you should really consider normalizing the values in order to obtain smaller weights in the network.

Same thing for the output: Since your task is effectively a bounded regression (those 127 values are not classes), you'd be better off with a single output neuron that can predict values $\in [-1, 1]$ using a tanh activation function. This would rescale the last layer of your network from $Q*H$ (not including biases) to $Q$ weights, where $Q$ is the number of neurons in the last hidden layer and $H$ is the number of output neurons. During inference you can multiply your output by $63$, round it to the nearest integer and obtain your prediction.

Since you only have 4 features ranging $[-63, 63]$ you have only $260144641 = 127^4$ values, and it'd be interesting to study the distribution of each single feature, pair of features and triplets of feature, in order to understand if there are some kind of repeated values or collinearities.

Usually, earlier layers of the neural networks tend to learn more basic patterns, while deep layers handle more complex, fine details. I'd still suggest, based on my experience and the previous point, to add more neurons to early layers, since you have loads of data (the magnitude of your dataset makes me think it's some sort of scraped values with lots of noise) and lots of updates are gonna hit the weight space in those dimensions. I can sense that the distribution of those features are not uniform, thus you'd avoid handling problems like small differences in input leading to big differences in output with less neurons in the early layers.

Yes, the whole dataset can't fit inside the memory, but it can fit inside your disk (if I understood correctly, you are training with a large, offline dataset rather than an online stream of data). There is no need to load it at once though! You can serialize batches of processed data on your disk, and load/unload the batches you need for training, focusing on the biggest batch you can fit in the remaining memory in order to obtain the best results. Of course you're going to account for a time complexity overhead but that was your problem for the get-go. With this solution you will train a neural network without using exotic libraries or frameworks, and focus only on hyperparameter tuning and metrics.


text:
How to transform a PDDL to search?
I have a question about search and planning:
I still haven't understood the difference from the two, but they seem very similar to me; here is a question I am struggling with:

"Having formulated a PDDL problem, transform it into research,
  emphasizing what the differences are."

Someone can do an example?
I attached an example of simple PDDL from my book (I'm using  Russell & Norvig)

This is an old question, but could you please clarify where you took that slide from? Which section/page of the mentioned book were you reading at the time?

Not all search is planning (is A connected to B), but all planning is search (how do I get from this to that).
Here's an example in Prolog with a domain described in terms of actions, when they are possible, and what the result of the actions are. The description is of an uncomputed graph of un-calculated size where each node is a situation and each edge is an action. Then we have A* search algorithm that searches this graph, calculating it as it goes, to find a plan to reach the goal state. Running the final query will produce a plan via search.


text:
Could the normalisation of the inputs make the neural network insensitive to changes in the inputs?
When using neural networks (NNs), we often normalized the inputs. I think this is done to equally capture the changes in any input feature, that is, if any feature takes huge values and other features take small values, we don't want the NN not to be able to "see" the change in the smaller value.
However, what if we cause the NN to become insensitive to the input, that is, the NN is not able to identify changes in the input because the changes are too small?

You should also make sure you aren't confusing scaling the inputs with normalizing the inputs.  These are very different things.

When using neural networks (NNs), we often normalized the inputs. I
think this is done to equally capture the changes in any input
feature, that is, if any feature takes huge values and other features
take small values, we don't want the NN not to be able to "see" the change
in the smaller value.
However, what if we cause the NN to become insensitive to the input,
that is, the NN is not able to identify changes in the input
because the changes are too small?

We don't normalize the input to make the model less sensitive to small changes in the input (theoretically, given the correct optimization strategy, the model will learn to approximate the smaller-ranged input as well).
An example of this would be Convolutional Neural Networks. Traditionally, images were represented with integer values ranging from $0$ to $255$. This means that a given pixel could have only $256$ distinct values. However, assuming we normalize the input, let's say to $[0, 1]$, this gives the pixel a whole range of values to occupy, making the input more sensitive to changes.
Instead, normalization is done to help with the model's convergence.

I do not disagree with you, but what you are describing is scaling, not normalizing.  Normalizing the input implies that you are forcing it to take more of a Gaussian distribution's shape.  Scaling is simply forcing the values to be in a specific range.

Hi, in the context of data science normalization means bringing the inputs to take a range of $[0, 1]$ (e.g. see here). Normalization is just a type of feature scaling.

I don't have time to find a better reference for you at the moment, but I'd refer you to https://towardsai.net/p/data-science/scaling-vs-normalizing-data-5c3514887a84 for now

Under different contexts, the term "normalization" can mean different things Most people in data science when saying normalization mean scaling to $[0, 1]$. You could do a google search on "normalization data science", "feature scaling" or something like that to see what I'm talking about.

I totally get what you're saying.  It's just not my experience.  The distinction is pretty important because when you normalize (gaussian) your training data, it becomes very difficult to apply the same transformation to reality.  Scaling, however, is trivial. :)

As examples, I'd point you to The Deep Learning Book (Goodfellow,et al) pages 73, 138, 183, 184, 262, and others.

Scaling the input from 0-255 to 0-1 doesn't increase the sensitivity, if you were to stick with integer numbers. Arguably you should extend the scale to 16-bit integers, or just use floats (what you are implying).


text:
Can I train a neural network incrementally given new daily data?
I would like to know if it was possible to train a neural network on daily new data. Let me explain this more in detail. Let's say you have daily data from 2010 to 2019. You train your NN on all of it, but, from now on, every day in 2019 you get new data. Is it possible to "append" the training of the NN or do we need to retrain an entire NN with the data from $2010$ to $2019+n$ with $n$ the day for every new day?
I don't know if it is relevant but my work is on binary classification.

There is a similar question here, but it focuses on the case where new classes are introduced later.

Yes, this is possible. Continuously extending your training data is known as incremental learning.
You might also want to take a look at transfer learning, in which you reuse a trained model for a different purpose. This is very useful if you have a smaller dataset.
In your particular case, you could train a NN once using your data from 2010 to 2019 and use it as a base model. Every time you get new data, you can use transfer learning to slightly re-train this model. Based on parameters such as the number of epochs and the learning rate, you can determine how much of an impact this new data will have.

This is interesting given that I tried to do it once with a for loop, when i = 0 I did a model.fit with the data from 2010 to 2019 and for i !=0 i just added the new data, but I had a problem with the learning when i != 0, even 100 epochs wasn't enough to make the NN change his prediction to make it correct
Is it because I didn't do it properly with a save.model ?

Or maybe because the i = 0's X_train has a shape like (4000,3) and the i != 0's X_train has a shape like (1,3), is that relevant ?

There is not so much of a "transfer" if the learning is on the new data but of similar data type as the past data. Maybe "fine-tuning" is the term to use here.


text:
Why do neural networks have bias units?
Why do neural networks have bias units? Why is it sometimes okay to opt them out?

Hey, take a look at this post, it explains it quite well.


text:
Is DDPG just for deterministic environments?
I want to develop an AI for continuous space. I reached to DDPG algorithm that takes actions deterministically.
If DDPG takes actions deterministically, should the environment also be deterministic? I want non-deterministic, continuous real-world environments. Is DDPG the algorithm I am looking for? Is there any other algorithm for my need?

I am not an expert in this area. But I believe that the word "Deterministic" is for "Policy" in the "Deterministic Policy" Gradient. It does not mean  deterministic environment.
Stochastic policy: Probabilistic(random) action choice for a given state.
Deterministic policy: one action is chosen for a given state.
Deterministic Policy Gradient algorithm still can handle a stochastic (and continuous, of cause) environment, but the policy will be deterministic.
Reference
"in DDPG, the Actor directly maps states to actions (the output of the network directly the output) instead of outputting the probability distribution across a discrete action space"  -towards Data Science
Deterministic Policy Gradient Algorithms by Silver et al. PDF

thank you. I also read this from the source but i cant get it. Recently i read a nice tutorial that has implementation and it accurate. On that tutorial there is a line says: "Deterministic policies are used in deterministic environments. These are environments where the actions taken determine the outcome. There is no uncertainty" and this makes me confused! I don't know what I have to do. I read a lot but cant find anything that verify this. i read that here: https://www.freecodecamp.org/news/an-introduction-to-policy-gradients-with-cartpole-and-doom-495b5ef2207f/


text:
Which loss functions for transforming a density function to another density function?
I am looking at a problem which can be distilled as follows:  I have a phenomenon which can be modeled as a probability density function which is "messy" in that it sums to unity over its support but is somewhat jagged and spiky, and does not correspond to any particular textbook function.  It takes considerable amounts of time to generate these experimental density functions, along with conditional data for machine learning, but I have them.  I also have a crude model which runs quickly but performs poorly, i.e., generates poor quality density functions.
I would like to train a neural network to transform the crude estimated pdfs to something closer to the experimentally generated pdfs, if possible.
To investigate this, I've further reduced this to the most toy-like toy problem I can think of:  Feeding a narrow, smooth (relatively narrow) normal curve into a 1D convolutional neural network, and trying to transform it to a similar narrow curve with a different mean.  Both input and output have fine enough support (101 points) to be considered as a smooth pdf.
Here is the crux of the problem I think I have: I do not know what a good loss function is for this problem.
L1, L2 and similar losses are useless, given that once the non-zero parts of the pdfs are non-overlapping, it doesn't matter how far apart the means are, the loss remains the same.
I have been experimenting with Sinkhorn approximations to optimal transport, to properly capture the intuition of "distance" but somewhat surprisingly these have not been helpful either.  I think part of the problem may be an (unavoidable?) numerical stability issue related to the support, but I would not stake hard money on that assumption.
(If support is at percentiles on the [0,1] it is quite instructive (and dismaying) to look at the sinkhorn loss for normal functions with the mean directly on a point of support, vs normal functions with the mean directly between two points of support.)
For a problem in this vein, are there any recommended loss functions (preferably supported by or easily implement in PyTorch) which might work better?

Moderators, I waffled between asking this here (for the machine learning application) vs Cross Validated (for the statistics insight.)  If it seems better posed there, let me know and I can remove and repost.

Hi. What is the "crude deterministic model" used for in your context? You also say "I would like to train a neural network to transform the crude estimate to the experimental data", but to transform to what? Maybe edit your question to specify (even though from the title it seems you want to convert a "messy probability distribution" to another probability distribution).

@nbro I'm not sure what you're asking.  Yes, I want to feed in the crude estimated pdf (along with conditional data) and get out a substantially better estimate of the messy, experimentally generated pdf, if that's what you mean.

You say "I also have a crude deterministic model which runs quickly but performs poorly.". What does "crude deterministic model" mean in this context? Model of what? What is the relationship between this model and the probability density that models the phenomenon?

@nbro I'm trying not to get sidetracked into the domain knowledge of the problem.  'Deterministic' might be the problem-- it is in retrospect a poorly chosen term.  I mean I have a crude, computationally cheap model that outputs crude, poorly performing density functions which I would like to improve by training against expensive density functions that I consider as ground truth.

Updated the question in a fashion I hope is more clear.


text:
How does the CTC loss work?
I am trying to implement CTC loss in TensorFlow, but their documentation is pretty limited. So I am not sure how to approach the problem. I found a good example in Theano.
Are any other resources that explain the CTC loss?
I am also trying to understand how its forward-backward algorithm works and what the beam decoder in the case of the CTC loss is.

Connectionist Temporal Classification (CTC) can be useful for sequence modeling problems, like speech recognition and handwritten recognition, where the input and output sequences might have different sizes, so there's the problem of aligning the sequences. For instance, in speech recognition, not all sounds in speech correspond to a character, so how do we know if a sound should be converted to one of the possible chars? Moreover, we assume that we don't have a training dataset where the input and output sequences are aligned. The creation/labeling of such a dataset would be quite consuming. That's why CTC was introduced.
So, mathematically, the speech/handwritten recognition task can be written as
$$
Y^* = \text{argmax}_Y p(Y \mid X),
$$
where $Y^* = [y_1, \dots, y_M]$ is the ideal output sequence for $X = [x_1, \dots, x_T]$. Note that $T$ may be different from $M$.
Now, let's say that you have a speech $X = [x_1, \dots, x_N]$ and the output should be the sequence $Y^* = [h, e, l, l, o]$. One naive approach to solve this problem would be, for each input $x_i$, we would predict the most likely char, so we could end up with an output sequence like $\hat{Y} = [h, e, e, l, l, l, o]$ (when $T = 7$ and $M = 5$), then we could remove all duplicates, so we would end up with $\hat{Y}' = [h, e, l, o]$. However, this is not the correct approach, because, as you can see, there are words where the same letter appears twice in a row.
To solve this problem, we can introduce a special character, which we can denote by $\epsilon$. So, in this case, the idea is that $\epsilon$ should be predicted around exactly two (and not more or less) "l". Once the sequence is predicted, we can remove $\epsilon$ and, hopefully, we have a valid word, rather than a word like "helo" or "hellllo".
The idea of CTC is, for each $x_i$, the neural network produces a probability distribution over the possible chars, which we can denote by $p_t(a_t \mid X)$. In the example above, a probability distribution over $\{h, e, l, o, \epsilon \}$. So, for example, the probability vector for $x_1$ could be $p_1(a_1 \mid X) = [0.6, 0.1, 0.1, 0.1, 0.1]$. Given all probability vectors $p_t(a_t \mid X)$, for $t=1, \dots, T$, we can compute the probability of an alignment (a specific output sequence). Then we marginalize over the set of alignments.
To reflect these ideas, the CTC loss function is defined as follows
$$
p(Y \mid X)=\underbrace{\sum_{A \in \mathcal{A}_{X, Y}} }_{\text{Marginalization}\\\text{over set of}\\ \text{alignments}} \underbrace{\prod_{t=1}^{T} p_{t}\left(a_{t} \mid X\right)}_{\text{Probability}\\\text{for a single}\\\text{alignment}}
$$
We can then use an RNN to model $p_t(a_t \mid X)$ given that RNNs are good for sequence prediction.
Now, another problem is that there can be many alignments, so the computation of the loss may be expensive if done naively. To solve this problem, you can use a dynamic programming algorithm, the CTC forward-backward algorithm. The details of how this is done, how the gradient of the CTC loss is computed, how inference is done in this context (including the details of beam search), and other details can be found in this nice article Sequence Modeling With CTC (2017) by Awni Hannun, which this answer is based on.
You can also read the original paper Connectionist Temporal Classification: Labeling Unsegmented Sequence Data with Recurrent Neural Networks (2006), by Alex Graves et al., mentioned in the linked TensorFlow documentation, which presents and explains the CTC loss and the CTC forward-backward algorithm (in section 4.1).


text:
Why is graph convolution network in time-varying graphs useful for anomaly detection?
In this paper, the authors refer to the application of time-varying graphs as an open problem.　And they say it will be useful for anomaly detection in financial networks, etc. But why is that useful?


text:
In sequence-to-sequence, why is the output of the decoder used as its input?
The basic seq-2-seq model consists of 2 parts: a recurrent encoder that compresses a sequence to a vector and decoder that unrolls the vector into the output sequence:

Why is the output, w, x, y, z of the decoder used as its input? Shouldn't the hidden state of the RNN from the previous timestamps be enough?

In seq2seq they model the joint distribution of whatever char/word sequence by decomposing it into time-forward conditionals:
\begin{align*}
p(w_1,w_2, \dots,w_n) &= \ p(w_1)*p(w_2|w_1) * \ ... \ * p(w_n|w_1, \dots,w_{n-1}) \\
 &= \ p(w_1)*\prod_{i=2}^{n}p(w_i|w_{<i})
\end{align*}
This can be sampled by sampling each of the conditional in ascending order. So, that's exactly what they're trying to imitate. You want the second output dependant on the sampled first output, not its distribution.
This is why the hidden state is NOT good for modeling this setup because it is a latent representation of the distribution, not a sample of the distribution.
Note: In training, they use ground-truth as input by default because it working under the assumption the model should've predicted the correct word, and, if it didn't, the gradient of the word/char level loss will reflect that (this is called teacher forcing and has a multitude of pitfalls).

can it be improved by entering position flags  for input like ( w,1) (x,2) ( y,3)???

@user8426627 maybe. probably dpends on the data and problem. Im assuming what you mean, is if you add some form of positional embedding will it improve the model? Positional embeddings are used alot recently because popular attention-only architectures dont embed position inherently, while RNN's do. So in this case, youd hope its not necessary because of the LSTM, but you never know, adding that representation may assist in the training. Could be a fun experiment :)

Shouldn't the hidden state of the RNN from the previous timestamps be enough?

It is theoretically enough to generate a sequence. However, allowing an input offers a couple of convenient extras:

Training data for output sequences is used twice - once as input (as previous sequence data), once as target (to establish loss metric). This may help training process as the decoder trains both as a decoder to the new sequence type and as a predictive model over the output sequence semi-independently - i.e. weights from input to RNN layer are affected by error gradients separately to weights between previous hidden state and next state, although the two sets of weights together influence output and next state, so are not fully independent over a sequence.
By allowing input of sequence so far generated, the decoder can work as a generator, where the next item in the sequence does not need to be the maximum probability item, but can be sampled or have rules applied. This allows for approaches such as BEAM search, commonly used in machine translation, which maintains several potential outputs, selecting best one at the end.

I have not done the experiment, but I suspect the first item results in faster and better generalisation. The second one is very convenient for natural language generation and similar problems.

@DuttA: Yes, with that intuition, it can also be considered a form of regularisation, because the weights have to satisfy two constraints instead of one.

In the original seq2seq paper, they used two RNN, one for encoding and one for decoding. In the encoder they need to unroll the inputs to capture the time dependency. Now if we want to pass the hidden state from the encoder to the decoder that means that the decoder hidden state shape needs to match the encoder (aka same architecture). Since the architecture is the same, we can not directly generate a sequence of n samples within the decoder without unrolling it and you can not unroll it without an input.