Skip to content

Commit

Permalink
Release 0.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatovFedor committed Sep 28, 2021
2 parents f5117cd + 05ca9e3 commit d73f457
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions deeppavlov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .configs import configs
from .core.commands.infer import build_model
from .core.commands.train import train_evaluate_model_from_config
from .core.common.base import Element, Model
from .core.common.chainer import Chainer
from .core.common.log import init_logger
from .download import deep_download
Expand Down
2 changes: 1 addition & 1 deletion deeppavlov/_meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.17.0'
__version__ = '0.17.1'
__author__ = 'Neural Networks and Deep Learning lab, MIPT'
__description__ = 'An open source library for building end-to-end dialog systems and training chatbots.'
__keywords__ = ['NLP', 'NER', 'SQUAD', 'Intents', 'Chatbot']
Expand Down
77 changes: 77 additions & 0 deletions deeppavlov/core/common/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2021 Neural Networks and Deep Learning lab, MIPT
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from types import FunctionType
from typing import List, Optional, Union

from deeppavlov.core.common.chainer import Chainer
from deeppavlov.core.models.component import Component


class Element:
"""DeepPavlov model pipeline element."""
def __init__(self, component: Union[Component, FunctionType],
x: Optional[Union[str, list]] = None,
out: Optional[Union[str, list]] = None,
y: Optional[Union[str, list]] = None,
main: bool = False) -> None:
"""
Args:
component: Pipeline component object.
x: Names of the component inference inputs. Output from other pipeline elements with such names will be fed
to the input of this component.
out: Names of the component inference outputs. Component outputs can be fed to other pipeline elements
using this names.
y: Names of additional inputs (targets) for component training and evaluation.
main: Set True if this is the main component. Main component is trained during model training process.
"""
self.component = component
self.x = x
self.y = y
self.out = out
self.main = main


class Model(Chainer):
"""Builds a component pipeline to train and infer models."""
def __init__(self, x: Optional[Union[str, list]] = None,
out: Optional[Union[str, list]] = None,
y: Optional[Union[str, list]] = None,
pipe: Optional[List[Element]] = None) -> None:
"""
Args:
x: Names of pipeline inference inputs.
out: Names of pipeline inference outputs.
y: Names of additional inputs (targets) for pipeline training and evaluation.
pipe: List of pipeline elements.
Example:
.. code:: python
>>> from deeppavlov.models.nemo.asr import NeMoASR
>>> from deeppavlov import Element, Model
>>> asr = NeMoASR(nemo_params_path="~/.deeppavlov/models/nemo/quartznet15x5/quartznet15x5.yaml",
load_path="~/.deeppavlov/models/nemo/quartznet15x5")
>>> upper = lambda batch: list(map(str.upper, batch))
>>> model = Model(x=["speech"],
out=["upper_text"],
pipe=[Element(asr, "speech", "text"), Element(upper, "text", "upper_text")])
>>> model(["8088-284756-0037.wav"])
['I WALKED ALONG BRISKLY FOR PERHAPS FIVE MINUTES']
"""
super().__init__(in_x=x, out_params=out, in_y=y)
if pipe is not None:
for element in pipe:
self.append(element.component, element.x, element.out, element.y, element.main)
8 changes: 8 additions & 0 deletions docs/apiref/core/common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ Registration and classes initialization functionality, class method decorators.

.. automethod:: __call__

.. autoclass:: deeppavlov.core.common.base.Element

.. automethod:: __init__

.. autoclass:: deeppavlov.core.common.base.Model

.. automethod:: __init__

.. automodule:: deeppavlov.core.common.metrics_registry
:members:

Expand Down

0 comments on commit d73f457

Please sign in to comment.