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
6b1f4c28
Commit
6b1f4c28
authored
2 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added script to clean w2v file of long words
parent
258180d3
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/cleanW2V.py
+44
-0
44 additions, 0 deletions
scripts/cleanW2V.py
with
44 additions
and
0 deletions
scripts/cleanW2V.py
0 → 100755
+
44
−
0
View file @
6b1f4c28
#! /usr/bin/env python3
import
sys
def
printUsageAndExit
()
:
print
(
"
USAGE: %s w2vFilename wordSizeLimit
"
%
sys
.
argv
[
0
],
file
=
sys
.
stderr
)
exit
(
1
)
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
!=
3
:
printUsageAndExit
()
nbWords
=
None
embSize
=
None
lineNumber
=
0
deleted
=
set
()
for
line
in
open
(
sys
.
argv
[
1
],
"
r
"
)
:
lineNumber
+=
1
line
=
line
.
strip
()
splited
=
line
.
split
()
if
nbWords
is
None
:
nbWords
=
int
(
splited
[
0
])
embSize
=
int
(
splited
[
1
])
deleted
.
add
(
lineNumber
)
continue
wordLen
=
int
(
len
(
splited
[
0
]))
numValues
=
int
(
len
(
splited
))
-
1
if
numValues
!=
embSize
:
print
(
"
ERROR: in line %d expected %d values got %d instead
"
%
(
lineNumber
,
embSize
,
numValues
),
file
=
sys
.
stderr
)
continue
if
wordLen
>
int
(
sys
.
argv
[
2
])
:
print
(
"
deleting line %d: word length = %d (%s...)
"
%
(
lineNumber
,
wordLen
,
splited
[
0
][:
10
]),
file
=
sys
.
stderr
)
deleted
.
add
(
lineNumber
)
newNb
=
lineNumber
-
1
-
len
(
deleted
)
print
(
newNb
,
embSize
)
lineNumber
=
0
for
line
in
open
(
sys
.
argv
[
1
],
"
r
"
)
:
lineNumber
+=
1
if
lineNumber
not
in
deleted
:
print
(
line
,
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