Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RL-Parsing
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
RL-Parsing
Commits
67435b57
Commit
67435b57
authored
3 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
States working for oracle learning
parent
bbdc365a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Train.py
+28
-8
28 additions, 8 deletions
Train.py
with
28 additions
and
8 deletions
Train.py
+
28
−
8
View file @
67435b57
...
...
@@ -54,7 +54,7 @@ def extractExamples(debug, transitionSets, strat, config, dicts, network, dynami
config
.
printForDebug
(
sys
.
stderr
)
print
(
str
([[
c
[
0
],
str
(
c
[
1
])]
for
c
in
candidates
])
+
"
\n
"
+
(
"
-
"
*
80
)
+
"
\n
"
,
file
=
sys
.
stderr
)
if
dynamic
:
networ
d
.
setState
(
config
.
state
)
networ
k
.
setState
(
config
.
state
)
output
=
network
(
features
.
unsqueeze
(
0
).
to
(
getDevice
()))
scores
=
sorted
([[
float
(
output
[
0
][
index
]),
ts
[
index
].
appliable
(
config
),
ts
[
index
]]
for
index
in
range
(
len
(
ts
))])[::
-
1
]
candidate
=
[[
cand
[
0
],
cand
[
2
]]
for
cand
in
scores
if
cand
[
1
]][
0
][
1
]
...
...
@@ -117,7 +117,9 @@ def trainModelOracle(debug, modelDir, filename, nbEpochs, batchSize, devFile, tr
extracted
=
extractExamples
(
debug
,
transitionSets
,
strategy
,
config
,
dicts
,
network
,
False
)
for
e
in
range
(
len
(
examples
))
:
examples
[
e
]
+=
extracted
[
e
]
print
(
"
%s : Extracted %s examples
"
%
(
timeStamp
(),
prettyInt
(
len
(
examples
),
3
)),
file
=
sys
.
stderr
)
totalNbExamples
=
sum
(
map
(
len
,
examples
))
print
(
"
%s : Extracted %s examples
"
%
(
timeStamp
(),
prettyInt
(
totalNbExamples
,
3
)),
file
=
sys
.
stderr
)
for
e
in
range
(
len
(
examples
))
:
examples
[
e
]
=
torch
.
stack
(
examples
[
e
])
...
...
@@ -128,32 +130,50 @@ def trainModelOracle(debug, modelDir, filename, nbEpochs, batchSize, devFile, tr
bestScore
=
None
for
epoch
in
range
(
1
,
nbEpochs
+
1
)
:
if
bootstrapInterval
is
not
None
and
epoch
>
1
and
(
epoch
-
1
)
%
bootstrapInterval
==
0
:
examples
=
[]
examples
=
[
[]
for
_
in
transitionSets
]
sentences
=
copy
.
deepcopy
(
sentencesOriginal
)
print
(
"
%s : Starting to extract dynamic examples...
"
%
(
timeStamp
()),
file
=
sys
.
stderr
)
for
config
in
sentences
:
extracted
=
extractExamples
(
debug
,
transitionSets
,
strategy
,
config
,
dicts
,
network
,
True
)
for
e
in
range
(
len
(
examples
))
:
examples
[
e
]
+=
extracted
[
e
]
print
(
"
%s : Extracted %s examples
"
%
(
timeStamp
(),
prettyInt
(
len
(
examples
),
3
)),
file
=
sys
.
stderr
)
totalNbExamples
=
sum
(
map
(
len
,
examples
))
print
(
"
%s : Extracted %s examples
"
%
(
timeStamp
(),
prettyInt
(
totalNbExamples
,
3
)),
file
=
sys
.
stderr
)
for
e
in
range
(
len
(
examples
))
:
examples
[
e
]
=
torch
.
stack
(
examples
[
e
])
network
.
train
()
examples
=
examples
.
index_select
(
0
,
torch
.
randperm
(
examples
.
size
(
0
)))
for
e
in
range
(
len
(
examples
))
:
examples
[
e
]
=
examples
[
e
].
index_select
(
0
,
torch
.
randperm
(
examples
[
e
].
size
(
0
)))
totalLoss
=
0.0
nbEx
=
0
printInterval
=
2000
advancement
=
0
for
batchIndex
in
range
(
0
,
examples
.
size
(
0
)
-
batchSize
,
batchSize
)
:
batch
=
examples
[
batchIndex
:
batchIndex
+
batchSize
].
to
(
getDevice
())
distribution
=
[
len
(
e
)
/
totalNbExamples
for
e
in
examples
]
curIndexes
=
[
0
for
_
in
examples
]
while
True
:
state
=
random
.
choices
(
population
=
range
(
len
(
examples
)),
weights
=
distribution
,
k
=
1
)[
0
]
if
curIndexes
[
state
]
>=
len
(
examples
[
state
])
:
state
=
-
1
for
i
in
range
(
len
(
examples
))
:
if
curIndexes
[
i
]
<
len
(
examples
[
i
])
:
state
=
i
if
state
==
-
1
:
break
batch
=
examples
[
state
][
curIndexes
[
state
]:
curIndexes
[
state
]
+
batchSize
].
to
(
getDevice
())
curIndexes
[
state
]
+=
batchSize
targets
=
batch
[:,:
1
].
view
(
-
1
)
inputs
=
batch
[:,
1
:]
nbEx
+=
targets
.
size
(
0
)
advancement
+=
targets
.
size
(
0
)
if
not
silent
and
advancement
>=
printInterval
:
advancement
=
0
print
(
"
Current epoch %6.2f%%
"
%
(
100.0
*
nbEx
/
examples
.
size
(
0
)),
end
=
"
\r
"
,
file
=
sys
.
stderr
)
print
(
"
Current epoch %6.2f%%
"
%
(
100.0
*
nbEx
/
totalNbExamples
),
end
=
"
\r
"
,
file
=
sys
.
stderr
)
network
.
setState
(
state
)
outputs
=
network
(
inputs
)
loss
=
lossFct
(
outputs
,
targets
)
network
.
zero_grad
()
...
...
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