Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit 56e2729

Browse files
committed
Remove hapi.text apis' reuse parameter args for coverage.
test=develop
1 parent 6e96261 commit 56e2729

4 files changed

Lines changed: 148 additions & 803 deletions

File tree

examples/sentiment_classification/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
from paddle.fluid.dygraph.base import to_variable
1717
import numpy as np
1818
from hapi.model import Model
19-
from hapi.text.text import GRUEncoder as BiGRUEncoder
20-
from hapi.text.test import BOWEncoder, CNNEncoder, GRUEncoder
19+
from hapi.text.text import _GRUEncoder as GRUEncoder
20+
from hapi.text.text import _GRUEncoder as BiGRUEncoder
21+
from hapi.text.test import BOWEncoder, CNNEncoder
2122

2223

2324
class CNN(Model):

hapi/tests/test_text.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,6 @@
2828
from hapi.text.text import *
2929

3030

31-
def sigmoid(x):
32-
return 1. / (1. + np.exp(-x))
33-
34-
35-
def tanh(x):
36-
return 2. * sigmoid(2. * x) - 1.
37-
38-
39-
def lstm_step(step_in, pre_hidden, pre_cell, gate_w, gate_b, forget_bias=1.0):
40-
concat_1 = np.concatenate([step_in, pre_hidden], 1)
41-
42-
gate_input = np.matmul(concat_1, gate_w)
43-
gate_input += gate_b
44-
i, j, f, o = np.split(gate_input, indices_or_sections=4, axis=1)
45-
46-
new_cell = pre_cell * sigmoid(f + forget_bias) + sigmoid(i) * tanh(j)
47-
new_hidden = tanh(new_cell) * sigmoid(o)
48-
49-
return new_hidden, new_cell
50-
51-
52-
def gru_step(step_in, pre_hidden, gate_w, gate_b, candidate_w, candidate_b):
53-
concat_1 = np.concatenate([step_in, pre_hidden], 1)
54-
55-
gate_input = np.matmul(concat_1, gate_w)
56-
gate_input += gate_b
57-
gate_input = sigmoid(gate_input)
58-
r, u = np.split(gate_input, indices_or_sections=2, axis=1)
59-
60-
r_hidden = r * pre_hidden
61-
62-
candidate = np.matmul(np.concatenate([step_in, r_hidden], 1), candidate_w)
63-
64-
candidate += candidate_b
65-
c = tanh(candidate)
66-
67-
new_hidden = u * pre_hidden + (1 - u) * c
68-
69-
return new_hidden
70-
71-
7231
class ModuleApiTest(unittest.TestCase):
7332
@classmethod
7433
def setUpClass(cls):

hapi/text/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
from hapi.text.text import TransformerCell as TransformerCell
3838
from hapi.text.text import TransformerBeamSearchDecoder as TransformerBeamSearchDecoder
3939

40-
from hapi.text.text import GRUCell as GRUCell
41-
from hapi.text.text import GRUEncoderCell as GRUEncoderCell
42-
from hapi.text.text import BiGRU as BiGRU
4340
from hapi.text.text import LinearChainCRF as LinearChainCRF
4441
from hapi.text.text import CRFDecoding as CRFDecoding
4542
from hapi.text.text import SequenceTagging as SequenceTagging

0 commit comments

Comments
 (0)