Skip to main content

SpaCy Arguing Lexicon

A spaCy extension that wraps around the arguing lexicon by MPQA. It allows easy programmatic access to labeled sentences containing arguing lexicon. Using spaCy you can then apply the latest machine learning technologies with little effort.

Use the arguing lexicon extension for instance for deep argument mining. It is available in English and Dutch.

Getting started

You can install the spaCy extension through pip. It requires spaCy 2.

pip install spacy_arguing_lexicon
python -m spacy download en  # optional, downloads a spaCy language model if you haven't downloaded one already

Then enable the extension by adding the arguing lexicon parser to the spaCy pipeline.

import spacy
from spacy_arguing_lexicon import ArguingLexiconParser

nlp = spacy.load("en")
nlp.add_pipe(ArguingLexiconParser(lang=nlp.lang))

Now you can load any document and access the parts of that document which contain arguments. You access the arguments through the doc._.arguments attribute, which gets added by this extension.

doc = nlp("""
    A changing society should not cling to traditional family models. 
    Society is changing, and the traditional idea of the nuclear family 
    with married mother and father 
    is no longer the only acceptable alternative.
""")

argument_span = next(doc._.arguments.get_argument_spans())
print("Argument lexicon:", argument_span.text)
print("Label of lexicon:", argument_span.label_)
print("Sentence where lexicon occurs:", argument_span.sent.text.strip())

The above will output

Argument lexicon: should
Label of lexicon: necessity
Sentence where lexicon occurs: A changing society should not cling to traditional family models.

As get_argument_spans yields spaCy Spans it is trivial to retrieve things like average word embeddings for sentences that contain arguing lexicon. These average embeddings can serve as input for your deep learning models.

You can for example access the built-in spaCy vectors for a sentence containing argument lexicon with

print("Vector type:", type(argument_span.sent.vector))
print("Vector shape:", argument_span.sent.vector.shape)

Which will output

Vector type: <class 'numpy.ndarray'>
Vector shape: (384,)

How it works

The MPQA arguing lexicon is made available under the GNU General Public License. It is a set of about 200 regular expressions with macros divided into 17 categories. For more information about how the lexicon was created we refer to the arguing lexicon homepage.

The Dutch arguing lexicon is a translation of the English lexicon and is available only through this extension.

Under the hood this extension parses the regular expressions and unpacks any macros inside of them. The doc._.arguments.get_argument_spans method tries to match any lexicon regular expression against the text of the input spaCy Doc. When a match is found the match gets transformed into a spaCy Span before it gets yielded.

doc._.arguments.get_argument_spans is the only recommended way of using this extension at the moment.

As the MPQA arguing lexicon is made available as a list of regular expressions we side stepped the spaCy Matcher, but we think that loading the lexicon as a set of matchers might improve the performance.

Citation

Please cite the following when using this software:

Swapna Somasundaran, Josef Ruppenhofer and Janyce Wiebe (2007) Detecting Arguing and Sentiment in Meetings, 
SIGdial Workshop on Discourse and Dialogue, Antwerp, Belgium, September 2007 (SIGdial Workshop 2007)

Metadata

Release files for spacy-arguing-lexicon 0.0.3

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

Source distribution (sdist)

Source distribution for spacy-arguing-lexicon 0.0.3
File Size Uploaded
spacy_arguing_lexicon-0.0.3.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spacy-arguing-lexicon 0.0.3
File Interpreter ABI Platform
spacy_arguing_lexicon-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 40.3 kB

Release files / spacy_arguing_lexicon-0.0.3.tar.gz

Download URL spacy_arguing_lexicon-0.0.3.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
87530104ee438136ceef0a33362ee2c38c4f761dc916abe45b51f5f362be4cba
BLAKE2b-256 checksum
How to use checksums
1e024c1ea675e74018ac2bf7a5c3d7a01c773d28f4a2e68b8a76306536c7b510
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.4

Release files / spacy_arguing_lexicon-0.0.3-py3-none-any.whl

Download URL spacy_arguing_lexicon-0.0.3-py3-none-any.whl
Size 25.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa80b266421f74c523075280ad57d0775292c51be5f59e1f7609af9380ba92e8
BLAKE2b-256 checksum
How to use checksums
88a449f3ab0b36952cc2e58544ef47c26bb293f9160c42593208d811aeaefbb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.4

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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