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

Commit 50ef702

Browse files
shreydesaifacebook-github-bot
authored andcommitted
created weight norm option (#809)
Summary: Pull Request resolved: #809 Weight norm decouples a weight matrix into its magnitude and direction and optimizes them separately -- this is very helpful in speeding up convergence and getting better performance overall. This diff adds an option to use weight norm as a normalization strategy on conv1d layers. Reviewed By: geof90 Differential Revision: D16403533 fbshipit-source-id: 0890da42fc0fb5fa80c5985718fa1ae8f51b9b1b
1 parent 9f3b2b0 commit 50ef702

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

pytext/config/module_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class CNNParams(ConfigBase):
2222
kernel_num: int = 100
2323
# Kernel sizes to use in convolution
2424
kernel_sizes: List[int] = [3, 4]
25+
# Use weight norm in convolution
26+
weight_norm: bool = False
2527

2628

2729
class PoolingType(Enum):

pytext/models/representations/deepcnn.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, config: Config, embed_dim: int) -> None:
3030

3131
out_channels = config.cnn.kernel_num
3232
kernel_sizes = config.cnn.kernel_sizes
33+
weight_norm = config.cnn.weight_norm
3334

3435
conv_layers = []
3536
linear_layers = []
@@ -46,6 +47,9 @@ def __init__(self, config: Config, embed_dim: int) -> None:
4647
single_conv = nn.Conv1d(
4748
in_channels, 2 * out_channels, k, padding=int((k - 1) / 2)
4849
)
50+
single_conv = (
51+
nn.utils.weight_norm(single_conv) if weight_norm else single_conv
52+
)
4953
conv_layers.append(single_conv)
5054
in_channels = out_channels
5155

0 commit comments

Comments
 (0)