Skip to main content

Aspect extraction based on word embeddings

Project description

cat-aspect-extraction🐈

Easy to use library for implement Contrastive Attention Topic Modeling describe in Embarrassingly Simple Unsupervised Aspect Extraction

Read the paper & the original repository for details about the algorithm !

cat walking on a computer keyboard

Installation

pip install cat-aspect-extraction

or

git clone
python -m pip install .

Example

from cat_aspect_extraction import CAt, RBFAttention # for using the model
from reach import Reach # for loading word embeddings

# Load in-domain word embeddings and create a CAt instance
r = Reach.load("path/to/embeddings", unk_word="UNK")
cat = CAt(r)

# Initialize candidate aspects

candidates = [
    "food",
    "service",
    "ambiance",
    "price",
    "location",
    "experience"
]

for aspect in candidates:
    cat.add_candidate(aspect)

# Add topics

cat.add_topic("food", ["taste", "flavor", "quality", "portion", "menu", "dish", "cuisine", "ingredient"])

cat.add_topic("service", ["staff", "waiter", "waitress", "service", "server", "host", "manager", "bartender"])

cat.add_topic("ambiance", ["atmosphere", "decor", "interior", "design", "lighting", "music", "noise", "vibe"])

# Compute topic score

sentence = "The food was great !".split() # tokenize your sentence

att = RBFAttention() # Using attention

cat.get_scores(sentence, attention=att)
>>> [('food', 1), ('service', 0.5), ('ambiance', 0.0)] # Score are scaled by RobustScaler followed by MinMaxScaler

Citations

I'm not the author of the original paper, so if you use this library, please cite the original paper :

@inproceedings{tulkens2020embarrassingly,
    title = "Embarrassingly Simple Unsupervised Aspect Extraction",
    author = "Tulkens, St{\'e}phan  and  van Cranenburgh, Andreas",
    booktitle = "Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics",
    month = jul,
    year = "2020",
    address = "Online",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/2020.acl-main.290",
    doi = "10.18653/v1/2020.acl-main.290",
    pages = "3182--3187",
}

License

GNU General Public License v3.0

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

cat_aspect_extraction-2.0.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cat_aspect_extraction-2.0.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file cat_aspect_extraction-2.0.0.tar.gz.

File metadata

  • Download URL: cat_aspect_extraction-2.0.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for cat_aspect_extraction-2.0.0.tar.gz
Algorithm Hash digest
SHA256 3df2aa9dfed29c6af75747dfab7424aa3433438952b96bbaa4adf7eb81679697
MD5 bba84e803388894a4f35ca833a1855ee
BLAKE2b-256 07b4e0c039ee1da66a6eeb674eafdb49a37bbf071899d81ed138d47f47e51b8f

See more details on using hashes here.

File details

Details for the file cat_aspect_extraction-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cat_aspect_extraction-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc415e912155ef479985615eb23eaaaa58562be9175d483ff8d4f930b5941716
MD5 c38de29eb7307009ed89c4670adf6e6a
BLAKE2b-256 c850bded7d0148fb101a1af323d0701e1f9e6a1580d3e22f1858942f2766b19a

See more details on using hashes here.

Supported by

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