QubitPi commited on
Commit
b7258ac
·
verified ·
0 Parent(s):

Implement vanilla RNN

Browse files
.github/pull_request_template.md ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Changelog
2
+ ---------
3
+
4
+ ### Added
5
+
6
+ ### Changed
7
+
8
+ ### Deprecated
9
+
10
+ ### Removed
11
+
12
+ ### Fixed
13
+
14
+ ### Security
15
+
16
+
17
+ Checklist
18
+ ---------
19
+
20
+ - [ ] Test
21
+ - [ ] Self-review
22
+ - [ ] Documentation
23
+ - [ ] Version Bumped Manually*
.github/workflows/ci-cd.yml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright Jiaqi Liu
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ ---
15
+ name: CI/CD
16
+
17
+ "on":
18
+ pull_request:
19
+ push:
20
+ branches:
21
+ - master
22
+
23
+ jobs:
24
+ release:
25
+ name: Publish Lamassu To PyPI
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Python 3.10
30
+ uses: actions/setup-python@v4
31
+ with:
32
+ python-version: "3.10"
33
+ - name: Package up SDK
34
+ if: github.ref == 'refs/heads/master'
35
+ run: python setup.py sdist
36
+ - name: Publish a Python distribution to PyPI
37
+ if: github.ref == 'refs/heads/master'
38
+ uses: pypa/gh-action-pypi-publish@release/v1
39
+ with:
40
+ user: __token__
41
+ password: ${{ secrets.PYPI_API_TOKEN }}
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .idea/
2
+ .DS_Store
.readthedocs.yaml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright Jiaqi Liu
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ version: 2
15
+
16
+ build:
17
+ os: ubuntu-22.04
18
+ tools:
19
+ python: "3.11"
20
+
21
+ sphinx:
22
+ configuration: docs/source/conf.py
23
+
24
+ python:
25
+ install:
26
+ - requirements: docs/source/requirements.txt
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div align="center">
2
+
3
+ <img src="lamassu-logo.png" width="30%"/>
4
+
5
+ </div>
6
+
7
+ ![Python Version][Python Version Badge]
8
+ [![GitHub Workflow Status][GitHub Workflow Status badge]][GitHub Workflow Status URL]
9
+ [![Read the Docs][Read the Docs badge]][Read the Docs URL]
10
+ [![PyPI][PyPI project badge]][PyPI project url]
11
+ [![Apache License badge]][Apache License URL]
12
+
13
+ Lamassu
14
+ =======
15
+
16
+ Lamassu is a project that empowers individual to agnostically run machine learning algorithms to produce ad-hoc NLP
17
+ features.
18
+
19
+ Documentation
20
+ -------------
21
+
22
+ [**Lamassu is in beta development phase for the moment**](https://lamassu.readthedocs.io/en/latest/)
23
+
24
+ License
25
+ -------
26
+
27
+ The use and distribution terms for Lamassu are covered by the
28
+ [Apache License, Version 2.0][Apache License, Version 2.0].
29
+
30
+ <div align="center">
31
+ <a href="https://opensource.org/licenses">
32
+ <img align="center" width="50%" alt="License Illustration" src="https://github.com/QubitPi/QubitPi/blob/master/img/apache-2.png?raw=true">
33
+ </a>
34
+ </div>
35
+
36
+ [Apache License badge]: https://img.shields.io/badge/Apache%202.0-F25910.svg?style=for-the-badge&logo=Apache&logoColor=white
37
+ [Apache License URL]: https://www.apache.org/licenses/LICENSE-2.0
38
+ [Apache License, Version 2.0]: http://www.apache.org/licenses/LICENSE-2.0.html
39
+
40
+ [GitHub Workflow Status badge]: https://img.shields.io/github/actions/workflow/status/QubitPi/lamassu/ci-cd.yml?logo=github&style=for-the-badge
41
+ [GitHub Workflow Status URL]: https://github.com/QubitPi/lamassu/actions/workflows/ci-cd.yml
42
+
43
+ [Python Version Badge]: https://img.shields.io/badge/Python-3.10-brightgreen?style=for-the-badge&logo=python&logoColor=white
44
+ [PyPI project badge]: https://img.shields.io/pypi/v/lamassu?logo=pypi&logoColor=white&style=for-the-badge
45
+ [PyPI project url]: https://pypi.org/project/lamassu/
46
+
47
+ [Read the Docs badge]: https://img.shields.io/readthedocs/lamassu?style=for-the-badge&logo=readthedocs&logoColor=white&label=Read%20the%20Docs&labelColor=8CA1AF
48
+ [Read the Docs URL]: https://lamassu.readthedocs.io/en/latest/
docs/Makefile ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright Jiaqi Liu
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Minimal makefile for Sphinx documentation
16
+ #
17
+
18
+ # You can set these variables from the command line, and also
19
+ # from the environment for the first two.
20
+ SPHINXOPTS ?=
21
+ SPHINXBUILD ?= sphinx-build
22
+ SOURCEDIR = source
23
+ BUILDDIR = build
24
+
25
+ # Put it first so that "make" without argument is like "make help".
26
+ help:
27
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
28
+
29
+ .PHONY: help Makefile
30
+
31
+ # Catch-all target: route all unknown targets to Sphinx using the new
32
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
33
+ %: Makefile
34
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
docs/make.bat ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @ECHO OFF
2
+
3
+ pushd %~dp0
4
+
5
+ REM Command file for Sphinx documentation
6
+
7
+ if "%SPHINXBUILD%" == "" (
8
+ set SPHINXBUILD=sphinx-build
9
+ )
10
+ set SOURCEDIR=source
11
+ set BUILDDIR=build
12
+
13
+ if "%1" == "" goto help
14
+
15
+ %SPHINXBUILD% >NUL 2>NUL
16
+ if errorlevel 9009 (
17
+ echo.
18
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19
+ echo.installed, then set the SPHINXBUILD environment variable to point
20
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
21
+ echo.may add the Sphinx directory to PATH.
22
+ echo.
23
+ echo.If you don't have Sphinx installed, grab it from
24
+ echo.http://sphinx-doc.org/
25
+ exit /b 1
26
+ )
27
+
28
+ %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29
+ goto end
30
+
31
+ :help
32
+ %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33
+
34
+ :end
35
+ popd
docs/source/conf.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # This file only contains a selection of the most common options. For a full
4
+ # list see the documentation:
5
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
6
+
7
+ # -- Path setup --------------------------------------------------------------
8
+
9
+ # If extensions (or modules to document with autodoc) are in another directory,
10
+ # add these directories to sys.path here. If the directory is relative to the
11
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
12
+ #
13
+ import os
14
+ import sys
15
+ sys.path.insert(0, os.path.abspath('../../'))
16
+
17
+
18
+ # -- Project information -----------------------------------------------------
19
+
20
+ project = 'lamassu'
21
+ copyright = '2023, Jiaqi Liu'
22
+ author = 'Jiaqi Liu'
23
+
24
+ # The full version, including alpha/beta/rc tags
25
+ release = '0.1.0'
26
+
27
+
28
+ # -- General configuration ---------------------------------------------------
29
+
30
+ # Add any Sphinx extension module names here, as strings. They can be
31
+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32
+ # ones.
33
+ extensions = [
34
+ 'sphinx.ext.autodoc',
35
+ 'hoverxref.extension',
36
+ 'notfound.extension',
37
+ 'sphinx.ext.coverage',
38
+ 'sphinx.ext.intersphinx',
39
+ 'sphinx.ext.viewcode',
40
+ "sphinx.ext.graphviz",
41
+ "pyan.sphinx"
42
+ ]
43
+
44
+ # add graphviz options
45
+ graphviz_output_format = "svg"
46
+
47
+ # Add any paths that contain templates here, relative to this directory.
48
+ templates_path = ['_templates']
49
+
50
+ # List of patterns, relative to source directory, that match files and
51
+ # directories to ignore when looking for source files.
52
+ # This pattern also affects html_static_path and html_extra_path.
53
+ exclude_patterns = []
54
+
55
+
56
+ # -- Options for HTML output -------------------------------------------------
57
+
58
+ # The theme to use for HTML and HTML Help pages. See the documentation for
59
+ # a list of builtin themes.
60
+ #
61
+ html_theme = 'sphinx_rtd_theme'
62
+
63
+ # Add any paths that contain custom static files (such as style sheets) here,
64
+ # relative to this directory. They are copied after the builtin static files,
65
+ # so a file named "default.css" will overwrite the builtin "default.css".
66
+ html_static_path = ['_static']
67
+
68
+ intersphinx_mapping = {
69
+ 'attrs': ('https://www.attrs.org/en/stable/', None),
70
+ 'coverage': ('https://coverage.readthedocs.io/en/stable', None),
71
+ 'cryptography': ('https://cryptography.io/en/latest/', None),
72
+ 'cssselect': ('https://cssselect.readthedocs.io/en/latest', None),
73
+ 'itemloaders': ('https://itemloaders.readthedocs.io/en/latest/', None),
74
+ 'pytest': ('https://docs.pytest.org/en/latest', None),
75
+ 'python': ('https://docs.python.org/3', None),
76
+ 'sphinx': ('https://www.sphinx-doc.org/en/master', None),
77
+ 'tox': ('https://tox.wiki/en/latest/', None),
78
+ 'twisted': ('https://docs.twisted.org/en/stable/', None),
79
+ 'twistedapi': ('https://docs.twisted.org/en/stable/api/', None),
80
+ 'w3lib': ('https://w3lib.readthedocs.io/en/latest', None),
81
+ }
82
+ intersphinx_disabled_reftypes = []
83
+
84
+ hoverxref_auto_ref = True
85
+ hoverxref_role_types = {
86
+ "class": "tooltip",
87
+ "command": "tooltip",
88
+ "confval": "tooltip",
89
+ "hoverxref": "tooltip",
90
+ "mod": "tooltip",
91
+ "ref": "tooltip",
92
+ "reqmeta": "tooltip",
93
+ "setting": "tooltip",
94
+ "signal": "tooltip",
95
+ }
96
+ hoverxref_roles = ['command', 'reqmeta', 'setting', 'signal']
docs/source/faq.rst ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. _faq:
2
+
3
+ ==========================
4
+ Frequently Asked Questions
5
+ ==========================
6
+
7
+
8
+ Python Sphinx Autodoc Is Not Rendering on readthedocs
9
+ =====================================================
10
+
11
+ The project's dependencies are not specified on RTD, but instead have installed the dependencies locally. We can verify
12
+ this in the `build log <https://readthedocs.org/api/v2/build/17857935.txt>`_. Visit the project's Builds, click a build,
13
+ and click "view raw"::
14
+
15
+ WARNING: autodoc: failed to import module 'rnn' from module 'lamassu'; the following exception was raised:
16
+ No module named 'matplotlib'
17
+
18
+ To remedy the situation, we must specify that the project's dependencies to be installed. See
19
+ `Specifying Dependencies <https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html>`_.
20
+
21
+
22
+ Generate Sphinx Documentation Locally
23
+ =====================================
24
+
25
+ This site is auto-generated using `Sphinx <https://www.sphinx-doc.org/en/master/>`_ with the following command in venv::
26
+
27
+ cd /path/to/lamassu/
28
+ python3 -m venv venv
29
+ source venv/bin/activate
30
+ pip3 install .
31
+ pip3 install -r docs/source/requirements.txt
32
+ sphinx-build -a -b html docs/source/ /path/to/html/output/dir
33
+ deactivate
34
+
35
+ .. NOTE::
36
+ The command above works for Linux/UNIX systems. Some commands will
37
+ `differ on Windows OS <https://realpython.com/python-virtual-environments-a-primer/>`_
38
+
39
+
40
+ Install Lamassu from Source Locally
41
+ ===================================
42
+
43
+ We recommend creating a virtualenv for your application and activate it
44
+
45
+ Navigate to the ``lamassu`` root directory and run::
46
+
47
+ pip3 install -e .
48
+
49
+ For more general information, please refer to the
50
+ `Hitchhiker's Guide to Python <https://docs.python-guide.org/writing/structure/#structuring-your-project>`_: "Structuring Your Project".
51
+
52
+
53
+ "module 'collections' has no attribute 'Callable' Error When Running nosetests
54
+ ==============================================================================
55
+
56
+ First, uninstall nose with the following command::
57
+
58
+ pip3 uninstall -y nose
59
+
60
+ Second, reinstall nose but with ``--nobinaries`` flag::
61
+
62
+ pip3 install -U nose --no-binary :all:
63
+
64
+ Why does this work? At the time of this writing the binary generated by nose was likely generated with a version of
65
+ Python 3.4 or older. This command forces to rebuild from source.
66
+
67
+
68
+ No module named 'pytest' while Running Test Directly in PyCharm
69
+ ===============================================================
70
+
71
+ "Right-click" run a ``test_**.py`` file results in::
72
+
73
+ Traceback (most recent call last):
74
+ File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py", line 5, in <module>
75
+ import pytest
76
+ ModuleNotFoundError: No module named 'pytest'
77
+
78
+ The solution is going to '**Settings** -> **Tools** -> **Python Integrated Tools**' and scroll down to where it says
79
+ `pytest not found` and there is a **FIX** button. Clicking on it and apply the settings shall resolve the problem
docs/source/img/architecture-rnn-ltr.png ADDED
docs/source/img/architecture-rnn-ltr.psd ADDED
docs/source/img/description-block-rnn-ltr.png ADDED
docs/source/img/description-block-rnn-ltr.psd ADDED
docs/source/img/gradient-clipping.png ADDED
docs/source/img/rnn-many-to-many-different-ltr.png ADDED
docs/source/img/rnn-many-to-many-same-ltr.png ADDED
docs/source/img/rnn-many-to-one-ltr.png ADDED
docs/source/img/rnn-one-to-many-ltr.png ADDED
docs/source/img/rnn-one-to-one-ltr.png ADDED
docs/source/index.rst ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ =====================
2
+ Lamassu documentation
3
+ =====================
4
+
5
+
6
+ Getting help
7
+ ============
8
+
9
+ Having trouble? We'd like to help!
10
+
11
+ * Try the :doc:`FAQ <faq>` -- it's got answers to some common questions.
12
+ * Looking for specific information? Try the :ref:`genindex` or :ref:`modindex`.
13
+ * Report bugs with lamassu in our `issue tracker`_.
14
+ * Join the Discord community `Lamassu Discord`_.
15
+
16
+ .. hint::
17
+ * Since methods with two underscores (`__`) cannot be tested due to the
18
+ `name mangling <https://qubitpi.github.io/cpython/tutorial/classes.html#private-variables>`_. Lamassu requires
19
+ all private methods and attributes to be prefixed with **single underscore prefix (`_`) only**
20
+ * The phrase "Chinese" used throughout this documentation referse to "**Simplified Chinese**", instead of
21
+ "Traditional Chinese"
22
+
23
+
24
+ First Steps
25
+ ===========
26
+
27
+ .. toctree::
28
+ :caption: First steps
29
+ :hidden:
30
+
31
+ intro/install
32
+
33
+ :doc:`intro/install`
34
+ Get lamassu installed on your computer.
35
+
36
+
37
+ Usage
38
+ =====
39
+
40
+ .. toctree::
41
+ :maxdepth: 100
42
+
43
+ lamassu
44
+
45
+ .. _issue tracker: https://github.com/QubitPi/lamassu/issues
46
+ .. _Lamassu Discord: https://discord.com/widget?id=1208960229002317934&theme=dark
docs/source/intro/install.rst ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. _intro-install:
2
+
3
+ ==================
4
+ Installation guide
5
+ ==================
6
+
7
+
8
+ Supported Python versions
9
+ =========================
10
+
11
+ Lamassu has been tested with Python 3.10. It may work with older versions of Python but it is not guaranteed.
12
+
13
+
14
+ Installing Lamassu
15
+ ==================
16
+
17
+ If you are already familiar with installation of Python packages, we can install Lamassu and its dependencies from
18
+ `PyPI <https://pypi.org/project/lamassu/>`_ with::
19
+
20
+ pip3 install lamassu
21
+
22
+ We strongly recommend that you install Lamassu in :ref:`a dedicated virtualenv <intro-using-virtualenv>`, to avoid
23
+ conflicting with your system packages.
24
+
25
+ If you're using `Anaconda <https://docs.anaconda.com/anaconda/>`_ or
26
+ `Miniconda <https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html>`_, please allow me to
27
+ apologize because I hate those two, so we won't install the package from there.
28
+
29
+
30
+ Installing from Source
31
+ ======================
32
+
33
+ When we want to apply a bug fix quicly by installing Lamassu locally, we can use::
34
+
35
+ git clone https://github.com/QubitPi/lamassu.git
36
+ cd lamassu
37
+ pip3 install -e .
38
+
39
+
40
+ .. _intro-using-virtualenv:
41
+
42
+ Using a virtual environment (recommended)
43
+ -----------------------------------------
44
+
45
+ We recommend installing lamassu a virtual environment on all platforms.
46
+
47
+ Python packages can be installed either globally (a.k.a system wide), or in user-space. We do not recommend installing
48
+ lamassu system wide. Instead, we recommend installing lamassu within a "virtual environment" (:mod:`venv`),
49
+ which keep you from conflicting with already-installed Python system packages.
50
+
51
+ See :ref:`tut-venv` on how to create your virtual environment.
52
+
53
+ Once you have created a virtual environment, we can install lamassu inside it with ``pip3``, just like any other
54
+ Python package.
docs/source/lamassu.rst ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ =======
2
+ Lamassu
3
+ =======
4
+
5
+
6
+ Machine Learning
7
+ ================
8
+
9
+ .. toctree::
10
+ :maxdepth: 100
11
+
12
+ machine_learning/rnn
docs/source/machine_learning/rnn.rst ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ================================================
2
+ Introduction to Recurrent Neural Networks (RNNs)
3
+ ================================================
4
+
5
+ .. contents:: Table of Contents
6
+ :depth: 2
7
+
8
+
9
+ .. automodule:: lamassu.rnn.vanilla
10
+ :members:
11
+ :undoc-members:
12
+ :show-inheritance:
13
+
14
+
15
+ Mathematical Formulation
16
+ ------------------------
17
+
18
+ Recurrent neural networks, also known as RNNs, are a class of neural networks that allow previous outputs to be used as
19
+ inputs while having hidden states. They are typically as follows:
20
+
21
+ .. figure:: ../img/architecture-rnn-ltr.png
22
+ :align: center
23
+
24
+ For each timestep :math:`t` the activation :math:`a^{\langle t \rangle}` and the output :math:`y^{\langle t \rangle}` are expressed as follows:
25
+
26
+ .. math::
27
+
28
+ h^{\langle t \rangle} = g_1\left( W_{hh}h^{\langle t - 1 \rangle} + W_{hx}x^{\langle t \rangle} + b_h \right)
29
+
30
+ y^{\langle t \rangle} = g_2\left( W_{yh}h^{\langle t \rangle} + b_y \right)
31
+
32
+ where :math:`W_{hx}`, :math:`W_{hh}`, :math:`W_{yh}`, :math:`b_h`, :math:`b_y` are coefficients that are shared temporally and :math:`g_1`, :math:`g_2` are activation functions.
33
+
34
+ .. figure:: ../img/description-block-rnn-ltr.png
35
+ :align: center
36
+
37
+ A Python implementation of network above, as an example, could be as follows:
38
+
39
+ .. code-block:: python
40
+
41
+ import numpy as np
42
+ from math import exp
43
+
44
+ np.random.seed(0)
45
+ class VanillaRecurrentNetwork(object):
46
+
47
+ def __init__(self):
48
+ self.hidden_state = np.zeros((3, 3))
49
+ self.W_hh = np.random.randn(3, 3)
50
+ self.W_xh = np.random.randn(3, 3)
51
+ self.W_hy = np.random.randn(3, 3)
52
+ self.Bh = np.random.randn(3,)
53
+ self.By = np.random.rand(3,)
54
+
55
+ self.hidden_state_activation_function = lambda x : np.tanh(x)
56
+ self.y_activation_function = lambda x : x
57
+
58
+ def forward_prop(self, x):
59
+ self.hidden_state = self.hidden_state_activation_function(
60
+ np.dot(self.hidden_state, self.W_hh) + np.dot(x, self.W_xh) + self.Bh
61
+ )
62
+
63
+ return self.y_activation_function(self.W_hy.dot(self.hidden_state) + self.By)
64
+
65
+ Notice the weight matrix above are randomly initialized. This makes it a "silly" network that doesn't help us anything
66
+ good:
67
+
68
+ .. code-block:: python
69
+
70
+ input_vector = np.ones((3, 3))
71
+ silly_network = RecurrentNetwork()
72
+
73
+ # Notice that same input, but leads to different ouptut at every single time step.
74
+ print silly_network.forward_prop(input_vector)
75
+ print silly_network.forward_prop(input_vector)
76
+ print silly_network.forward_prop(input_vector)
77
+
78
+ # this gives us
79
+ [[-1.73665315 -2.40366542 -2.72344361]
80
+ [ 1.61591482 1.45557046 1.13262256]
81
+ [ 1.68977504 1.54059305 1.21757531]]
82
+ [[-2.15023381 -2.41205828 -2.71701457]
83
+ [ 1.71962883 1.45767515 1.13101034]
84
+ [ 1.80488553 1.542929 1.21578594]]
85
+ [[-2.15024751 -2.41207375 -2.720968 ]
86
+ [ 1.71963227 1.45767903 1.13200175]
87
+ [ 1.80488935 1.54293331 1.21688628]]
88
+
89
+ This is because we haven't train our RNN network yet, which we discuss next
90
+
91
+ Training
92
+ --------
93
+
94
+ .. admonition:: Prerequisite
95
+
96
+ We would assume some basic Artificial Neural Network concepts, which are drawn from *Chapter 4 - Artificial Neural
97
+ Networks* (p. 81) of `MACHINE LEARNING by Mitchell, Thom M. (1997)`_ Paperback. Please, if possible, read the
98
+ chapter beforehand and refer to it if something looks confusing in the discussion of this section
99
+
100
+ In the case of a recurrent neural network, we are essentially backpropagation through time, which means that we are
101
+ forwarding through entire sequence to compute losses, then backwarding through entire sequence to compute gradients.
102
+ Formally, the `loss function`_ :math:`\mathcal{L}` of all time steps is defined as the sum of
103
+ the loss at every time step:
104
+
105
+ .. math::
106
+
107
+ \mathcal{L}\left( \hat{y}, y \right) = \sum_{t = 1}^{T_y}\mathcal{L}\left( \hat{y}^{<t>}, y^{<t>} \right)
108
+
109
+ However, this becomes problematic when we want to train a sequence that is very long. For example, if we were to train a
110
+ a paragraph of words, we have to iterate through many layers before we can compute one simple gradient step. In
111
+ practice, for the back propagation, we examine how the output at the very *last* timestep affects the weights at the
112
+ very first time step. Then we can compute the gradient of loss function, the details of which can be found in the
113
+ `Vanilla RNN Gradient Flow & Vanishing Gradient Problem`_
114
+
115
+ .. admonition:: Gradient Clipping
116
+
117
+ Gradient clipping is a technique used to cope with the `exploding gradient`_ problem sometimes encountered when
118
+ performing backpropagation. By capping the maximum value for the gradient, this phenomenon is controlled in
119
+ practice.
120
+
121
+ .. figure:: ../img/gradient-clipping.png
122
+ :align: center
123
+
124
+ In order to remedy the vanishing gradient problem, specific gates are used in some types of RNNs and usually have a
125
+ well-defined purpose. They are usually noted :math:`\Gamma` and are defined as
126
+
127
+ .. math::
128
+
129
+ \Gamma = \sigma(Wx^{<t>} + Ua^{<t - 1>} + b)
130
+
131
+ where :math:`W`, :math:`U`, and :math:`b` are coefficients specific to the gate and :math:`\sigma` is the sigmoid
132
+ function
133
+
134
+ LSTM Formulation
135
+ ^^^^^^^^^^^^^^^^
136
+
137
+ Now we know that Vanilla RNN has Vanishing/exploding gradient problem, `LSTM Formulation`_ discusses the theory of LSTM
138
+ which is used to remedy this problem.
139
+
140
+ Applications of RNNs
141
+ --------------------
142
+
143
+ RNN models are mostly used in the fields of natural language processing and speech recognition. The different
144
+ applications are summed up in the table below:
145
+
146
+ .. list-table:: Applications of RNNs
147
+ :widths: 20 60 20
148
+ :align: center
149
+ :header-rows: 1
150
+
151
+ * - Type of RNN
152
+ - Illustration
153
+ - Example
154
+ * - | One-to-one
155
+ | :math:`T_x = T_y = 1`
156
+ - .. figure:: ../img/rnn-one-to-one-ltr.png
157
+ - Traditional neural network
158
+ * - | One-to-many
159
+ | :math:`T_x = 1`, :math:`T_y > 1`
160
+ - .. figure:: ../img/rnn-one-to-many-ltr.png
161
+ - Music generation
162
+ * - | Many-to-one
163
+ | :math:`T_x > 1`, :math:`T_y = 1`
164
+ - .. figure:: ../img/rnn-many-to-one-ltr.png
165
+ - Sentiment classification
166
+ * - | Many-to-many
167
+ | :math:`T_x = T_y`
168
+ - .. figure:: ../img/rnn-many-to-many-same-ltr.png
169
+ - Named entity recognition
170
+ * - | Many-to-many
171
+ | :math:`T_x \ne T_y`
172
+ - .. figure:: ../img/rnn-many-to-many-different-ltr.png
173
+ - Machine translation
174
+
175
+ .. _`exploding gradient`: https://qubitpi.github.io/stanford-cs231n.github.io/rnn/#vanilla-rnn-gradient-flow--vanishing-gradient-problem
176
+
177
+ .. _`MACHINE LEARNING by Mitchell, Thom M. (1997)`: https://a.co/d/bjmsEOg
178
+
179
+ .. _`loss function`: https://qubitpi.github.io/stanford-cs231n.github.io/neural-networks-2/#losses
180
+ .. _`LSTM Formulation`: https://qubitpi.github.io/stanford-cs231n.github.io/rnn/#lstm-formulation
181
+
182
+ .. _`Vanilla RNN Gradient Flow & Vanishing Gradient Problem`: https://qubitpi.github.io/stanford-cs231n.github.io/rnn/#vanilla-rnn-gradient-flow--vanishing-gradient-problem
docs/source/requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ sphinx==5.0.2
2
+ sphinx-hoverxref==1.1.1
3
+ sphinx-notfound-page==0.8
4
+ sphinx-rtd-theme==1.0.0
5
+ pycodestyle
6
+ requests
7
+ pyan3
lamassu-logo.png ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ numpy
rnn/vanilla.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from math import exp
3
+
4
+ np.random.seed(0)
5
+ class VanillaRecurrentNetwork(object):
6
+
7
+ def __init__(self):
8
+ self.hidden_state = np.zeros((3, 3))
9
+ self.W_hh = np.random.randn(3, 3)
10
+ self.W_xh = np.random.randn(3, 3)
11
+ self.W_hy = np.random.randn(3, 3)
12
+ self.Bh = np.random.randn(3,)
13
+ self.By = np.random.rand(3,)
14
+
15
+ self.hidden_state_activation_function = lambda x : np.tanh(x)
16
+ self.y_activation_function = lambda x : x
17
+
18
+ self.loss_funciton = lambda y : exp(y) / np.sum(exp(y))
19
+
20
+ def forward_prop(self, x):
21
+ self.hidden_state = self.hidden_state_activation_function(
22
+ np.dot(self.hidden_state, self.W_hh) + np.dot(x, self.W_xh) + self.Bh
23
+ )
24
+
25
+ return self.y_activation_function(self.W_hy.dot(self.hidden_state) + self.By)
setup.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="lamassu",
5
+ version="0.0.8",
6
+ description="Empowering individual to agnostically run machine learning algorithms to produce ad-hoc AI features",
7
+ url="https://github.com/QubitPi/lamassu",
8
+ author="Jiaqi liu",
9
+ author_email="[email protected]",
10
+ license="Apache-2.0",
11
+ packages=find_packages(),
12
+ python_requires='>=3.10',
13
+ install_requires=[
14
+
15
+ ],
16
+ zip_safe=False,
17
+ include_package_data=True
18
+ )