This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Help us improve Python packaging - Donate today!
Project Description

Hidden alignment conditional random field for classifying string pairs - a learnable edit distance.

This package aims to implement the HACRF machine learning model with a sklearn-like interface. It includes ways to fit a model to training examples and score new example.

The model takes string pairs as input and classify them into any number of classes. In McCallum’s original paper the model was applied to the database deduplication problem. Each database entry was paired with every other entry and the model then classified whether the pair was a ‘match’ or a ‘mismatch’ based on training examples of matches and mismatches.

I also tried to use it as learnable string edit distance for normalizing noisy text. See A Conditional Random Field for Discriminatively-trained Finite-state String Edit Distance by McCallum, Bellare, and Pereira, and the report Conditional Random Fields for Noisy text normalisation by Dirko Coetsee.

Example

from pyhacrf import StringPairFeatureExtractor, Hacrf

training_X = [('helloooo', 'hello'), # Matching examples
              ('h0me', 'home'),
              ('krazii', 'crazy'),
              ('non matching string example', 'no really'), # Non-matching examples
              ('and another one', 'yep')]
training_y = ['match',
              'match',
              'match',
              'non-match',
              'non-match']

# Extract features
feature_extractor = StringPairFeatureExtractor(match=True, numeric=True)
training_X_extracted = feature_extractor.fit_transform(training_X)

# Train model
model = Hacrf(l2_regularization=1.0)
model.fit(training_X_extracted, training_y)

# Evaluate
from sklearn.metrics import confusion_matrix
predictions = model.predict(training_X_extracted)

print(confusion_matrix(training_y, predictions))
> [[0 3]
>  [2 0]]

print(model.predict_proba(training_X_extracted))
> [[ 0.94914812  0.05085188]
>  [ 0.92397711  0.07602289]
>  [ 0.86756034  0.13243966]
>  [ 0.05438812  0.94561188]
>  [ 0.02641275  0.97358725]]

Dependencies

This package depends on numpy. The LBFGS optimizer in pylbfgs is used, but alternative optimizers can be passed.

Install

Install by running:

python setup.py install

or from pypi:

pip install pyhacrf

Developing

Clone from repository, then

pip install -r requirements.txt
cython pyhacrf/*.pyx
python setup.py install

To deploy to pypi, make sure you have compiled the *.pyx files to *.c

Release History

Release History

0.2.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pyhacrf_datamade-0.2.1-cp27-cp27m-macosx_10_11_x86_64.whl (208.1 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp27-cp27m-manylinux1_i686.whl (664.8 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp27-cp27m-manylinux1_x86_64.whl (712.9 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp27-cp27mu-manylinux1_i686.whl (664.7 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp27-cp27mu-manylinux1_x86_64.whl (713.0 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp27-cp27m-win32.whl (148.7 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp27-cp27m-win_amd64.whl (177.8 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp34-cp34m-manylinux1_i686.whl (685.6 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp34-cp34m-manylinux1_x86_64.whl (729.7 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp34-cp34m-win32.whl (143.4 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp34-cp34m-win_amd64.whl (164.2 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp35-cp35m-manylinux1_i686.whl (676.0 kB) Copy SHA256 Checksum SHA256 cp35 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp35-cp35m-manylinux1_x86_64.whl (722.3 kB) Copy SHA256 Checksum SHA256 cp35 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp36-cp36m-macosx_10_11_x86_64.whl (200.8 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp36-cp36m-manylinux1_i686.whl (682.4 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-cp36-cp36m-manylinux1_x86_64.whl (727.8 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Mar 27, 2017
pyhacrf_datamade-0.2.1-py2.7-win32.egg (146.9 kB) Copy SHA256 Checksum SHA256 2.7 Egg Mar 27, 2017
pyhacrf_datamade-0.2.1-py2.7-win-amd64.egg (176.0 kB) Copy SHA256 Checksum SHA256 2.7 Egg Mar 27, 2017
pyhacrf_datamade-0.2.1-py3.4-win32.egg (141.6 kB) Copy SHA256 Checksum SHA256 3.4 Egg Mar 27, 2017
pyhacrf_datamade-0.2.1-py3.4-win-amd64.egg (162.3 kB) Copy SHA256 Checksum SHA256 3.4 Egg Mar 27, 2017
pyhacrf-datamade-0.2.1.tar.gz (255.8 kB) Copy SHA256 Checksum SHA256 Source Mar 27, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting