Skip to main content

SPAR: Semantic Projection with Active Retrieval

Project description

Overview

SPAR is a Python NLP package that facilitates interactive measurement of text using LLMs. With SPAR, you can quantify short documents (e.g., social media posts) based on theoretical concepts such as creativity and collaboration, by measuring their semantic similarity with a set of example (seed) documents.

How it works:

  1. Start with
    i. A corpus of documents that you want to measure;
    ii. generic seed sentences that define theoretical concepts, e.g., Creativity: we should innovate and Collaboration: we should collaborate.
  2. Embed them into a semantic space using a pre-trained LLM.
  3. Use semantic search to find domain-specific exemplary documents in the corpus that reflect the theoretical concepts in context. For example: 'We encourage new ways of thinking', 'We should working together to weather the storm'.
  4. Compute the dot product between docuements and exemplary documents.

Main features:

  • Enables domain-adaptive and few-shot measurements of theoretical concepts without requiring model training or fine-tuning.
  • Combines the idea of semantic projection with active semantic search, which allows users to find the most relevant, context-specific documents to define the theoretical scales.
  • Supports multiple state-of-the-arts text embedding models, such as Sentence Transformers and OpenAI Text Embeddings API.
  • Comes with a user-friendly web interface that makes defining theoretical scales and conducting measurements intuitive and accessible.
  • Reference:
    • Bei Yan, Feng Mai, Chaojiang Wu, Rong Chen, Xiaolin Li (2024). A Computational Framework for Understanding Firm Communication During Disasters. Information Systems Research 35(2):590-608. https://doi.org/10.1287/isre.2022.0128

SPAR is built on open source packages such as HuggingFace Transformers, SentenceTransformers, and Gradio.

Installation and Quick Start

To quickly launch SPAR in Google Colab, click the following button and run the notebook code:

Open In Colab

You can also install SPAR on your own machine. It is recommended to use a virtual environment and upgrade pip first with pip install -U pip. SPAR can be installed via pip:

pip install -U spar-measure

To launch SPAR on your own machine, use the following command in the terminal:

python -m spar_measure.gui

And open the interactive app in your browser at http://localhost:7860/.

If a CUDA GPU is available, SPAR will use it to speed up embedding. If you choose not to use a GPU, you can set the CUDA_VISIBLE_DEVICES environment variable to an empty string:

CUDA_VISIBLE_DEVICES="" python -m spar_measure.gui

Limitations

  • SPAR may not be suitable for longer or more complex documents since it represents a document using a single vector.
  • Sentence embeddings may not be suitable for theoretical constructs that rely primarily on syntactic features.
  • Pretrained LLMs may not have up-to-date world knowledge or new vocabularies.
  • Semantic projection is a linear operation, so it may not capture non-linear patterns in the data as well as fine-tuning approaches.

Additional Details

For additional details and source code, please refer to the project's GitHub Repository.

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

spar_measure-0.3.4.tar.gz (3.3 MB view details)

Uploaded Source

Built Distribution

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

spar_measure-0.3.4-py3-none-any.whl (3.2 MB view details)

Uploaded Python 3

File details

Details for the file spar_measure-0.3.4.tar.gz.

File metadata

  • Download URL: spar_measure-0.3.4.tar.gz
  • Upload date:
  • Size: 3.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for spar_measure-0.3.4.tar.gz
Algorithm Hash digest
SHA256 be10ba55726f017b90ec31f431bc69662fc66b094b9a48a63bbef7b2dca0b8dc
MD5 0015eb8a69ae57e10070f6fb82b5d228
BLAKE2b-256 6d6f3b1144c8d0ff39b20f6bdb84b9deb028b2381bf77b0fd18af8765d519d61

See more details on using hashes here.

File details

Details for the file spar_measure-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: spar_measure-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for spar_measure-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1b621fc1cd3dacf033aaf7a313645aa2fcbc47bbf2679ad2b84476e1d067cef3
MD5 f488e76d2ba8bce3e1b0869d89954408
BLAKE2b-256 448556b93ca910898783e97140027ac68868a54850df5a0927633351a824265a

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