Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

funnel transformer #1419

Merged
merged 14 commits into from
Dec 23, 2021
17 changes: 10 additions & 7 deletions examples/machine_reading_comprehension/SQuAD/run_squad.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
import paddlenlp as ppnlp

from paddlenlp.data import Pad, Stack, Tuple, Dict
from paddlenlp.transformers import BertForQuestionAnswering, BertTokenizer, ErnieForQuestionAnswering, ErnieTokenizer
from paddlenlp.transformers import BertForQuestionAnswering, BertTokenizer, ErnieForQuestionAnswering, ErnieTokenizer, FunnelForQuestionAnswering, FunnelTokenizer
from paddlenlp.transformers import LinearDecayWithWarmup
from paddlenlp.metrics.squad import squad_evaluate, compute_prediction
from paddlenlp.datasets import load_dataset

MODEL_CLASSES = {
"bert": (BertForQuestionAnswering, BertTokenizer),
"ernie": (ErnieForQuestionAnswering, ErnieTokenizer)
"ernie": (ErnieForQuestionAnswering, ErnieTokenizer),
'funnel':(FunnelForQuestionAnswering, FunnelTokenizer)
}


Expand Down Expand Up @@ -162,9 +163,9 @@ def evaluate(model, data_loader, args):
tic_eval = time.time()

for batch in data_loader:
input_ids, token_type_ids = batch
input_ids, token_type_ids, attention_mask = batch
start_logits_tensor, end_logits_tensor = model(input_ids,
token_type_ids)
token_type_ids=token_type_ids, attention_mask=attention_mask)

for idx in range(start_logits_tensor.shape[0]):
if len(all_start_logits) % 1000 == 0 and len(all_start_logits):
Expand Down Expand Up @@ -251,6 +252,7 @@ def run(args):
train_batchify_fn = lambda samples, fn=Dict({
"input_ids": Pad(axis=0, pad_val=tokenizer.pad_token_id),
"token_type_ids": Pad(axis=0, pad_val=tokenizer.pad_token_type_id),
'attention_mask': Pad(axis=0, pad_val=tokenizer.pad_token_type_id),
"start_positions": Stack(dtype="int64"),
"end_positions": Stack(dtype="int64")
}): fn(samples)
Expand Down Expand Up @@ -288,10 +290,10 @@ def run(args):
for epoch in range(num_train_epochs):
for step, batch in enumerate(train_data_loader):
global_step += 1
input_ids, token_type_ids, start_positions, end_positions = batch
input_ids, token_type_ids, attention_mask, start_positions, end_positions = batch

logits = model(
input_ids=input_ids, token_type_ids=token_type_ids)
input_ids=input_ids, token_type_ids=token_type_ids, attention_mask=attention_mask)
loss = criterion(logits, (start_positions, end_positions))

if global_step % args.logging_steps == 0:
Expand Down Expand Up @@ -329,7 +331,8 @@ def run(args):

dev_batchify_fn = lambda samples, fn=Dict({
"input_ids": Pad(axis=0, pad_val=tokenizer.pad_token_id),
"token_type_ids": Pad(axis=0, pad_val=tokenizer.pad_token_type_id)
"token_type_ids": Pad(axis=0, pad_val=tokenizer.pad_token_type_id),
"attention_mask": Pad(axis=0, pad_val=tokenizer.pad_token_type_id)
}): fn(samples)

dev_data_loader = DataLoader(
Expand Down
2 changes: 2 additions & 0 deletions paddlenlp/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@
from .reformer.tokenizer import *
from .mobilebert.modeling import *
from .mobilebert.tokenizer import *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方冲突了,注意解决冲突~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经修改

from .funnel.modeling import *
from .funnel.tokenizer import *
2 changes: 2 additions & 0 deletions paddlenlp/transformers/funnel/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .modeling import *
from .tokenizer import *
Loading