Skip to main content

A KeyBERT-style negative sentiment and keyword extractor for workforce intelligence and marketing analysis

Project description

KeyNeg Logo

KeyNeg

A KeyBERT-style Negative Sentiment and Keyword Extractor for Workforce Intelligence

PyPI version Python versions Downloads License


Author: Kaossara Osseni Email: admin@grandnasser.com

KeyNeg extracts negative keywords, frustration indicators, and discontent signals from text. Designed for analyzing employee feedback, forum discussions, customer reviews, and more.

Installation

# Install from PyPI
pip install keyneg

# With Streamlit app
pip install keyneg[app]

# Full installation (includes zero-shot classification)
pip install keyneg[all]

Quick Start

from keyneg import KeyNeg

# Initialize (uses all-mpnet-base-v2 by default)
kn = KeyNeg()

# Extract negative sentiments
sentiments = kn.extract_sentiments(
    "I'm frustrated with the constant micromanagement and lack of recognition"
)
print(sentiments)
# [('micromanagement', 0.72), ('frustration', 0.68), ('lack of recognition', 0.65), ...]

# Extract negative keywords
keywords = kn.extract_keywords(
    "The toxic culture and burnout is unbearable"
)
print(keywords)
# [('toxic culture', 0.81), ('burnout', 0.75), ('unbearable', 0.62), ...]

# Full analysis
result = kn.analyze("My manager never listens and I'm thinking of quitting")
print(result)
# {
#     'keywords': [...],
#     'sentiments': [...],
#     'top_sentiment': 'poor leadership',
#     'negativity_score': 0.65,
#     'categories': ['work_environment_culture', 'job_satisfaction']
# }

Features

Sentiment Extraction

Extract predefined negative sentiment categories:

sentiments = kn.extract_sentiments(
    text,
    top_n=5,           # Number of results
    threshold=0.3,     # Minimum similarity score
    diversity=0.0      # MMR diversity (0-1)
)

Keyword Extraction

Extract negative keywords from both taxonomy and document:

keywords = kn.extract_keywords(
    text,
    top_n=10,
    threshold=0.25,
    keyphrase_ngram_range=(1, 2),
    use_taxonomy=True,
    diversity=0.0
)

Batch Processing

Efficiently process multiple documents:

docs = ["Comment 1...", "Comment 2...", "Comment 3..."]

# Batch analysis
results = kn.analyze_batch(docs, show_progress=True)

# Or individually
keywords_batch = kn.extract_keywords_batch(docs)
sentiments_batch = kn.extract_sentiments_batch(docs)

Special Detectors

Departure Intent Detection:

result = kn.detect_departure_intent("I'm updating my resume and interviewing")
# {'detected': True, 'confidence': 0.67, 'signals': ['updating resume', 'interviewing']}

Escalation Risk Detection:

result = kn.detect_escalation_risk("I'm going to contact my lawyer")
# {'detected': True, 'risk_level': 'high', 'signals': ['contact my lawyer']}

Intensity Analysis:

result = kn.get_intensity("I'm absolutely furious about this")
# {'level': 3, 'label': 'strong', 'indicators': ['furious']}

Taxonomy Categories

KeyNeg includes a comprehensive taxonomy covering:

  • Work Environment & Culture: toxic culture, harassment, discrimination, favoritism
  • Management Issues: micromanagement, poor leadership, lack of direction
  • Recognition & Value: undervalued, unappreciated, credit stolen
  • Workload & Burnout: exhaustion, overwhelmed, unrealistic deadlines
  • Compensation: underpaid, pay disparity, poor benefits
  • Career Development: no growth, dead end job, glass ceiling
  • Work-Life Balance: excessive hours, no flexibility
  • Team Dynamics: conflict, poor collaboration, isolation
  • Job Satisfaction: low morale, frustration, disengagement
  • Customer/Product Issues: poor quality, bad service, overpriced

Customization

Add Custom Labels

kn.add_custom_labels(["impostor syndrome", "quiet firing"])

Add Custom Keywords

kn.add_custom_keywords("tech_specific", [
    "pager duty", "on-call nightmare", "technical debt"
])

Use Custom Model

kn = KeyNeg(model="all-MiniLM-L6-v2")  # Faster, slightly less accurate

Utility Functions

from keyneg.utils import (
    highlight_keywords,      # Highlight detected keywords in text
    score_to_severity,       # Convert score to severity label
    aggregate_batch_results, # Aggregate batch statistics
    export_to_json,          # Export results to JSON
    export_batch_to_csv,     # Export batch to CSV
    preprocess_text,         # Clean/preprocess text
    chunk_text,              # Split long text into chunks
)

# Highlight keywords in HTML
highlighted = highlight_keywords(text, keywords, format="html")

# Get severity
severity = score_to_severity(0.75)  # "critical"

# Aggregate batch results
summary = aggregate_batch_results(results)
print(summary['top_sentiments'])
print(summary['avg_negativity_score'])

Streamlit App

Launch the interactive UI:

streamlit run keyneg_app.py

Features:

  • Single text analysis with detailed results
  • Batch processing with file upload
  • Interactive visualizations
  • Export results to CSV

Use Cases

  1. Employee Survey Analysis: Identify patterns of dissatisfaction across responses
  2. Exit Interview Processing: Extract reasons for departure at scale
  3. Forum Monitoring: Track sentiment on workforce forums (e.g., TheLayoffradar.com, Blind)
  4. Customer Feedback: Analyze product reviews and support tickets
  5. Social Media Monitoring: Track brand sentiment and complaints

API Integration

from fastapi import FastAPI
from keyneg import KeyNeg

app = FastAPI()
kn = KeyNeg()

@app.post("/analyze")
def analyze(text: str):
    return kn.analyze(text)

@app.post("/analyze_batch")
def analyze_batch(texts: list):
    return kn.analyze_batch(texts)

License

MIT License

Author

Kaossara Osseni Email: admin@grandnasser.com GitHub: https://github.com/Osseni94

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

keyneg-1.1.0.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

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

keyneg-1.1.0-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file keyneg-1.1.0.tar.gz.

File metadata

  • Download URL: keyneg-1.1.0.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for keyneg-1.1.0.tar.gz
Algorithm Hash digest
SHA256 1187902fa577189fbc4209121a29b7af4ad37447778bbe6b3c0dae7a32e8a35f
MD5 cb4334762bbdb7f04ae69790b353deff
BLAKE2b-256 e3b75b3f79448ee188ffcad708b5f4d0a49e9b021bc86baf0655a915c6ae3226

See more details on using hashes here.

File details

Details for the file keyneg-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: keyneg-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for keyneg-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40faa6bf6883232945b1218e13bb2dc5bcb6e7616dfc3d8f71ef0ff4103d70a6
MD5 9eabd80e16fb372127dead3fa6c28849
BLAKE2b-256 6081e9333e7e98e22d9ec476387fb36c637db332fcb1156758a34de5f90e9c5f

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