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
2976d7cc
Commit
2976d7cc
authored
4 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Changed reduce
parent
c8bbf27b
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/Action.hpp
+3
-1
3 additions, 1 deletion
reading_machine/include/Action.hpp
reading_machine/src/Action.cpp
+117
-3
117 additions, 3 deletions
reading_machine/src/Action.cpp
reading_machine/src/Transition.cpp
+6
-3
6 additions, 3 deletions
reading_machine/src/Transition.cpp
with
126 additions
and
7 deletions
reading_machine/include/Action.hpp
+
3
−
1
View file @
2976d7cc
...
...
@@ -51,13 +51,15 @@ class Action
static
Action
setRoot
(
int
bufferIndex
);
static
Action
updateIds
(
int
bufferIndex
);
static
Action
endWord
();
static
Action
assertIsEmpty
(
const
std
::
string
&
colName
);
static
Action
assertIsEmpty
(
const
std
::
string
&
colName
,
Config
::
Object
object
,
int
relativeIndex
);
static
Action
assertIsNotEmpty
(
const
std
::
string
&
colName
,
Config
::
Object
object
,
int
relativeIndex
);
static
Action
attach
(
Config
::
Object
governorObject
,
int
governorIndex
,
Config
::
Object
dependentObject
,
int
dependentIndex
);
static
Action
addCurCharToCurWord
();
static
Action
ignoreCurrentCharacter
();
static
Action
consumeCharacterIndex
(
util
::
utf8string
consumed
);
static
Action
setMultiwordIds
(
int
multiwordSize
);
static
Action
split
(
int
index
);
static
Action
setRootUpdateIdsEmptyStackIfSentChanged
();
};
#endif
This diff is collapsed.
Click to expand it.
reading_machine/src/Action.cpp
+
117
−
3
View file @
2976d7cc
...
...
@@ -368,7 +368,7 @@ Action Action::ignoreCurrentCharacter()
return
{
Type
::
MoveChar
,
apply
,
undo
,
appliable
};
}
Action
Action
::
assertIsEmpty
(
const
std
::
string
&
colName
)
Action
Action
::
assertIsEmpty
(
const
std
::
string
&
colName
,
Config
::
Object
object
,
int
relativeIndex
)
{
auto
apply
=
[](
Config
&
,
Action
&
)
{
...
...
@@ -378,9 +378,29 @@ Action Action::assertIsEmpty(const std::string & colName)
{
};
auto
appliable
=
[
colName
](
const
Config
&
config
,
const
Action
&
)
auto
appliable
=
[
colName
,
object
,
relativeIndex
](
const
Config
&
config
,
const
Action
&
)
{
return
util
::
isEmpty
(
config
.
getAsFeature
(
colName
,
config
.
getWordIndex
()));
auto
lineIndex
=
config
.
getRelativeWordIndex
(
object
,
relativeIndex
);
return
util
::
isEmpty
(
config
.
getAsFeature
(
colName
,
lineIndex
));
};
return
{
Type
::
Check
,
apply
,
undo
,
appliable
};
}
Action
Action
::
assertIsNotEmpty
(
const
std
::
string
&
colName
,
Config
::
Object
object
,
int
relativeIndex
)
{
auto
apply
=
[](
Config
&
,
Action
&
)
{
};
auto
undo
=
[](
Config
&
,
Action
&
)
{
};
auto
appliable
=
[
colName
,
object
,
relativeIndex
](
const
Config
&
config
,
const
Action
&
)
{
auto
lineIndex
=
config
.
getRelativeWordIndex
(
object
,
relativeIndex
);
return
!
util
::
isEmpty
(
config
.
getAsFeature
(
colName
,
lineIndex
));
};
return
{
Type
::
Check
,
apply
,
undo
,
appliable
};
...
...
@@ -626,3 +646,97 @@ Action Action::split(int index)
return
{
Type
::
Write
,
apply
,
undo
,
appliable
};
}
Action
Action
::
setRootUpdateIdsEmptyStackIfSentChanged
()
{
auto
apply
=
[](
Config
&
config
,
Action
&
a
)
{
int
lineIndex
=
config
.
getWordIndex
();
int
rootIndex
=
-
1
;
int
lastSentId
=
-
1
;
int
firstIndexOfSentence
=
lineIndex
;
if
(
config
.
getAsFeature
(
Config
::
EOSColName
,
lineIndex
)
!=
Config
::
EOSSymbol1
)
return
;
for
(
int
i
=
lineIndex
-
1
;
true
;
--
i
)
{
if
(
!
config
.
has
(
0
,
i
,
0
))
{
if
(
i
<
0
)
break
;
util
::
myThrow
(
"The current sentence is too long to be completly held by the data strucure. Consider increasing SubConfig::SpanSize"
);
}
if
(
!
config
.
isTokenPredicted
(
i
))
continue
;
if
(
config
.
getAsFeature
(
Config
::
EOSColName
,
i
)
==
Config
::
EOSSymbol1
)
{
lastSentId
=
std
::
stoi
(
config
.
getAsFeature
(
Config
::
sentIdColName
,
i
));
break
;
}
if
(
util
::
isEmpty
(
config
.
getAsFeature
(
Config
::
headColName
,
i
)))
rootIndex
=
i
;
firstIndexOfSentence
=
i
;
}
if
(
firstIndexOfSentence
<
0
)
util
::
myThrow
(
"could not find any token in current sentence"
);
for
(
int
i
=
firstIndexOfSentence
;
i
<=
lineIndex
;
++
i
)
{
if
(
!
config
.
has
(
0
,
i
,
0
))
{
if
(
i
<
0
)
break
;
util
::
myThrow
(
"The current sentence is too long to be completly held by the data strucure. Consider increasing SubConfig::SpanSize"
);
}
if
(
!
config
.
isTokenPredicted
(
i
))
continue
;
if
(
util
::
isEmpty
(
config
.
getAsFeature
(
Config
::
headColName
,
i
)))
{
if
(
i
==
rootIndex
)
{
config
.
getFirstEmpty
(
Config
::
headColName
,
i
)
=
"0"
;
config
.
getFirstEmpty
(
Config
::
deprelColName
,
i
)
=
"root"
;
}
else
{
config
.
getFirstEmpty
(
Config
::
headColName
,
i
)
=
std
::
to_string
(
rootIndex
);
}
}
}
for
(
int
i
=
firstIndexOfSentence
,
currentId
=
1
;
i
<=
lineIndex
;
++
i
)
{
if
(
config
.
isComment
(
i
)
||
config
.
isEmptyNode
(
i
))
continue
;
if
(
config
.
isMultiwordPredicted
(
i
))
config
.
getFirstEmpty
(
Config
::
idColName
,
i
)
=
fmt
::
format
(
"{}-{}"
,
currentId
,
currentId
+
config
.
getMultiwordSizePredicted
(
i
));
else
config
.
getFirstEmpty
(
Config
::
idColName
,
i
)
=
fmt
::
format
(
"{}"
,
currentId
++
);
config
.
getFirstEmpty
(
Config
::
sentIdColName
,
i
)
=
fmt
::
format
(
"{}"
,
lastSentId
+
1
);
}
while
(
config
.
hasStack
(
0
))
config
.
popStack
();
};
auto
undo
=
[](
Config
&
config
,
Action
&
a
)
{
//TODO undo this
};
auto
appliable
=
[](
const
Config
&
config
,
const
Action
&
)
{
int
lineIndex
=
config
.
getWordIndex
();
return
config
.
has
(
0
,
lineIndex
,
0
);
};
return
{
Type
::
Write
,
apply
,
undo
,
appliable
};
}
This diff is collapsed.
Click to expand it.
reading_machine/src/Transition.cpp
+
6
−
3
View file @
2976d7cc
...
...
@@ -158,7 +158,7 @@ void Transition::initEndWord()
void
Transition
::
initAddCharToWord
()
{
sequence
.
emplace_back
(
Action
::
assertIsEmpty
(
Config
::
idColName
));
sequence
.
emplace_back
(
Action
::
assertIsEmpty
(
Config
::
idColName
,
Config
::
Object
::
Buffer
,
0
));
sequence
.
emplace_back
(
Action
::
addLinesIfNeeded
(
0
));
sequence
.
emplace_back
(
Action
::
addCurCharToCurWord
());
sequence
.
emplace_back
(
Action
::
moveCharacterIndex
(
1
));
...
...
@@ -185,8 +185,8 @@ void Transition::initAddCharToWord()
void
Transition
::
initSplitWord
(
std
::
vector
<
std
::
string
>
words
)
{
auto
consumedWord
=
util
::
splitAsUtf8
(
words
[
0
]);
sequence
.
emplace_back
(
Action
::
assertIsEmpty
(
Config
::
idColName
));
sequence
.
emplace_back
(
Action
::
assertIsEmpty
(
"FORM"
));
sequence
.
emplace_back
(
Action
::
assertIsEmpty
(
Config
::
idColName
,
Config
::
Object
::
Buffer
,
0
));
sequence
.
emplace_back
(
Action
::
assertIsEmpty
(
"FORM"
,
Config
::
Object
::
Buffer
,
0
));
sequence
.
emplace_back
(
Action
::
addLinesIfNeeded
(
words
.
size
()));
sequence
.
emplace_back
(
Action
::
consumeCharacterIndex
(
consumedWord
));
for
(
unsigned
int
i
=
0
;
i
<
words
.
size
();
i
++
)
...
...
@@ -228,6 +228,7 @@ void Transition::initSplit(int index)
void
Transition
::
initShift
()
{
sequence
.
emplace_back
(
Action
::
pushWordIndexOnStack
());
sequence
.
emplace_back
(
Action
::
setRootUpdateIdsEmptyStackIfSentChanged
());
cost
=
[](
const
Config
&
config
)
{
...
...
@@ -303,6 +304,7 @@ void Transition::initRight(std::string label)
sequence
.
emplace_back
(
Action
::
attach
(
Config
::
Object
::
Stack
,
0
,
Config
::
Object
::
Buffer
,
0
));
sequence
.
emplace_back
(
Action
::
addHypothesisRelative
(
Config
::
deprelColName
,
Config
::
Object
::
Buffer
,
0
,
label
));
sequence
.
emplace_back
(
Action
::
pushWordIndexOnStack
());
sequence
.
emplace_back
(
Action
::
setRootUpdateIdsEmptyStackIfSentChanged
());
cost
=
[
label
](
const
Config
&
config
)
{
...
...
@@ -354,6 +356,7 @@ void Transition::initRight(std::string label)
void
Transition
::
initReduce
()
{
sequence
.
emplace_back
(
Action
::
assertIsNotEmpty
(
Config
::
headColName
,
Config
::
Object
::
Stack
,
0
));
sequence
.
emplace_back
(
Action
::
popStack
());
cost
=
[](
const
Config
&
config
)
...
...
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