Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macaon_data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Franck Dary
macaon_data
Commits
282c818e
Commit
282c818e
authored
3 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added script to split UD corpus into k folds
parent
ada1cdb1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/createKFolds.py
+70
-0
70 additions, 0 deletions
scripts/createKFolds.py
with
70 additions
and
0 deletions
scripts/createKFolds.py
0 → 100755
+
70
−
0
View file @
282c818e
#! /usr/bin/env python3
import
sys
import
os
import
random
################################################################################
def
printUsageAndExit
()
:
print
(
"
USAGE : %s UDDir outputDir nbFolds
"
%
sys
.
argv
[
0
],
file
=
sys
.
stderr
)
exit
(
1
)
################################################################################
################################################################################
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
!=
4
:
printUsageAndExit
()
random
.
seed
(
100
)
inputFiles
=
[
sys
.
argv
[
1
]
+
"
/
"
+
filename
for
filename
in
os
.
listdir
(
sys
.
argv
[
1
])
if
"
.conllu
"
in
filename
]
sentences
=
[]
header
=
"
# global.columns = ID FORM LEMMA UPOS XPOS FEATS HEAD DEPREL DEPS MISC
"
for
filename
in
inputFiles
:
prevWasBlank
=
True
for
line
in
open
(
filename
,
"
r
"
)
:
line
=
line
.
strip
()
if
len
(
line
)
==
0
:
prevWasBlank
=
True
continue
if
"
# global.columns =
"
in
line
:
header
=
line
continue
if
prevWasBlank
:
sentences
.
append
([])
prevWasBlank
=
False
sentences
[
-
1
].
append
(
line
)
random
.
shuffle
(
sentences
)
print
(
header
)
for
sentence
in
sentences
:
print
(
"
\n
"
.
join
(
sentence
)
+
"
\n
"
)
nbFolds
=
int
(
sys
.
argv
[
3
])
testSize
=
int
(
len
(
sentences
)
/
nbFolds
)
partition
=
[
i
for
i
in
range
(
0
,
len
(
sentences
),
testSize
)]
partition
=
[[
partition
[
i
],
partition
[
i
+
1
]]
for
i
in
range
(
len
(
partition
)
-
1
)]
partition
[
-
1
][
-
1
]
=
len
(
sentences
)
partition
=
[
range
(
p
[
0
],
p
[
1
])
for
p
in
partition
]
for
k
in
range
(
len
(
partition
))
:
test
=
[
sentences
[
i
]
for
i
in
partition
[
k
]]
trainDev
=
[
sentences
[
i
]
for
i
in
range
(
len
(
sentences
))
if
i
not
in
partition
[
k
]]
train
=
trainDev
[:
-
testSize
]
dev
=
trainDev
[
-
testSize
:]
outDir
=
sys
.
argv
[
2
]
+
"
/
"
+
sys
.
argv
[
1
]
while
outDir
[
-
1
]
==
'
/
'
:
outDir
=
outDir
[:
-
1
]
outDir
=
outDir
+
"
_
"
+
str
(
k
)
os
.
makedirs
(
outDir
,
exist_ok
=
True
)
for
sents
,
name
in
[(
train
,
"
train
"
),
(
dev
,
"
dev
"
),
(
test
,
"
test
"
)]
:
with
open
(
outDir
+
"
/
"
+
"
%s.conllu
"
%
name
,
"
w
"
)
as
outFile
:
print
(
header
,
file
=
outFile
)
for
sentence
in
sents
:
print
(
"
\n
"
.
join
(
sentence
)
+
"
\n
"
,
file
=
outFile
)
################################################################################
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