Skip to content
GitLab
探索
登录
主导航
搜索或转到…
项目
F
fairseq
管理
动态
成员
标记
计划
议题
0
议题看板
里程碑
迭代
Wiki
代码
合并请求
0
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
产物
部署
发布
软件包库
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
Contributor analytics
CI/CD 分析
仓库分析
代码评审分析
议题分析
模型实验
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
快捷键
?
支持
扫描加入微信群:
1. 获取企业级DevOps解决方案支持
2. 免费或折扣极狐GitLab 官方培训认证
代码片段
群组
项目
HPCSource
fairseq
提交
339bb607
未验证
提交
339bb607
编辑于
2年前
作者:
padentomasello
提交者:
GitHub
2年前
浏览文件
操作
下载
差异文件
Merge branch 'main' into padentomasello-patch-2
上级
d05f43cf
6c57de3c
分支
padentomasello-patch-2
无相关合并请求
变更
1
隐藏空白变更内容
行内
左右并排
显示
1 个更改的文件
examples/audio_nlp/nlu/generate_manifests.py
+83
-0
83 个添加, 0 个删除
examples/audio_nlp/nlu/generate_manifests.py
有
83 个添加
和
0 个删除
examples/audio_nlp/nlu/generate_manifests.py
0 → 100644
+
83
−
0
浏览文件 @
339bb607
import
argparse
from
pathlib
import
Path
import
soundfile
def
get_insl_frame
(
parse
):
out
=
[]
def
is_ont_token
(
tok
):
return
tok
[
0
]
in
[
"
[
"
,
"
]
"
];
res
=
[]
x
=
[]
for
tok
in
parse
.
split
():
if
is_ont_token
(
tok
):
res
.
extend
(
'
_
'
.
join
(
x
))
x
=
[]
res
.
append
(
tok
.
upper
())
else
:
x
.
append
(
tok
.
upper
())
return
"
"
.
join
(
res
)
+
'
|
'
def
sequencify_utterance
(
utterance
):
utterance
=
utterance
.
upper
()
utterance
=
utterance
.
replace
(
'
'
,
'
|
'
)
+
'
|
'
utterance
=
list
(
utterance
)
utterance
=
'
'
.
join
(
utterance
)
return
utterance
def
generate_fairseq_manifests
(
manifest
,
output_path
,
audio_root
=
None
):
with
open
(
manifest
,
'
r
'
)
as
i
:
parses
=
[]
utterances
=
[]
filepaths
=
[]
keys
=
None
for
(
idx
,
line
)
in
enumerate
(
i
):
if
idx
==
0
:
keys
=
line
.
strip
().
split
(
'
\t
'
)
else
:
data
=
{
k
:
v
for
(
k
,
v
)
in
zip
(
keys
,
line
.
split
(
'
\t
'
))}
parses
.
append
(
get_insl_frame
(
data
[
'
decoupled_normalized_seqlogical
'
]))
utterances
.
append
(
sequencify_utterance
(
data
[
'
normalized_utterance
'
]))
filepaths
.
append
(
data
[
'
file_id
'
])
parses_fp
=
output_path
.
with_suffix
(
'
.parse
'
)
with
open
(
str
(
parses_fp
),
'
w
'
)
as
o
:
for
p
in
parses
:
o
.
write
(
p
+
'
\n
'
)
utterances_fp
=
output_path
.
with_suffix
(
'
.ltr
'
)
with
open
(
str
(
utterances_fp
),
'
w
'
)
as
o
:
for
u
in
utterances
:
o
.
write
(
u
+
'
\n
'
)
filepaths_fp
=
output_path
.
with_suffix
(
'
.tsv
'
)
with
open
(
str
(
filepaths_fp
),
'
w
'
)
as
o
:
o
.
write
(
str
(
audio_root
)
+
'
\n
'
)
for
f
in
filepaths
:
fullpath
=
audio_root
/
f
assert
fullpath
.
exists
(),
f
'
{
fullpath
}
'
frames
=
soundfile
.
info
(
fullpath
).
frames
o
.
write
(
f
'
{
f
}
\t
{
frames
}
\n
'
)
def
main
(
args
):
splits
=
[
'
train
'
,
'
eval
'
,
'
test
'
]
root
=
Path
(
args
.
stop_root
)
output_root
=
Path
(
args
.
output
)
for
split
in
splits
:
stop_manifest_path
=
root
/
'
manifests
'
/
(
split
+
'
.tsv
'
)
output_path
=
output_root
/
(
split
)
generate_fairseq_manifests
(
stop_manifest_path
,
output_path
,
root
)
if
__name__
==
'
__main__
'
:
parser
=
argparse
.
ArgumentParser
(
description
=
'
Process some integers.
'
)
parser
.
add_argument
(
'
--stop_root
'
,
type
=
str
,
help
=
'
path to stop root directory
'
)
parser
.
add_argument
(
'
--output
'
,
type
=
str
,
help
=
'
output directory
'
)
args
=
parser
.
parse_args
()
main
(
args
)
This diff is collapsed.
Click to expand it.
预览
0%
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录