Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
f889e77b
Commit
f889e77b
authored
Aug 06, 2019
by
wangfei
Browse files
Fix examples of loading pretrained models in docstring
parent
beb03ec6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
pytorch_transformers/modeling_gpt2.py
pytorch_transformers/modeling_gpt2.py
+17
-17
No files found.
pytorch_transformers/modeling_gpt2.py
View file @
f889e77b
...
...
@@ -433,11 +433,11 @@ class GPT2Model(GPT2PreTrainedModel):
Examples::
>>>
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
>>>
model = GPT2Model.from_pretrained('gpt2')
>>>
input_ids = torch.tensor(tokenizer.encode("Hello, my dog is cute")).unsqueeze(0) # Batch size 1
>>>
outputs = model(input_ids)
>>>
last_hidden_states = outputs[0] # The last hidden-state is the first element of the output tuple
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = GPT2Model.from_pretrained('gpt2')
input_ids = torch.tensor(tokenizer.encode("Hello, my dog is cute")).unsqueeze(0) # Batch size 1
outputs = model(input_ids)
last_hidden_states = outputs[0] # The last hidden-state is the first element of the output tuple
"""
def
__init__
(
self
,
config
):
...
...
@@ -566,11 +566,11 @@ class GPT2LMHeadModel(GPT2PreTrainedModel):
Examples::
>>>
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
>>>
model = GPT2LMHeadModel.from_pretrained('gpt2')
>>>
input_ids = torch.tensor(tokenizer.encode("Hello, my dog is cute")).unsqueeze(0) # Batch size 1
>>>
outputs = model(input_ids, labels=input_ids)
>>>
loss, logits = outputs[:2]
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = GPT2LMHeadModel.from_pretrained('gpt2')
input_ids = torch.tensor(tokenizer.encode("Hello, my dog is cute")).unsqueeze(0) # Batch size 1
outputs = model(input_ids, labels=input_ids)
loss, logits = outputs[:2]
"""
def
__init__
(
self
,
config
):
...
...
@@ -681,13 +681,13 @@ class GPT2DoubleHeadsModel(GPT2PreTrainedModel):
Examples::
>>>
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
>>>
model = GPT2DoubleHeadsModel.from_pretrained('gpt2')
>>>
choices = ["Hello, my dog is cute [CLS]", "Hello, my cat is cute [CLS]"] # Assume you've added [CLS] to the vocabulary
>>>
input_ids = torch.tensor([tokenizer.encode(s) for s in choices]).unsqueeze(0) # Batch size 1, 2 choices
>>>
mc_token_ids = torch.tensor([-1, -1]).unsqueeze(0) # Batch size 1
>>>
outputs = model(input_ids, mc_token_ids)
>>>
lm_prediction_scores, mc_prediction_scores = outputs[:2]
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = GPT2DoubleHeadsModel.from_pretrained('gpt2')
choices = ["Hello, my dog is cute [CLS]", "Hello, my cat is cute [CLS]"] # Assume you've added [CLS] to the vocabulary
input_ids = torch.tensor([tokenizer.encode(s) for s in choices]).unsqueeze(0) # Batch size 1, 2 choices
mc_token_ids = torch.tensor([-1, -1]).unsqueeze(0) # Batch size 1
outputs = model(input_ids, mc_token_ids)
lm_prediction_scores, mc_prediction_scores = outputs[:2]
"""
def
__init__
(
self
,
config
):
...
...
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