Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
69bbdc1c
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,发现更多精彩内容 >>
提交
69bbdc1c
编写于
11月 02, 2022
作者:
A
A. Unique TensorFlower
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Internal change
PiperOrigin-RevId: 485690158
上级
66f76664
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
18 addition
and
6 deletion
+18
-6
official/nlp/modeling/layers/mixing.py
official/nlp/modeling/layers/mixing.py
+2
-0
official/nlp/modeling/networks/fnet.py
official/nlp/modeling/networks/fnet.py
+16
-6
未找到文件。
official/nlp/modeling/layers/mixing.py
浏览文件 @
69bbdc1c
...
...
@@ -30,6 +30,7 @@ import enum
import
functools
from
typing
import
Callable
,
Tuple
,
Union
import
gin
import
numpy
as
np
from
scipy
import
linalg
import
tensorflow
as
tf
...
...
@@ -41,6 +42,7 @@ _Initializer = Union[str, tf.keras.initializers.Initializer]
default_kernel_initializer
=
tf
.
keras
.
initializers
.
TruncatedNormal
(
stddev
=
2e-2
)
@
gin
.
constants_from_enum
class
MixingMechanism
(
enum
.
Enum
):
"""Determines the type of mixing layer.
...
...
official/nlp/modeling/networks/fnet.py
浏览文件 @
69bbdc1c
...
...
@@ -89,6 +89,8 @@ class FNet(tf.keras.layers.Layer):
layers. If set False, output of attention and intermediate dense layers is
normalized.
with_dense_inputs: Whether to accept dense embeddings as the input.
num_dense_tokens: Length of the token dimension of dense inputs if dense
inputs are used. This counts towards max_sequence_length.
"""
def
__init__
(
...
...
@@ -113,6 +115,7 @@ class FNet(tf.keras.layers.Layer):
embedding_layer
:
Optional
[
tf
.
keras
.
layers
.
Layer
]
=
None
,
norm_first
:
bool
=
False
,
with_dense_inputs
:
bool
=
False
,
num_dense_tokens
:
int
=
0
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
...
...
@@ -142,6 +145,7 @@ class FNet(tf.keras.layers.Layer):
'embedding_layer'
:
embedding_layer
,
'norm_first'
:
norm_first
,
'with_dense_inputs'
:
with_dense_inputs
,
'num_dense_tokens'
:
num_dense_tokens
,
}
if
embedding_layer
is
None
:
...
...
@@ -220,20 +224,26 @@ class FNet(tf.keras.layers.Layer):
name
=
'pooler_transform'
)
if
with_dense_inputs
:
if
max_sequence_length
-
num_dense_tokens
<
0
:
raise
ValueError
(
'FNet: `max_sequence_length` should include dense tokens, but got '
'`max_sequence_length` - `num_dense_tokens` = {} - {} < 0.'
.
format
(
max_sequence_length
,
num_dense_tokens
))
self
.
inputs
=
dict
(
input_word_ids
=
tf
.
keras
.
Input
(
shape
=
(
max_sequence_length
,),
dtype
=
tf
.
int32
),
shape
=
(
max_sequence_length
-
num_dense_tokens
,),
dtype
=
tf
.
int32
),
input_mask
=
tf
.
keras
.
Input
(
shape
=
(
max_sequence_length
,),
dtype
=
tf
.
int32
),
shape
=
(
max_sequence_length
-
num_dense_tokens
,),
dtype
=
tf
.
int32
),
input_type_ids
=
tf
.
keras
.
Input
(
shape
=
(
max_sequence_length
,),
dtype
=
tf
.
int32
),
shape
=
(
max_sequence_length
-
num_dense_tokens
,),
dtype
=
tf
.
int32
),
dense_inputs
=
tf
.
keras
.
Input
(
shape
=
(
max_sequence_length
,
embedding_width
),
dtype
=
tf
.
float32
),
shape
=
(
num_dense_tokens
,
embedding_width
),
dtype
=
tf
.
float32
),
dense_mask
=
tf
.
keras
.
Input
(
shape
=
(
max_sequence_length
,),
dtype
=
tf
.
int32
),
shape
=
(
num_dense_tokens
,),
dtype
=
tf
.
int32
),
dense_type_ids
=
tf
.
keras
.
Input
(
shape
=
(
max_sequence_length
,),
dtype
=
tf
.
int32
),
shape
=
(
num_dense_tokens
,),
dtype
=
tf
.
int32
),
)
else
:
self
.
inputs
=
dict
(
input_word_ids
=
tf
.
keras
.
Input
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录