Skip to main content

Lex2Sent - A bagging approach to unsupervised Sentiment Analysis

Lex2Sent is a text classification/clustering model that can be used with minimal a-priori-information to classify texts into two classes. While the original paper used it for sentiment analysis on english documents, it is not limited to that purpose, but can be used for any arbitrary type of classification and language as long as there are lexica that can be used as an information-basis.

Getting Started

You may install this package using either pypi

pip install lex2sent

or GitHub

pip install git+https://github.com/K-RLange/Lex2Sent.git

The following is an example of using the Opinion Lexicon to classify an iMDb movie review data set. You may have to use nltk.download() to download the opinion_lexicon first. First we configure our data set

from datasets import load_dataset
from nltk.corpus import opinion_lexicon
data = load_dataset('imdb')
ratings, reviews = [], []
for stars, text in zip(data["train"]["label"], data["train"]["text"]):
    if text:
        if stars == 0:
            ratings.append("negative")
        else:
            ratings.append("positive")
        reviews.append(text)

And now we can start applying Lex2Sent

from lex2sent.textClass import *
lexicon = ClusterLexicon([opinion_lexicon.positive(), opinion_lexicon.negative()])
rated_texts = RatedTexts(reviews, lexicon, ratings)

#Basic "counting" method of classification:
count_res = rated_texts.lexicon_classification_eval(label_list=["positive", "negative"])
l2s_res = rated_texts.lbte(label_list=["positive", "negative"], workers=4)
print("Counting accuracy: {}%; Lex2Sent accuracy: {}%".format(count_res * 100, l2s_res*100))

yielding the result "Counting accuracy: 73.772%; Lex2Sent accuracy: 78.172%".

Reference

Please refer to "Lex2Sent - A bagging approach to unsupervised Sentiment Analysis" when using this package. When you use this package in a publication, please cite it as

@misc{lex2sent,
  title = {{Lex2Sent}: {A} bagging approach to unsupervised sentiment analysis},
	shorttitle = {{Lex2Sent}},
	publisher = {arXiv},
	author = {Lange, Kai-Robin and Rieger, Jonas and Jentsch, Carsten},
	month = sep,
	year = {2022},
	note = {arXiv:2209.13023 [cs]},
	keywords = {Computer Science - Computation and Language},
}

Future Features

-Calling from the console

-FastText and SentenceBERT as alternatives to Doc2Vec

-Options to classify into more than two clusters

Release files for lex2sent 0.0.2

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

Source distribution (sdist)

Source distribution for lex2sent 0.0.2
File Size Uploaded
lex2sent-0.0.2.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lex2sent 0.0.2
File Interpreter ABI Platform
lex2sent-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release files / lex2sent-0.0.2.tar.gz

Download URL lex2sent-0.0.2.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
62cfe89b6ae4b4a63c3f125a618689e637ecf630c1feb0550bac15606653ace6
BLAKE2b-256 checksum
How to use checksums
53033042faa6bec7661cccc59f3e0a544e5f4b320c6c43650dce35001031be58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8

Release files / lex2sent-0.0.2-py3-none-any.whl

Download URL lex2sent-0.0.2-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14e6373f4d3ab4fe6bdeccd68eeb7b2fb036952d7f091b5979e56bf17dd6089c
BLAKE2b-256 checksum
How to use checksums
02b5b3b4b6f0f3439d4f9de8755ba0331a09bb96a13c57c0b552857cd44dff0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8

Release history Release notifications | RSS feed

This release

0.0.2 This release

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