importmathimportpaddle.fluid.dygraphasdgimportpaddle.fluidasfluidimportpaddle.fluid.layersaslayersclassPreNet(dg.Layer):def__init__(self,input_size,hidden_size,output_size,dropout_rate=0.2):""" :param input_size: dimension of input :param hidden_size: dimension of hidden unit :param output_size: dimension of output """super(PreNet,self).__init__()self.input_size=input_sizeself.hidden_size=hidden_sizeself.output_size=output_sizeself.dropout_rate=dropout_ratek=math.sqrt(1/input_size)self.linear1=dg.Linear(input_size,hidden_size,param_attr=fluid.ParamAttr(initializer=fluid.initializer.XavierInitializer()),bias_attr=fluid.ParamAttr(initializer=fluid.initializer.Uniform(low=-k,high=k)))k=math.sqrt(1/hidden_size)self.linear2=dg.Linear(hidden_size,output_size,param_attr=fluid.ParamAttr(initializer=fluid.initializer.XavierInitializer()),bias_attr=fluid.ParamAttr(initializer=fluid.initializer.Uniform(low=-k,high=k)))defforward(self,x):""" Pre Net before passing through the network. Args: x (Variable): Shape(B, T, C), dtype: float32. The input value. Returns: x (Variable), Shape(B, T, C), the result after pernet. """x=layers.dropout(layers.relu(self.linear1(x)),self.dropout_rate)x=layers.dropout(layers.relu(self.linear2(x)),self.dropout_rate)returnx