Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
1c4b18c0
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1c4b18c0
编写于
2月 02, 2021
作者:
Z
Zhong Hui
提交者:
GitHub
2月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix package requirement of regex and sentencepiece (#5261)
上级
4dba6afa
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
13 addition
and
11 deletion
+13
-11
PaddleNLP/examples/language_model/gpt2/data.py
PaddleNLP/examples/language_model/gpt2/data.py
+1
-1
PaddleNLP/paddlenlp/transformers/gpt2/modeling.py
PaddleNLP/paddlenlp/transformers/gpt2/modeling.py
+4
-3
PaddleNLP/paddlenlp/transformers/gpt2/tokenizer.py
PaddleNLP/paddlenlp/transformers/gpt2/tokenizer.py
+8
-7
未找到文件。
PaddleNLP/examples/language_model/gpt2/data.py
浏览文件 @
1c4b18c0
...
...
@@ -208,7 +208,7 @@ class GPT2Dataset(paddle.io.Dataset):
# -INF mask value as default
attention_mask
=
(
attention_mask
-
1.0
)
*
1e9
# Bool mask of attention
#
attention_mask = attention_mask.astype("float32")
attention_mask
=
attention_mask
.
astype
(
"float32"
)
return
[
tokens
,
loss_mask
,
attention_mask
,
position_ids
,
labels
]
def
_get_single_sample_from_idx
(
self
,
doc_index_f
,
doc_index_l
,
offset_f
,
...
...
PaddleNLP/paddlenlp/transformers/gpt2/modeling.py
浏览文件 @
1c4b18c0
...
...
@@ -13,16 +13,17 @@
# limitations under the License.
import
collections
import
math
import
numpy
as
np
import
paddle
import
paddle.nn
as
nn
import
paddle.tensor
as
tensor
import
paddle.nn.functional
as
F
import
math
import
paddle.tensor
as
tensor
from
paddle.fluid
import
layers
from
paddle.nn.layer.transformer
import
_convert_param_attr_to_list
from
..
import
PretrainedModel
,
register_base_model
from
paddle.nn.layer.transformer
import
_convert_param_attr_to_list
__all__
=
[
'GPT2Model'
,
...
...
PaddleNLP/paddlenlp/transformers/gpt2/tokenizer.py
浏览文件 @
1c4b18c0
...
...
@@ -13,14 +13,13 @@
# limitations under the License.
import
os
import
regex
as
re
import
unicodedata
from
functools
import
lru_cache
from
collections
import
namedtuple
import
json
import
sentencepiece
import
jieba
from
paddle.utils
import
try_import
from
functools
import
lru_cache
from
collections
import
namedtuple
from
..
import
PretrainedTokenizer
from
..tokenizer_utils
import
convert_to_unicode
,
whitespace_tokenize
,
\
_is_whitespace
,
_is_control
,
_is_punctuation
...
...
@@ -122,7 +121,8 @@ class GPT2ChineseTokenizer(PretrainedTokenizer):
self
.
max_len
=
max_len
if
max_len
is
not
None
else
int
(
1e12
)
self
.
encoder
=
json
.
load
(
open
(
vocab_file
))
self
.
decoder
=
{
v
:
k
for
k
,
v
in
self
.
encoder
.
items
()}
self
.
sp
=
sentencepiece
.
SentencePieceProcessor
(
model_file
=
model_file
)
mod
=
try_import
(
"sentencepiece"
)
self
.
sp
=
mod
.
SentencePieceProcessor
(
model_file
=
model_file
)
self
.
translator
=
str
.
maketrans
(
"
\n
"
,
"
\u2582\u2583
"
)
def
tokenize
(
self
,
text
):
...
...
@@ -220,7 +220,7 @@ class GPT2Tokenizer(PretrainedTokenizer):
bpe_merges
=
[
tuple
(
merge
.
split
())
for
merge
in
bpe_data
]
self
.
bpe_ranks
=
dict
(
zip
(
bpe_merges
,
range
(
len
(
bpe_merges
))))
self
.
cache
=
{}
re
=
try_import
(
"regex"
)
self
.
pat
=
re
.
compile
(
r
"""'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+"""
)
...
...
@@ -295,6 +295,7 @@ class GPT2Tokenizer(PretrainedTokenizer):
def
tokenize
(
self
,
text
):
""" Tokenize a string. """
bpe_tokens
=
[]
re
=
try_import
(
"regex"
)
for
token
in
re
.
findall
(
self
.
pat
,
text
):
token
=
''
.
join
(
self
.
byte_encoder
[
b
]
for
b
in
token
.
encode
(
'utf-8'
))
bpe_tokens
.
extend
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录