Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
7183cded
Commit
7183cded
authored
Dec 06, 2018
by
Grégory Châtel
Browse files
SwagExample class.
parent
3ba5470e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
examples/run_swag.py
examples/run_swag.py
+78
-0
No files found.
examples/run_swag.py
0 → 100644
View file @
7183cded
# coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""BERT finetuning runner."""
class
SwagExample
(
object
):
"""A single training/test example for the SWAG dataset."""
def
__init__
(
self
,
swag_id
,
context_sentence
,
start_ending
,
ending_0
,
ending_1
,
ending_2
,
ending_3
,
label
=
None
):
self
.
swag_id
=
swag_id
self
.
context_sentence
=
context_sentence
self
.
start_ending
=
start_ending
self
.
ending_0
=
ending_0
self
.
ending_1
=
ending_1
self
.
ending_2
=
ending_2
self
.
ending_3
=
ending_3
self
.
label
=
label
def
__str__
(
self
):
return
self
.
__repr__
()
def
__repr__
(
self
):
l
=
[
f
'swag_id:
{
self
.
swag_id
}
'
,
f
'context_sentence:
{
self
.
context_sentence
}
'
,
f
'start_ending:
{
self
.
start_ending
}
'
,
f
'ending_0:
{
self
.
ending_0
}
'
,
f
'ending_1:
{
self
.
ending_1
}
'
,
f
'ending_2:
{
self
.
ending_2
}
'
,
f
'ending_3:
{
self
.
ending_3
}
'
,
]
if
self
.
label
is
not
None
:
l
.
append
(
f
'label:
{
self
.
label
}
'
)
return
', '
.
join
(
l
)
if
__name__
==
"__main__"
:
e
=
SwagExample
(
3416
,
'Members of the procession walk down the street holding small horn brass instruments.'
,
'A drum line'
,
'passes by walking down the street playing their instruments.'
,
'has heard approaching them.'
,
"arrives and they're outside dancing and asleep."
,
'turns the lead singer watches the performance.'
,
)
print
(
e
)
e
=
SwagExample
(
3416
,
'Members of the procession walk down the street holding small horn brass instruments.'
,
'A drum line'
,
'passes by walking down the street playing their instruments.'
,
'has heard approaching them.'
,
"arrives and they're outside dancing and asleep."
,
'turns the lead singer watches the performance.'
,
0
)
print
(
e
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment