Suppose that you show a neural network its own code, and allow it to edit itself?

Can a neural network modify its own weights and architecture (the number of layers, the number of neurons per layer, etc.)?

Without using back propagation and gradient descent.

Neural networks modify its own weights and architectures.

Is this a valid notion? Is it being explored? Is this a valid concept in relation to NNs?

It feels like the ultimate thing to recognize and edit its own structure as data.


Since a neural network does iteratively learn its own weights I assume you mean the structure of the neural network - the number of layers and nodes per layer.

If what I said above was your question, then yes, it most definitely is being explored. Even when a neural network is allowed to learn its own structure it still needs to be suited to a specific problem. Google wrote a blog where they used machine learning to explore the architecture of a neural network calling it the AutoML project where the blog claimed "To make this process of designing machine learning models much more accessible, we’ve been exploring ways to automate the design of machine learning models." It was found that AutoML can design small neural networks that perform on par with neural networks designed by human experts, but these results were constrained to small academic datasets like CIFAR-10, and Penn Treebank.

This study was further extended to more challenging problems and datasets in another blog where they proposed NASNet

Both these blogs were written in 2017 and I'm not very sure how much progress has been made on this since, but I hope these blogs helped!

  • $\begingroup$ What I mean by "structure" is the nodes and weights. $\endgroup$ – Dimer Jul 26 at 9:56
  • 1
    $\begingroup$ Technically yes. Backpropogation can be represented by neural networks, but it makes no sense as such to do so as if a well defined fixed algorithm can achieve something why use an approximation. There are alternatives to gradient descent but I cant think of any for backpropogation as whole (might still exist) because when on a specific point on a curve (loss function), all you have is the gradient at that point and the neighboring points, cant see how there can be another way to reach the minima without following the path of maximum descent $\endgroup$ – Aman Shenoy Jul 26 at 10:54
  • 1
    $\begingroup$ i dont think brain is using BP or GD.. $\endgroup$ – Dimer Jul 26 at 11:14
  • 6
    $\begingroup$ Neural networks are not modelling a human brain. The most basic part of a neural network is a neuron which is modeled from the idea of how our brain cells work. Hence the name. Again, Neural networks are not modelling a human brain $\endgroup$ – Aman Shenoy Jul 26 at 11:24
  • 4
    $\begingroup$ Since a neural network does iteratively learn its own weights, this is wrong. Neural networks do not usually modify their own weights. It's the gradient descent (combined with back-propagation) that usually changes the weights of the network. $\endgroup$ – nbro Jul 28 at 20:00

Yes, the notion is valid and it has been indeed explored to some extent, although we are still far away from a breath-taking result. These are the topics that have been explored in that regard and as far as I know:

Regarding code generation, the most successful results imply the use of Domain-Specific Languages and/or strong restrictions. A neural policy would then be used to dynamically explore that domain. I recommend you these articles:

  • S. Reed & N. de Freitas. Neural Programmer-Interpreters.
  • M. Balog et al. DeepCoder: Learning to Write Programs
  • D. A. Abolafia et al. Neural Program Synthesis with Priority Queue Training

Regarding the use of a NN as an optimizer, I'd highlight two articles, which explore a neural optimizer and an initial-state predictor, respectively:

  • O. Wichrowska et al. Learned Optimizers that Scale and Generalize.
  • S. Ravi & H. Larochelle. Optimization as a Model for Few-Shot Learning.

My personal bet goes for the descriptive methods i.e. the ones that solve the problem by creating a representation to work on (like generating code, which isn't the only way), but as said, this is starting and is mostly speculative.


Can a neural network modify its own weights?

One important step in training a neural network is called backpropagation. In the course of this process, the weights of the neural network are updated into a direction that minimizes the training loss. Usually, this step happens after each batch (with batch gradient descent) or after each sample (with stochastic gradient descent).

In other words, training a neural network does not mean anything else than iteratively updating its weights. However, note that the weights are not updated by the neural network itself, but by the optimizer and the machine learning framework you use.

Can a neural network modify its architecture?

Currently, there is no popular solution of a neural network which is able to change its own structure. However, there has been a lot of research in this area at least since the 90s. The search-term with which you will find most research in this area is self-organizing networks. Some of the first self-organizing networks were from Fritzke (1994) and from Bruske and Sommer (1994).

However, these were not neural networks that learned how to optimize themselves but neural networks that had the ability to grow while following certain rules. And that has a reason. If you think about it, you want your network to be optimized in solving a certain problem (e.g. detecting breast cancer on X-ray images) as good as possible. You do not want it to waste time and resources on learning how to optimize neural networks.

But there are other approaches in this direction! There is a lot of research on how to train a neural network on the task of creating other neural networks. Currently, the most famous are MetaQNN (2017) (less known) and NASNet (2017). They use reinforcement learning to train a model on creating architectures that maximize the performance (e.g. validation accuracy). However, even as they use reinforcement learning, they perform only slightly better than random search (see here). That means the question is more how you define the search space than whether you use neural networks for architecture optimization.


I believe the question you're asking is whether or not it is possible for a neural network to edit it's own structure and learning ability intelligently.

I would argue this is a matter of philosophy, of how intelligent can we program a computer to be, and I personally believe that yes, at some point humans will develop some form of an algorithm capable of intelligently improving upon on its own learning ability. Right now, I do not think it exists (as far as I know), and there are equal arguments stating that this isn't possible.

It is by no means an easy task, as even nature couldn't replicate it. Sure, humans have gotten great at tailoring the information we receive so it is easier to learn, but as to actually improving the learning ability we were born with, I don't believe we can do much about it. The only way intelligence emerged in nature was through evolution, a mechanic of chance, not meaningful decisions.

Ultimately, I do believe effort is being dedicated to this idea, but I don't think it has yet been achieved. The reason I can't be sure, is because there is a rather large incentive to keep something like this a secret should it be done.


There are works on expandable neural networks, for example, Lifelong learning with dynamically expandable networks by Yoon et al. So, if you consider the whole system with expanding algorithm (in the same way as you consider an SGD optimizer as part of a network system), then yes, it's totally possible.

But they didn't show breakthrough performance on any task, as far as I know, at least at the moment. The key challenge is that's hard to say, do you need to expand or just train more - and where exactly do you need to expand.


There is absolutely zero evidence that an artificial neural network (ANN) can change itself. Arguably, self-modification requires some form of consciousness (that is, the state of being aware of and responsive to one's surroundings) or self-awareness (that is, conscious knowledge of one's own character and feelings), which (arguably) no ANN currently possesses (and probably will never possess).

Humans create algorithms or ANNs that change other ANNs. Nobody else does this apart from humans (AFAIK)!

There are people that suggest that evolutionary algorithms or gradient-based optimization algorithms (like gradient descent) combined with back-propagation applied to ANNs are a form of self-modification, but this is at best misleading and at worst completely wrong, because these are external (to the ANN) algorithms.

Humans can modify themselves (e.g. we can dye our own hair) because we are conscious and self-aware beings. Our hair is part of us (as opposed to the case of the relation between gradient descent and ANNs).


Neural Networks aren't the same as human brains, thus as per that the first question you ask is maybe thinking too far. The neural networks cannot be aware of anything and thus not understand nor edit any code.

OK, you further explained it would fine tune some parameters, but that I wouldn't call editing the code. Editing the algorithm to some other would be called editing code and that would need higher level of knowledge and AI level, that NNs do not have.

The idea itself in question 1 is valid, surely it has been discussed and also researched, but the level of which any computer then is aware about itself and how much variety it can generate to code or alter its function, is a different topic. And NNs are too dummy for that.

To get some idea, look:


That article pretty much tells what NNs can do and what not. Neural networks as simply put try find inner logic of certain (matrix) function. About data it could handle, the hyper parameters of a NN could be also numbers and thus are as datatype suitable. Whether that is feasible, please read question on


where the only one answer is mainly filled on drawbacks of such a case and primarily, that doing so in a single NN tuning itself is impossible. Main issue is that hyper parameters are not differentiable and no gradient descent can't thus learn them.


While I dont know if something like what I will describe exist, I will give my idea of how this might be achieved. I think there are two ways, one being an nlp network that as you said, you "show the net its own code" and let if try to output code that runs but is different, likely this would be done in an rl environment with another problem domain to determine loss or fitness of the new code it outputs to be evaluated then you (meaning it would also have outputs for the this task domain as it needs to be evaluated just like the new version of itself is). The other way would be a cppn that has output functions that control the modification of new structures and weights of itself, you may have one node that determines if you should add or remove a layer (sigmoid), another two ouputs one that determines which layer and another for the amount of nodes to add or remove to the layer (maybe relu or some other linear function that could be rounded down and used for this), and so on and so forth for whatever you want it to learn to control. Again you would likely have this running in an rl environment with an accompanying fitness function for a problem other than modifying itself and set of outputs that are evaluated by the fitness function, then you would have a self contained network that can learn to "build itself" into a network that converges to a high degree of fitness. You would have some sort of optimization algorithm to adjusts weights before making the modifications that are output. This is just a total shot in the dark but I imagine it could be done by weaseling in the modification of itself into your existing rl environments problem space.


I am very surprised no one mentioned the 'Lottery Ticket Hypothesis' paper which won the best paper award in ICLR 2019. Although, the main idea has been presented as ways to reduce connections between successive nodes in a Neural Network, it can be viewed as a way Neural Network learning for itself which of its connections are not important.

The main aim is as follows:

  • Reduce the number of weights by cutting connecting weights between successive nodes.

How to know which weight to trim?

  • The method used in the paper is very simple, remove connections with lowest values of weights (after some epochs of training).

What is the effect?

  • Very strangely the authors found out these Neural Nets with less number of connections performed significantly better than denser Neural Networks. In my opinion, or as I interpret it, these dense connections were introducing noise/irrelevant details which was fudging actual important things, and hence removing these improved the performance of the Neural Net drastically.

The authors have proposed several experiments which show that even if you start to train with the final sparse (lesser number of connections) structure itself, the performance will not reach the desired level. Hence, the final architecture is also a function of the initialisation of weights. Thus a Neural Network itself is learning how to depending on initialisation and inputs which structure is suitable for it. The authors have also extended the results for CNN's.

  • $\begingroup$ PS:I am working on a somewhat similar idea and I'll post it if it is formalised. $\endgroup$ – DuttaA Jul 31 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.