未验证 提交 ff7e6ec5 编写于 作者: M megemini 提交者: GitHub

[Fix]fix cleandoc with a first blank line (#55052)

* [Fix]fix cleandoc with a first blank line

* [Fix]fix metrics.py code-block

* [Fix]fix metrics.py code-block indent
上级 ef19521c
...@@ -82,7 +82,8 @@ class Metric(metaclass=abc.ABCMeta): ...@@ -82,7 +82,8 @@ class Metric(metaclass=abc.ABCMeta):
prediction of each sample like follows, while the correct prediction prediction of each sample like follows, while the correct prediction
matrix shape is [N, 5]. matrix shape is [N, 5].
.. code-block:: text .. code-block:: python
:name: code-compute-example
def compute(pred, label): def compute(pred, label):
# sort prediction and slice the top-5 scores # sort prediction and slice the top-5 scores
...@@ -96,7 +97,8 @@ class Metric(metaclass=abc.ABCMeta): ...@@ -96,7 +97,8 @@ class Metric(metaclass=abc.ABCMeta):
shape as [N, 5] instead of 2 tensors with shapes as [N, 10] and [N, 1]. shape as [N, 5] instead of 2 tensors with shapes as [N, 10] and [N, 1].
:code:`update` can be define as follows: :code:`update` can be define as follows:
.. code-block:: text .. code-block:: python
:name: code-update-example
def update(self, correct): def update(self, correct):
accs = [] accs = []
...@@ -195,9 +197,9 @@ class Accuracy(Metric): ...@@ -195,9 +197,9 @@ class Accuracy(Metric):
name (str, optional): String name of the metric instance. Default name (str, optional): String name of the metric instance. Default
is `acc`. is `acc`.
Example by standalone: Examples:
.. code-block:: python .. code-block:: python
:name: code-standalone-example
import numpy as np import numpy as np
import paddle import paddle
...@@ -215,10 +217,8 @@ class Accuracy(Metric): ...@@ -215,10 +217,8 @@ class Accuracy(Metric):
res = m.accumulate() res = m.accumulate()
print(res) # 0.75 print(res) # 0.75
Example with Model API:
.. code-block:: python .. code-block:: python
:name: code-model-api-example
import paddle import paddle
from paddle.static import InputSpec from paddle.static import InputSpec
...@@ -349,9 +349,9 @@ class Precision(Metric): ...@@ -349,9 +349,9 @@ class Precision(Metric):
name (str, optional): String name of the metric instance. name (str, optional): String name of the metric instance.
Default is `precision`. Default is `precision`.
Example by standalone: Examples:
.. code-block:: python .. code-block:: python
:name: code-standalone-example
import numpy as np import numpy as np
import paddle import paddle
...@@ -364,10 +364,8 @@ class Precision(Metric): ...@@ -364,10 +364,8 @@ class Precision(Metric):
res = m.accumulate() res = m.accumulate()
print(res) # 1.0 print(res) # 1.0
Example with Model API:
.. code-block:: python .. code-block:: python
:name: code-model-api-example
import numpy as np import numpy as np
...@@ -482,9 +480,9 @@ class Recall(Metric): ...@@ -482,9 +480,9 @@ class Recall(Metric):
name (str, optional): String name of the metric instance. name (str, optional): String name of the metric instance.
Default is `recall`. Default is `recall`.
Example by standalone: Examples:
.. code-block:: python .. code-block:: python
:name: code-standalone-example
import numpy as np import numpy as np
import paddle import paddle
...@@ -497,10 +495,8 @@ class Recall(Metric): ...@@ -497,10 +495,8 @@ class Recall(Metric):
res = m.accumulate() res = m.accumulate()
print(res) # 2.0 / 3.0 print(res) # 2.0 / 3.0
Example with Model API:
.. code-block:: python .. code-block:: python
:name: code-model-api-example
import numpy as np import numpy as np
...@@ -624,8 +620,9 @@ class Auc(Metric): ...@@ -624,8 +620,9 @@ class Auc(Metric):
"NOTE: only implement the ROC curve type via Python now." "NOTE: only implement the ROC curve type via Python now."
Example by standalone: Examples:
.. code-block:: python .. code-block:: python
:name: code-standalone-example
import numpy as np import numpy as np
import paddle import paddle
...@@ -642,10 +639,8 @@ class Auc(Metric): ...@@ -642,10 +639,8 @@ class Auc(Metric):
m.update(preds=preds, labels=labels) m.update(preds=preds, labels=labels)
res = m.accumulate() res = m.accumulate()
Example with Model API:
.. code-block:: python .. code-block:: python
:name: code-model-api-example
import numpy as np import numpy as np
import paddle import paddle
......
...@@ -151,7 +151,7 @@ def extract_code_blocks_from_docstr(docstr): ...@@ -151,7 +151,7 @@ def extract_code_blocks_from_docstr(docstr):
# nonlocal code_blocks, cb_cur, cb_cur_name, cb_cur_seq_id, cb_required # nonlocal code_blocks, cb_cur, cb_cur_name, cb_cur_seq_id, cb_required
code_blocks.append( code_blocks.append(
{ {
'codes': inspect.cleandoc("\n".join(cb_info['cb_cur'])), 'codes': inspect.cleandoc("\n" + "\n".join(cb_info['cb_cur'])),
'name': cb_info['cb_cur_name'], 'name': cb_info['cb_cur_name'],
'id': cb_info['cb_cur_seq_id'], 'id': cb_info['cb_cur_seq_id'],
'required': cb_info['cb_required'], 'required': cb_info['cb_required'],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册