# Converting SymbolicNeuralNetwork to numeric function

**URL:** <https://discourse.julialang.org/t/converting-symbolicneuralnetwork-to-numeric-function/134939>\
**Category:** General Usage\
**Tags:** question, modelingtoolkit\
**Created:** [January 7, 2026, 4:37pm UTC](https://discourse.julialang.org/t/converting-symbolicneuralnetwork-to-numeric-function/134939 "2026-01-07T16:37:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oudeis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oudeis/32/220231_2.png) [@oudeis](https://discourse.julialang.org/u/oudeis)\
**Post date:** [January 7, 2026, 4:37pm UTC](https://discourse.julialang.org/t/converting-symbolicneuralnetwork-to-numeric-function/134939/1 "2026-01-07T16:37:13Z")

</div>

Hi all,

I have a symbolic neural network, parameterised by `theta=theta_vals` which I wish to evaluate at some point `x`. I construct the neural network as:

```julia-auto
using Lux, ModelingToolkit, ModelingToolkitNeuralNets

nn_arch = Lux.Chain(
    Lux.Dense(1 => 3, Lux.softplus, use_bias = true),
    Lux.Dense(3 => 1, Lux.softplus, use_bias = true)
)

nn, theta = SymbolicNeuralNetwork(; 
    nn_p_name = :theta,
    chain = nn_arch,
    n_input = 1,
    n_output = 1
    )
    
theta_vals = ModelingToolkit.getdefault(theta)

```

I tried to convert nn to a function I could evaluate numerically by running

```julia-auto
@variables x[1]
nn_num = ModelingToolkit.build_function(nn.f, theta, x; expression = Val{false})
nn_num(theta_vals, [1.0])

```

But this threw

```julia-auto
ERROR: UndefVarError: `NN` not defined in `Symbolics`

```

I’m not sure where I’m going wrong here - how can I construct the parameterised neural network function that I can evaluate numerically?

Thanks!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 8, 2026, 4:09pm UTC](https://discourse.julialang.org/t/converting-symbolicneuralnetwork-to-numeric-function/134939/2 "2026-01-08T16:09:09Z")

</div>

Is there a reason you used `nn.f` instead of `nn`?

---

<div class="post-metadata">

**Author:** ![oudeis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oudeis/32/220231_2.png) [@oudeis](https://discourse.julialang.org/u/oudeis)\
**Post date:** [January 9, 2026, 10:33pm UTC](https://discourse.julialang.org/t/converting-symbolicneuralnetwork-to-numeric-function/134939/3 "2026-01-09T22:33:40Z")

</div>

Not particularly - I did try using nn instead, but got the same error.

When I run `typeof(nn)` I get:

`Symbolics.CallWithMetadata{SymbolicUtils.FnType{Tuple, Vector{Real}, ModelingToolkitNeuralNets.StatelessApplyWrapper{Chain{@NamedTuple{layer_1::Dense{typeof(softplus), Int64, Int64, Nothing, Nothing, Static.True}, layer_2::Dense{typeof(softplus), Int64, Int64, Nothing, Nothing, Static.True}}, Nothing}}}, Base.ImmutableDict{DataType, Any}}`

and I think I want to ‘get at’ the `ModelingToolkitNeuralNets...Static.True}}, Nothing}}` bit, which I would hope to pass parameters and inputs to.
