模组

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

class ltp.nn.Swish[source]

Bases: 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)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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 ltp.nn.HSwish[source]

Bases: 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)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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 ltp.nn.Mish[source]

Bases: 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)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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 ltp.nn.Bilinear(in1_features, in2_features, out_features, expand=False, bias_x=True, bias_y=True)[source]

Bases: torch.nn.modules.module.Module

forward(x1, x2)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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()[source]

Set the extra representation of the module

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

class ltp.nn.Biaffine(in1_features, in2_features, out_features, bias_x=True, bias_y=True, **kwargs)[source]

Bases: torch.nn.modules.module.Module

forward(x1, x2)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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()[source]

Set the extra representation of the module

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

class ltp.nn.RelativeTransformer(input_size, num_layers, hidden_size, num_heads, dropout, after_norm=True, max_length=1024)[source]

Bases: torch.nn.modules.module.Module

forward(x, length, gold=None)[source]
Parameters
  • x – batch_size x max_len

  • length – sequence length, B