Skip to main content

An implementation of Monroe et. al's Fightin' Words Analysis

Project description

A scikit-learn compliant implementation of Monroe et al.’s Fightin’ Words analysis method.

Features

  • Computes a (word, z-score) result for a pair of text corpora.

  • Works with scikit-learn estimators and pipelines.

Installation

Distributed via PyPI:

pip install fightin-words

Usage

fightin-words implements FWExtractor, which inherits from the scikit-learn BaseEstimator and TransformerMixin.

Example:

import fightin-words as fw
import sklearn.feature_extraction.text as sk_text

# Strings/text corpora to be compared
l1 = 'The quick brown fox jumps over the lazy pig'
l2 = 'The lazy purple pig jumps over the lazier donkey'

# Extractor configuration parameters
prior = 0.05
cv = sk_text.CountVectorizer(max_features=15000)

fw.FWExtractor(prior, cv).fit_transform([l1, l2])

Note that to maintain parity with scikit-learn conventions, fit_transform takes in one variable (the canonical X for samples/features). Therefore the two strings to be compared should be marshaled into a single sequence-type (list or tuple) variable.

prior and cv do not need to be specified. prior defaults to 0.01, and cv defaults to a naively initialized scikit-learn CountVectorizer. If a list of precomputed priors is specified, it is expected that the user also passes in a vectorizer that is responsible for producing a vocabulary whose dimensionality matches the precomputed priors—we do not check for that.

Credits

The original implementation by Jack Hessel at the Department of Computer Science, Cornell University. This version heavily borrows from it for the core computation. A more eloquent description of the algorithm is available there as well.

Monroe, B. L., Colaresi, M. P., & Quinn, K. M. (2008). Fightin’words: Lexical feature selection and evaluation for identifying the content of political conflict. Political Analysis, 16(4), 372–403.

@article{monroe2008fightin,
  title={Fightin' words: Lexical feature selection and evaluation for identifying the content of political conflict},
  author={Monroe, Burt L and Colaresi, Michael P and Quinn, Kevin M},
  journal={Political Analysis},
  volume={16},
  number={4},
  pages={372--403},
  year={2008},
  publisher={SPM-PMSAPSA}
}

LICENSE

The MIT License (MIT) Copyright (c) 2019 Kenneth Lim

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

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

Source Distribution

fightin-words-1.0.5.tar.gz (5.3 kB view details)

Uploaded Source

Built Distributions

fightin_words-1.0.5-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

fightin_words-1.0.5-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file fightin-words-1.0.5.tar.gz.

File metadata

  • Download URL: fightin-words-1.0.5.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.5.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.16

File hashes

Hashes for fightin-words-1.0.5.tar.gz
Algorithm Hash digest
SHA256 d7bb79a7ac4aa15b5c0a6cc8fdccd5bc69c78778a56fc34e33b11d17b08fb1b9
MD5 b849987e0ca65311a15ac6cb22bce37c
BLAKE2b-256 35cc641312506c1df923069bc7233325b78a7f47ed2d241ce9dc977da01c97a3

See more details on using hashes here.

File details

Details for the file fightin_words-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: fightin_words-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.5.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.16

File hashes

Hashes for fightin_words-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 177a0ebe57f142800e69801f7ff481fbf6303f8e620522ab9382fa820b16010a
MD5 800ace8db41d415d397f9d4ee8cc78a5
BLAKE2b-256 16bbcc527167c39b1cae2925e58a717b496b9b42c11d9cefab03c936c9296711

See more details on using hashes here.

File details

Details for the file fightin_words-1.0.5-py2.py3-none-any.whl.

File metadata

  • Download URL: fightin_words-1.0.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/38.5.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.16

File hashes

Hashes for fightin_words-1.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cb7f265e3294ed70186ca6426326e8f2172c0b7d822db5a82bc952813a5d39f6
MD5 2cef6941e2764196feeba42178ea6247
BLAKE2b-256 c0e1ca8926b7146171f3fa0b1fd27693418f0a5094ba686ee00e9692668a4198

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page