Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DeepGrail Tagger
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
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
PNRIA
Global Helper
DeepGrail Tagger
Commits
a7008a57
Commit
a7008a57
authored
3 years ago
by
Julien Rabault
Browse files
Options
Downloads
Patches
Plain Diff
Add predict and train file
parent
eeb4774c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
SuperTagger/SuperTagger.py
+5
-4
5 additions, 4 deletions
SuperTagger/SuperTagger.py
SuperTagger/Utils/helpers.py
+0
-0
0 additions, 0 deletions
SuperTagger/Utils/helpers.py
predict.py
+35
-0
35 additions, 0 deletions
predict.py
train.py
+5
-4
5 additions, 4 deletions
train.py
with
45 additions
and
8 deletions
SuperTagger/SuperTagger.py
+
5
−
4
View file @
a7008a57
...
...
@@ -105,7 +105,8 @@ class SuperTagger:
"""
self
.
trainable
=
False
print
(
"
#
"
*
15
)
print
(
"
#
"
*
20
)
print
(
"
\n
Loading...
"
)
try
:
params
=
torch
.
load
(
model_file
,
map_location
=
self
.
device
)
args
=
params
[
'
args
'
]
...
...
@@ -127,7 +128,7 @@ class SuperTagger:
except
Exception
as
e
:
print
(
"
\n
/!\ Can
'
t load checkpoint model /!\ because :
\n\n
"
+
str
(
e
),
file
=
sys
.
stderr
)
raise
e
print
(
"
#
"
*
15
)
print
(
"
#
"
*
20
)
self
.
model_load
=
True
self
.
trainable
=
True
...
...
@@ -224,7 +225,7 @@ class SuperTagger:
for
epoch_i
in
range
(
0
,
epochs
):
print
(
""
)
print
(
'
======== Epoch {:} / {:} ========
'
.
format
(
epoch_i
,
epochs
))
print
(
'
======== Epoch {:} / {:} ========
'
.
format
(
epoch_i
+
1
,
epochs
))
print
(
'
Training...
'
)
# Train
...
...
@@ -310,7 +311,7 @@ class SuperTagger:
targets
=
batch
[
2
].
to
(
self
.
device
)
self
.
optimizer
.
zero_grad
()
loss
,
logit
=
self
.
model
((
b_sents_tokenized
,
b_sents_mask
,
targets
))
loss
,
logit
,
_
=
self
.
model
((
b_sents_tokenized
,
b_sents_mask
,
targets
))
predictions
=
torch
.
argmax
(
logit
,
dim
=
2
).
detach
().
cpu
().
numpy
()
label_ids
=
targets
.
cpu
().
numpy
()
...
...
This diff is collapsed.
Click to expand it.
SuperTagger/Utils/
util
s.py
→
SuperTagger/Utils/
helper
s.py
+
0
−
0
View file @
a7008a57
File moved
This diff is collapsed.
Click to expand it.
predict.py
0 → 100644
+
35
−
0
View file @
a7008a57
from
SuperTagger.SuperTagger
import
SuperTagger
from
SuperTagger.Utils.helpers
import
categorical_accuracy_str
#### DATA ####
a_s
=
"
( 1 ) parmi les huit
\"
partants
\"
acquis ou potentiels , MM. Lacombe , Koehler et Laroze ne sont pas membres
"
\
"
du PCF .
"
tags_s
=
[[
'
let
'
,
'
dr(0,s,s)
'
,
'
let
'
,
'
dr(0,dr(0,s,s),np)
'
,
'
dr(0,np,n)
'
,
'
dr(0,n,n)
'
,
'
let
'
,
'
n
'
,
'
let
'
,
'
dl(0,n,n)
'
,
'
dr(0,dl(0,dl(0,n,n),dl(0,n,n)),dl(0,n,n))
'
,
'
dl(0,n,n)
'
,
'
let
'
,
'
dr(0,np,np)
'
,
'
np
'
,
'
dr(0,dl(0,np,np),np)
'
,
'
np
'
,
'
dr(0,dl(0,np,np),np)
'
,
'
np
'
,
'
dr(0,dl(0,np,s),dl(0,np,s))
'
,
'
dr(0,dl(0,np,s),np)
'
,
'
dl(1,s,s)
'
,
'
np
'
,
'
dr(0,dl(0,np,np),n)
'
,
'
n
'
,
'
dl(0,s,txt)
'
]]
#### MODEL ####
tagger
=
SuperTagger
()
model
=
"
models/flaubert_super_98%_V2_50e.pt
"
tagger
.
load_weights
(
model
)
#### TEST ####
_
,
pred_convert
,
_
=
tagger
.
predict
(
a_s
)
print
(
"
Model :
"
,
model
)
print
(
"
\t
Len Text :
"
,
len
(
a_s
.
split
()))
print
(
"
\t
Len tags :
"
,
len
(
tags_s
[
0
]))
print
(
"
\t
Len pred_convert :
"
,
len
(
pred_convert
[
0
]))
print
()
print
(
"
\t
Text :
"
,
a_s
)
print
()
print
(
"
\t
Tags :
"
,
tags_s
[
0
])
print
()
print
(
"
\t
Pred_convert :
"
,
pred_convert
[
0
])
print
()
print
(
"
\t
Score :
"
,
categorical_accuracy_str
(
pred_convert
,
tags_s
))
This diff is collapsed.
Click to expand it.
train.py
+
5
−
4
View file @
a7008a57
from
SuperTagger.SuperTagger
import
SuperTagger
from
SuperTagger.Utils.
util
s
import
read_csv_pgbar
,
load_obj
from
SuperTagger.Utils.
helper
s
import
read_csv_pgbar
,
load_obj
#### DATA ####
file_path
=
'
Datasets/m2_dataset.csv
'
df
=
read_csv_pgbar
(
file_path
,
1000
)
texts
=
df
[
'
X
'
].
tolist
()
tags
=
df
[
'
Y1
'
].
tolist
()
...
...
@@ -16,9 +15,9 @@ tags_s = tags[:4]
texts
=
texts
[
4
:]
tags
=
tags
[
4
:]
index_to_super
=
load_obj
(
'
Datasets/index_to_pos1
'
)
#### MODEL ####
tagger
=
SuperTagger
()
tagger
.
create_new_model
(
len
(
index_to_super
),
'
camembert-base
'
,
index_to_super
)
...
...
@@ -26,6 +25,8 @@ tagger.create_new_model(len(index_to_super),'camembert-base',index_to_super)
tagger
.
train
(
texts
,
tags
,
batch_size
=
16
,
validation_rate
=
0.1
,
tensorboard
=
True
,
checkpoint
=
True
)
#### TEST ####
pred
=
tagger
.
predict
(
test_s
)
print
(
test_s
)
...
...
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