模组

这里用于提供类似Pytorch原生的一些模块,之后使用Modules进行包装调用。

class Swish[源代码]

基类:torch.nn.modules.module.Module

Swish activation function:

\[\text{Swish}(x) = x * Sigmoid(x)\]
Shape:
  • Input: \((N, *)\) where * means, any number of additional dimensions

  • Output: \((N, *)\), same shape as the input

forward(input)[源代码]

Defines the computation performed at every call.

Should be overridden by all subclasses.

注解

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class HSwish[源代码]

基类:torch.nn.modules.module.Module

Hard Swish activation function:

\[\text{Swish}(x) = x * \frac{ReLU6(x+3)}{6}\]
Shape:
  • Input: \((N, *)\) where * means, any number of additional dimensions

  • Output: \((N, *)\), same shape as the input

forward(input)[源代码]

Defines the computation performed at every call.

Should be overridden by all subclasses.

注解

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class Mish[源代码]

基类:torch.nn.modules.module.Module

Mish activation function:

\[\text{Mish}(x) = x * tanh(\ln(1 + e^x))\]
Shape:
  • Input: \((N, *)\) where * means, any number of additional dimensions

  • Output: \((N, *)\), same shape as the input

forward(input)[源代码]

Defines the computation performed at every call.

Should be overridden by all subclasses.

注解

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class Bilinear(in1_features, in2_features, out_features, expand=False, bias_x=True, bias_y=True)[源代码]

基类:torch.nn.modules.module.Module

forward(x1, x2)[源代码]

Defines the computation performed at every call.

Should be overridden by all subclasses.

注解

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

extra_repr()[源代码]

Set the extra representation of the module

To print customized extra information, you should reimplement this method in your own modules. Both single-line and multi-line strings are acceptable.

class Biaffine(in1_features, in2_features, out_features, bias_x=True, bias_y=True, **kwargs)[源代码]

基类:torch.nn.modules.module.Module

forward(x1, x2)[源代码]

Defines the computation performed at every call.

Should be overridden by all subclasses.

注解

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

extra_repr()[源代码]

Set the extra representation of the module

To print customized extra information, you should reimplement this method in your own modules. Both single-line and multi-line strings are acceptable.

class RelativeTransformer(input_size, num_layers, hidden_size, num_heads, dropout, after_norm=True, max_length=1024)[源代码]

基类:torch.nn.modules.module.Module

forward(x, length, gold=None)[源代码]
参数
  • x – batch_size x max_len

  • length – sequence length, B