Skip to content

Slow tokenization #1

@forrestbao

Description

@forrestbao

PrefScore/model.py

Lines 10 to 25 in 05e2ffb

import config as CFG
class Scorer(nn.Module):
def __init__(self):
super(Scorer, self).__init__()
self.tokenizer = BertTokenizer.from_pretrained(CFG.BERT_MODEL)
self.model = BertModel.from_pretrained(CFG.BERT_MODEL)
self.fc = nn.Linear(self.model.config.hidden_size, 1)
def forward(self, article, summary):
inputs = self.tokenizer(article, summary, padding='longest', truncation="longest_first" , return_tensors='pt').to(CFG.DEVICE)
outputs = self.model(**inputs)
x = self.fc(outputs.pooler_output)
return x
class Siamese(nn.Module):

Text pieces or pairs are tokenized individually and move to GPU. This is very slow.

At least we should tokenize them after a batch is loaded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions