title: Julia network expression Flux
body: <p>Learning Julia metaprogramming to automatically construct ANN by expression. While everything works well for inference, a backward stage raises an error:</p>
  
  <blockquote>
    <p>LoadError: Can't differentiate foreigncall expression</p>
  </blockquote>
  
  <p>The next code shows where the problem appears. While eval(net(x)) works well, for some reason it throws an error at the gradient computation stage.</p>
  
  <pre><code># define ANN by expression
  net(x) = :($w2 * relu.($w1 * $x .+ $b1) .+ $b2)
  
  # define loss and network evaluation
  loss(x, y) = Flux.logitcrossentropy(eval(net(x)), y)
  
  θ = Flux.Params([w1, b1, w2, b2])
  
  # eval network and calculate gradients
  gs = gradient(() -&gt; loss(features, labels), θ)  # where the problem appears
  </code></pre>