Skip to content

Commit 8c9041f

Browse files
committed
Refine LinearCRF
1 parent 0d29e65 commit 8c9041f

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

paddle/fluid/operators/linear_chain_crf_op.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ class LinearChainCRFOpMaker : public framework::OpProtoAndCheckerMaker {
6767
"mini-batch. Note: S is equal to the sequence number in a mini-batch. "
6868
"The output is no longer a LoDTensor.");
6969
AddComment(R"DOC(
70-
LinearChainCRF Operator.
71-
7270
Conditional Random Field defines an undirected probabilistic graph with nodes
7371
denoting random variables and edges denoting dependencies between these
7472
variables. CRF learns the conditional probability $P(Y|X)$, where

python/paddle/fluid/layers/layer_function_generator.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ def __impl__(func):
224224
return __impl__
225225

226226

227+
_inline_math_single_dollar = re.compile(r"\$([^\$]+)\$")
228+
229+
227230
def templatedoc(op_type=None):
228231
"""
229232
Decorator of layer function. It will use the docstring from the layer
@@ -241,6 +244,9 @@ def templatedoc(op_type=None):
241244
def trim_ending_dot(msg):
242245
return msg.rstrip('.')
243246

247+
def escape_inline_math(msg):
248+
return _inline_math_single_dollar.sub(repl=r':math:`\1`', string=msg)
249+
244250
def __impl__(func):
245251
if op_type is None:
246252
op_type_name = func.__name__
@@ -254,8 +260,10 @@ def __impl__(func):
254260
for line in comment_lines:
255261
line = line.strip()
256262
if len(line) != 0:
257-
comment += line
263+
comment += escape_inline_math(line)
258264
comment += " "
265+
elif len(comment) != 0:
266+
comment += "\n \n "
259267

260268
args = {"comment": trim_ending_dot(comment)}
261269
for each_input in op_proto.inputs:

python/paddle/fluid/layers/learning_rate_scheduler.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
"""
15+
When training a model, it's often useful to decay the
16+
learning rate during training process, this is called
17+
learning_rate_decay. There are many strategies to do
18+
this, this module will provide some classical method.
19+
User can also implement their own learning_rate_decay
20+
strategy according to this module.
21+
"""
1422

1523
import control_flow
1624
import nn
@@ -22,14 +30,6 @@
2230
'exponential_decay', 'natural_exp_decay', 'inverse_time_decay',
2331
'polynomial_decay', 'piecewise_decay', 'noam_decay'
2432
]
25-
"""
26-
When training a model, it's often useful to decay the
27-
learning rate during training process, this is called
28-
learning_rate_decay. There are many strategies to do
29-
this, this module will provide some classical method.
30-
User can also implement their own learning_rate_decay
31-
strategy according to this module.
32-
"""
3333

3434

3535
def _decay_step_counter(begin=0):
@@ -41,18 +41,20 @@ def _decay_step_counter(begin=0):
4141

4242

4343
def noam_decay(d_model, warmup_steps):
44-
"""Apply decay to learning rate.
45-
```python
46-
lr_value = np.power(d_model, -0.5) * np.min([
47-
np.power(current_steps, -0.5),
48-
np.power(warmup_steps, -1.5) * current_steps
49-
])
50-
```
44+
"""
45+
Noam decay method. The numpy implementation of noam decay as follows.
46+
47+
>>> import numpy as np
48+
>>> lr_value = np.power(d_model, -0.5) * np.min([
49+
>>> np.power(current_steps, -0.5),
50+
>>> np.power(warmup_steps, -1.5) * current_steps])
51+
52+
Please reference `attention is all you need
53+
<https://arxiv.org/pdf/1706.03762.pdf>`_.
5154
5255
Args:
5356
d_model(Variable): The dimensionality of input and output of model.
54-
Reference: attention is all you need
55-
https://arxiv.org/pdf/1706.03762.pdf
57+
5658
warmup_steps(Variable): A super parameter.
5759
5860
Returns:

0 commit comments

Comments
 (0)