项目作者: jpuigcerver

项目描述 :
Probabilistic relevance scores from PHOC embeddings
高级语言: Shell
项目地址: git://github.com/jpuigcerver/prob-phoc.git
创建时间: 2018-05-14T16:22:02Z
项目社区:https://github.com/jpuigcerver/prob-phoc

开源协议:MIT License

下载


prob-phoc

Build Status

PyTorch functions to compute meaningful probabilistic relevance scores from
PHOC (Pyramid of Histograms of Characters) embeddings.
Although they are called Pyramid of Histograms of Characters, in practice
they are a Pyramid of Bag of Characters. At the end, each word is
represented by a high-dimensional binary vector.

See the wiki
for additional details.

Usage

The library provides two functions: cphoc and pphoc, which are
similar to SciPy’s cdist and pdist:

Both functions can operate with PHOC embeddings in the probability space (where
each dimension is a real number in the range [0, 1]), or in the log-probability
space (where each dimension is the logarithm of a probability). These are also
sometimes refered to as the Real and Log semirings.

  1. import torch
  2. from prob_phoc import cphoc, pphoc
  3. x = torch.Tensor(...)
  4. y = torch.Tensor(...)
  5. # Compute the log-relevance scores between all pairs of rows in x, y.
  6. # Note: x and y must have the PHOC log-probabilities.
  7. logprob = cphoc(x, y)
  8. # This is equivalent to:
  9. logprob = cphoc(x, y, method="sum_prod_log")
  10. # If your matrices have probabilities instead of log-probabilities, use:
  11. prob = cphoc(x, y, method="sum_prob_real")
  12. # Compute the log-relevance scores between all pairs of distinct rows in x.
  13. # Note: The output is a vector with N * (N - 1) / 2 elements.
  14. logprob = pphoc(x)

Installation

The easiest way is to install the package from PyPI:

  1. pip install prob-phoc

If you want to install the latest version from the repository, clone it
and use the setup.py script to compile and install the library.

  1. python setup.py install

You will need a C++11 compiler (tested with GCC 4.9).
If you want to compile with CUDA support, you will also need to install
the CUDA Toolkit (tested with versions 8.0, 9.0 and 10.0)

Tests and benchmarks

After the installation, you can run the tests to ensure that everything is
working fine.

  1. python -m prob_phoc.test

I have also some benchmarks to compare CPU vs. CUDA, for different matrix
sizes and float precision. These take quite a long to run, so don’t hold
your breath.

  1. python -m prob_phoc.benchmark