Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
outillage
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
Alice Brenon
outillage
Commits
bb824282
Commit
bb824282
authored
1 year ago
by
Alice Brenon
Browse files
Options
Downloads
Patches
Plain Diff
BERT file went into the BERT directory as a package, removing left-over file
parent
d7e8544f
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
scripts/ML/BERT.py
+0
-45
0 additions, 45 deletions
scripts/ML/BERT.py
with
0 additions
and
45 deletions
scripts/ML/BERT.py
deleted
100644 → 0
+
0
−
45
View file @
d7e8544f
from
loaders
import
get_device
from
transformers
import
BertForSequenceClassification
,
BertTokenizer
def
loader
(
f
):
def
wrapped
(
*
args
,
**
kwargs
):
name
=
f
.
__name__
.
replace
(
'
_init_
'
,
''
)
print
(
f
'
-
{
name
}
'
,
end
=
''
)
f
(
*
args
,
**
kwargs
)
print
(
f
'
\r
✔️
{
name
}
'
)
return
wrapped
class
BERT
:
model_name
=
'
bert-base-multilingual-cased
'
def
__init__
(
self
,
root_path
,
training
=
False
):
self
.
device
=
get_device
()
print
(
'
Loading BERT tools
'
)
self
.
_init_tokenizer
()
self
.
root_path
=
root_path
_init_classifier
(
training
)
@loader
def
_init_tokenizer
():
self
.
tokenizer
=
BertTokenizer
.
from_pretrained
(
BERT
.
model_name
)
@loader
def
_init_classifier
(
training
)
if
training
bert
=
BertForSequenceClassification
.
from_pretrained
(
self
.
root_path
)
else
:
bert
=
BertForSequenceClassification
.
from_pretrained
(
model_name
,
# 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.
)
self
.
model
=
bert
.
to
(
self
.
device
.
type
)
def
import_data
(
self
,
data
):
return
map
(
lambda
d
:
d
.
to
(
self
.
device
),
data
)
def
save
(
self
):
self
.
model
.
save_pretrained
(
self
.
root_path
)
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