From e58295d657a4a8730b5041d53bff0a163efe4272 Mon Sep 17 00:00:00 2001 From: xuyige Date: Tue, 28 Aug 2018 13:40:12 +0800 Subject: [PATCH] add test code for testing other modules --- test/modules/test_other_modules.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/modules/test_other_modules.py diff --git a/test/modules/test_other_modules.py b/test/modules/test_other_modules.py new file mode 100644 index 00000000..908b7b5d --- /dev/null +++ b/test/modules/test_other_modules.py @@ -0,0 +1,30 @@ + + +import torch +import unittest + +from fastNLP.modules.other_modules import GroupNorm, LayerNormalization, BiLinear + + +class TestGroupNorm(unittest.TestCase): + def test_case_1(self): + gn = GroupNorm(num_features=1, num_groups=10, eps=1.5e-5) + x = torch.randn((20, 50, 10)) + y = gn(x) + + +class TestLayerNormalization(unittest.TestCase): + def test_case_1(self): + ln = LayerNormalization(d_hid=5, eps=2e-3) + x = torch.randn((20, 50, 5)) + y = ln(x) + + +class TestBiLinear(unittest.TestCase): + def test_case_1(self): + bl = BiLinear(n_left=5, n_right=5, n_out=10, bias=True) + x_left = torch.randn((7, 10, 20, 5)) + x_right = torch.randn((7, 10, 20, 5)) + y = bl(x_left, x_right) + print(bl) + bl2 = BiLinear(n_left=15, n_right=15, n_out=10, bias=False)