Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xdoctest][task 330] reformat example code with google style in python/paddle/base/data_feed_desc.py #57137

Merged
merged 9 commits into from
Sep 12, 2023
220 changes: 110 additions & 110 deletions python/paddle/base/data_feed_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ class DataFeedDesc:

.. code-block:: python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放在 Examples: 之下吧,记得整体加缩进


import paddle.base as base
f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2'
print >> f, 'multi_slot_desc {'
print >> f, ' slots {'
print >> f, ' name: "words"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, ' slots {'
print >> f, ' name: "label"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, '}'
f.close()
data_feed = base.DataFeedDesc('data.proto')
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码换成 python3 写法吧

with open(xxx) as f:
    f.write('')
    f.write('')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段应该不能算是示例,把 .. code-block:: python 改为 .. code-block:: text,原来代码的地方不用加 >>> ,保持原样就行,即使加了也没法运行 ~


However, users usually shouldn't care about the message format; instead,
they are encouraged to use :code:`Data Generator` as a tool to generate a
Expand All @@ -64,17 +64,17 @@ class DataFeedDesc:

.. code-block:: python

import paddle.base as base
data_feed = base.DataFeedDesc('data.proto')
data_feed.set_batch_size(128)
data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense
data_feed.set_use_slots('wd') # The slot named 'wd' will be used
>>> import paddle.base as base
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_batch_size(128)
>>> data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense
>>> data_feed.set_use_slots('wd') # The slot named 'wd' will be used

Finally, the content can be dumped out for debugging purpose:

.. code-block:: python

print(data_feed.desc())
>>> print(data_feed.desc())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上 ~


Args:
proto_file(string): Disk file containing a data feed description.
Expand All @@ -99,27 +99,27 @@ def set_batch_size(self, batch_size):
Example:
yoyoIcy marked this conversation as resolved.
Show resolved Hide resolved
.. code-block:: python

import paddle.base as base
f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2'
print >> f, 'multi_slot_desc {'
print >> f, ' slots {'
print >> f, ' name: "words"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, ' slots {'
print >> f, ' name: "label"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, '}'
f.close()
data_feed = base.DataFeedDesc('data.proto')
data_feed.set_batch_size(128)
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_batch_size(128)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果这里作为示例出现的话,需要把里面的这些 print 修改一下,改为正常 python 的写文件语句~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

统一一下吧,改成可以跑的

我一小时前 review 一半干别的去了,结果回来后你已经 review 了 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github 时好时坏 ... ... 趁着好用 review 一下 ~


Args:
batch_size (int): The number of batch size.
Expand All @@ -140,27 +140,27 @@ def set_dense_slots(self, dense_slots_name):
Example:
.. code-block:: python

import paddle.base as base
f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2'
print >> f, 'multi_slot_desc {'
print >> f, ' slots {'
print >> f, ' name: "words"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, ' slots {'
print >> f, ' name: "label"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, '}'
f.close()
data_feed = base.DataFeedDesc('data.proto')
data_feed.set_dense_slots(['words'])
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_dense_slots(['words'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上


Args:
dense_slots_name (list(str)): a list of slot names which will be set dense.
Expand All @@ -187,27 +187,27 @@ def set_use_slots(self, use_slots_name):
Example:
.. code-block:: python

import paddle.base as base
f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2'
print >> f, 'multi_slot_desc {'
print >> f, ' slots {'
print >> f, ' name: "words"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, ' slots {'
print >> f, ' name: "label"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, '}'
f.close()
data_feed = base.DataFeedDesc('data.proto')
data_feed.set_use_slots(['words'])
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_use_slots(['words'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上


Args:
use_slots_name: a list of slot names which will be used in training
Expand All @@ -231,27 +231,27 @@ def desc(self):
Example:
.. code-block:: python

import paddle.base as base
f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2'
print >> f, 'multi_slot_desc {'
print >> f, ' slots {'
print >> f, ' name: "words"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, ' slots {'
print >> f, ' name: "label"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, '}'
f.close()
data_feed = base.DataFeedDesc('data.proto')
print(data_feed.desc())
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
>>> print(data_feed.desc())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上


Returns:
A string message
Expand Down