diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000..d0c3cbf --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/doc/make.bat b/doc/make.bat new file mode 100644 index 0000000..6247f7e --- /dev/null +++ b/doc/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/doc/source/conf.py b/doc/source/conf.py new file mode 100644 index 0000000..d0d00db --- /dev/null +++ b/doc/source/conf.py @@ -0,0 +1,62 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'parakeet' +copyright = '2020, parakeet-developers' +author = 'parakeet-developers' + +# The full version, including alpha/beta/rc tags +release = '0.2' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.viewcode', + "sphinx_rtd_theme", + 'sphinx.ext.napoleon', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "sphinx_rtd_theme" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] +source_suffix = ['.rst', '.md'] + +# -- Extension configuration ------------------------------------------------- \ No newline at end of file diff --git a/doc/source/index.rst b/doc/source/index.rst new file mode 100644 index 0000000..389f291 --- /dev/null +++ b/doc/source/index.rst @@ -0,0 +1,20 @@ +.. parakeet documentation master file, created by + sphinx-quickstart on Thu Dec 17 20:01:34 2020. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to parakeet's documentation! +==================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/doc/source/modules.rst b/doc/source/modules.rst new file mode 100644 index 0000000..936991c --- /dev/null +++ b/doc/source/modules.rst @@ -0,0 +1,7 @@ +parakeet +======== + +.. toctree:: + :maxdepth: 4 + + parakeet diff --git a/doc/source/parakeet.audio.rst b/doc/source/parakeet.audio.rst new file mode 100644 index 0000000..c0477ef --- /dev/null +++ b/doc/source/parakeet.audio.rst @@ -0,0 +1,29 @@ +parakeet.audio package +====================== + +Submodules +---------- + +parakeet.audio.audio module +--------------------------- + +.. automodule:: parakeet.audio.audio + :members: + :undoc-members: + :show-inheritance: + +parakeet.audio.spec\_normalizer module +-------------------------------------- + +.. automodule:: parakeet.audio.spec_normalizer + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: parakeet.audio + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/parakeet.data.rst b/doc/source/parakeet.data.rst new file mode 100644 index 0000000..0222bac --- /dev/null +++ b/doc/source/parakeet.data.rst @@ -0,0 +1,29 @@ +parakeet.data package +===================== + +Submodules +---------- + +parakeet.data.batch module +-------------------------- + +.. automodule:: parakeet.data.batch + :members: + :undoc-members: + :show-inheritance: + +parakeet.data.dataset module +---------------------------- + +.. automodule:: parakeet.data.dataset + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: parakeet.data + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/parakeet.datasets.rst b/doc/source/parakeet.datasets.rst new file mode 100644 index 0000000..79d4b99 --- /dev/null +++ b/doc/source/parakeet.datasets.rst @@ -0,0 +1,29 @@ +parakeet.datasets package +========================= + +Submodules +---------- + +parakeet.datasets.common module +------------------------------- + +.. automodule:: parakeet.datasets.common + :members: + :undoc-members: + :show-inheritance: + +parakeet.datasets.ljspeech module +--------------------------------- + +.. automodule:: parakeet.datasets.ljspeech + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: parakeet.datasets + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/parakeet.frontend.rst b/doc/source/parakeet.frontend.rst new file mode 100644 index 0000000..74f5059 --- /dev/null +++ b/doc/source/parakeet.frontend.rst @@ -0,0 +1,37 @@ +parakeet.frontend package +========================= + +Submodules +---------- + +parakeet.frontend.phonectic module +---------------------------------- + +.. automodule:: parakeet.frontend.phonectic + :members: + :undoc-members: + :show-inheritance: + +parakeet.frontend.punctuation module +------------------------------------ + +.. automodule:: parakeet.frontend.punctuation + :members: + :undoc-members: + :show-inheritance: + +parakeet.frontend.vocab module +------------------------------ + +.. automodule:: parakeet.frontend.vocab + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: parakeet.frontend + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/parakeet.models.rst b/doc/source/parakeet.models.rst new file mode 100644 index 0000000..9299c81 --- /dev/null +++ b/doc/source/parakeet.models.rst @@ -0,0 +1,45 @@ +parakeet.models package +======================= + +Submodules +---------- + +parakeet.models.tacotron2 module +-------------------------------- + +.. automodule:: parakeet.models.tacotron2 + :members: + :undoc-members: + :show-inheritance: + +parakeet.models.transformer\_tts module +--------------------------------------- + +.. automodule:: parakeet.models.transformer_tts + :members: + :undoc-members: + :show-inheritance: + +parakeet.models.waveflow module +------------------------------- + +.. automodule:: parakeet.models.waveflow + :members: + :undoc-members: + :show-inheritance: + +parakeet.models.wavenet module +------------------------------ + +.. automodule:: parakeet.models.wavenet + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: parakeet.models + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/parakeet.modules.rst b/doc/source/parakeet.modules.rst new file mode 100644 index 0000000..1802234 --- /dev/null +++ b/doc/source/parakeet.modules.rst @@ -0,0 +1,93 @@ +parakeet.modules package +======================== + +Submodules +---------- + +parakeet.modules.attention module +--------------------------------- + +.. automodule:: parakeet.modules.attention + :members: + :undoc-members: + :show-inheritance: + +parakeet.modules.audio module +----------------------------- + +.. automodule:: parakeet.modules.audio + :members: + :undoc-members: + :show-inheritance: + +parakeet.modules.cbhg module +---------------------------- + +.. automodule:: parakeet.modules.cbhg + :members: + :undoc-members: + :show-inheritance: + +parakeet.modules.connections module +----------------------------------- + +.. automodule:: parakeet.modules.connections + :members: + :undoc-members: + :show-inheritance: + +parakeet.modules.conv module +---------------------------- + +.. automodule:: parakeet.modules.conv + :members: + :undoc-members: + :show-inheritance: + +parakeet.modules.geometry module +-------------------------------- + +.. automodule:: parakeet.modules.geometry + :members: + :undoc-members: + :show-inheritance: + +parakeet.modules.losses module +------------------------------ + +.. automodule:: parakeet.modules.losses + :members: + :undoc-members: + :show-inheritance: + +parakeet.modules.masking module +------------------------------- + +.. automodule:: parakeet.modules.masking + :members: + :undoc-members: + :show-inheritance: + +parakeet.modules.positional\_encoding module +-------------------------------------------- + +.. automodule:: parakeet.modules.positional_encoding + :members: + :undoc-members: + :show-inheritance: + +parakeet.modules.transformer module +----------------------------------- + +.. automodule:: parakeet.modules.transformer + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: parakeet.modules + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/parakeet.rst b/doc/source/parakeet.rst new file mode 100644 index 0000000..2e24f37 --- /dev/null +++ b/doc/source/parakeet.rst @@ -0,0 +1,25 @@ +parakeet package +================ + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + parakeet.audio + parakeet.data + parakeet.datasets + parakeet.frontend + parakeet.models + parakeet.modules + parakeet.training + parakeet.utils + +Module contents +--------------- + +.. automodule:: parakeet + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/parakeet.training.rst b/doc/source/parakeet.training.rst new file mode 100644 index 0000000..992119c --- /dev/null +++ b/doc/source/parakeet.training.rst @@ -0,0 +1,37 @@ +parakeet.training package +========================= + +Submodules +---------- + +parakeet.training.cli module +---------------------------- + +.. automodule:: parakeet.training.cli + :members: + :undoc-members: + :show-inheritance: + +parakeet.training.default\_config module +---------------------------------------- + +.. automodule:: parakeet.training.default_config + :members: + :undoc-members: + :show-inheritance: + +parakeet.training.experiment module +----------------------------------- + +.. automodule:: parakeet.training.experiment + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: parakeet.training + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/parakeet.utils.rst b/doc/source/parakeet.utils.rst new file mode 100644 index 0000000..8217245 --- /dev/null +++ b/doc/source/parakeet.utils.rst @@ -0,0 +1,61 @@ +parakeet.utils package +====================== + +Submodules +---------- + +parakeet.utils.checkpoint module +-------------------------------- + +.. automodule:: parakeet.utils.checkpoint + :members: + :undoc-members: + :show-inheritance: + +parakeet.utils.display module +----------------------------- + +.. automodule:: parakeet.utils.display + :members: + :undoc-members: + :show-inheritance: + +parakeet.utils.internals module +------------------------------- + +.. automodule:: parakeet.utils.internals + :members: + :undoc-members: + :show-inheritance: + +parakeet.utils.layer\_tools module +---------------------------------- + +.. automodule:: parakeet.utils.layer_tools + :members: + :undoc-members: + :show-inheritance: + +parakeet.utils.mp\_tools module +------------------------------- + +.. automodule:: parakeet.utils.mp_tools + :members: + :undoc-members: + :show-inheritance: + +parakeet.utils.scheduler module +------------------------------- + +.. automodule:: parakeet.utils.scheduler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: parakeet.utils + :members: + :undoc-members: + :show-inheritance: diff --git a/parakeet/models/transformer_tts.py b/parakeet/models/transformer_tts.py index 839e18c..f84a9f8 100644 --- a/parakeet/models/transformer_tts.py +++ b/parakeet/models/transformer_tts.py @@ -33,8 +33,7 @@ __all__ = ["TransformerTTS", "TransformerTTSLoss"] # Transformer TTS's own implementation of transformer class MultiheadAttention(nn.Layer): - """ - Multihead scaled dot product attention with drop head. See + """Multihead scaled dot product attention with drop head. See [Scheduled DropHead: A Regularization Method for Transformer Models](https://arxiv.org/abs/2004.13342) for details. diff --git a/parakeet/modules/attention.py b/parakeet/modules/attention.py index 838f886..cb0ae63 100644 --- a/parakeet/modules/attention.py +++ b/parakeet/modules/attention.py @@ -25,22 +25,30 @@ def scaled_dot_product_attention(q, mask=None, dropout=0.0, training=True): - """ - scaled dot product attention with mask. Assume q, k, v all have the same - leader dimensions(denoted as * in descriptions below). Dropout is applied to - attention weights before weighted sum of values. - - Args: - q (Tensor): shape(*, T_q, d), the query tensor. - k (Tensor): shape(*, T_k, d), the key tensor. - v (Tensor): shape(*, T_k, d_v), the value tensor. - mask (Tensor, optional): shape(*, T_q, T_k) or broadcastable shape, the - mask tensor, 0 correspond to padding. Defaults to None. + """Scaled dot product attention with masking. - Returns: - (out, attn_weights) - out (Tensor): shape(*, T_q, d_v), the context vector. - attn_weights (Tensor): shape(*, T_q, T_k), the attention weights. + Assume that q, k, v all have the same leading dimensions (denoted as * in + descriptions below). Dropout is applied to attention weights before + weighted sum of values. + + Parameters + ----------- + + q: Tensor [shape=(*, T_q, d)] + the query tensor. + k: Tensor [shape=(*, T_k, d)] + the key tensor. + v: Tensor [shape=(*, T_k, d_v)] + the value tensor. + mask: Tensor, [shape=(*, T_q, T_k) or broadcastable shape], optional + the mask tensor, zeros correspond to paddings. Defaults to None. + + Returns + ---------- + out: Tensor [shape(*, T_q, d_v)] + the context vector. + attn_weights [Tensor shape(*, T_q, T_k)] + the attention weights. """ d = q.shape[-1] # we only support imperative execution qk = paddle.matmul(q, k, transpose_y=True) diff --git a/parakeet/training/__init__.py b/parakeet/training/__init__.py new file mode 100644 index 0000000..cb1c59b --- /dev/null +++ b/parakeet/training/__init__.py @@ -0,0 +1,2 @@ +from parakeet.training.cli import * +from parakeet.training.experiment import * diff --git a/parakeet/training/experiment.py b/parakeet/training/experiment.py index 8c44f93..7070d39 100644 --- a/parakeet/training/experiment.py +++ b/parakeet/training/experiment.py @@ -25,6 +25,7 @@ from collections import defaultdict import parakeet from parakeet.utils import checkpoint, mp_tools +__all__ = ["ExperimentBase"] class ExperimentBase(object): """ @@ -41,6 +42,7 @@ class ExperimentBase(object): Feel free to add/overwrite other methods and standalone functions if you need. + Examples: -------- def main_sp(config, args):