Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
old_macaon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Franck Dary
old_macaon
Commits
9ea75e43
Commit
9ea75e43
authored
6 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added debug info
parent
c091abf3
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
neural_network/include/MLPBase.hpp
+5
-0
5 additions, 0 deletions
neural_network/include/MLPBase.hpp
neural_network/src/MLP.cpp
+11
-3
11 additions, 3 deletions
neural_network/src/MLP.cpp
neural_network/src/MLPBase.cpp
+25
-0
25 additions, 0 deletions
neural_network/src/MLPBase.cpp
with
41 additions
and
3 deletions
neural_network/include/MLPBase.hpp
+
5
−
0
View file @
9ea75e43
...
...
@@ -35,6 +35,11 @@ class MLPBase
/// @brief gold classes of the current minibatch.
std
::
vector
<
unsigned
int
>
golds
;
private
:
/// \brief Check gradients values for debug purpose.
void
checkGradients
();
public
:
/// @brief Add the parameters of a layer into the dynet model.
...
...
This diff is collapsed.
Click to expand it.
neural_network/src/MLP.cpp
+
11
−
3
View file @
9ea75e43
...
...
@@ -26,15 +26,23 @@ dynet::Trainer * MLP::createTrainer()
{
auto
optimizer
=
noAccentLower
(
ProgramParameters
::
optimizer
);
dynet
::
Trainer
*
trainer
=
nullptr
;
if
(
optimizer
==
"amsgrad"
)
return
new
dynet
::
AmsgradTrainer
(
model
,
ProgramParameters
::
learningRate
,
ProgramParameters
::
beta1
,
ProgramParameters
::
beta2
,
ProgramParameters
::
bias
);
trainer
=
new
dynet
::
AmsgradTrainer
(
model
,
ProgramParameters
::
learningRate
,
ProgramParameters
::
beta1
,
ProgramParameters
::
beta2
,
ProgramParameters
::
bias
);
else
if
(
optimizer
==
"adam"
)
return
new
dynet
::
AdamTrainer
(
model
,
ProgramParameters
::
learningRate
,
ProgramParameters
::
beta1
,
ProgramParameters
::
beta2
,
ProgramParameters
::
bias
);
trainer
=
new
dynet
::
AdamTrainer
(
model
,
ProgramParameters
::
learningRate
,
ProgramParameters
::
beta1
,
ProgramParameters
::
beta2
,
ProgramParameters
::
bias
);
else
if
(
optimizer
==
"sgd"
)
return
new
dynet
::
SimpleSGDTrainer
(
model
,
ProgramParameters
::
learningRate
);
trainer
=
new
dynet
::
SimpleSGDTrainer
(
model
,
ProgramParameters
::
learningRate
);
else
if
(
optimizer
==
"none"
)
return
nullptr
;
if
(
trainer
)
{
trainer
->
sparse_updates_enabled
=
true
;
return
trainer
;
}
fprintf
(
stderr
,
"ERROR (%s) : unknown optimizer
\'
%s
\'
. Aborting.
\n
"
,
ERRINFO
,
optimizer
.
c_str
());
exit
(
1
);
...
...
This diff is collapsed.
Click to expand it.
neural_network/src/MLPBase.cpp
+
25
−
0
View file @
9ea75e43
...
...
@@ -135,12 +135,37 @@ float MLPBase::update(FeatureModel::FeatureDescription & fd, int gold)
cg
.
backward
(
batchedLoss
);
checkGradients
();
fds
.
clear
();
golds
.
clear
();
return
as_scalar
(
batchedLoss
.
value
());
}
void
MLPBase
::
checkGradients
()
{
bool
printGradients
=
false
;
if
(
printGradients
)
{
fprintf
(
stderr
,
"Gradients :
\n
"
);
for
(
auto
&
layer
:
parameters
)
for
(
auto
&
param
:
layer
)
{
auto
dim
=
param
.
dim
();
auto
gradients
=
param
.
gradients
()
->
v
;
fprintf
(
stderr
,
"Parameter's gradients :
\n
"
);
int
nbRows
=
dim
.
rows
();
int
nbCols
=
dim
.
cols
();
for
(
int
i
=
0
;
i
<
nbRows
;
i
++
)
for
(
int
j
=
0
;
j
<
nbCols
;
j
++
)
fprintf
(
stderr
,
"%8.5f%s"
,
gradients
[
i
*
nbRows
+
j
],
j
==
nbCols
-
1
?
"
\n
"
:
" "
);
}
}
}
dynet
::
Expression
MLPBase
::
weightedLoss
(
dynet
::
Expression
&
output
,
std
::
vector
<
unsigned
int
>
&
oneHotGolds
)
{
std
::
vector
<
dynet
::
Expression
>
lossExpr
;
...
...
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