Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#228 from yingyibiao/develop
Browse files Browse the repository at this point in the history
modify docstring code example, and doc's language
  • Loading branch information
moebius21 authored Apr 6, 2021
2 parents 0ad3888 + 9d41b0d commit 97213e4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 43 deletions.
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
locale_dirs = ['locale/']
gettext_compact = False
language = 'zh_CN'
add_module_names = False

# List of patterns, relative to source directory, that match files and
Expand Down
87 changes: 45 additions & 42 deletions paddlenlp/transformers/xlnet/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,20 +964,21 @@ def forward(
the weighted average in the self-attention heads. Each Tensor (one for each layer) has a data type
of `float32` and has a shape of [batch_size, num_heads, sequence_length, sequence_length].
Example::
>>> import paddle
>>> from paddlenlp.transformers.xlnet.modeling import XLNetModel
>>> from paddlenlp.transformers.xlnet.tokenizer import XLNetTokenizer
>>>
>>> tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
>>> model = XLNetModel.from_pretrained('xlnet-base-cased')
>>>
>>> inputs = tokenizer("Hey, Paddle-paddle is awesome !")
>>> inputs = {k:paddle.to_tensor(v) for (k, v) in inputs.items()}
>>> outputs = model(**inputs)
>>>
>>> last_hidden_states = outputs[0]
Example:
.. code-block::
import paddle
from paddlenlp.transformers.xlnet.modeling import XLNetModel
from paddlenlp.transformers.xlnet.tokenizer import XLNetTokenizer
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
model = XLNetModel.from_pretrained('xlnet-base-cased')
inputs = tokenizer("Hey, Paddle-paddle is awesome !")
inputs = {k:paddle.to_tensor(v) for (k, v) in inputs.items()}
outputs = model(**inputs)
last_hidden_states = outputs[0]
"""

if self.training:
Expand Down Expand Up @@ -1313,20 +1314,21 @@ def forward(
attentions (`List[Tensor]`, optional):
See :class:`XLNetModel`.
Example::
>>> import paddle
>>> from paddlenlp.transformers.xlnet.modeling import XLNetForSequenceClassification
>>> from paddlenlp.transformers.xlnet.tokenizer import XLNetTokenizer
>>>
>>> tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
>>> model = XLNetForSequenceClassification.from_pretrained('xlnet-base-cased')
>>>
>>> inputs = tokenizer("Hey, Paddle-paddle is awesome !")
>>> inputs = {k:paddle.to_tensor(v) for (k, v) in inputs.items()}
>>> outputs = model(**inputs)
>>>
>>> logits = outputs[0]
Example:
.. code-block::
import paddle
from paddlenlp.transformers.xlnet.modeling import XLNetForSequenceClassification
from paddlenlp.transformers.xlnet.tokenizer import XLNetTokenizer
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
model = XLNetForSequenceClassification.from_pretrained('xlnet-base-cased')
inputs = tokenizer("Hey, Paddle-paddle is awesome !")
inputs = {k:paddle.to_tensor(v) for (k, v) in inputs.items()}
outputs = model(**inputs)
logits = outputs[0]
"""

transformer_outputs = self.transformer(
Expand Down Expand Up @@ -1444,20 +1446,21 @@ def forward(
- attentions (`List[Tensor]`, optional):
See :class:`XLNetModel`.
Example::
>>> import paddle
>>> from paddlenlp.transformers.xlnet.modeling import XLNetForTokenClassification
>>> from paddlenlp.transformers.xlnet.tokenizer import XLNetTokenizer
>>>
>>> tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
>>> model = XLNetForTokenClassification.from_pretrained('xlnet-base-cased')
>>>
>>> inputs = tokenizer("Hey, Paddle-paddle is awesome !")
>>> inputs = {k:paddle.to_tensor(v) for (k, v) in inputs.items()}
>>> outputs = model(**inputs)
>>>
>>> logits = outputs[0]
Example:
.. code-block::
import paddle
from paddlenlp.transformers.xlnet.modeling import XLNetForTokenClassification
from paddlenlp.transformers.xlnet.tokenizer import XLNetTokenizer
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
model = XLNetForTokenClassification.from_pretrained('xlnet-base-cased')
inputs = tokenizer("Hey, Paddle-paddle is awesome !")
inputs = {k:paddle.to_tensor(v) for (k, v) in inputs.items()}
outputs = model(**inputs)
logits = outputs[0]
"""
transformer_outputs = self.transformer(
input_ids,
Expand Down

0 comments on commit 97213e4

Please sign in to comment.