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
d145be52
Commit
d145be52
authored
5 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Reseting strategy between different corpuses
parent
5cc6a43b
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/Strategy.hpp
+2
-0
2 additions, 0 deletions
reading_machine/include/Strategy.hpp
reading_machine/src/Strategy.cpp
+10
-2
10 additions, 2 deletions
reading_machine/src/Strategy.cpp
trainer/src/macaon_train.cpp
+4
-2
4 additions, 2 deletions
trainer/src/macaon_train.cpp
with
16 additions
and
4 deletions
reading_machine/include/Strategy.hpp
+
2
−
0
View file @
d145be52
...
...
@@ -21,6 +21,7 @@ class Strategy
std
::
map
<
std
::
pair
<
std
::
string
,
std
::
string
>
,
std
::
pair
<
std
::
string
,
int
>>
edges
;
std
::
map
<
std
::
string
,
bool
>
isDone
;
std
::
vector
<
std
::
string
>
defaultCycle
;
std
::
vector
<
std
::
string
>
originalDefaultCycle
;
std
::
string
initialState
{
"UNDEFINED"
};
private
:
...
...
@@ -33,6 +34,7 @@ class Strategy
Strategy
(
const
std
::
vector
<
std
::
string_view
>
&
lines
);
std
::
pair
<
std
::
string
,
int
>
getMovement
(
const
Config
&
c
,
const
std
::
string
&
transition
);
const
std
::
string
getInitialState
()
const
;
void
reset
();
};
#endif
This diff is collapsed.
Click to expand it.
reading_machine/src/Strategy.cpp
+
10
−
2
View file @
d145be52
...
...
@@ -41,6 +41,7 @@ Strategy::Strategy(const std::vector<std::string_view> & lines)
util
::
myThrow
(
"Strategy is empty"
);
defaultCycle
.
pop_back
();
std
::
reverse
(
defaultCycle
.
begin
(),
defaultCycle
.
end
());
originalDefaultCycle
=
defaultCycle
;
}
std
::
pair
<
std
::
string
,
int
>
Strategy
::
getMovement
(
const
Config
&
c
,
const
std
::
string
&
transition
)
...
...
@@ -96,7 +97,7 @@ std::pair<std::string, int> Strategy::getMovementIncremental(const Config & c, c
auto
foundGeneric
=
edges
.
find
(
std
::
make_pair
(
c
.
getState
(),
""
));
std
::
string
target
;
int
movement
;
int
movement
=
-
1
;
if
(
foundSpecific
!=
edges
.
end
())
{
...
...
@@ -113,7 +114,7 @@ std::pair<std::string, int> Strategy::getMovementIncremental(const Config & c, c
util
::
myThrow
(
fmt
::
format
(
"no suitable movement found for current state '{}' and transition '{}'"
,
c
.
getState
(),
transition
));
if
(
!
isDone
[
target
])
return
{
target
,
target
==
defaultCycle
.
back
(
)
?
movement
:
0
};
return
{
target
,
c
.
canMoveWordIndex
(
movement
)
?
movement
:
0
};
if
(
defaultCycle
.
empty
())
return
endMovement
;
...
...
@@ -126,3 +127,10 @@ const std::string Strategy::getInitialState() const
return
initialState
;
}
void
Strategy
::
reset
()
{
for
(
auto
&
it
:
isDone
)
it
.
second
=
false
;
defaultCycle
=
originalDefaultCycle
;
}
This diff is collapsed.
Click to expand it.
trainer/src/macaon_train.cpp
+
4
−
2
View file @
d145be52
...
...
@@ -92,12 +92,14 @@ int main(int argc, char * argv[])
for
(
int
i
=
0
;
i
<
nbEpoch
;
i
++
)
{
float
loss
=
trainer
.
epoch
(
!
debug
);
machine
.
getStrategy
().
reset
();
auto
devConfig
=
devGoldConfig
;
if
(
debug
)
fmt
::
print
(
stderr
,
"Decoding dev :
\n
"
);
else
fmt
::
print
(
stderr
,
"
\r
{:80}
\r
Decoding dev..."
,
" "
);
decoder
.
decode
(
devConfig
,
1
,
debug
);
machine
.
getStrategy
().
reset
();
decoder
.
evaluate
(
devConfig
,
modelPath
,
devTsvFile
);
std
::
vector
<
std
::
pair
<
float
,
std
::
string
>>
devScores
=
decoder
.
getF1Scores
(
machine
.
getPredicted
());
std
::
string
devScoresStr
=
""
;
...
...
@@ -117,9 +119,9 @@ int main(int argc, char * argv[])
machine
.
save
();
}
if
(
debug
)
fmt
::
print
(
stderr
,
"Epoch {:^
9
} loss = {:
7.2
f} dev = {} {:5}
\n
"
,
fmt
::
format
(
"{}/{}"
,
i
+
1
,
nbEpoch
),
loss
,
devScoresStr
,
saved
?
"SAVED"
:
""
);
fmt
::
print
(
stderr
,
"Epoch {:^
5
} loss = {:
6.1
f} dev = {} {:5}
\n
"
,
fmt
::
format
(
"{}/{}"
,
i
+
1
,
nbEpoch
),
loss
,
devScoresStr
,
saved
?
"SAVED"
:
""
);
else
fmt
::
print
(
stderr
,
"
\r
{:80}
\r
Epoch {:^
9
} loss = {:
7.2
f} dev = {} {:5}
\n
"
,
" "
,
fmt
::
format
(
"{}/{}"
,
i
+
1
,
nbEpoch
),
loss
,
devScoresStr
,
saved
?
"SAVED"
:
""
);
fmt
::
print
(
stderr
,
"
\r
{:80}
\r
Epoch {:^
5
} loss = {:
6.1
f} dev = {} {:5}
\n
"
,
" "
,
fmt
::
format
(
"{}/{}"
,
i
+
1
,
nbEpoch
),
loss
,
devScoresStr
,
saved
?
"SAVED"
:
""
);
}
}
...
...
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