Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

created weight_norm option for deep cnn representation #809

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pytext/config/module_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class CNNParams(ConfigBase):
kernel_num: int = 100
# Kernel sizes to use in convolution
kernel_sizes: List[int] = [3, 4]
# Use weight norm in convolution
weight_norm: bool = False


class PoolingType(Enum):
Expand Down
4 changes: 4 additions & 0 deletions pytext/models/representations/deepcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, config: Config, embed_dim: int) -> None:

out_channels = config.cnn.kernel_num
kernel_sizes = config.cnn.kernel_sizes
weight_norm = config.cnn.weight_norm

conv_layers = []
linear_layers = []
Expand All @@ -46,6 +47,9 @@ def __init__(self, config: Config, embed_dim: int) -> None:
single_conv = nn.Conv1d(
in_channels, 2 * out_channels, k, padding=int((k - 1) / 2)
)
single_conv = (
nn.utils.weight_norm(single_conv) if weight_norm else single_conv
)
conv_layers.append(single_conv)
in_channels = out_channels

Expand Down