Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
F
Fairseq-S2T
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
xuchen
Fairseq-S2T
Commits
d3bef363
Commit
d3bef363
authored
May 11, 2021
by
xuchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adaptive softmax bug fix
parent
d4a68f26
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
2 行删除
+39
-2
fairseq/criterions/label_smoothed_cross_entropy.py
+1
-1
fairseq/models/speech_to_text/s2t_transformer.py
+34
-1
fairseq/models/transformer.py
+4
-0
没有找到文件。
fairseq/criterions/label_smoothed_cross_entropy.py
查看文件 @
d3bef363
...
@@ -95,7 +95,7 @@ class LabelSmoothedCrossEntropyCriterion(FairseqCriterion):
...
@@ -95,7 +95,7 @@ class LabelSmoothedCrossEntropyCriterion(FairseqCriterion):
return
loss
,
sample_size
,
logging_output
return
loss
,
sample_size
,
logging_output
def
get_lprobs_and_target
(
self
,
model
,
net_output
,
sample
):
def
get_lprobs_and_target
(
self
,
model
,
net_output
,
sample
):
lprobs
=
model
.
get_normalized_probs
(
net_output
,
log_probs
=
True
)
lprobs
=
model
.
get_normalized_probs
(
net_output
,
log_probs
=
True
,
sample
=
sample
)
target
=
model
.
get_targets
(
sample
,
net_output
)
target
=
model
.
get_targets
(
sample
,
net_output
)
if
self
.
ignore_prefix_size
>
0
:
if
self
.
ignore_prefix_size
>
0
:
if
getattr
(
lprobs
,
"batch_first"
,
False
):
if
getattr
(
lprobs
,
"batch_first"
,
False
):
...
...
fairseq/models/speech_to_text/s2t_transformer.py
查看文件 @
d3bef363
...
@@ -220,6 +220,11 @@ class S2TTransformerModel(FairseqEncoderDecoderModel):
...
@@ -220,6 +220,11 @@ class S2TTransformerModel(FairseqEncoderDecoderModel):
action
=
"store_true"
,
action
=
"store_true"
,
help
=
"if True, dont scale embeddings"
,
help
=
"if True, dont scale embeddings"
,
)
)
parser
.
add_argument
(
'--adaptive-softmax-cutoff'
,
metavar
=
'EXPR'
,
help
=
'comma separated list of adaptive softmax cutoff points. '
'Must be used with adaptive_loss criterion'
),
parser
.
add_argument
(
'--adaptive-softmax-dropout'
,
type
=
float
,
metavar
=
'D'
,
help
=
'sets adaptive softmax dropout for the tail projections'
)
parser
.
add_argument
(
'--max-encoder-relative-length'
,
type
=
int
,
default
=-
1
,
parser
.
add_argument
(
'--max-encoder-relative-length'
,
type
=
int
,
default
=-
1
,
help
=
'the max relative length'
)
help
=
'the max relative length'
)
parser
.
add_argument
(
'--max-decoder-relative-length'
,
type
=
int
,
default
=-
1
,
parser
.
add_argument
(
'--max-decoder-relative-length'
,
type
=
int
,
default
=-
1
,
...
@@ -526,6 +531,30 @@ class TransformerDecoderScriptable(TransformerDecoder):
...
@@ -526,6 +531,30 @@ class TransformerDecoderScriptable(TransformerDecoder):
)
)
return
x
,
None
return
x
,
None
def
get_normalized_probs_scriptable
(
self
,
net_output
:
Tuple
[
Tensor
,
Optional
[
Dict
[
str
,
List
[
Optional
[
Tensor
]]]]],
log_probs
:
bool
,
sample
:
Optional
[
Dict
[
str
,
Tensor
]]
=
None
,
):
"""Get normalized probabilities (or log probs) from a net's output."""
if
hasattr
(
self
,
"adaptive_softmax"
)
and
self
.
adaptive_softmax
is
not
None
:
if
sample
is
not
None
:
assert
"target"
in
sample
target
=
sample
[
"target"
]
else
:
target
=
None
out
=
self
.
adaptive_softmax
.
get_log_prob
(
net_output
[
0
],
target
=
target
)
return
out
.
exp_
()
if
not
log_probs
else
out
logits
=
net_output
[
0
]
if
log_probs
:
return
utils
.
log_softmax
(
logits
,
dim
=-
1
,
onnx_trace
=
self
.
onnx_trace
)
else
:
return
utils
.
softmax
(
logits
,
dim
=-
1
,
onnx_trace
=
self
.
onnx_trace
)
@register_model_architecture
(
model_name
=
"s2t_transformer"
,
arch_name
=
"s2t_transformer"
)
@register_model_architecture
(
model_name
=
"s2t_transformer"
,
arch_name
=
"s2t_transformer"
)
def
base_architecture
(
args
):
def
base_architecture
(
args
):
...
@@ -554,6 +583,10 @@ def base_architecture(args):
...
@@ -554,6 +583,10 @@ def base_architecture(args):
args
.
activation_fn
=
getattr
(
args
,
"activation_fn"
,
"relu"
)
args
.
activation_fn
=
getattr
(
args
,
"activation_fn"
,
"relu"
)
args
.
adaptive_softmax_cutoff
=
getattr
(
args
,
"adaptive_softmax_cutoff"
,
None
)
args
.
adaptive_softmax_cutoff
=
getattr
(
args
,
"adaptive_softmax_cutoff"
,
None
)
args
.
adaptive_softmax_dropout
=
getattr
(
args
,
"adaptive_softmax_dropout"
,
0
)
args
.
adaptive_softmax_dropout
=
getattr
(
args
,
"adaptive_softmax_dropout"
,
0
)
args
.
tie_adaptive_weights
=
getattr
(
args
,
"tie_adaptive_weights"
,
False
)
args
.
tie_adaptive_proj
=
getattr
(
args
,
"tie_adaptive_proj"
,
False
)
args
.
adaptive_softmax_factor
=
getattr
(
args
,
"adaptive_softmax_factor"
,
4
)
args
.
share_decoder_input_output_embed
=
getattr
(
args
.
share_decoder_input_output_embed
=
getattr
(
args
,
"share_decoder_input_output_embed"
,
False
args
,
"share_decoder_input_output_embed"
,
False
)
)
...
@@ -586,7 +619,7 @@ def s2t_transformer_s(args):
...
@@ -586,7 +619,7 @@ def s2t_transformer_s(args):
@register_model_architecture
(
"s2t_transformer"
,
"s2t_transformer_s_relative"
)
@register_model_architecture
(
"s2t_transformer"
,
"s2t_transformer_s_relative"
)
def
s2t_transformer_s_relative
(
args
):
def
s2t_transformer_s_relative
(
args
):
args
.
max_encoder_relative_length
=
2
0
args
.
max_encoder_relative_length
=
10
0
args
.
max_decoder_relative_length
=
20
args
.
max_decoder_relative_length
=
20
args
.
k_only
=
True
args
.
k_only
=
True
s2t_transformer_s
(
args
)
s2t_transformer_s
(
args
)
...
...
fairseq/models/transformer.py
查看文件 @
d3bef363
...
@@ -1150,6 +1150,10 @@ def base_architecture(args):
...
@@ -1150,6 +1150,10 @@ def base_architecture(args):
args
.
dropout
=
getattr
(
args
,
"dropout"
,
0.1
)
args
.
dropout
=
getattr
(
args
,
"dropout"
,
0.1
)
args
.
adaptive_softmax_cutoff
=
getattr
(
args
,
"adaptive_softmax_cutoff"
,
None
)
args
.
adaptive_softmax_cutoff
=
getattr
(
args
,
"adaptive_softmax_cutoff"
,
None
)
args
.
adaptive_softmax_dropout
=
getattr
(
args
,
"adaptive_softmax_dropout"
,
0
)
args
.
adaptive_softmax_dropout
=
getattr
(
args
,
"adaptive_softmax_dropout"
,
0
)
args
.
tie_adaptive_weights
=
getattr
(
args
,
"tie_adaptive_weights"
,
False
)
args
.
tie_adaptive_proj
=
getattr
(
args
,
"tie_adaptive_proj"
,
False
)
args
.
adaptive_softmax_factor
=
getattr
(
args
,
"adaptive_softmax_factor"
,
4
)
args
.
share_decoder_input_output_embed
=
getattr
(
args
.
share_decoder_input_output_embed
=
getattr
(
args
,
"share_decoder_input_output_embed"
,
False
args
,
"share_decoder_input_output_embed"
,
False
)
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论