Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nlp-cw
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
Service Desk
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
Roko Parac
nlp-cw
Merge requests
!2
Implements Ensamble model
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Implements Ensamble model
ensamble
into
master
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Roko Parac
requested to merge
ensamble
into
master
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
df363700
1 commit,
2 years ago
1 file
+
18
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
lib/huggingface_utils.py
+
18
−
0
Options
@@ -43,3 +43,21 @@ def make_predictions(model, tokenizer, dataset, batch_size, device):
y_true
=
None
return
y_pred
,
y_true
class
EnsambleModel
:
def
__init__
(
self
,
models
,
tokenizers
):
self
.
models
=
models
self
.
tokenizers
=
tokenizers
if
len
(
models
)
%
2
==
0
:
raise
ValueError
(
'
Need an odd number of models to avoid ties
'
)
def
make_predictions
(
self
,
dataset
,
batch_size
,
device
):
y_preds
,
y_true
=
torch
.
Tensor
([
0
]).
int
(),
None
for
model
,
tokenizer
in
zip
(
self
.
models
,
self
.
tokenizers
):
y_pred
,
y_true
=
make_predictions
(
model
,
tokenizer
,
dataset
,
batch_size
,
device
)
y_preds
+=
torch
.
Tensor
(
y_pred
).
int
()
y_preds
=
(
y_preds
>
len
(
self
.
models
)
//
2
).
int
().
tolist
()
return
y_preds
,
y_true
Loading