Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TensorFSTs.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FAST
FST
TensorFSTs.jl
Commits
755c6d24
Commit
755c6d24
authored
1 year ago
by
Lucas Ondel Yang
Browse files
Options
Downloads
Plain Diff
Merge branch '44-wrong-emission-ids' into 'main'
Resolve "Wrong emission IDs" Closes
#44
See merge request
!58
parents
57d8d47e
69bbde22
Branches
27-read-iarpa-format-lm-2
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!58
Resolve "Wrong emission IDs"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/SpeechRecognitionFSTs/SpeechRecognitionFSTs.jl
+40
-32
40 additions, 32 deletions
lib/SpeechRecognitionFSTs/SpeechRecognitionFSTs.jl
src/symboltable.jl
+2
-2
2 additions, 2 deletions
src/symboltable.jl
test/speechrecfsts.jl
+3
-3
3 additions, 3 deletions
test/speechrecfsts.jl
with
45 additions
and
37 deletions
lib/SpeechRecognitionFSTs/SpeechRecognitionFSTs.jl
+
40
−
32
View file @
755c6d24
...
...
@@ -46,6 +46,9 @@ function tokenfst(
states
=
Set
(
Int
[])
arcs
,
init
,
final
=
[],
[],
[]
initdict
=
Dict
(
initweights
...
)
finaldict
=
Dict
(
finalweights
...
)
if
isnothing
(
mapping
)
st
=
Set
(
Int
[])
for
_
in
tokens
...
...
@@ -57,9 +60,9 @@ function tokenfst(
mapping
=
EmissionMapping
(
length
(
st
),
length
(
tokens
))
end
# Extra state
(infinite loop)
init
_state
=
length
(
mapping
)
+
1
push!
(
states
,
init
_state
)
# Extra state
extra
_state
=
length
(
mapping
)
+
1
push!
(
states
,
extra
_state
)
for
(
j
,
token
)
in
enumerate
(
tokens
)
offset
=
length
(
states
)
-
1
...
...
@@ -76,55 +79,60 @@ function tokenfst(
weight
=
S
(
weight
)
)
# Init
arc to sou
rc
e
s
if
topo_arc
[
1
]
==
1
# Init
ialization a
rcs
if
topo_arc
[
1
]
in
keys
(
initdict
)
init_arc
=
Arc
(
src
=
init
_state
,
src
=
extra
_state
,
isym
=
0
,
osym
=
token
,
dest
=
src
,
weight
=
S
(
weight
)
weight
=
S
(
initdict
[
topo_arc
[
1
]])
)
push!
(
arcs
,
init_arc
)
end
if
topo_arc
[
2
]
in
keys
(
initdict
)
init_arc
=
Arc
(
src
=
extra_state
,
isym
=
0
,
osym
=
token
,
dest
=
dest
,
weight
=
S
(
initdict
[
topo_arc
[
2
]])
)
push!
(
arcs
,
init_arc
)
end
# Final arcs to destinations
if
topo_arc
[
2
]
==
size
(
mapping
,
1
)
# Final arcs
if
topo_arc
[
1
]
in
keys
(
finaldict
)
final_arc
=
Arc
(
src
=
src
,
isym
=
0
,
osym
=
0
,
dest
=
extra_state
,
weight
=
S
(
finaldict
[
topo_arc
[
1
]])
)
push!
(
arcs
,
final_arc
)
end
if
topo_arc
[
2
]
in
keys
(
finaldict
)
final_arc
=
Arc
(
src
=
dest
,
isym
=
0
,
osym
=
0
,
dest
=
init
_state
,
weight
=
S
(
weight
)
)
dest
=
extra
_state
,
weight
=
S
(
finaldict
[
topo_arc
[
2
]]
)
)
push!
(
arcs
,
final_arc
)
end
push!
(
states
,
src
)
push!
(
states
,
dest
)
push!
(
arcs
,
arc
)
end
# for (state, weight) in initweights
# print(state)
# state = offset + state
# push!(states, state)
# push!(init, state => S(weight))
# end
for
(
state
,
weight
)
in
finalweights
state
=
offset
+
state
push!
(
states
,
state
)
push!
(
final
,
state
=>
S
(
weight
))
end
end
# Actually, there is just one init state
for
(
_
,
weight
)
in
initweights
push!
(
init
,
init_state
=>
S
(
weight
))
end
end
push!
(
init
,
extra_state
=>
one
(
S
))
push!
(
final
,
extra_state
=>
one
(
S
))
TensorFST
(
arcs
,
init
,
final
)
TensorFST
(
collect
(
Set
(
arcs
))
,
init
,
final
)
end
include
(
"trie.jl"
)
...
...
This diff is collapsed.
Click to expand it.
src/symboltable.jl
+
2
−
2
View file @
755c6d24
...
...
@@ -44,7 +44,7 @@ function SymbolTable(syms)
end
"""
syms(t [, exclude_ϵ])
syms(t [, exclude_ϵ
=tru
])
Return all symbols from symbol table `t`.
"""
...
...
@@ -57,7 +57,7 @@ function syms(t::SymbolTable; exclude_ϵ=true)
end
"""
ids(t [, exclude_ϵ])
ids(t [, exclude_ϵ
=true
])
Return all IDs from symbol table `t`.
"""
...
...
This diff is collapsed.
Click to expand it.
test/speechrecfsts.jl
+
3
−
3
View file @
755c6d24
...
...
@@ -31,11 +31,11 @@ S = BoolSemiring
# # Extra node
# Source
(
src
=
(
7
,),
isym
=
0
,
osym
=
4
,
weight
=
one
(
S
),
dest
=
(
5
,)),
(
src
=
(
7
,),
isym
=
0
,
osym
=
3
,
weight
=
one
(
S
),
dest
=
(
3
,
)),
(
src
=
(
7
,),
isym
=
0
,
osym
=
3
,
weight
=
one
(
S
),
dest
=
(
3
,)),
(
src
=
(
7
,),
isym
=
0
,
osym
=
2
,
weight
=
one
(
S
),
dest
=
(
1
,)),
# Destination
(
src
=
(
6
,),
isym
=
0
,
osym
=
0
,
weight
=
one
(
S
),
dest
=
(
7
,)),
(
src
=
(
4
,),
isym
=
0
,
osym
=
0
,
weight
=
one
(
S
),
dest
=
(
7
,
)),
(
src
=
(
4
,),
isym
=
0
,
osym
=
0
,
weight
=
one
(
S
),
dest
=
(
7
,)),
(
src
=
(
2
,),
isym
=
0
,
osym
=
0
,
weight
=
one
(
S
),
dest
=
(
7
,)),
...
...
@@ -49,7 +49,7 @@ S = BoolSemiring
],
[(
7
,)
=>
one
(
S
)],
[(
4
,)
=>
one
(
S
),
(
6
,)
=>
one
(
S
),
(
2
,)
=>
one
(
S
)]
,
[(
7
,)
=>
one
(
S
)]
)
@test
issame
(
U
,
U2
)
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment