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
f811c17b
Commit
f811c17b
authored
4 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added script to filter embeddings file based on vocabulary from conllu files
parent
6e33d91c
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/filterEmbeddings.py
+44
-0
44 additions, 0 deletions
scripts/filterEmbeddings.py
with
44 additions
and
0 deletions
scripts/filterEmbeddings.py
0 → 100755
+
44
−
0
View file @
f811c17b
#! /usr/bin/env python3
import
sys
################################################################################
def
printUsageAndExit
()
:
print
(
"
USAGE : %s embeddings.w2v vocabFile1.conllu vocabFile2.conllu...
"
%
sys
.
argv
[
0
],
file
=
sys
.
stderr
)
exit
(
1
)
################################################################################
################################################################################
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
<
3
:
printUsageAndExit
()
vocab
=
{}
for
filename
in
sys
.
argv
[
2
:]
:
formIndex
=
None
for
line
in
open
(
filename
,
"
r
"
)
:
line
=
line
.
strip
()
if
len
(
line
)
==
0
:
continue
if
"
# global.columns =
"
in
line
:
formIndex
=
line
.
split
(
'
=
'
)[
-
1
].
strip
().
split
(
'
'
).
index
(
"
FORM
"
)
if
line
[
0
]
==
'
#
'
:
continue
word
=
line
.
split
(
'
\t
'
)[
formIndex
]
vocab
[
word
]
=
True
print
(
"
Vocabulary size = %d words
"
%
len
(
vocab
),
file
=
sys
.
stderr
)
for
line
in
open
(
sys
.
argv
[
1
])
:
line
=
line
.
strip
()
splited
=
line
.
split
(
'
'
)
# Ignore optional w2v header
if
len
(
splited
)
==
2
:
continue
word
=
splited
[
0
]
if
word
in
vocab
:
print
(
line
)
################################################################################
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