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
8c50dd3a
Verified
Commit
8c50dd3a
authored
2 years ago
by
Lucas Ondel Yang
Browse files
Options
Downloads
Patches
Plain Diff
mwe gradient
parent
0dac1121
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Project.toml
+1
-0
1 addition, 0 deletions
Project.toml
src/FiniteStateAutomata.jl
+3
-0
3 additions, 0 deletions
src/FiniteStateAutomata.jl
src/iterate.jl
+1
-1
1 addition, 1 deletion
src/iterate.jl
src/ops.jl
+0
-16
0 additions, 16 deletions
src/ops.jl
src/sum.jl
+61
-0
61 additions, 0 deletions
src/sum.jl
with
66 additions
and
17 deletions
Project.toml
+
1
−
0
View file @
8c50dd3a
...
...
@@ -6,4 +6,5 @@ version = "0.2.2"
[deps]
ChainRulesCore
=
"d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
LinearAlgebra
=
"37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Semirings
=
"900aad66-9ca5-44d4-b043-321c62cb7767"
SparseArrays
=
"2f01184e-e22b-5df5-ae63-d93ebab69eaf"
This diff is collapsed.
Click to expand it.
src/FiniteStateAutomata.jl
+
3
−
0
View file @
8c50dd3a
...
...
@@ -3,7 +3,9 @@
module
FiniteStateAutomata
using
LinearAlgebra
using
ChainRulesCore
using
SparseArrays
using
Semirings
export
# Abstract types
...
...
@@ -48,6 +50,7 @@ include("fst.jl")
include
(
"dense_fsa.jl"
)
include
(
"reverse.jl"
)
include
(
"sum.jl"
)
include
(
"ops.jl"
)
include
(
"intersect.jl"
)
...
...
This diff is collapsed.
Click to expand it.
src/iterate.jl
+
1
−
1
View file @
8c50dd3a
...
...
@@ -4,6 +4,6 @@ Base.iterate(A::AbstractFST) = nstates(A) == 0 ? nothing : (α(A), α(A))
function
Base.iterate
(
A
::
AbstractFST
,
uₙ
)
uₙ₊₁
=
T
(
A
)
'
*
uₙ
nnz
(
uₙ
)
>
0
?
(
uₙ₊₁
,
uₙ₊₁
)
:
nothing
nnz
(
uₙ
₊₁
)
>
0
?
(
uₙ₊₁
,
uₙ₊₁
)
:
nothing
end
This diff is collapsed.
Click to expand it.
src/ops.jl
+
0
−
16
View file @
8c50dd3a
...
...
@@ -25,22 +25,6 @@ function addskipedges(M, states, weights)
FST
(
αₙ
,
Tₙ
,
ωₙ
,
ρₙ
,
λ
(
M
))
end
"""
Base.sum(A[; init = α(A), n = nstates(A)])
Accumulate the weight of all the paths of length less or equal to
`n`.
"""
function
Base.sum
(
A
::
AbstractFST
;
init
=
α
(
A
),
n
=
nstates
(
A
))
v
=
init
σ
=
dot
(
v
,
ω
(
A
))
+
ρ
(
A
)
for
_
in
2
:
n
v
=
T
(
A
)
'
*
v
σ
+=
dot
(
v
,
ω
(
A
))
end
σ
end
"""
cat(A1[, A2, ...])
...
...
This diff is collapsed.
Click to expand it.
src/sum.jl
0 → 100644
+
61
−
0
View file @
8c50dd3a
# SPDX-License-Identifier: CECILL-2.1
"""
Base.sum(A; n = nstates(A))
Accumulate the weights of all the paths. For cyclic FSTs sum after `n`
steps.
"""
#function Base.sum(A::AbstractFST; n = nstates(A))
# W = ρ(A)
# for (i, uₙ) in enumerate(A)
# i <= n || break
# W += dot(uₙ, ω(A))
# end
# W
#end
function
ChainRulesCore.rrule
(
::
typeof
(
Base
.
sum
),
A
::
AbstractFST
{
K
})
where
K
W
=
ρ
(
A
)
U
=
[]
for
uₙ
in
A
push!
(
U
,
uₙ
)
W
+=
dot
(
uₙ
,
ω
(
A
))
end
function
pullback
(
ΔY
)
V
=
[]
for
vₙ
in
reverse
(
A
)
push!
(
V
,
vₙ
)
end
ū
=
sum
(
U
)
I_α
,
_
=
findnz
(
α
(
A
))
I_T
,
J_T
,
_
=
findnz
(
T
(
A
))
V_T
=
zeros
(
K
,
length
(
J_T
))
k_1
=
length
(
U
)
for
i
in
1
:
k_1
for
j
in
1
:
(
k_1
-
i
)
uᵢ
,
vⱼ
=
U
[
i
],
V
[
k_1
-
j
]
V_T
.+=
uᵢ
[
I_T
]
.*
vⱼ
[
J_T
]
end
end
v̄
=
sum
(
V
)
I_ω
,
_
=
findnz
(
ω
(
A
))
ΔA
=
FST
(
sparsevec
(
I_α
,
ū
[
I_α
],
nstates
(
A
)),
sparse
(
I_T
,
J_T
,
V_T
,
nstates
(
A
),
nstates
(
A
)),
sparsevec
(
I_ω
,
v̄
[
I_ω
],
nstates
(
A
)),
iszero
(
ρ
(
A
))
?
zero
(
K
)
:
one
(
K
),
λ
(
A
)
)
(
NoTangent
(),
ΔA
)
end
W
,
pullback
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