Commit 0b05467d authored by Liezl Puzon's avatar Liezl Puzon Committed by Facebook Github Bot
Browse files

Black formatting in fairseq/test_noising (#341)

Summary:
Pull Request resolved: https://github.com/pytorch/fairseq/pull/341

Use black formatting in test_noising.py

Reviewed By: xianxl

Differential Revision: D12810285

fbshipit-source-id: 5517dd5d2f086831f487d88acf6bc2fa18820297
parent 726a47dc
......@@ -5,17 +5,17 @@
# the root directory of this source tree. An additional grant of patent rights
# can be found in the PATENTS file in the same directory.
import torch
import unittest
import tests.utils as test_utils
import torch
from fairseq import utils
from fairseq.data import (
AppendEosDataset,
Dictionary,
LanguagePairDataset,
data_utils,
noising,
LanguagePairDataset,
)
......@@ -69,12 +69,12 @@ class TestDataNoising(unittest.TestCase):
"""Asserts last token of every sentence in x is EOS """
for i in range(len(x_len)):
self.assertEqual(
x[x_len[i]-1][i],
x[x_len[i] - 1][i],
eos,
(
"Expected eos (token id {eos}) at the end of sentence {i} but "
"got {other} instead"
).format(i=i, eos=eos, other=x[i][-1])
).format(i=i, eos=eos, other=x[i][-1]),
)
def assert_word_dropout_correct(self, x, x_noised, x_len, l_noised):
......@@ -197,11 +197,11 @@ class TestDataNoising(unittest.TestCase):
"""Asserts that the last token of each sentence in x is not EOS """
for i in range(len(x_len)):
self.assertNotEqual(
x[x_len[i]-1][i],
x[x_len[i] - 1][i],
eos,
"Expected no eos (token id {eos}) at the end of sentence {i}.".format(
eos=eos, i=i,
)
eos=eos, i=i
),
)
def test_word_dropout_without_eos(self):
......@@ -273,10 +273,7 @@ class TestDataNoising(unittest.TestCase):
if use_append_eos_dataset:
tgt = AppendEosDataset(src_dataset, src_dict.eos())
language_pair_dataset = LanguagePairDataset(
src=noising_dataset,
tgt=tgt,
src_sizes=None,
src_dict=src_dict
src=noising_dataset, tgt=tgt, src_sizes=None, src_dict=src_dict
)
dataloader = torch.utils.data.DataLoader(
......@@ -361,5 +358,5 @@ class TestDataNoising(unittest.TestCase):
self.assertEqual(t1.ne(t2).long().sum(), 0)
if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment