Skip to content

Commit 7a56705

Browse files
committed
polish doc
1 parent fda1a78 commit 7a56705

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

paddle/fluid/operators/lstm_op.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,17 @@ Long-Short Term Memory (LSTM) Operator.
184184
The defalut implementation is diagonal/peephole connection
185185
(https://arxiv.org/pdf/1402.1128.pdf), the formula is as follows:
186186
187-
$$
188-
i_t = \sigma(W_{ix}x_{t} + W_{ih}h_{t-1} + W_{ic}c_{t-1} + b_i) \\
187+
$$ i_t = \\sigma(W_{ix}x_{t} + W_{ih}h_{t-1} + W_{ic}c_{t-1} + b_i) $$
189188
190-
f_t = \sigma(W_{fx}x_{t} + W_{fh}h_{t-1} + W_{fc}c_{t-1} + b_f) \\
189+
$$ f_t = \\sigma(W_{fx}x_{t} + W_{fh}h_{t-1} + W_{fc}c_{t-1} + b_f) $$
191190
192-
\tilde{c_t} = act_g(W_{cx}x_t + W_{ch}h_{t-1} + b_c) \\
191+
$$ \\tilde{c_t} = act_g(W_{cx}x_t + W_{ch}h_{t-1} + b_c) $$
193192
194-
o_t = \sigma(W_{ox}x_{t} + W_{oh}h_{t-1} + W_{oc}c_t + b_o) \\
193+
$$ o_t = \\sigma(W_{ox}x_{t} + W_{oh}h_{t-1} + W_{oc}c_t + b_o) $$
195194
196-
c_t = f_t \odot c_{t-1} + i_t \odot \tilde{c_t} \\
195+
$$ c_t = f_t \\odot c_{t-1} + i_t \\odot \\tilde{c_t} $$
197196
198-
h_t = o_t \odot act_h(c_t)
199-
$$
197+
$$ h_t = o_t \\odot act_h(c_t) $$
200198
201199
- W terms denote weight matrices (e.g. $W_{xi}$ is the matrix
202200
of weights from the input gate to the input), $W_{ic}, W_{fc}, W_{oc}$

python/paddle/fluid/layers/layer_function_generator.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ def _type_to_str_(tp):
4949
_two_bang_pattern_ = re.compile(r"!!([^!]+)!!")
5050

5151

52+
def escape_math(text):
53+
return _two_bang_pattern_.sub(
54+
r'$$\1$$',
55+
_single_dollar_pattern_.sub(r':math:`\1`',
56+
_two_dollar_pattern_.sub(r"!!\1!!", text)))
57+
58+
5259
def _generate_doc_string_(op_proto):
5360
"""
5461
Generate docstring by OpProto
@@ -60,12 +67,6 @@ def _generate_doc_string_(op_proto):
6067
str: the document string
6168
"""
6269

63-
def escape_math(text):
64-
return _two_bang_pattern_.sub(
65-
r'$$\1$$',
66-
_single_dollar_pattern_.sub(
67-
r':math:`\1`', _two_dollar_pattern_.sub(r"!!\1!!", text)))
68-
6970
if not isinstance(op_proto, framework_pb2.OpProto):
7071
raise TypeError("OpProto should be `framework_pb2.OpProto`")
7172

@@ -233,9 +234,6 @@ def __impl__(func):
233234
return __impl__
234235

235236

236-
_inline_math_single_dollar = re.compile(r"\$([^\$]+)\$")
237-
238-
239237
def templatedoc(op_type=None):
240238
"""
241239
Decorator of layer function. It will use the docstring from the layer
@@ -253,9 +251,6 @@ def templatedoc(op_type=None):
253251
def trim_ending_dot(msg):
254252
return msg.rstrip('.')
255253

256-
def escape_inline_math(msg):
257-
return _inline_math_single_dollar.sub(repl=r':math:`\1`', string=msg)
258-
259254
def __impl__(func):
260255
if op_type is None:
261256
op_type_name = func.__name__
@@ -269,7 +264,7 @@ def __impl__(func):
269264
for line in comment_lines:
270265
line = line.strip()
271266
if len(line) != 0:
272-
comment += escape_inline_math(line)
267+
comment += escape_math(line)
273268
comment += " "
274269
elif len(comment) != 0:
275270
comment += "\n \n "

0 commit comments

Comments
 (0)