microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.51k stars 4.28k forks source link

Use of brackets vs braces #872

Closed embeddetech closed 8 years ago

embeddetech commented 8 years ago

Hello, I'm currently trying to slowly digest the brainscript syntax. Is it correct that the use of the bracket in the example below (beginning "BrainScriptNetworkBuilder = [") is deprecated, and the use of braces is recommended (i.e. "BrainScriptNetworkBuilder = {")? And the best explanation for this is that "BrainScriptNetworkBuilder = " is a record declaration as opposed to a function/macro declaration?

https://github.com/Microsoft/CNTK/wiki/Train-a-regression-model-on-images

frankseide commented 8 years ago

Yes, it is deprecated; yes, it is a record declaration.

However, many functions also create a record and either return the entire record, or select one element to return (this in a way of using local variables).

embeddetech commented 8 years ago

Thank you Frank! So from the example above, this is the definition of a function that returns a record:

model (features) = {...}

Then inside that, this line below calls the LinearLayer function with arguments in the braces, and that function returns a function pointer/lambda which is then immediately called with (featNorm) as its argument, and this result is assigned to h1?

h1 = LinearLayer {100, init="gaussian", initValueScale=1.5} (featNorm)

Think I'm slowly getting there... thanks for helping the slow kids in class...

frankseide commented 8 years ago

Typically, it is

model (features) = { a = ... ; b = ...;  z = ... }.z

which technically creates a record but then immediately pulls out z. You can think of a and b etc as variables in a local scope.

h1 = LinearLayer {100, init="gaussian", initValueScale=1.5} (featNorm)

Here, the curly braces mean something entirely different--function calls can use ( ) or { }, and by convention, functions that create model parameters use { }. The above is actually two function calls:

This separation was done so that it is always clear where new parameters are created. It also has additional benefits: