Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

wheels PyPI version

LP-SparseMAP

Differentiable sparse structured prediction in coarse factor graphs

This repo contains:

  • ad3qp: an updated fork of ad3, supporting the solving of SparseMAP QPs in arbitrary factor graphs. (C++, LGPL license.)

  • dysparsemap: a library that provides a dynet function using ad3qp for forward and backward pass computation for structured hidden layers. (C++, MIT license.)

  • lpsmap: a python wrapper for ad3qp and some example usage scripts. (cython and python, MIT license.) This repository is a work-in-progress, with the end-goal to drastically simplify the AD3 API.

Reference

Vlad Niculae and Andre F. T. Martins. LP-SparseMAP: Differentiable Relaxed Optimization for Sparse Structured Prediction. https://arxiv.org/abs/2001.04437

lpsmap

Requirements:

  • Cython
  • Eigen (if it's a non-standard directory, set EIGEN_DIR=/path/to/eigen.)

For examples and tests: numpy, pytest.

Installation:

pip install lp-sparsemap    # installs a wheel, if available.

In-place installation from source:

# export MACOS_DEPLOYMENT_TARGET=10.14  # on MacOS
export EIGEN_DIR=/path/to/eigen
python setup.py build_clib  # builds ad3 in-place
pip install -e .            # builds lpsmap and creates a link

Using the Cython API from your own code.

You can add custom factors and other extensions by cimporting the base classes provided. (See an example in this project.) The installed lp-sparsemap package provides a copy of libad3 to statically link against. To get the path to it, use lpsmap.config.get_libdir(). Warning: both lp-sparsemap as well as client libraries linking against it should be compiled with the same standard library implementation. On MacOS you may have issues unless MACOS_DEPLOYMENT_TARGET >= 10.14. If you get undefined symbol errors for AD3 symbols, try compiling your code with the same toolchain as the installed lp-sparsemap. (If in doubt, recompile both locally.)

dysparsemap

Requires this patch to dynet in order to make dynet export cmake targets to link against. (sorry, I'm new to cmake and haven't managed to test it and make a PR yet.)

Once the patched dynet is installed, do

cd cbuild
cmake ..
make

Then you can try the dynet gradient check tests that get compiled.

About

LP-SparseMAP: Differentiable sparse structured prediction in coarse factor graphs

Resources

License

Stars

Watchers

Forks

Packages

No packages published