Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Young-AI committed Oct 9, 2020
1 parent a207632 commit 3aa7524
Show file tree
Hide file tree
Showing 30 changed files with 16 additions and 38 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
# This source code is licensed under the Apache-2.0 license found in the
# LICENSE file in the root directory of this source tree.


import os
import sys
import shutil
import setuptools


# ------------------Package Meta-Data------------------
PACKAGE_INFO = {}

Expand Down
5 changes: 1 addition & 4 deletions ynmt/binaries/default/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
# LICENSE file in the root directory of this source tree.


import os
import collections

import ynmt.hocon.arguments as harg

from ynmt.tasks import build_task

from ynmt.utilities.random import fix_random_procedure
from ynmt.utilities.logging import setup_logger, get_logger, logging_level
from ynmt.utilities.logging import setup_logger, logging_level


def preprocess(args):
Expand Down
3 changes: 1 addition & 2 deletions ynmt/binaries/default/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
# This source code is licensed under the Apache-2.0 license found in the
# LICENSE file in the root directory of this source tree.


import os
import torch
import importlib
import pickle

import ynmt.hocon.arguments as harg

Expand Down
3 changes: 0 additions & 3 deletions ynmt/binaries/default/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
# LICENSE file in the root directory of this source tree.


import os
import torch
import importlib
import pickle

import ynmt.hocon.arguments as harg

Expand Down
1 change: 1 addition & 0 deletions ynmt/criterions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from ynmt.utilities.registration import Registration, import_modules


criterion_registration = Registration(Criterion)


Expand Down
1 change: 0 additions & 1 deletion ynmt/criterions/criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import torch


from ynmt.utilities.statistics import Statistics


Expand Down
1 change: 0 additions & 1 deletion ynmt/criterions/cross_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import torch


from ynmt.criterions import register_criterion, Criterion


Expand Down
1 change: 0 additions & 1 deletion ynmt/criterions/label_smoothing_cross_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import torch


from ynmt.criterions import register_criterion, Criterion


Expand Down
3 changes: 0 additions & 3 deletions ynmt/data/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
# LICENSE file in the root directory of this source tree.


import torch


class Batch(object):
def __init__(self, structure, instances=list()):
assert isinstance(structure, set), 'Type of structure should be set().'
Expand Down
3 changes: 1 addition & 2 deletions ynmt/data/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
import random

from ynmt.data.batch import Batch
from ynmt.data.instance import Instance, InstanceComparator
from ynmt.data.instance import InstanceComparator
from ynmt.utilities.file import load_datas
from ynmt.utilities.random import shuffled
from ynmt.utilities.statistics import Statistics


class Iterator(object):
Expand Down
1 change: 0 additions & 1 deletion ynmt/hocon/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import argparse
import collections


from ynmt.utilities.constant import Constant


Expand Down
1 change: 1 addition & 0 deletions ynmt/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from ynmt.utilities.registration import Registration, import_modules


model_registration = Registration(Model)


Expand Down
1 change: 0 additions & 1 deletion ynmt/modules/decoders/transformer_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import math
import torch


from ynmt.modules.embeddings import TrigonometricPositionalEmbedding
from ynmt.modules.attentions import MultiHeadAttention
from ynmt.modules.perceptrons import PositionWiseFeedForward
Expand Down
1 change: 0 additions & 1 deletion ynmt/modules/embeddings/learned_positional_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# LICENSE file in the root directory of this source tree.


import math
import torch


Expand Down
1 change: 0 additions & 1 deletion ynmt/modules/encoders/transformer_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import math
import torch


from ynmt.modules.embeddings import TrigonometricPositionalEmbedding
from ynmt.modules.attentions import MultiHeadAttention
from ynmt.modules.perceptrons import PositionWiseFeedForward
Expand Down
1 change: 1 addition & 0 deletions ynmt/schedulers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from ynmt.utilities.registration import Registration, import_modules


scheduler_registration = Registration(Scheduler)


Expand Down
1 change: 0 additions & 1 deletion ynmt/tasks/mixins/seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import collections


from ynmt.utilities.file import load_plain
from ynmt.utilities.multiprocessing import multi_process

Expand Down
2 changes: 1 addition & 1 deletion ynmt/tasks/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from ynmt.data.dataset import Dataset

from ynmt.utilities.file import mk_temp, rm_temp, load_data, load_datas, dump_data, dump_datas
from ynmt.utilities.file import mk_temp, rm_temp, load_data, dump_data, dump_datas
from ynmt.utilities.multiprocessing import multi_process


Expand Down
2 changes: 0 additions & 2 deletions ynmt/testers/seq2seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# LICENSE file in the root directory of this source tree.


import os
import re
import torch

from ynmt.testers import register_tester, Tester
Expand Down
1 change: 0 additions & 1 deletion ynmt/testers/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# LICENSE file in the root directory of this source tree.


import re
import torch

from ynmt.utilities.timer import Timer
Expand Down
8 changes: 4 additions & 4 deletions ynmt/trainers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
# LICENSE file in the root directory of this source tree.


import re
import torch


from ynmt.utilities.timer import Timer
from ynmt.utilities.statistics import Statistics, perplexity
from ynmt.utilities.statistics import Statistics
from ynmt.utilities.checkpoint import save_checkpoint
from ynmt.utilities.distributed import reduce_all, gather_all

Expand Down Expand Up @@ -133,7 +131,9 @@ def launch(self, accumulated_train_batches, accumulated_valid_batches):
if self.step % self.training_period == 0:
self.save()

self.save()
if self.step % self.training_period != 0:
self.save()

return

def train(self, accumulated_train_batch):
Expand Down
1 change: 0 additions & 1 deletion ynmt/utilities/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import torch
import threading


from ynmt.utilities.file import dumps, loads


Expand Down
1 change: 0 additions & 1 deletion ynmt/utilities/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import logging


from ynmt.utilities.file import mk_temp


Expand Down
3 changes: 0 additions & 3 deletions ynmt/utilities/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import importlib


from ynmt.utilities.constant import Constant


def import_modules(father, directory):
file_names = os.listdir(directory)
for file_name in file_names:
Expand Down
1 change: 0 additions & 1 deletion ynmt/utilities/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import time


from ynmt.utilities.constant import Constant


Expand Down
1 change: 0 additions & 1 deletion ynmt/utilities/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import inspect
import datetime


from ynmt.utilities.file import get_temp_file_path


Expand Down
1 change: 0 additions & 1 deletion ynmt/utilities/visualizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import json
import visdom


from ynmt.utilities.file import mk_temp
from ynmt.utilities.constant import Constant

Expand Down
1 change: 1 addition & 0 deletions ynmt_cli/default/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# This source code is licensed under the Apache-2.0 license found in the
# LICENSE file in the root directory of this source tree.


from ynmt.binaries.default.preprocess import main


Expand Down
1 change: 1 addition & 0 deletions ynmt_cli/default/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# This source code is licensed under the Apache-2.0 license found in the
# LICENSE file in the root directory of this source tree.


from ynmt.binaries.default.test import main


Expand Down
1 change: 1 addition & 0 deletions ynmt_cli/default/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# This source code is licensed under the Apache-2.0 license found in the
# LICENSE file in the root directory of this source tree.


from ynmt.binaries.default.train import main


Expand Down

0 comments on commit 3aa7524

Please sign in to comment.