Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation. #104

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Build documentation with MkDocs
#mkdocs:
# configuration: mkdocs.yml

# Optionally build your docs in additional formats such as PDF and ePub
formats: all

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
install:
- requirements: docs/doc-requirements.txt
- method: pip
path: .
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# finalfusion-python
[![Documentation Status](https://readthedocs.org/projects/finalfusion-python/badge/?version=latest)](https://finalfusion-python.readthedocs.io/en/latest/?badge=latest)

## Introduction

Expand Down Expand Up @@ -124,6 +125,7 @@ $ ffp-convert -f fasttext fasttext.bin -t finalfusion embeddings.fifu

## Where to go from here

* [documentation](https://finalfusion-python.readthedocs.io/en/)
* [finalfrontier](https://finalfusion.github.io/finalfrontier)
* [finalfusion](https://finalfusion.github.io/)
* [pretrained embeddings](https://finalfusion.github.io/pretrained)
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -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 = .
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)
14 changes: 14 additions & 0 deletions docs/_static/theme_overrides.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* override table width restrictions */
@media screen and (min-width: 767px) {

.wy-table-responsive table td {
/* !important prevents the common CSS stylesheets from overriding
this as on RTD they are loaded after this stylesheet */
white-space: normal !important;
}

.wy-table-responsive {
overflow: visible !important;
}
}

89 changes: 89 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 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('../../src/'))


# -- Project information -----------------------------------------------------

project = 'finalfusion'
copyright = '2020, The finalfusion contributors'
author = 'Sebastian Pütz'

# The full version, including alpha/beta/rc tags
release = '0.7pre'


# -- 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.coverage',
'sphinx.ext.napoleon',
'sphinx.ext.intersphinx',
'sphinx.ext.autosummary',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
]

napoleon_google_docstring = False
napoleon_numpy_docstring = True
napoleon_include_init_with_doc = True
napoleon_include_special_with_doc = True
napoleon_use_param = False
napoleon_use_ivar = True
autodoc_member_order = 'bysource'
autodoc_inherit_docstrings = True

intersphinx_mapping = {'python': ('http://docs.python.org/3', None),
'numpy': ('http://docs.scipy.org/doc/numpy/', None),
'np': ('http://docs.scipy.org/doc/numpy/', None),}

# 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 = ['_build', 'Thumbs.db', '.DS_Store', '.idea', '.github']


# -- 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']

html_context = {
'css_files': [
'_static/theme_overrides.css', # override wide tables in RTD theme
],
}
html_theme_options = {
# Toc options
'collapse_navigation': False,
'sticky_navigation': True,
'navigation_depth': 4,
'includehidden': True,
'titles_only': False,
'prev_next_buttons_location': 'both'
}
4 changes: 4 additions & 0 deletions docs/doc-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cython
numpy
toml
sphinx>=3
68 changes: 68 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.. finalfusion documentation master file, created by
sphinx-quickstart on Fri May 1 12:35:09 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Finalfusion in Python
=====================

``finalfusion`` is a Python package for reading, writing and using
`finalfusion <https://finalfusion.github.io>`__ embeddings, but also supports other commonly used
embeddings like fastText, GloVe and word2vec.

The Python package supports the same types of embeddings as the
`finalfusion-rust crate <https://docs.rs/finalfusion/>`__:

* Vocabulary

* No subwords
* Subwords

* Embedding matrix

* Array
* Memory-mapped
* Quantized

* Norms
* Metadata

This package extends (de-)serialization capabilities of ``finalfusion`` :class:`~.Chunk`\ s by
allowing loading and writing single chunks. E.g. a :class:`~.Vocab` can be loaded from a
`finalfusion spec <https://finalfusion.github.io/spec>`__ file without loading the
:class:`~.Storage`. Single chunks can also be serialized to their own files
through :meth:`~.Chunk.write`. This is different from the functionality of ``finalfusion-rust``,
loading stand-alone components is only supported by the Python package. Reading will fail with
other tools from the ``finalfusion`` ecosystem.

It integrates nicely with :mod:`.numpy` since its :class:`~.Storage` types can be
treated as numpy arrays.

``finalfusion`` comes with :doc:`ffp-convert <scripts/finalfusion.scripts.ffp-convert>` to convert between
any of the supported embedding formats.

The package is implemented in Python with some ``Cython`` extensions, it is not based on bindings
to the `finalfusion-rust crate <https://github.com/finalfusion/finalfusion-rust/>`__.

Contents
--------
.. toctree::
:hidden:

self

.. toctree::
:maxdepth: 2

quickstart
install
modules/re-exports
modules/api
scripts/finalfusion.scripts.ffp-convert

Indices and tables
------------------

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
41 changes: 41 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Install
=======

``finalfusion`` is compatible with Python ``3.6`` and more recent versions. Direct dependencies
are `numpy <https://numpy.org/>`__ and `toml <https://github.com/uiri/toml>`__.
Installing for ``3.6`` additionally depends on
`dataclasses <https://github.com/ericvsmith/dataclasses>`__.

Pip
----

From Pypi:

``$ pip install finalfusion``

From GitHub:

``$ pip install git+https://github.com/finalfusion/finalfusion-python``

Source
------

Installing from source requires `Cython <http://docs.cython.org/>`__. When ``finalfusion`` is built
with ``pip``, you don't need to install ``Cython`` manually since the dependency is specified in
``pyproject.toml``.


.. code-block:: bash

$ git clone https://github.com/finalfusion/finalfusion-python
$ cd finalfusion-python
$ pip install . # or python setup.py install

Building a wheel from source is possible if `wheel <https://wheel.readthedocs.io/en/stable/>`__
is installed by:

.. code-block:: bash

$ git clone https://github.com/finalfusion/finalfusion-python
$ cd finalfusion-python
$ python setup.py bdist_wheel
14 changes: 14 additions & 0 deletions docs/modules/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
API
===

.. toctree::
:maxdepth: 2

finalfusion.embeddings
storage/finalfusion.storage
vocab/finalfusion.vocab
subword/finalfusion.subword
finalfusion.metadata
finalfusion.norms
finalfusion.io
compat/finalfusion.compat
5 changes: 5 additions & 0 deletions docs/modules/compat/finalfusion.compat.fasttext.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FastText
--------

.. automodule:: finalfusion.compat.fasttext
:members:
23 changes: 23 additions & 0 deletions docs/modules/compat/finalfusion.compat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Compat
======

``finalfusion.compat``

.. autosummary::
finalfusion.compat.load_fasttext
finalfusion.compat.write_fasttext
finalfusion.compat.load_text
finalfusion.compat.write_text
finalfusion.compat.load_text_dims
finalfusion.compat.write_text_dims
finalfusion.compat.load_word2vec
finalfusion.compat.write_word2vec

.. toctree::
:maxdepth: 2
:caption: Content

finalfusion.compat.word2vec
finalfusion.compat.text
finalfusion.compat.fasttext

5 changes: 5 additions & 0 deletions docs/modules/compat/finalfusion.compat.text.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Text
----

.. automodule:: finalfusion.compat.text
:members:
5 changes: 5 additions & 0 deletions docs/modules/compat/finalfusion.compat.word2vec.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Word2Vec
--------

.. automodule:: finalfusion.compat.word2vec
:members:
5 changes: 5 additions & 0 deletions docs/modules/finalfusion.embeddings.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Embeddings
==========

.. automodule:: finalfusion.embeddings
:members:
19 changes: 19 additions & 0 deletions docs/modules/finalfusion.io.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
IO
==

.. autoclass:: finalfusion.io.Chunk
:members:

.. autoclass:: finalfusion.io.ChunkIdentifier
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: finalfusion.io.FinalfusionFormatError
:show-inheritance:

.. autoclass:: finalfusion.io.TypeId
:show-inheritance:
:members:
:undoc-members:

6 changes: 6 additions & 0 deletions docs/modules/finalfusion.metadata.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Metadata
========

.. automodule:: finalfusion.metadata
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/modules/finalfusion.norms.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Norms
=====

.. automodule:: finalfusion.norms
:members:
:show-inheritance:
Loading