Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
paolodragone committed Mar 25, 2018
1 parent 11c540b commit f841428
Show file tree
Hide file tree
Showing 248 changed files with 7,545 additions and 1,187 deletions.
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: ec1c0fe74ca0e34a685e7ef83366b246
config: d95d9fafc74e858d83bcd9e7baed02a8
tags: 645f666f9bcd5a90fca523b33c5a78b7
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 12 additions & 8 deletions docs/_sources/install.rst.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Install
=======

Weaver can be installed via Pip::
Pyconstruct can be installed via Pip::

pip install pyconstruct

Expand All @@ -10,12 +10,16 @@ on `GitHub <https://github.com/unitn-sml/pyconstruct/releases/latest>`__::

python setup.py install

Currently, Pyconstruct is developed and maintained in Python 3.5 with a
porting to Python 2.7 at every major release (the python2 branch does not always
contain the most recent changes).

Pyconstruct requires PyMzn to be installed on your machine, together with
MiniZinc and at least one solver (e.g. `Gecode <http://www.gecode.org/>`__,
`Gurobi <http://www.gurobi.com/>`__). Check-out `PyMzn installation guide
<http://paolodragone.com/pymzn/install.html>`__ for details.
`MiniZinc <https://github.com/MiniZinc/MiniZincIDE/releases/latest>`. Check-out
`PyMzn installation guide <http://paolodragone.com/pymzn/install.html>`__ for
details.

Alongside MiniZinc, you will need a constraint solver. PyMzn supports many
open-source solvers such as `Gecode <http://www.gecode.org/>` and `Chuffed
<https://github.com/chuffed/chuffed>`. However, we recommend you give `Gurobi
<http://www.gurobi.com/>`__ a try, it's blazingly fast for the kind of problems
we usually solve in structured-output prediction, even more so when adding
constraints to them. If you are in academia, they provide `free licenses
<http://www.gurobi.com/academia/for-universities>` for research purpose.

50 changes: 44 additions & 6 deletions docs/_sources/quick_start.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ constraints and the features of the objects. To do so, we need to create a
]
{% endcall %}

{% endset %}
{% endcall %}

{{ solve(problem, model, discretize=True) }}

Expand Down Expand Up @@ -126,13 +126,51 @@ available in Pyconstruct out-of-the-box. You can load the domain by simply::
ocr_dom = Domain('ocr')

After defining the domain, using the predefined one or the `ocr.pmzn` file, we
can start learning by instantiating a learner, say a `StructuredPerceptron`, and
fitting the data::
can start learning. We first need to instantiate a learner, say a
`StructuredPerceptron`::

from pyconstruct import StructuredPerceptron
sp = StructuredPerceptron(domain=ocr_dom)
sp.fit(ocr.data, ocr.targets)

This will take a while... If you need a quick benchmark, Pyconstruct contains
pretrained models for many domains and learners (link).
Pyconstruct is built to be compatible with most of the available utilities in
Scikit-learn. One thing one would like to do at this point is to shuffle and
split the data into training and test set. We can use Scikit-learn like this::

from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test = train_test_split(ocr.data, ocr.target, test_size=0.05)

Pyconstruct has also its own utilities to deal with structured data. In order
to use train the `StructuredPerceptron` we will need to divide the data in
mini-batches and use its `partial_fit` method.::

from pyconstruct.utils import batches

for X_batch, Y_batch in batches(X_train, Y_train, batch_size=50):
sp.partial_fit(X_batch, Y_batch)

To evaluate the learner we will need a suitable metric. What it usually done
used with OCR is the normalized Hamming loss. Pyconstruct has a Hamming loss
function already available::

from pyconstruct.metrics import hamming

def loss(Y_pred, Y_true):
return hamming(Y_pred, Y_true, key='sequence', normalize=True).mean()

The `hamming` function returns the Hamming distance between each pair of
elements in the input arrays, so we take the mean. We can then compute the loss
over the test set while training::

for X_batch, Y_batch in batches(X_train, Y_train, batch_size=50):
sp.partial_fit(X_batch, Y_batch)
Y_pred = sp.predict(X_test)
print('Loss = {}'.format(loss(Y_pred, Y_test)))

This will take a while, depending on the computational resources you have. You
can parallelize inference by passing `n_jobs` to the `Domain` constructor, as
well as to the `hamming` function. Additionally, if you need a quick benchmark,
Pyconstruct also contains pretrained models for many domains and learners
(link).



This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions docs/_sources/reference/datasets/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ Datasets
load
load_ocr
load_conll00
ocr
conll00
utils

.. automodule:: pyconstruct.datasets

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 5 additions & 4 deletions docs/_sources/reference/domains/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ Domains

.. currentmodule:: pyconstruct.domains

.. toctree::
:maxdepth: 2

predefined

.. autosummary::
:toctree: generated/

get_path
get_source
get_info
print_info
BaseDomain
MiniZincDomain

Expand Down
7 changes: 7 additions & 0 deletions docs/_sources/reference/domains/predefined.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Predefined domains
------------------

.. currentmodule:: pyconstruct.domains.predefined

.. automodule:: pyconstruct.domains.predefined

2 changes: 1 addition & 1 deletion docs/_sources/reference/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is the reference manual of Weaver.
datasets/index
domains/index
learners/index
metrics
metrics/index
models/index
utils/index

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.BaseModel.decision\_function
===============================================

.. currentmodule:: pyconstruct.models

.. automethod:: BaseModel.decision_function
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.BaseModel.loss
=================================

.. currentmodule:: pyconstruct.models

.. automethod:: BaseModel.loss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.BaseModel.margin
===================================

.. currentmodule:: pyconstruct.models

.. automethod:: BaseModel.margin
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.BaseModel.phi
================================

.. currentmodule:: pyconstruct.models

.. automethod:: BaseModel.phi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.BaseModel.predict
====================================

.. currentmodule:: pyconstruct.models

.. automethod:: BaseModel.predict
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pyconstruct.models.BaseModel
============================

.. currentmodule:: pyconstruct.models

.. autoclass:: BaseModel



.. rubric:: Methods

.. autosummary::
:toctree:

~BaseModel.decision_function
~BaseModel.loss
~BaseModel.margin
~BaseModel.phi
~BaseModel.predict





.. rubric:: Attributes

.. autosummary::

~BaseModel.parameters


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.LinearModel.decision\_function
=================================================

.. currentmodule:: pyconstruct.models

.. automethod:: LinearModel.decision_function
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.LinearModel.loss
===================================

.. currentmodule:: pyconstruct.models

.. automethod:: LinearModel.loss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.LinearModel.margin
=====================================

.. currentmodule:: pyconstruct.models

.. automethod:: LinearModel.margin
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.LinearModel.phi
==================================

.. currentmodule:: pyconstruct.models

.. automethod:: LinearModel.phi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyconstruct.models.LinearModel.predict
======================================

.. currentmodule:: pyconstruct.models

.. automethod:: LinearModel.predict
Loading

0 comments on commit f841428

Please sign in to comment.