Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
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
S2T
Commits
aed36ae4
Commit
aed36ae4
authored
Mar 16, 2024
by
xuchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize the implementation of lang tag
parent
a64cdfcc
全部展开
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
26 行增加
和
20 行删除
+26
-20
fairseq/criterions/ctc.py
+2
-0
fairseq/criterions/label_smoothed_cross_entropy_with_ctc.py
+3
-0
fairseq/data/audio/speech_to_text_dataset.py
+0
-0
fairseq/models/speech_to_text/s2t_transformer.py
+21
-20
没有找到文件。
fairseq/criterions/ctc.py
查看文件 @
aed36ae4
...
...
@@ -367,9 +367,11 @@ class CtcCriterion(FairseqCriterion):
src_tokens
=
sample
[
"net_input"
][
"src_tokens"
]
src_lengths
=
sample
[
"net_input"
][
"src_lengths"
]
src_lang_idx
=
sample
[
"net_input"
]
.
get
(
"src_lang_idx"
,
None
)
tgt_lang_idx
=
sample
[
"net_input"
]
.
get
(
"tgt_lang_idx"
,
None
)
with
torch
.
no_grad
():
encoder_out
=
model
.
encoder
(
src_tokens
,
src_lengths
,
src_lang_idx
=
src_lang_idx
,
tgt_lang_idx
=
tgt_lang_idx
)
ctc_logit
=
None
...
...
fairseq/criterions/label_smoothed_cross_entropy_with_ctc.py
查看文件 @
aed36ae4
...
...
@@ -82,6 +82,7 @@ class LabelSmoothedCrossEntropyCriterionWithCTC(
src_tokens
=
sample
[
"net_input"
][
"src_tokens"
]
src_lengths
=
sample
[
"net_input"
][
"src_lengths"
]
prev_output_tokens
=
sample
[
"net_input"
][
"prev_output_tokens"
]
src_lang_idx
=
sample
[
"net_input"
]
.
get
(
"src_lang_idx"
,
None
)
tgt_lang_idx
=
sample
[
"net_input"
]
.
get
(
"tgt_lang_idx"
,
None
)
train_enc_only
=
False
...
...
@@ -105,10 +106,12 @@ class LabelSmoothedCrossEntropyCriterionWithCTC(
ctc_alignment_oracle
=
self
.
ctc_criterion
.
get_ground_truth_alignment
(
model
,
sample
)
encoder_out
=
model
.
encoder
(
src_tokens
,
src_lengths
,
ctc_alignment_oracle
=
ctc_alignment_oracle
,
src_lang_idx
=
src_lang_idx
,
tgt_lang_idx
=
tgt_lang_idx
)
else
:
encoder_out
=
model
.
encoder
(
src_tokens
=
src_tokens
,
src_lengths
=
src_lengths
,
src_lang_idx
=
src_lang_idx
,
tgt_lang_idx
=
tgt_lang_idx
)
net_output
=
model
.
decoder
(
...
...
fairseq/data/audio/speech_to_text_dataset.py
查看文件 @
aed36ae4
差异被折叠。
点击展开。
fairseq/models/speech_to_text/s2t_transformer.py
查看文件 @
aed36ae4
...
...
@@ -1364,6 +1364,8 @@ class S2TTransformerEncoder(FairseqEncoder):
self
.
compression_stat
=
False
self
.
log_flag_dict
=
dict
()
# gather cosine similarity
self
.
gather_cos_sim
=
getattr
(
args
,
"gather_cos_sim"
,
False
)
self
.
gather_cos_sim_dis
=
2
...
...
@@ -1775,27 +1777,15 @@ class S2TTransformerEncoder(FairseqEncoder):
if
self
.
history
is
not
None
:
self
.
history
.
clean
()
src_lang_idx
=
kwargs
.
get
(
"src_lang_idx"
,
None
)
tgt_lang_idx
=
kwargs
.
get
(
"tgt_lang_idx"
,
None
)
has_add_lang_tag
=
False
# (B, T, D) -> (T, B, D)
x
=
src_tokens
.
transpose
(
0
,
1
)
input_lengths
=
src_lengths
org_bsz
=
x
.
size
(
1
)
if
(
self
.
mixup
and
layer_idx
==
mixup_layer
):
if
tgt_lang_idx
is
not
None
:
assert
self
.
embed_tokens
is
not
None
tgt_lang_embed
=
self
.
embed_tokens
(
tgt_lang_idx
)
.
unsqueeze
(
0
)
if
mixup
is
not
None
:
pass
x
=
torch
.
cat
((
tgt_lang_embed
,
x
),
0
)
input_lengths
+=
1
has_add_lang_tag
=
True
if
(
(
self
.
training
or
self
.
mixup_infer
)
and
self
.
mixup
and
layer_idx
==
mixup_layer
...
...
@@ -1815,15 +1805,26 @@ class S2TTransformerEncoder(FairseqEncoder):
x
,
input_lengths
=
self
.
subsample
(
x
,
input_lengths
)
self
.
show_debug
(
x
,
"x after subsampling"
)
#if tgt_lang_idx is not None and False:
if
tgt_lang_idx
is
not
None
and
not
has_add_lang_tag
:
if
src_lang_idx
is
not
None
:
assert
self
.
embed_tokens
is
not
None
src_lang_embed
=
self
.
embed_tokens
(
src_lang_idx
)
.
unsqueeze
(
0
)
x
=
torch
.
cat
((
src_lang_embed
,
x
),
0
)
input_lengths
+=
1
if
"prepend_src_lang"
not
in
self
.
log_flag_dict
:
self
.
log_flag_dict
[
"prepend_src_lang"
]
=
True
logger
.
info
(
"Prepend the source language tag into the encoder input."
)
if
tgt_lang_idx
is
not
None
:
assert
self
.
embed_tokens
is
not
None
tgt_lang_embed
=
self
.
embed_tokens
(
tgt_lang_idx
)
.
unsqueeze
(
0
)
if
mixup
is
not
None
:
pass
x
=
torch
.
cat
((
tgt_lang_embed
,
x
),
0
)
input_lengths
+=
1
if
"prepend_tgt_lang"
not
in
self
.
log_flag_dict
:
self
.
log_flag_dict
[
"prepend_tgt_lang"
]
=
True
logger
.
info
(
"Prepend the target language tag into the encoder input."
)
encoder_padding_mask
=
lengths_to_padding_mask
(
input_lengths
)
if
encoder_padding_mask
.
size
(
1
)
<
x
.
size
(
0
):
bsz
=
encoder_padding_mask
.
size
(
0
)
...
...
@@ -2248,12 +2249,12 @@ class S2TTransformerEncoder(FairseqEncoder):
)
if
self
.
use_ctc
and
ctc_logit
is
None
:
ctc_logit
=
self
.
ctc
(
x
,
encoder_padding_mask
,
"Encoder output"
,
is_top
=
True
)
ctc_logit
=
self
.
ctc
(
x
,
encoder_padding_mask
,
"Encoder
CTC
output"
,
is_top
=
True
)
self
.
show_debug
(
x
,
"x after ctc"
)
if
self
.
use_xctc
and
xctc_logit
is
None
:
xctc_logit
=
self
.
xctc
(
x
,
encoder_padding_mask
,
"Encoder output"
,
is_top
=
True
x
,
encoder_padding_mask
,
"Encoder
XCTC
output"
,
is_top
=
True
)
self
.
show_debug
(
x
,
"x after xctc"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论