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
3c41224b
Commit
3c41224b
authored
4 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Explore different transitions only for parser
parent
a4487b91
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
+2
-0
2 additions, 0 deletions
reading_machine/include/Transition.hpp
reading_machine/src/Transition.cpp
+37
-0
37 additions, 0 deletions
reading_machine/src/Transition.cpp
trainer/src/Trainer.cpp
+5
-1
5 additions, 1 deletion
trainer/src/Trainer.cpp
with
44 additions
and
1 deletion
reading_machine/include/Transition.hpp
+
2
−
0
View file @
3c41224b
...
...
@@ -43,6 +43,7 @@ class Transition
void
initGoldReduce_strict
();
void
initReduce_relaxed
();
void
initEOS
(
int
bufferIndex
);
void
initNotEOS
(
int
bufferIndex
);
void
initNothing
();
void
initIgnoreChar
();
void
initEndWord
();
...
...
@@ -52,6 +53,7 @@ class Transition
void
initTransformSuffix
(
std
::
string
fromCol
,
std
::
string
fromObj
,
std
::
string
fromIndex
,
std
::
string
toCol
,
std
::
string
toObj
,
std
::
string
toIndex
,
std
::
string
rule
);
void
initUppercase
(
std
::
string
col
,
std
::
string
obj
,
std
::
string
index
);
void
initUppercaseIndex
(
std
::
string
col
,
std
::
string
obj
,
std
::
string
index
,
std
::
string
inIndex
);
void
initNothing
(
std
::
string
col
,
std
::
string
obj
,
std
::
string
index
);
void
initLowercase
(
std
::
string
col
,
std
::
string
obj
,
std
::
string
index
);
void
initLowercaseIndex
(
std
::
string
col
,
std
::
string
obj
,
std
::
string
index
,
std
::
string
inIndex
);
...
...
This diff is collapsed.
Click to expand it.
reading_machine/src/Transition.cpp
+
37
−
0
View file @
3c41224b
...
...
@@ -43,6 +43,8 @@ Transition::Transition(const std::string & name)
[
this
](
auto
sm
){
initEOS
(
std
::
stoi
(
sm
[
1
]));}},
{
std
::
regex
(
"NOTHING"
),
[
this
](
auto
){
initNothing
();}},
{
std
::
regex
(
"NOTEOS b
\\
.(.+)"
),
[
this
](
auto
sm
){
initNotEOS
(
std
::
stoi
(
sm
[
1
]));}},
{
std
::
regex
(
"IGNORECHAR"
),
[
this
](
auto
){
initIgnoreChar
();}},
{
std
::
regex
(
"ENDWORD"
),
...
...
@@ -57,6 +59,8 @@ Transition::Transition(const std::string & name)
[
this
](
auto
sm
){(
initUppercase
(
sm
[
1
],
sm
[
2
],
sm
[
3
]));}},
{
std
::
regex
(
"UPPERCASEINDEX (.+) ([bs])
\\
.(.+) (.+)"
),
[
this
](
auto
sm
){(
initUppercaseIndex
(
sm
[
1
],
sm
[
2
],
sm
[
3
],
sm
[
4
]));}},
{
std
::
regex
(
"NOTHING (.+) ([bs])
\\
.(.+)"
),
[
this
](
auto
sm
){(
initNothing
(
sm
[
1
],
sm
[
2
],
sm
[
3
]));}},
{
std
::
regex
(
"LOWERCASE (.+) ([bs])
\\
.(.+)"
),
[
this
](
auto
sm
){(
initLowercase
(
sm
[
1
],
sm
[
2
],
sm
[
3
]));}},
{
std
::
regex
(
"LOWERCASEINDEX (.+) ([bs])
\\
.(.+) (.+)"
),
...
...
@@ -713,6 +717,20 @@ void Transition::initEOS(int bufferIndex)
costStatic
=
costDynamic
;
}
void
Transition
::
initNotEOS
(
int
bufferIndex
)
{
costDynamic
=
[
bufferIndex
](
const
Config
&
config
)
{
int
lineIndex
=
config
.
getRelativeWordIndex
(
Config
::
Buffer
,
bufferIndex
);
if
(
config
.
getConst
(
Config
::
EOSColName
,
lineIndex
,
0
)
==
Config
::
EOSSymbol1
)
return
std
::
numeric_limits
<
int
>::
max
();
return
0
;
};
costStatic
=
costDynamic
;
}
void
Transition
::
initDeprel
(
std
::
string
label
)
{
sequence
.
emplace_back
(
Action
::
deprel
(
label
));
...
...
@@ -815,6 +833,25 @@ void Transition::initUppercaseIndex(std::string col, std::string obj, std::strin
costStatic
=
costDynamic
;
}
void
Transition
::
initNothing
(
std
::
string
col
,
std
::
string
obj
,
std
::
string
index
)
{
auto
objectValue
=
Config
::
str2object
(
obj
);
int
indexValue
=
std
::
stoi
(
index
);
costDynamic
=
[
col
,
objectValue
,
indexValue
](
const
Config
&
config
)
{
int
lineIndex
=
config
.
getRelativeWordIndex
(
objectValue
,
indexValue
);
auto
&
expectedValue
=
config
.
getConst
(
col
,
lineIndex
,
0
);
std
::
string
currentValue
=
config
.
getAsFeature
(
col
,
lineIndex
).
get
();
if
(
expectedValue
==
currentValue
)
return
0
;
return
1
;
};
costStatic
=
costDynamic
;
}
void
Transition
::
initLowercase
(
std
::
string
col
,
std
::
string
obj
,
std
::
string
index
)
{
auto
objectValue
=
Config
::
str2object
(
obj
);
...
...
This diff is collapsed.
Click to expand it.
trainer/src/Trainer.cpp
+
5
−
1
View file @
3c41224b
...
...
@@ -128,7 +128,11 @@ void Trainer::extractExamples(SubConfig & config, bool debug, std::filesystem::p
Transition
*
transition
=
nullptr
;
auto
goldTransitions
=
machine
.
getTransitionSet
(
config
.
getState
()).
getBestAppliableTransitions
(
config
,
appliableTransitions
,
true
or
dynamicOracle
);
Transition
*
goldTransition
=
goldTransitions
[
std
::
rand
()
%
goldTransitions
.
size
()];
Transition
*
goldTransition
=
goldTransitions
[
0
];
if
(
config
.
getState
()
==
"parser"
)
goldTransitions
[
std
::
rand
()
%
goldTransitions
.
size
()];
int
nbClasses
=
machine
.
getTransitionSet
(
config
.
getState
()).
size
();
if
(
dynamicOracle
and
util
::
choiceWithProbability
(
1.0
)
and
config
.
getState
()
!=
"tokenizer"
and
config
.
getState
()
!=
"segmenter"
)
...
...
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