Skip to main content

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.

Metadata

Release files for fightin-words 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fightin-words 1.0.5
File Size Uploaded
fightin-words-1.0.5.tar.gz 5.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fightin-words 1.0.5
File Interpreter ABI Platform
fightin_words-1.0.5-py3-none-any.whl Python 3 none any Details
fightin_words-1.0.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 17.9 kB

Release files / fightin-words-1.0.5.tar.gz

Download URL fightin-words-1.0.5.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d7bb79a7ac4aa15b5c0a6cc8fdccd5bc69c78778a56fc34e33b11d17b08fb1b9
BLAKE2b-256 checksum
How to use checksums
35cc641312506c1df923069bc7233325b78a7f47ed2d241ce9dc977da01c97a3
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / fightin_words-1.0.5-py3-none-any.whl

Download URL fightin_words-1.0.5-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
177a0ebe57f142800e69801f7ff481fbf6303f8e620522ab9382fa820b16010a
BLAKE2b-256 checksum
How to use checksums
16bbcc527167c39b1cae2925e58a717b496b9b42c11d9cefab03c936c9296711
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / fightin_words-1.0.5-py2.py3-none-any.whl

Download URL fightin_words-1.0.5-py2.py3-none-any.whl
Size 6.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
cb7f265e3294ed70186ca6426326e8f2172c0b7d822db5a82bc952813a5d39f6
BLAKE2b-256 checksum
How to use checksums
c0e1ca8926b7146171f3fa0b1fd27693418f0a5094ba686ee00e9692668a4198
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.5 This release

3 release files

1.0.4

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page