Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
PSB_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
bongminkim
2020-03-31 17:06:03 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9b3c0b9db79b77cd5c3deedae7d58a375102cc1b
9b3c0b9d
1 parent
ad3271d6
KoBERT_model
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
KoBERT/Bert_model.py
면담확인서/캡디면담확인서03.jpg
KoBERT/Bert_model.py
0 → 100644
View file @
9b3c0b9
import
torch
from
torch
import
nn
class
BERTClassifier
(
nn
.
Module
):
def
__init__
(
self
,
bert
,
hidden_size
=
768
,
num_classes
=
2
,
dr_rate
=
None
):
super
(
BERTClassifier
,
self
)
.
__init__
()
self
.
bert
=
bert
self
.
dr_rate
=
dr_rate
self
.
classifier
=
nn
.
Linear
(
hidden_size
,
num_classes
)
if
dr_rate
:
self
.
dropout
=
nn
.
Dropout
(
p
=
dr_rate
)
def
gen_attention_mask
(
self
,
token_ids
,
valid_length
):
attention_mask
=
torch
.
zeros_like
(
token_ids
)
for
i
,
v
in
enumerate
(
valid_length
):
attention_mask
[
i
][:
v
]
=
1
return
attention_mask
.
float
()
def
forward
(
self
,
token_ids
,
valid_length
,
segment_ids
):
attention_mask
=
self
.
gen_attention_mask
(
token_ids
,
valid_length
)
_
,
pooler
=
self
.
bert
(
input_ids
=
token_ids
,
token_type_ids
=
segment_ids
.
long
(),
attention_mask
=
attention_mask
.
float
()
.
to
(
token_ids
.
device
))
if
self
.
dr_rate
:
out
=
self
.
dropout
(
pooler
)
return
self
.
classifier
(
out
)
면담확인서/캡디면담확인서03.jpg
0 → 100644
View file @
9b3c0b9
1.13 MB
Please
register
or
login
to post a comment