pytorch / text

Models, data loaders and abstractions for language processing, powered by PyTorch
https://pytorch.org/text
BSD 3-Clause "New" or "Revised" License
3.49k stars 815 forks source link

Add padding direction #2121

Open smsm8898 opened 1 year ago

smsm8898 commented 1 year ago

give small flexibility to pad transformer

joecummings commented 1 year ago

@SM-Jang Thanks for the addition! A couple of notes:

  1. Can you refer to our style guide and make sure the code passes our linting?
  2. Can you add a brief note on the motivation behind this addition?
smsm8898 commented 1 year ago
  1. Can you refer to our style guide and make sure the code passes our linting? Okay, I check flake8 and I follow change the name as begin:bool, default=False To verify it, i modify the unittest and pass it all (test/torchtext_unittest/test_transfoms.py)

  2. Can you add a brief note on the motivation behind this addition? When I work for modeling timeserise, I have to pad on begin or end. The old PadTransform only give left pad... So I have to use torch.nn.functional.pad()

ex) ... self.query_transformer = Sequential(

Truncate(10),

VocabTransform(query_vocab),
ToTensor(),

) ... x = query_transformer(x) x = torch.nn.functional.pad(x, (0, pad_amount), value=self.pad_value) ...

That's why