Answers.Body: <p>You discovered already one solution for your problem: Zero-Padding.</p>
  
  <p>There are two other common possibilities:</p>
  
  <ol>
  <li>Using Recurrent NNs<br />This is often used at text processing, where you feed each word one after another into your model.</li>
  <li>Using Recursive NNs (I wont recommend this for your use case)<br />This method is also frequently used in word processing, but is more often applied in the semantic analysis of text. You reduce the text to the essential, until it has reached the desired length. However, information is lost in this process.</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-17T00:10:11.493Z
Answers.Text: It would be nice if you can also provide a link to a research work/paper where your suggestions are applied in the context of the original problem.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-16T21:20:36.393Z
Answers.LastActivityDate: 2020-02-16T21:20:36.393Z
Answers.UserDisplayName: Luca Jung
Body: <p>In my work I have a given source code for a module. From this module I generate an AST, whose size is dependent on the size of the module (e.g. more source code -> bigger AST). I want to train a neural network model which will learn a general structure of a module and be able to rate (on a scale of 0 to 1) how "good" a module is structure wise (if requires are at the beginning, followed by local functions, variables and finally returns). Now I have learnt that Convolutional NNs are quite convenient for this, but the problem I can't seem to solve is that they require a fixed sized input which I can't produce. If I add zero-padding then the outcome will be skewed and the accuracy will suffer. Is there a clear solution to this problem?</p>
  
Tags: <neural-networks><convolutional-neural-networks><graphs>
Title: How to solve the problem of variable-sized AST as input for a (convolutional) neural network model?
UserDisplayName: Michael Kročka
ThreadText: # How to solve the problem of variable-sized AST as input for a (convolutional) neural network model?
  
  (Asked by: username_0 on 2020-02-13)
  
  In my work I have a given source code for a module. From this module I generate an AST, whose size is dependent on the size of the module (e.g. more source code -> bigger AST). I want to train a neural network model which will learn a general structure of a module and be able to rate (on a scale of 0 to 1) how "good" a module is structure wise (if requires are at the beginning, followed by local functions, variables and finally returns). Now I have learnt that Convolutional NNs are quite convenient for this, but the problem I can't seem to solve is that they require a fixed sized input which I can't produce. If I add zero-padding then the outcome will be skewed and the accuracy will suffer. Is there a clear solution to this problem?
  
  **Tags:** neural-networks, convolutional-neural-networks, graphs
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-02-16. Score: 1
  
  You discovered already one solution for your problem: Zero-Padding.
  
  There are two other common possibilities:
  
  1. Using Recurrent NNs  
     This is often used at text processing, where you feed each word one after another into your model.
  2. Using Recursive NNs (I wont recommend this for your use case)  
     This method is also frequently used in word processing, but is more often applied in the semantic analysis of text. You reduce the text to the essential, until it has reached the desired length. However, information is lost in this process.
  
  > **Comments:**
  > **username_2**: It would be nice if you can also provide a link to a research work/paper where your suggestions are applied in the context of the original problem.  
  
  ---
  
  