Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
f3641f23
M
Models
项目概览
曾经的那一瞬间
/
Models
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f3641f23
编写于
10月 21, 2020
作者:
H
Hongkun Yu
提交者:
A. Unique TensorFlower
10月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change Seq2SeqTransformer inputs to dictionary.
PiperOrigin-RevId: 338309524
上级
09b9dad7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
14 addition
and
17 deletion
+14
-17
official/nlp/modeling/models/seq2seq_transformer.py
official/nlp/modeling/models/seq2seq_transformer.py
+5
-9
official/nlp/modeling/models/seq2seq_transformer_test.py
official/nlp/modeling/models/seq2seq_transformer_test.py
+6
-6
official/nlp/transformer/transformer_forward_test.py
official/nlp/transformer/transformer_forward_test.py
+3
-2
未找到文件。
official/nlp/modeling/models/seq2seq_transformer.py
浏览文件 @
f3641f23
...
...
@@ -130,9 +130,9 @@ class Seq2SeqTransformer(tf.keras.Model):
"""Calculate target logits or inferred target sequences.
Args:
inputs:
input tensor list of size 1 or 2
.
F
irst item, inputs
: int tensor with shape [batch_size, input_length].
Second item (optional), targets
: None or int tensor with shape
inputs:
a dictionary of tensors
.
F
eature `inputs`
: int tensor with shape [batch_size, input_length].
Feature `targets` (optional)
: None or int tensor with shape
[batch_size, target_length].
Returns:
...
...
@@ -147,12 +147,8 @@ class Seq2SeqTransformer(tf.keras.Model):
Raises:
NotImplementedError: If try to use padded decode method on CPU/GPUs.
"""
inputs
=
inputs
if
isinstance
(
inputs
,
list
)
else
[
inputs
]
if
len
(
inputs
)
==
2
:
sources
,
targets
=
inputs
[
0
],
inputs
[
1
]
else
:
# Decoding path.
sources
,
targets
=
inputs
[
0
],
None
sources
=
inputs
[
"inputs"
]
targets
=
inputs
.
get
(
"targets"
,
None
)
attention_bias
=
model_utils
.
get_padding_bias
(
sources
)
attention_bias
=
tf
.
cast
(
attention_bias
,
self
.
_dtype
)
# Prepare inputs to the layer stack by adding positional encodings and
...
...
official/nlp/modeling/models/seq2seq_transformer_test.py
浏览文件 @
f3641f23
...
...
@@ -82,15 +82,15 @@ class Seq2SeqTransformerTest(tf.test.TestCase, parameterized.TestCase):
return
tf
.
nest
.
map_structure
(
distribution
.
experimental_local_results
,
outputs
)
fake_inputs
=
[
np
.
zeros
((
batch_size
,
decode_max_length
),
dtype
=
np
.
int32
)]
fake_inputs
=
dict
(
inputs
=
np
.
zeros
((
batch_size
,
decode_max_length
),
dtype
=
np
.
int32
))
local_outputs
=
step
(
fake_inputs
)
logging
.
info
(
"local_outputs=%s"
,
local_outputs
)
self
.
assertEqual
(
local_outputs
[
"outputs"
][
0
].
shape
,
(
4
,
10
))
fake_inputs
=
[
np
.
zeros
((
batch_size
,
decode_max_length
),
dtype
=
np
.
int32
),
np
.
zeros
((
batch_size
,
8
),
dtype
=
np
.
int32
)
]
fake_inputs
=
dict
(
inputs
=
np
.
zeros
((
batch_size
,
decode_max_length
),
dtype
=
np
.
int32
),
targets
=
np
.
zeros
((
batch_size
,
8
),
dtype
=
np
.
int32
))
local_outputs
=
step
(
fake_inputs
)
logging
.
info
(
"local_outputs=%s"
,
local_outputs
)
self
.
assertEqual
(
local_outputs
[
0
].
shape
,
(
4
,
8
,
100
))
...
...
@@ -108,7 +108,7 @@ class Seq2SeqTransformerTest(tf.test.TestCase, parameterized.TestCase):
@
tf
.
function
def
serve
(
self
,
inputs
):
return
self
.
model
.
call
(
[
inputs
]
)
return
self
.
model
.
call
(
dict
(
inputs
=
inputs
)
)
save_module
=
SaveModule
(
model
)
if
padded_decode
:
...
...
official/nlp/transformer/transformer_forward_test.py
浏览文件 @
f3641f23
...
...
@@ -70,7 +70,8 @@ def _create_model(params, is_train):
inputs
=
tf
.
keras
.
layers
.
Input
((
None
,),
dtype
=
"int64"
,
name
=
"inputs"
)
targets
=
tf
.
keras
.
layers
.
Input
((
None
,),
dtype
=
"int64"
,
name
=
"targets"
)
internal_model
=
models
.
Seq2SeqTransformer
(
**
model_kwargs
)
logits
=
internal_model
([
inputs
,
targets
],
training
=
is_train
)
logits
=
internal_model
(
dict
(
inputs
=
inputs
,
targets
=
targets
),
training
=
is_train
)
vocab_size
=
params
[
"vocab_size"
]
label_smoothing
=
params
[
"label_smoothing"
]
if
params
[
"enable_metrics_in_training"
]:
...
...
@@ -90,7 +91,7 @@ def _create_model(params, is_train):
dtype
=
"int64"
,
name
=
"inputs"
)
internal_model
=
models
.
Seq2SeqTransformer
(
**
model_kwargs
)
ret
=
internal_model
(
[
inputs
]
,
training
=
is_train
)
ret
=
internal_model
(
dict
(
inputs
=
inputs
)
,
training
=
is_train
)
outputs
,
scores
=
ret
[
"outputs"
],
ret
[
"scores"
]
return
tf
.
keras
.
Model
(
inputs
,
[
outputs
,
scores
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录