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
82afc4f3
Commit
82afc4f3
authored
2 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added more complexity metrics
parent
f71baac6
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
+1
-0
1 addition, 0 deletions
reading_machine/include/Action.hpp
reading_machine/src/Action.cpp
+57
-0
57 additions, 0 deletions
reading_machine/src/Action.cpp
reading_machine/src/Transition.cpp
+197
-32
197 additions, 32 deletions
reading_machine/src/Transition.cpp
with
255 additions
and
32 deletions
reading_machine/include/Action.hpp
+
1
−
0
View file @
82afc4f3
...
...
@@ -44,6 +44,7 @@ class Action
static
Action
addHypothesis
(
const
std
::
string
&
colName
,
std
::
size_t
lineIndex
,
const
std
::
string
&
hypothesis
);
static
Action
addToHypothesis
(
const
std
::
string
&
colName
,
std
::
size_t
lineIndex
,
const
std
::
string
&
addition
);
static
Action
sumToHypothesis
(
const
std
::
string
&
colName
,
std
::
size_t
lineIndex
,
float
addition
,
bool
mean
);
static
Action
maxWithHypothesis
(
const
std
::
string
&
colName
,
std
::
size_t
lineIndex
,
float
addition
);
static
Action
addHypothesisRelative
(
const
std
::
string
&
colName
,
Config
::
Object
object
,
int
relativeIndex
,
const
std
::
string
&
hypothesis
);
static
Action
addHypothesisRelativeRelaxed
(
const
std
::
string
&
colName
,
Config
::
Object
object
,
int
relativeIndex
,
const
std
::
string
&
hypothesis
);
static
Action
addToHypothesisRelative
(
const
std
::
string
&
colName
,
Config
::
Object
object
,
int
relativeIndex
,
const
std
::
string
&
addition
);
...
...
This diff is collapsed.
Click to expand it.
reading_machine/src/Action.cpp
+
57
−
0
View file @
82afc4f3
...
...
@@ -295,6 +295,63 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
return
{
Type
::
Write
,
apply
,
undo
,
appliable
};
}
Action
Action
::
maxWithHypothesis
(
const
std
::
string
&
colName
,
std
::
size_t
lineIndex
,
float
addition
)
{
auto
apply
=
[
colName
,
lineIndex
,
addition
](
Config
&
config
,
Action
&
)
{
std
::
string
totalStr
=
std
::
string
(
config
.
getLastNotEmptyHypConst
(
colName
,
lineIndex
));
if
(
totalStr
.
empty
()
||
totalStr
==
"_"
)
totalStr
=
fmt
::
format
(
"{}={}|{}"
,
std
::
string
(
config
.
getState
()),
0.0
,
0
);
auto
byStates
=
util
::
split
(
totalStr
,
','
);
int
index
=
-
1
;
for
(
unsigned
int
i
=
0
;
i
<
byStates
.
size
();
i
++
)
{
auto
state
=
util
::
split
(
byStates
[
i
],
'='
)[
0
];
if
(
state
==
config
.
getState
())
{
index
=
i
;
break
;
}
}
if
(
index
==
-
1
)
{
byStates
.
emplace_back
(
fmt
::
format
(
"{}={}|{}"
,
std
::
string
(
config
.
getState
()),
0.0
,
0
));
index
=
byStates
.
size
()
-
1
;
}
auto
splited
=
util
::
split
(
util
::
split
(
byStates
[
index
],
'='
)[
1
],
'|'
);
float
curVal
=
0.0
;
int
curNb
=
0
;
if
(
splited
.
size
()
==
2
)
{
curVal
=
std
::
stof
(
splited
[
0
]);
curNb
=
std
::
stoi
(
splited
[
1
]);
}
curNb
+=
1
;
curVal
=
addition
;
byStates
[
index
]
=
fmt
::
format
(
"{}={}|{}"
,
std
::
string
(
config
.
getState
()),
curVal
,
curNb
);
config
.
getLastNotEmptyHyp
(
colName
,
lineIndex
)
=
util
::
join
(
","
,
byStates
);
};
auto
undo
=
[](
Config
&
,
Action
&
)
{
//TODO: not done
};
auto
appliable
=
[
colName
,
lineIndex
,
addition
](
const
Config
&
config
,
const
Action
&
)
{
return
config
.
has
(
colName
,
lineIndex
,
0
);
};
return
{
Type
::
Write
,
apply
,
undo
,
appliable
};
}
Action
Action
::
addToHypothesisRelative
(
const
std
::
string
&
colName
,
Config
::
Object
object
,
int
relativeIndex
,
const
std
::
string
&
addition
)
{
auto
apply
=
[
colName
,
object
,
relativeIndex
,
addition
](
Config
&
config
,
Action
&
a
)
...
...
This diff is collapsed.
Click to expand it.
reading_machine/src/Transition.cpp
+
197
−
32
View file @
82afc4f3
...
...
@@ -116,67 +116,232 @@ void Transition::apply(Config & config, float entropy)
curValue
=
fmt
::
format
(
"_"
);
}
}
// Entropy of the action that attach a word to the tree
if
(
config
.
hasColIndex
(
"ENTROPY_ATTACH"
))
float
surprisal
=
-
log
(
config
.
getChosenActionScore
());
if
(
config
.
hasColIndex
(
"ENT_CUR_ADD"
))
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT_CUR_ADD"
,
config
.
getWordIndex
(),
entropy
,
false
);
action
.
apply
(
config
,
action
);
}
if
(
config
.
hasColIndex
(
"ENT_CUR_MEAN"
))
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT_CUR_MEAN"
,
config
.
getWordIndex
(),
entropy
,
true
);
action
.
apply
(
config
,
action
);
}
if
(
config
.
hasColIndex
(
"ENT_CUR_MAX"
))
{
auto
action
=
Action
::
maxWithHypothesis
(
"ENT_CUR_MAX"
,
config
.
getWordIndex
(),
entropy
);
action
.
apply
(
config
,
action
);
}
if
(
config
.
hasColIndex
(
"ENT_ATT_ADD"
))
{
bool
mean
=
false
;
if
(
name
.
find
(
"SHIFT"
)
==
std
::
string
::
npos
and
name
.
find
(
"REDUCE"
)
==
std
::
string
::
npos
)
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
)
{
if
(
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"ENTROPY_ATTACH"
,
config
.
getStack
(
0
),
entropy
,
mean
);
action
.
apply
(
config
,
action
);
}
else
auto
action
=
Action
::
sumToHypothesis
(
"ENT_ATT_ADD"
,
config
.
getStack
(
0
),
entropy
,
false
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT_ATT_ADD"
,
config
.
getWordIndex
(),
entropy
,
false
);
action
.
apply
(
config
,
action
);
if
(
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
||
name
.
find
(
"RIGHT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT
ROPY_ATTACH
"
,
config
.
get
WordIndex
(
),
entropy
,
mean
);
auto
action
=
Action
::
sumToHypothesis
(
"ENT
_ATT_ADD
"
,
config
.
get
Stack
(
0
),
entropy
,
false
);
action
.
apply
(
config
,
action
);
}
}
}
if
(
config
.
hasColIndex
(
"ENT
ROPY
_ATT
ACH
_MEAN"
))
if
(
config
.
hasColIndex
(
"ENT_ATT_MEAN"
))
{
bool
mean
=
true
;
if
(
name
.
find
(
"SHIFT"
)
==
std
::
string
::
npos
and
name
.
find
(
"REDUCE"
)
==
std
::
string
::
npos
)
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
)
{
if
(
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
)
auto
action
=
Action
::
sumToHypothesis
(
"ENT_ATT_MEAN"
,
config
.
getStack
(
0
),
entropy
,
true
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT_ATT_MEAN"
,
config
.
getWordIndex
(),
entropy
,
true
);
action
.
apply
(
config
,
action
);
if
(
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
||
name
.
find
(
"RIGHT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT
ROPY
_ATT
ACH
_MEAN"
,
config
.
getStack
(
0
),
entropy
,
mean
);
auto
action
=
Action
::
sumToHypothesis
(
"ENT_ATT_MEAN"
,
config
.
getStack
(
0
),
entropy
,
true
);
action
.
apply
(
config
,
action
);
}
else
}
}
if
(
config
.
hasColIndex
(
"ENT_ATT_MAX"
))
{
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
maxWithHypothesis
(
"ENT_ATT_MAX"
,
config
.
getStack
(
0
),
entropy
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
maxWithHypothesis
(
"ENT_ATT_MAX"
,
config
.
getWordIndex
(),
entropy
);
action
.
apply
(
config
,
action
);
if
(
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
||
name
.
find
(
"RIGHT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumTo
Hypothesis
(
"ENT
ROPY_ATTACH_MEAN
"
,
config
.
get
WordIndex
(
),
entropy
,
mean
);
auto
action
=
Action
::
maxWith
Hypothesis
(
"ENT
_ATT_MAX
"
,
config
.
get
Stack
(
0
),
entropy
);
action
.
apply
(
config
,
action
);
}
}
}
// Entropy of every action is taken into account
if
(
config
.
hasColIndex
(
"ENT
ROPY_ALL
"
))
if
(
config
.
hasColIndex
(
"ENT
_TGT_ADD
"
))
{
bool
mean
=
false
;
auto
action
=
Action
::
sumToHypothesis
(
"ENTROPY_ALL"
,
config
.
getWordIndex
(),
entropy
,
mean
);
action
.
apply
(
config
,
action
);
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
||
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT_TGT_ADD"
,
config
.
getStack
(
0
),
entropy
,
false
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT_TGT_ADD"
,
config
.
getWordIndex
(),
entropy
,
false
);
action
.
apply
(
config
,
action
);
}
}
if
(
config
.
hasColIndex
(
"ENT
ROPY_ALL
_MEAN"
))
if
(
config
.
hasColIndex
(
"ENT
_TGT
_MEAN"
))
{
bool
mean
=
true
;
auto
action
=
Action
::
sumToHypothesis
(
"ENTROPY_ALL_MEAN"
,
config
.
getWordIndex
(),
entropy
,
mean
);
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
||
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT_TGT_MEAN"
,
config
.
getStack
(
0
),
entropy
,
true
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
sumToHypothesis
(
"ENT_TGT_MEAN"
,
config
.
getWordIndex
(),
entropy
,
true
);
action
.
apply
(
config
,
action
);
}
}
if
(
config
.
hasColIndex
(
"ENT_TGT_MAX"
))
{
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
||
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
maxWithHypothesis
(
"ENT_TGT_MAX"
,
config
.
getStack
(
0
),
entropy
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
maxWithHypothesis
(
"ENT_TGT_MAX"
,
config
.
getWordIndex
(),
entropy
);
action
.
apply
(
config
,
action
);
}
}
if
(
config
.
hasColIndex
(
"SUR_CUR_ADD"
))
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_CUR_ADD"
,
config
.
getWordIndex
(),
surprisal
,
false
);
action
.
apply
(
config
,
action
);
}
if
(
config
.
hasColIndex
(
"SUR
PRISAL
"
))
if
(
config
.
hasColIndex
(
"SUR
_CUR_MEAN
"
))
{
float
surprisal
=
-
log
(
config
.
getChosenActionScore
());
auto
action
=
Action
::
sumToHypothesis
(
"SURPRISAL"
,
config
.
getWordIndex
(),
surprisal
,
false
);
auto
action
=
Action
::
sumToHypothesis
(
"SUR_CUR_MEAN"
,
config
.
getWordIndex
(),
surprisal
,
true
);
action
.
apply
(
config
,
action
);
}
if
(
config
.
hasColIndex
(
"SUR
PRISAL_MEAN
"
))
if
(
config
.
hasColIndex
(
"SUR
_CUR_MAX
"
))
{
float
surprisal
=
-
log
(
config
.
getChosenActionScore
());
auto
action
=
Action
::
sumToHypothesis
(
"SURPRISAL_MEAN"
,
config
.
getWordIndex
(),
surprisal
,
true
);
auto
action
=
Action
::
maxWithHypothesis
(
"SUR_CUR_MAX"
,
config
.
getWordIndex
(),
surprisal
);
action
.
apply
(
config
,
action
);
}
if
(
config
.
hasColIndex
(
"SUR_ATT_ADD"
))
{
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_ATT_ADD"
,
config
.
getStack
(
0
),
surprisal
,
false
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_ATT_ADD"
,
config
.
getWordIndex
(),
surprisal
,
false
);
action
.
apply
(
config
,
action
);
if
(
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
||
name
.
find
(
"RIGHT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_ATT_ADD"
,
config
.
getStack
(
0
),
surprisal
,
false
);
action
.
apply
(
config
,
action
);
}
}
}
if
(
config
.
hasColIndex
(
"SUR_ATT_MEAN"
))
{
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_ATT_MEAN"
,
config
.
getStack
(
0
),
surprisal
,
true
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_ATT_MEAN"
,
config
.
getWordIndex
(),
surprisal
,
true
);
action
.
apply
(
config
,
action
);
if
(
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
||
name
.
find
(
"RIGHT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_ATT_MEAN"
,
config
.
getStack
(
0
),
surprisal
,
true
);
action
.
apply
(
config
,
action
);
}
}
}
if
(
config
.
hasColIndex
(
"SUR_ATT_MAX"
))
{
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
maxWithHypothesis
(
"SUR_ATT_MAX"
,
config
.
getStack
(
0
),
surprisal
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
maxWithHypothesis
(
"SUR_ATT_MAX"
,
config
.
getWordIndex
(),
surprisal
);
action
.
apply
(
config
,
action
);
if
(
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
||
name
.
find
(
"RIGHT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
maxWithHypothesis
(
"SUR_ATT_MAX"
,
config
.
getStack
(
0
),
surprisal
);
action
.
apply
(
config
,
action
);
}
}
}
if
(
config
.
hasColIndex
(
"SUR_TGT_ADD"
))
{
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
||
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_TGT_ADD"
,
config
.
getStack
(
0
),
surprisal
,
false
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_TGT_ADD"
,
config
.
getWordIndex
(),
surprisal
,
false
);
action
.
apply
(
config
,
action
);
}
}
if
(
config
.
hasColIndex
(
"SUR_TGT_MEAN"
))
{
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
||
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_TGT_MEAN"
,
config
.
getStack
(
0
),
surprisal
,
true
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
sumToHypothesis
(
"SUR_TGT_MEAN"
,
config
.
getWordIndex
(),
surprisal
,
true
);
action
.
apply
(
config
,
action
);
}
}
if
(
config
.
hasColIndex
(
"SUR_TGT_MAX"
))
{
if
(
name
.
find
(
"REDUCE"
)
!=
std
::
string
::
npos
||
name
.
find
(
"LEFT"
)
!=
std
::
string
::
npos
)
{
auto
action
=
Action
::
maxWithHypothesis
(
"SUR_TGT_MAX"
,
config
.
getStack
(
0
),
surprisal
);
action
.
apply
(
config
,
action
);
}
else
{
auto
action
=
Action
::
maxWithHypothesis
(
"SUR_TGT_MAX"
,
config
.
getWordIndex
(),
surprisal
);
action
.
apply
(
config
,
action
);
}
}
apply
(
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