CNNArch.mc4 4.82 KB
Newer Older
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
1
package de.monticore.lang.monticar;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
2 3 4

grammar CNNArch extends de.monticore.common.Common {

5 6
    CNNArchCompilationUnit = Architecture;

7
    symbol scope Architecture = "architecture"
8
                                 Name& "{"
9 10 11
                                 (MainLayer)+
                                 OutputLayer
                                 "}";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
12

13 14 15
    //InputPort = Name "-->";
    //OutputPort = "-->" Name;

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
16 17 18 19 20 21 22 23
    interface Layer;
    ast Layer = method ASTMethod getMethod(){};
    interface Method;
    interface MainLayerMethod extends Method;
    interface OutputLayerMethod extends Method;

    interface ArgumentAssignment;
    ast ArgumentAssignment = method public Enum getLhs(){}
24
                             method public ASTArgumentRhs getRhs(){};
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
25

26 27 28 29 30
    ArgumentRhs = stringVal:String
                | intVal:Num_Int
                | doubleVal:Num_Double
                | intTuple:IntTuple
                | refOrBool:Name;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
31 32 33 34 35 36 37 38 39 40
    IntTuple = "(" values:Num_Int "," values:(Num_Int || ",")+ ")";



    MainLayer implements Layer = method:MainLayerMethod;
    OutputLayer implements Layer = method:OutputLayerMethod;



    ConvolutionMethod implements MainLayerMethod = name:"Convolution" "(" arguments:(ConvolutionArgumentAssignment || ",")* ")";
41
    ConvolutionArgumentAssignment implements ArgumentAssignment = lhs:ConvolutionArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
42 43 44 45 46 47 48
    enum ConvolutionArgument = KERNEL:"kernel"               //required
                             | NUMFILTER:"num_filter"        //required
                             | STRIDE:"stride"
                             | PAD:"pad"
                             | NOBIAS:"no_bias";

    FullyConnectedMethod implements MainLayerMethod = name:"FullyConnected" "(" arguments:(FullyConnectedArgumentAssignment || ",")* ")";
49
    FullyConnectedArgumentAssignment implements ArgumentAssignment = lhs:FullyConnectedArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
50 51 52 53
    enum FullyConnectedArgument = NUMHIDDEN:"num_hidden"     //required
                                | NOBIAS:"no_bias";

    ActivationMethod implements MainLayerMethod = name:"Activation" "(" arguments:(ActivationArgumentAssignment || ",")* ")";
54
    ActivationArgumentAssignment implements ArgumentAssignment = lhs:ActivationArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
55 56 57
    enum ActivationArgument = ACTTYPE:"act_type";            //required

    PoolingMethod implements MainLayerMethod = name:"Pooling" "(" arguments:(PoolingArgumentAssignment || ",")* ")";
58
    PoolingArgumentAssignment implements ArgumentAssignment = lhs:PoolingArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
59 60 61 62 63 64 65
    enum PoolingArgument = KERNEL:"kernel"                   //required
                         | POOLTYPE:"pool_type"              //required
                         | POOLINGCONVENTION:"pooling_convention"
                         | STRIDE:"stride"
                         | PAD:"pad";

    DropoutMethod implements MainLayerMethod = name:"Dropout" "(" arguments:(DropoutArgumentAssignment || ",")* ")";
66
    DropoutArgumentAssignment implements ArgumentAssignment = lhs:DropoutArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
67 68 69 70
    enum DropoutArgument = P:"p"
                         | MODE:"mode";

    LRNMethod implements MainLayerMethod = name:"LRN" "(" arguments:(LRNArgumentAssignment || ",")* ")";
71
    LRNArgumentAssignment implements ArgumentAssignment = lhs:LRNArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    enum LRNArgument = ALPHA:"alpha"
                     | BETA:"beta"
                     | KNORM:"knorm"
                     | NSIZE:"nsize";                         //required

    FlattenMethod implements MainLayerMethod = name:"Flatten" "(" ")";




    StandardOutputLayerMethod implements OutputLayerMethod = (optName:"SoftmaxOutput"
                                                           | optName:"MAERegressionOutput"
                                                           | optName:"LinearRegressionOutput"
                                                           | optName:"LogisticRegressionOutput") "("
                                                             arguments:(StandardOutputArgumentAssignment || ",")* ")";
    ast StandardOutputLayerMethod = method public String getName(){
                                          return optName.get();
                                      };
90
    StandardOutputArgumentAssignment implements ArgumentAssignment = lhs:StandardOutputArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
91 92 93 94 95
    enum StandardOutputArgument = GRADSCALE:"grad_scale";


    SVMOutputLayerMethod implements OutputLayerMethod = name:"SVMOutput" "("
                                                            arguments:(SVMOutputArgumentAssignment || ",")* ")";
96
    SVMOutputArgumentAssignment implements ArgumentAssignment = lhs:SVMOutputArgument "=" rhs:ArgumentRhs;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
97 98 99 100
    enum SVMOutputArgument = MARGIN:"margin"
                           | REGULARIZATIONCOEFFICIENT:"regularization_coefficient"
                           | USELINEAR:"use_linear";
}