This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BERTTensorizerBaseImpl to reimplement BERTTensorizerBase to be TorchS…
…criptable (#1163) Summary: Pull Request resolved: #1163 BERTTensorizerBaseImpl to reimplement BERTTensorizerBase to be TorchScriptable Over design: PyText Tensorizer (for example: RoBERTaTensorizer) will delegate the numberize and tensorize logic to Scripted Tensorizer Implementation (for example: RoBERTaTensorizerImpl) This requires to reimplement numberize() and tensorize() logic in Torchscriptable, but good news is that we already have such implementation in pytext/torchscript/tensorizer, we just need to make minor change. On the PyText Tensorizer side, it will delegate numberize and tensorize logic to tensorizer_impl. ``` def numberize(self, row: Dict) -> Tuple[Any, ...]: per_sentence_tokens = [ self.tokenizer.tokenize(row[column]) for column in self.columns ] return self.tensorizer_impl.numberize(per_sentence_tokens) def tensorize(self, batch) -> Tuple[torch.Tensor, ...]: tokens, segment_labels, seq_lens, positions = zip(*batch) return self.tensorizer_impl.tensorize( tokens, segment_labels, seq_lens, positions ) ``` Reviewed By: rutyrinott Differential Revision: D18651538 fbshipit-source-id: aa56e84716496b73c021b70f996734215fb8f9ab
- Loading branch information
1 parent
e780023
commit 39467dc
Showing
5 changed files
with
353 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.