Skip to content

Commit a66a826

Browse files
authored
update_1.2 (PaddlePaddle#457)
* add_api_cn (PaddlePaddle#437) * add gpu benchmark page (PaddlePaddle#436) * add gpu benchmark * fix comments * add chinese link in gen_doc.py (PaddlePaddle#439) * modified gen_doc.py * Update gen_doc.py * update gen_doc.py * Update mobile doc (PaddlePaddle#440) * update_en_structure * update_Paddle_commitid * delete_DS * update_mobile_doc * Update book commit (PaddlePaddle#438) * update_en_structure * update_Paddle_commitid * delete_DS * update_book_commit_id * update_api_rst * Adjust structure of advanced usage (PaddlePaddle#442) * adjust_structure_of_advanced_usage * Update paddle_gpu_benchmark.md * adjust_toctree_hidden * fix_api_guide * Update index.rst * fix deadlinkes (PaddlePaddle#443) * add_toctree (PaddlePaddle#445) * adjust_beginners_structure (PaddlePaddle#446) * adjust_beginners_structure * Update index.rst * update install_doc for python3 (PaddlePaddle#418) * update install_doc for python3 * update python3.5+ info,test=develop * fix review, test=develop * fix_pic (PaddlePaddle#447) * delete en2zn link * update lod_tensor * 1207 1.english api reference links removed 2. formatted * update transpiler * update profilse_cn
1 parent 9aece65 commit a66a826

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

doc/fluid/user_guides/howto/basic_concept/lod_tensor.rst

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LoD 索引
3131

3232
假设一个mini-batch中有3个句子,每个句子中分别包含3个、1个和2个单词。我们可以用(3+1+2)xD维Tensor 加上一些索引信息来表示这个mini-batch:
3333

34-
.. code-block :: python
34+
.. code-block :: text
3535
3636
3 1 2
3737
| | | | | |
@@ -42,7 +42,8 @@ LoD 索引
4242

4343
让我们来看另一个2-level LoD-Tensor的例子:假设存在一个mini-batch中包含3个句子、1个句子和2个句子的文章,每个句子都由不同数量的单词组成,则这个mini-batch的样式可以看作:
4444

45-
.. code-block :: python
45+
.. code-block :: text
46+
4647
4748
3 1 2
4849
3 2 4 1 2 3
@@ -51,7 +52,7 @@ LoD 索引
5152
5253
表示的LoD信息为:
5354

54-
.. code-block :: python
55+
.. code-block :: text
5556
5657
[[3,1,2]/*level=0*/,[3,2,4,1,2,3]/*level=1*/]
5758
@@ -60,7 +61,7 @@ LoD 索引
6061

6162
在视觉任务中,时常需要处理视频和图像这些元素是高维的对象,假设现存的一个nimi-batch包含3个视频,分别有3个,1个和2个帧,每个帧都具有相同大小:640x480,则这个mini-batch可以被表示为:
6263

63-
.. code-block :: python
64+
.. code-block :: text
6465
6566
3 1 2
6667
口口口 口 口口
@@ -72,14 +73,14 @@ LoD 索引
7273

7374
在传统的情况下,比如有N个固定大小的图像的mini-batch,LoD-Tensor表示为:
7475

75-
.. code-block :: python
76+
.. code-block :: text
7677
7778
1 1 1 1 1
7879
口口口口 ... 口
7980
8081
在这种情况下,我们不会因为索引值都为1而忽略信息,仅仅把LoD-Tensor看作是一个普通的张量:
8182

82-
.. code-block :: python
83+
.. code-block :: text
8384
8485
口口口口 ... 口
8586
@@ -94,13 +95,13 @@ LoDTensor的偏移表示
9495

9596
在上述例子中,您可以计算基本元素的长度:
9697

97-
.. code-block :: python
98+
.. code-block :: text
9899
99100
3 2 4 1 2 3
100101
101102
将其转换为偏移表示:
102103

103-
.. code-block :: python
104+
.. code-block :: text
104105
105106
0 3 5 9 10 12 15
106107
= = = = = =
@@ -110,21 +111,21 @@ LoDTensor的偏移表示
110111

111112
类似的,LoD的顶层长度
112113

113-
.. code-block :: python
114+
.. code-block :: text
114115
115116
3 1 2
116117
117118
可以被转化成偏移形式:
118119

119-
.. code-block :: python
120+
.. code-block :: text
120121
121122
0 3 4 6
122123
= = =
123124
3 3+1 4+2
124125
125126
因此该LoD-Tensor的偏移表示为:
126127

127-
.. code-block :: python
128+
.. code-block :: text
128129
129130
0 3 4 6
130131
3 5 9 10 12 15
@@ -138,7 +139,7 @@ LoD-Tensor
138139

139140
以上文提到的一个2-level LoD-Tensor为例:
140141

141-
.. code-block :: python
142+
.. code-block :: text
142143
143144
3 1 2
144145
3 2 4 1 2 3
@@ -147,11 +148,12 @@ LoD-Tensor
147148
- 以偏移量表示此 LoD-Tensor:[ [0,3,4,6] , [0,3,5,9,10,12,15] ],
148149
- 以原始长度表达此 Lod-Tensor:recursive_sequence_lengths=[ [3-0 , 4-3 , 6-4] , [3-0 , 5-3 , 9-5 , 10-9 , 12-10 , 15-12] ]。
149150

150-
以文字序列为例: [3,1,2] 可以表示这个mini-batch中有3篇文章,每篇文章分别有3、2、1个句子,[3,2,4,1,2,3] 表示每个句子中分别含有3、2、4、1、2、3个字。
151+
152+
以文字序列为例: [3,1,2] 可以表示这个mini-batch中有3篇文章,每篇文章分别有3、1、2个句子,[3,2,4,1,2,3] 表示每个句子中分别含有3、2、4、1、2、3个字。
151153

152154
recursive_seq_lens 是一个双层嵌套列表,也就是列表的列表,最外层列表的size表示嵌套的层数,也就是lod-level的大小;内部的每个列表,对应表示每个lod-level下,每个元素的大小。
153155

154-
.. code-block :: python
156+
.. code-block :: text
155157
156158
#查看lod-tensor嵌套层数
157159
print len(recursive_seq_lengths)

0 commit comments

Comments
 (0)