Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macaon
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
Container registry
Model registry
Operate
Environments
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
macaon
Commits
28538df0
Commit
28538df0
authored
4 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added Arc Standard transition system
parent
c1698081
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
reading_machine/include/Transition.hpp
+4
-1
4 additions, 1 deletion
reading_machine/include/Transition.hpp
reading_machine/src/Config.cpp
+1
-1
1 addition, 1 deletion
reading_machine/src/Config.cpp
reading_machine/src/Transition.cpp
+76
-3
76 additions, 3 deletions
reading_machine/src/Transition.cpp
with
81 additions
and
5 deletions
reading_machine/include/Transition.hpp
+
4
−
1
View file @
28538df0
...
...
@@ -23,9 +23,12 @@ class Transition
void
initWrite
(
std
::
string
colName
,
std
::
string
object
,
std
::
string
index
,
std
::
string
value
);
void
initAdd
(
std
::
string
colName
,
std
::
string
object
,
std
::
string
index
,
std
::
string
value
);
void
initShift
();
void
initEagerShift
();
void
initStandardShift
();
void
initEagerLeft_rel
(
std
::
string
label
);
void
initEagerRight_rel
(
std
::
string
label
);
void
initStandardLeft_rel
(
std
::
string
label
);
void
initStandardRight_rel
(
std
::
string
label
);
void
initDeprel
(
std
::
string
label
);
void
initEagerLeft
();
void
initEagerRight
();
...
...
This diff is collapsed.
Click to expand it.
reading_machine/src/Config.cpp
+
1
−
1
View file @
28538df0
...
...
@@ -360,7 +360,7 @@ void Config::popStack()
void
Config
::
swapStack
(
int
relIndex1
,
int
relIndex2
)
{
int
tmp
=
getStack
(
relIndex1
);
getStackRef
(
relIndex1
)
=
relIndex2
;
getStackRef
(
relIndex1
)
=
getStack
(
relIndex2
)
;
getStackRef
(
relIndex2
)
=
tmp
;
}
...
...
This diff is collapsed.
Click to expand it.
reading_machine/src/Transition.cpp
+
76
−
3
View file @
28538df0
...
...
@@ -9,8 +9,10 @@ Transition::Transition(const std::string & name)
[
this
](
auto
sm
){(
initWrite
(
sm
[
3
],
sm
[
1
],
sm
[
2
],
sm
[
4
]));}},
{
std
::
regex
(
"ADD ([bs])
\\
.(.+) (.+) (.+)"
),
[
this
](
auto
sm
){(
initAdd
(
sm
[
3
],
sm
[
1
],
sm
[
2
],
sm
[
4
]));}},
{
std
::
regex
(
"SHIFT"
),
[
this
](
auto
){
initShift
();}},
{
std
::
regex
(
"eager_SHIFT"
),
[
this
](
auto
){
initEagerShift
();}},
{
std
::
regex
(
"standard_SHIFT"
),
[
this
](
auto
){
initStandardShift
();}},
{
std
::
regex
(
"REDUCE_strict"
),
[
this
](
auto
){
initReduce_strict
();}},
{
std
::
regex
(
"REDUCE_relaxed"
),
...
...
@@ -19,6 +21,10 @@ Transition::Transition(const std::string & name)
[
this
](
auto
sm
){(
initEagerLeft_rel
(
sm
[
1
]));}},
{
std
::
regex
(
"eager_RIGHT_rel (.+)"
),
[
this
](
auto
sm
){(
initEagerRight_rel
(
sm
[
1
]));}},
{
std
::
regex
(
"standard_LEFT_rel (.+)"
),
[
this
](
auto
sm
){(
initStandardLeft_rel
(
sm
[
1
]));}},
{
std
::
regex
(
"standard_RIGHT_rel (.+)"
),
[
this
](
auto
sm
){(
initStandardRight_rel
(
sm
[
1
]));}},
{
std
::
regex
(
"eager_LEFT"
),
[
this
](
auto
){(
initEagerLeft
());}},
{
std
::
regex
(
"eager_RIGHT"
),
...
...
@@ -233,7 +239,7 @@ void Transition::initSplit(int index)
};
}
void
Transition
::
initShift
()
void
Transition
::
init
Eager
Shift
()
{
sequence
.
emplace_back
(
Action
::
pushWordIndexOnStack
());
sequence
.
emplace_back
(
Action
::
setRootUpdateIdsEmptyStackIfSentChanged
());
...
...
@@ -250,6 +256,20 @@ void Transition::initShift()
};
}
void
Transition
::
initStandardShift
()
{
sequence
.
emplace_back
(
Action
::
pushWordIndexOnStack
());
sequence
.
emplace_back
(
Action
::
setRootUpdateIdsEmptyStackIfSentChanged
());
cost
=
[](
const
Config
&
config
)
{
if
(
config
.
hasStack
(
0
)
&&
config
.
getConst
(
Config
::
EOSColName
,
config
.
getStack
(
0
),
0
)
==
Config
::
EOSSymbol1
)
return
std
::
numeric_limits
<
int
>::
max
();
return
0
;
};
}
void
Transition
::
initEagerLeft_rel
(
std
::
string
label
)
{
sequence
.
emplace_back
(
Action
::
attach
(
Config
::
Object
::
Buffer
,
0
,
Config
::
Object
::
Stack
,
0
));
...
...
@@ -276,6 +296,32 @@ void Transition::initEagerLeft_rel(std::string label)
};
}
void
Transition
::
initStandardLeft_rel
(
std
::
string
label
)
{
sequence
.
emplace_back
(
Action
::
attach
(
Config
::
Object
::
Stack
,
0
,
Config
::
Object
::
Stack
,
1
));
sequence
.
emplace_back
(
Action
::
addHypothesisRelative
(
Config
::
deprelColName
,
Config
::
Object
::
Stack
,
1
,
label
));
sequence
.
emplace_back
(
Action
::
popStack
(
1
));
cost
=
[
label
](
const
Config
&
config
)
{
auto
stackIndex
=
config
.
getStack
(
1
);
auto
stackGovIndex
=
config
.
getConst
(
Config
::
headColName
,
stackIndex
,
0
);
auto
wordIndex
=
config
.
getStack
(
0
);
if
(
!
(
config
.
isToken
(
stackIndex
)
&&
config
.
isToken
(
wordIndex
)))
return
std
::
numeric_limits
<
int
>::
max
();
int
cost
=
getNbLinkedWith
(
config
.
getWordIndex
(),
getLastIndexOfSentence
(
config
.
getWordIndex
(),
config
),
Config
::
Object
::
Buffer
,
stackIndex
,
config
);
if
(
stackGovIndex
!=
std
::
to_string
(
wordIndex
))
++
cost
;
if
(
label
!=
config
.
getConst
(
Config
::
deprelColName
,
stackIndex
,
0
))
++
cost
;
return
cost
;
};
}
void
Transition
::
initEagerLeft
()
{
sequence
.
emplace_back
(
Action
::
attach
(
Config
::
Object
::
Buffer
,
0
,
Config
::
Object
::
Stack
,
0
));
...
...
@@ -329,6 +375,33 @@ void Transition::initEagerRight_rel(std::string label)
};
}
void
Transition
::
initStandardRight_rel
(
std
::
string
label
)
{
sequence
.
emplace_back
(
Action
::
attach
(
Config
::
Object
::
Stack
,
1
,
Config
::
Object
::
Stack
,
0
));
sequence
.
emplace_back
(
Action
::
addHypothesisRelative
(
Config
::
deprelColName
,
Config
::
Object
::
Stack
,
0
,
label
));
sequence
.
emplace_back
(
Action
::
popStack
(
0
));
cost
=
[
label
](
const
Config
&
config
)
{
auto
stackIndex
=
config
.
getStack
(
1
);
auto
wordIndex
=
config
.
getStack
(
0
);
if
(
!
(
config
.
isToken
(
stackIndex
)
&&
config
.
isToken
(
wordIndex
)))
return
std
::
numeric_limits
<
int
>::
max
();
auto
bufferGovIndex
=
config
.
getConst
(
Config
::
headColName
,
wordIndex
,
0
);
int
cost
=
getNbLinkedWith
(
config
.
getWordIndex
(),
getLastIndexOfSentence
(
config
.
getWordIndex
(),
config
),
Config
::
Object
::
Buffer
,
wordIndex
,
config
);
if
(
bufferGovIndex
!=
std
::
to_string
(
stackIndex
))
++
cost
;
if
(
label
!=
config
.
getConst
(
Config
::
deprelColName
,
wordIndex
,
0
))
++
cost
;
return
cost
;
};
}
void
Transition
::
initEagerRight
()
{
sequence
.
emplace_back
(
Action
::
attach
(
Config
::
Object
::
Stack
,
0
,
Config
::
Object
::
Buffer
,
0
));
...
...
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