Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Don-t-NLP-Me
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
Chen, Yitang
Don-t-NLP-Me
Commits
34ff75d3
Commit
34ff75d3
authored
1 year ago
by
mmzk1526
Browse files
Options
Downloads
Patches
Plain Diff
Auto format
parent
d362f66a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hypertune.py
+4
-2
4 additions, 2 deletions
hypertune.py
tools.py
+8
-4
8 additions, 4 deletions
tools.py
train.py
+2
-1
2 additions, 1 deletion
train.py
with
14 additions
and
7 deletions
hypertune.py
+
4
−
2
View file @
34ff75d3
...
...
@@ -13,7 +13,8 @@ from transformers import Trainer
def
get_optimal_hyperparameters
(
env
:
Env
)
->
dict
[
str
:
any
]:
print
(
f
"
device =
{
env
.
device
}
"
)
train_data
,
test_data
=
tools
.
preprocess_train_data
(
"
data/train.csv
"
,
env
,
upscale_factor
=
7
)
train_data
,
test_data
=
tools
.
preprocess_train_data
(
"
data/train.csv
"
,
env
,
upscale_factor
=
7
)
# validate_data = tools.preprocess_test_data("data/dev.csv", env)
with
env
.
tuning_toggle
:
...
...
@@ -60,7 +61,8 @@ if __name__ == '__main__':
logger
.
addHandler
(
logging
.
FileHandler
(
log_path
,
mode
=
"
w+
"
))
optuna
.
logging
.
enable_propagation
()
# Propagate logs to the root logger.
optuna
.
logging
.
disable_default_handler
()
# Stop showing logs in sys.stderr.
# Stop showing logs in sys.stderr.
optuna
.
logging
.
disable_default_handler
()
# Perform tuning
configs_optim
:
dict
[
str
,
any
]
=
get_optimal_hyperparameters
(
env
)
...
...
This diff is collapsed.
Click to expand it.
tools.py
+
8
−
4
View file @
34ff75d3
...
...
@@ -19,10 +19,14 @@ def preprocess_train_data(path: str, env: Env, upscale_factor: int = 7) -> tuple
dataset
=
Dataset
.
from_pandas
(
df
[[
'
label
'
,
'
text
'
]]).
map
(
lambda
d
:
env
.
tokeniser
(
str
(
d
[
'
text
'
]),
truncation
=
True
),
batched
=
False
)
dataset_0_split
=
dataset
.
filter
(
lambda
x
:
x
[
'
label
'
]
==
0
).
train_test_split
(
test_size
=
0.2
)
dataset_1_split
=
dataset
.
filter
(
lambda
x
:
x
[
'
label
'
]
==
1
).
train_test_split
(
test_size
=
0.2
)
dataset_train
=
ds
.
concatenate_datasets
([
dataset_0_split
[
'
train
'
]]
+
[
dataset_1_split
[
'
train
'
]]
*
upscale_factor
)
dataset_test
=
ds
.
concatenate_datasets
([
dataset_0_split
[
'
test
'
],
dataset_1_split
[
'
test
'
]])
dataset_0_split
=
dataset
.
filter
(
lambda
x
:
x
[
'
label
'
]
==
0
).
train_test_split
(
test_size
=
0.2
)
dataset_1_split
=
dataset
.
filter
(
lambda
x
:
x
[
'
label
'
]
==
1
).
train_test_split
(
test_size
=
0.2
)
dataset_train
=
ds
.
concatenate_datasets
(
[
dataset_0_split
[
'
train
'
]]
+
[
dataset_1_split
[
'
train
'
]]
*
upscale_factor
)
dataset_test
=
ds
.
concatenate_datasets
(
[
dataset_0_split
[
'
test
'
],
dataset_1_split
[
'
test
'
]])
return
dataset_train
,
dataset_test
...
...
This diff is collapsed.
Click to expand it.
train.py
+
2
−
1
View file @
34ff75d3
...
...
@@ -8,7 +8,8 @@ from transformers import Trainer
def
train
(
env
:
Env
)
->
None
:
print
(
f
"
device =
{
env
.
device
}
"
)
train_data
,
_
=
tools
.
preprocess_train_data
(
"
data/train.csv
"
,
env
,
upscale_factor
=
7
)
train_data
,
_
=
tools
.
preprocess_train_data
(
"
data/train.csv
"
,
env
,
upscale_factor
=
7
)
validate_data
=
tools
.
preprocess_test_data
(
"
data/dev.csv
"
,
env
)
trainer
=
Trainer
(
...
...
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