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
3308c406
Commit
3308c406
authored
5 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Improved multiMLP
parent
6eb7d405
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
neural_network/src/MultiMLP.cpp
+9
-7
9 additions, 7 deletions
neural_network/src/MultiMLP.cpp
with
9 additions
and
7 deletions
neural_network/src/MultiMLP.cpp
+
9
−
7
View file @
3308c406
#include
"MultiMLP.hpp"
#include
"MultiMLP.hpp"
#include
<cmath>
MultiMLP
::
MultiMLP
()
MultiMLP
::
MultiMLP
()
{
{
...
@@ -77,14 +78,19 @@ dynet::Trainer * MultiMLP::createTrainer()
...
@@ -77,14 +78,19 @@ dynet::Trainer * MultiMLP::createTrainer()
std
::
vector
<
float
>
MultiMLP
::
predict
(
FeatureModel
::
FeatureDescription
&
fd
)
std
::
vector
<
float
>
MultiMLP
::
predict
(
FeatureModel
::
FeatureDescription
&
fd
)
{
{
double
totalSum
=
0.0
;
std
::
vector
<
float
>
prediction
(
mlps
.
size
());
std
::
vector
<
float
>
prediction
(
mlps
.
size
());
for
(
unsigned
int
i
=
0
;
i
<
mlps
.
size
();
i
++
)
for
(
unsigned
int
i
=
0
;
i
<
mlps
.
size
();
i
++
)
{
{
int
id
=
std
::
stoi
(
split
(
mlps
[
i
].
name
,
'_'
)[
1
]);
int
id
=
std
::
stoi
(
split
(
mlps
[
i
].
name
,
'_'
)[
1
]);
auto
value
=
mlps
[
i
].
predict
(
fd
);
auto
value
=
mlps
[
i
].
predict
(
fd
);
prediction
[
id
]
=
value
[
1
];
prediction
[
id
]
=
exp
(
value
[
1
]);
totalSum
+=
prediction
[
id
];
}
}
for
(
unsigned
int
i
=
0
;
i
<
prediction
.
size
();
i
++
)
prediction
[
i
]
/=
totalSum
;
return
prediction
;
return
prediction
;
}
}
...
@@ -98,10 +104,8 @@ float MultiMLP::update(FeatureModel::FeatureDescription & fd, int gold)
...
@@ -98,10 +104,8 @@ float MultiMLP::update(FeatureModel::FeatureDescription & fd, int gold)
mlp
.
setBatchSize
(
getBatchSize
());
mlp
.
setBatchSize
(
getBatchSize
());
if
(
gold
>=
0
)
if
(
gold
>=
0
)
loss
+=
mlp
.
update
(
fd
,
id
==
gold
?
1
:
0
);
loss
+=
mlp
.
update
(
fd
,
id
==
gold
?
1
:
0
);
else
if
(
id
==
(
-
1
-
gold
))
loss
+=
mlp
.
update
(
fd
,
0
);
else
else
continue
;
loss
+=
mlp
.
update
(
fd
,
id
==
(
-
1
-
gold
)
?
0
:
1
)
;
trainer
->
update
();
trainer
->
update
();
}
catch
(
BatchNotFull
&
)
}
catch
(
BatchNotFull
&
)
...
@@ -128,10 +132,8 @@ float MultiMLP::getLoss(FeatureModel::FeatureDescription & fd, int gold)
...
@@ -128,10 +132,8 @@ float MultiMLP::getLoss(FeatureModel::FeatureDescription & fd, int gold)
mlp
.
setBatchSize
(
getBatchSize
());
mlp
.
setBatchSize
(
getBatchSize
());
if
(
gold
>=
0
)
if
(
gold
>=
0
)
loss
+=
mlp
.
update
(
fd
,
id
==
gold
?
1
:
0
);
loss
+=
mlp
.
update
(
fd
,
id
==
gold
?
1
:
0
);
else
if
(
id
==
(
-
1
-
gold
))
loss
+=
mlp
.
update
(
fd
,
0
);
else
else
continue
;
loss
+=
mlp
.
update
(
fd
,
id
==
(
-
1
-
gold
)
?
0
:
1
)
;
}
catch
(
BatchNotFull
&
)
}
catch
(
BatchNotFull
&
)
{
{
}
}
...
...
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