Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RL-Parsing
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
Franck Dary
RL-Parsing
Commits
4268691e
Commit
4268691e
authored
3 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added featuresSet taking into account stack element governor POS
parent
9fa94f3b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Dicts.py
+2
-0
2 additions, 0 deletions
Dicts.py
Features.py
+36
-3
36 additions, 3 deletions
Features.py
Transition.py
+1
-5
1 addition, 5 deletions
Transition.py
Util.py
+5
-0
5 additions, 0 deletions
Util.py
with
44 additions
and
8 deletions
Dicts.py
+
2
−
0
View file @
4268691e
...
...
@@ -7,6 +7,8 @@ class Dicts :
self
.
dicts
=
{}
self
.
unkToken
=
"
__unknown__
"
self
.
nullToken
=
"
__null__
"
self
.
noStackToken
=
"
__nostack__
"
self
.
oobToken
=
"
__oob__
"
def
readConllu
(
self
,
filename
,
colsSet
=
None
)
:
defaultMCD
=
"
ID FORM LEMMA UPOS XPOS FEATS HEAD DEPREL DEPS MISC
"
...
...
This diff is collapsed.
Click to expand it.
Features.py
+
36
−
3
View file @
4268691e
import
torch
import
sys
from
Util
import
isEmpty
################################################################################
def
extractFeatures
(
dicts
,
config
)
:
return
extractFeaturesPos
(
dicts
,
config
)
return
extractFeaturesPos
Extended
(
dicts
,
config
)
################################################################################
################################################################################
...
...
@@ -17,15 +18,47 @@ def extractFeaturesPos(dicts, config) :
insertIndex
=
0
for
i
in
bufferWindow
:
index
=
config
.
wordIndex
+
i
bufferPos
=
dicts
.
null
Token
if
index
not
in
range
(
len
(
config
.
lines
))
else
config
.
getAsFeature
(
index
,
"
UPOS
"
)
bufferPos
=
dicts
.
oob
Token
if
index
not
in
range
(
len
(
config
.
lines
))
else
config
.
getAsFeature
(
index
,
"
UPOS
"
)
result
[
insertIndex
]
=
dicts
.
get
(
"
UPOS
"
,
bufferPos
)
insertIndex
+=
1
for
i
in
stackWindow
:
stackPos
=
dicts
.
n
ull
Token
if
i
not
in
range
(
len
(
config
.
stack
))
else
config
.
getAsFeature
(
config
.
stack
[
-
1
-
i
],
"
UPOS
"
)
stackPos
=
dicts
.
n
oStack
Token
if
i
not
in
range
(
len
(
config
.
stack
))
else
config
.
getAsFeature
(
config
.
stack
[
-
1
-
i
],
"
UPOS
"
)
result
[
insertIndex
]
=
dicts
.
get
(
"
UPOS
"
,
stackPos
)
insertIndex
+=
1
return
result
################################################################################
################################################################################
# For each stack element, add its POS and the POS of its governor
def
extractFeaturesPosExtended
(
dicts
,
config
)
:
bufferWindow
=
range
(
-
2
,
2
+
1
)
stackWindow
=
range
(
0
,
3
+
1
)
totalSize
=
len
(
bufferWindow
)
+
2
*
len
(
stackWindow
)
result
=
torch
.
zeros
(
totalSize
,
dtype
=
torch
.
int
)
insertIndex
=
0
for
i
in
bufferWindow
:
index
=
config
.
wordIndex
+
i
bufferPos
=
dicts
.
oobToken
if
index
not
in
range
(
len
(
config
.
lines
))
else
config
.
getAsFeature
(
index
,
"
UPOS
"
)
result
[
insertIndex
]
=
dicts
.
get
(
"
UPOS
"
,
bufferPos
)
insertIndex
+=
1
for
i
in
stackWindow
:
stackPos
=
dicts
.
noStackToken
if
i
not
in
range
(
len
(
config
.
stack
))
else
config
.
getAsFeature
(
config
.
stack
[
-
1
-
i
],
"
UPOS
"
)
stackGovHead
=
dicts
.
nullToken
if
i
not
in
range
(
len
(
config
.
stack
))
else
config
.
getAsFeature
(
config
.
stack
[
-
1
-
i
],
"
HEAD
"
)
stackGovPos
=
dicts
.
nullToken
if
not
isEmpty
(
stackGovHead
)
and
stackGovHead
!=
dicts
.
nullToken
:
stackGovPos
=
config
.
getAsFeature
(
int
(
stackGovHead
),
"
UPOS
"
)
elif
stackGovHead
==
dicts
.
nullToken
:
stackGovPos
=
dicts
.
noStackToken
result
[
insertIndex
]
=
dicts
.
get
(
"
UPOS
"
,
stackPos
)
insertIndex
+=
1
result
[
insertIndex
]
=
dicts
.
get
(
"
UPOS
"
,
stackGovPos
)
insertIndex
+=
1
return
result
################################################################################
This diff is collapsed.
Click to expand it.
Transition.py
+
1
−
5
View file @
4268691e
import
sys
import
Config
################################################################################
def
isEmpty
(
value
)
:
return
value
==
"
_
"
or
value
==
""
################################################################################
from
Util
import
isEmpty
################################################################################
class
Transition
:
...
...
This diff is collapsed.
Click to expand it.
Util.py
+
5
−
0
View file @
4268691e
...
...
@@ -5,3 +5,8 @@ def timeStamp() :
return
"
[%s]
"
%
datetime
.
now
().
strftime
(
"
%H:%M:%S
"
)
################################################################################
################################################################################
def
isEmpty
(
value
)
:
return
value
==
"
_
"
or
value
==
""
################################################################################
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