Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SpeechDatasets.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
PTAL
Datasets
SpeechDatasets.jl
Commits
0d8fcc5a
Verified
Commit
0d8fcc5a
authored
9 months ago
by
Lucas Ondel Yang
Browse files
Options
Downloads
Patches
Plain Diff
speechdataset iterate over tuple of recording, annotation
parent
0b47f281
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dataset.jl
+20
-17
20 additions, 17 deletions
src/dataset.jl
with
20 additions
and
17 deletions
src/dataset.jl
+
20
−
17
View file @
0d8fcc5a
...
...
@@ -4,14 +4,12 @@ struct SpeechDataset <: MLUtils.AbstractDataContainer
idxs
::
Vector
{
AbstractString
}
annotations
::
Dict
{
AbstractString
,
Annotation
}
recordings
::
Dict
{
AbstractString
,
Recording
}
partition
::
Symbol
end
"""
dataset(manifestroot
, partition
)
dataset(manifestroot)
Load `SpeechDataset` from manifest files stored in `manifestroot`.
Partition is specified by `partition`, e.g. `:train`, `:test`.
Each item of the dataset is a nested tuple `((samples, sampling_rate), Annotation.data)`.
...
...
@@ -32,25 +30,20 @@ julia> ds[1]
)
```
"""
function
dataset
(
manifestroot
,
partition
)
function
dataset
(
manifestroot
::
AbstractString
,
partition
)
annot_path
=
joinpath
(
manifestroot
,
"annotations-
$(partition)
.jsonl"
)
rec_path
=
joinpath
(
manifestroot
,
"recordings.jsonl"
)
annotations
=
load
(
Annotation
,
annot_path
)
recordings
=
load
(
Recording
,
rec_path
)
dataset
(
annotations
,
recordings
,
partition
)
dataset
(
annotations
,
recordings
)
end
function
dataset
(
annotations
,
recordings
,
partition
)
function
dataset
(
annotations
::
AbstractDict
,
recordings
::
AbstractDict
)
idxs
=
collect
(
keys
(
annotations
))
SpeechDataset
(
idxs
,
annotations
,
recordings
,
Symbol
(
partition
)
)
SpeechDataset
(
idxs
,
annotations
,
recordings
)
end
function
Base.getindex
(
d
::
SpeechDataset
,
key
::
AbstractString
)
ann
=
d
.
annotations
[
key
]
rec
=
d
.
recordings
[
ann
.
recording_id
]
samples
,
sr
=
load
(
rec
,
ann
)
(
samples
=
samples
,
sampling_rate
=
sr
),
ann
.
data
end
Base
.
getindex
(
d
::
SpeechDataset
,
key
::
AbstractString
)
=
d
.
recordings
[
key
],
d
.
annotations
[
key
]
Base
.
getindex
(
d
::
SpeechDataset
,
idx
::
Integer
)
=
getindex
(
d
,
d
.
idxs
[
idx
])
# Fix1 -> partial funcion with fixed 1st argument
Base
.
getindex
(
d
::
SpeechDataset
,
idxs
::
AbstractVector
)
=
map
(
Base
.
Fix1
(
getindex
,
d
),
idxs
)
...
...
@@ -58,9 +51,19 @@ Base.getindex(d::SpeechDataset, idxs::AbstractVector) = map(Base.Fix1(getindex,
Base
.
length
(
d
::
SpeechDataset
)
=
length
(
d
.
idxs
)
function
Base.filter
(
fn
,
d
::
SpeechDataset
)
fidxs
=
filter
(
fn
,
d
.
idxs
)
fannotations
=
filter
(
k_v
->
fn
(
first
(
k_v
)),
d
.
annotations
)
frecs
=
filter
(
k_v
->
fn
(
first
(
k_v
)),
d
.
recordings
)
SpeechDataset
(
fidxs
,
fannotations
,
frecs
,
:
custom
)
fidxs
=
filter
(
d
.
idxs
)
do
i
fn
((
d
.
recordings
[
i
],
d
.
annotations
[
i
]))
end
idset
=
Set
(
fidxs
)
fannotations
=
filter
(
d
.
annotations
)
do
(
k
,
v
)
k
∈
idset
end
frecs
=
filter
(
d
.
recordings
)
do
(
k
,
v
)
k
∈
idset
end
SpeechDataset
(
fidxs
,
fannotations
,
frecs
)
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