Skip to content

Commit

Permalink
Merge pull request #107 from Yoctol/deprecate-step
Browse files Browse the repository at this point in the history
Deprecate step
  • Loading branch information
noobOriented authored Apr 11, 2019
2 parents e0ddef3 + b587ea1 commit 85b154c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 82 deletions.
38 changes: 23 additions & 15 deletions uttut/pipeline/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@

from .intermediate import Intermediate
from .ops.base import LabelAligner, Operator
from .step import Step
from .utils import unpack_datum


class Pipe:

"""Pipe is a container for a series of operators
Attributes:
_steps (Operators) : a list of operator instances
_checkpoints (strs): a list of checkpoints
"""

def __init__(self):
self._steps = []
self._checkpoints = {}

def add(self, op_name: str, op_kwargs: Dict = None, checkpoint: str = None):
"""Add step based on the operation name & kwargs.
"""Add op into steps based on the operation name & kwargs.
This method creates an operator given name & kwargs, and then append it
to steps.
This method creates a step, which has an op. The op
is created by name & kwargs.
Warning: This method will be deprecated, please use `add_op`.
Args:
op_name (str): the class name of operator.
Expand All @@ -41,7 +49,9 @@ def add(self, op_name: str, op_kwargs: Dict = None, checkpoint: str = None):
self.add_op(op, checkpoint=checkpoint)

def add_op(self, op: Operator, checkpoint: str = None):
"""Add step with given op.
"""Add op into steps
Append the input op to steps.
Args:
op (Operator): An operator instance to be added to steps.
Expand All @@ -52,15 +62,13 @@ def add_op(self, op: Operator, checkpoint: str = None):
KeyError: If the checkpoint name has already been added.
"""

step = Step(op)

if self.steps:
if step.input_type != self.output_type:
if op.input_type != self.output_type:
raise TypeError(
"InputType of the step op is not valid."
f"Got {step.input_type}, but requires {self.output_type}",
f"Got {op.input_type}, but requires {self.output_type}",
)
self._steps.append(step)
self._steps.append(op)

if checkpoint is not None:
if checkpoint in self.checkpoints:
Expand All @@ -85,7 +93,7 @@ def output_type(self):
return self.steps[-1].output_type

def transform(self, datum: Datum):
"""Process data based on Steps(Ops).
"""Process data based on steps
This method processes datum according to the Pipe's steps.
Expand All @@ -107,7 +115,7 @@ def transform(self, datum: Datum):
return output_sequence, intent_labels, updated_entity_labels, label_aligners, intermediate

def transform_sequence(self, input_sequence):
"""Process input_sequence based on Steps(Ops).
"""Process input_sequence based on steps
This method processes input_sequence according to the Pipe's steps.
Expand All @@ -125,16 +133,16 @@ def transform_sequence(self, input_sequence):
intermediate.add(input_sequence)
label_aligners = LabelAlignerSequence()

for step in self.steps:
input_sequence, label_aligner = step.transform(input_sequence)
for op in self.steps:
input_sequence, label_aligner = op.transform(input_sequence)
intermediate.add(input_sequence)
label_aligners.add(label_aligner)

return input_sequence, label_aligners, intermediate

def serialize(self) -> str:
return json.dumps({
'steps': [step.op.serialize() for step in self.steps],
'steps': [op.serialize() for op in self.steps],
'checkpoints': self.checkpoints,
})

Expand Down
24 changes: 0 additions & 24 deletions uttut/pipeline/step.py

This file was deleted.

43 changes: 0 additions & 43 deletions uttut/pipeline/tests/test_step.py

This file was deleted.

0 comments on commit 85b154c

Please sign in to comment.