Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EDdA Classification
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Projet GEODE
EDdA Classification
Commits
d4f07c5f
Commit
d4f07c5f
authored
3 years ago
by
Ludovic Moncla
Browse files
Options
Downloads
Patches
Plain Diff
Update training_bertFineTuning.py
parent
078c0596
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
training_bertFineTuning.py
+11
-11
11 additions, 11 deletions
training_bertFineTuning.py
with
11 additions
and
11 deletions
training_bertFineTuning.py
+
11
−
11
View file @
d4f07c5f
...
...
@@ -60,7 +60,7 @@ def format_time(elapsed):
return
str
(
datetime
.
timedelta
(
seconds
=
elapsed_rounded
))
def
training_bertFineTuning
(
chosen_model
,
sentences
,
labels
,
max_len
,
batch_size
,
epochs
=
4
):
def
training_bertFineTuning
(
chosen_model
,
model_path
,
sentences
,
labels
,
max_len
,
batch_size
,
epochs
=
4
):
# If there's a GPU available...
if
torch
.
cuda
.
is_available
():
...
...
@@ -82,12 +82,12 @@ def training_bertFineTuning(chosen_model, sentences, labels, max_len, batch_si
###########################################################################################################
if
chosen_model
==
'
bert
-base-multilingual-cased
'
:
if
chosen_model
==
'
bert
'
:
print
(
'
Loading Bert Tokenizer...
'
)
tokenizer
=
BertTokenizer
.
from_pretrained
(
chosen_
model
,
do_lower_case
=
True
)
elif
chosen_model
==
'
camembert
-base
'
:
tokenizer
=
BertTokenizer
.
from_pretrained
(
model
_path
,
do_lower_case
=
True
)
elif
chosen_model
==
'
camembert
'
:
print
(
'
Loading Camembert Tokenizer...
'
)
tokenizer
=
CamembertTokenizer
.
from_pretrained
(
chosen_
model
,
do_lower_case
=
True
)
tokenizer
=
CamembertTokenizer
.
from_pretrained
(
model
_path
,
do_lower_case
=
True
)
...
...
@@ -192,18 +192,18 @@ def training_bertFineTuning(chosen_model, sentences, labels, max_len, batch_si
# Load BertForSequenceClassification, the pretrained BERT model with a single
# linear classification layer on top.
if
chosen_model
==
'
bert
-base-multilingual-cased
'
:
if
chosen_model
==
'
bert
'
:
model
=
BertForSequenceClassification
.
from_pretrained
(
chosen_
model
,
# Use the 12-layer BERT model, with an uncased vocab.
model
_path
,
# Use the 12-layer BERT model, with an uncased vocab.
num_labels
=
numberOfClasses
,
# The number of output labels--2 for binary classification.
# You can increase this for multi-class tasks.
output_attentions
=
False
,
# Whether the model returns attentions weights.
output_hidden_states
=
False
,
# Whether the model returns all hidden-states.
)
elif
chosen_model
==
'
camembert
-base
'
:
elif
chosen_model
==
'
camembert
'
:
model
=
CamembertForSequenceClassification
.
from_pretrained
(
chosen_
model
,
# Use the 12-layer BERT model, with an uncased vocab.
model
_path
,
# Use the 12-layer BERT model, with an uncased vocab.
num_labels
=
numberOfClasses
,
# The number of output labels--2 for binary classification.
# You can increase this for multi-class tasks.
output_attentions
=
False
,
# Whether the model returns attentions weights.
...
...
@@ -456,7 +456,7 @@ if __name__ == "__main__":
minOfInstancePerClass
=
int
(
config
.
get
(
'
general
'
,
'
minOfInstancePerClass
'
))
maxOfInstancePerClass
=
int
(
config
.
get
(
'
general
'
,
'
maxOfInstancePerClass
'
))
chosen_tokeniser
=
config
.
get
(
'
model
'
,
'
tokeniser
'
)
model_path
=
config
.
get
(
'
model
'
,
'
path
'
)
chosen_model
=
config
.
get
(
'
model
'
,
'
model
'
)
max_len
=
int
(
config
.
get
(
'
model
'
,
'
max_len_sequences
'
))
...
...
@@ -484,7 +484,7 @@ if __name__ == "__main__":
#call train method
model
=
training_bertFineTuning
(
chosen_model
,
sentences
,
labels
,
max_len
,
batch_size
,
epochs
)
model
=
training_bertFineTuning
(
chosen_model
,
model_path
,
sentences
,
labels
,
max_len
,
batch_size
,
epochs
)
#save the model
...
...
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