Open Source

KeyNeg

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

Installation

Install KeyNeg from PyPI using pip:

# 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

Get started with KeyNeg in just a few lines of code:

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']
# }

Sentiment Extraction

Extract predefined negative sentiment categories from text:

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

Parameters

top_nNumber of sentiment results to return
thresholdMinimum similarity score (0-1) for inclusion
diversityMMR diversity factor for varied results

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
)

Parameters

keyphrase_ngram_rangeTuple specifying min/max n-gram length
use_taxonomyWhether to include taxonomy keywords

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)
Enterprise Feature: Summarize by Label

KeyNeg Enterprise includes summarize_by_label() which groups documents by sentiment label with example quotes - perfect for generating complaint reports from customer feedback or employee surveys.

Departure Intent Detection

Detect signals that an employee may be considering leaving:

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

Escalation Risk Detection

Identify text that indicates potential escalation or legal concerns:

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

Intensity Analysis

Measure the emotional intensity of negative sentiment:

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

Custom Labels

Add your own sentiment labels to the analysis:

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

Custom Keywords

Add industry-specific or domain-specific keywords:

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

Custom Model

Use a different sentence transformer model:

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

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

Utility Functions

Helper functions for common operations:

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'])

API Integration

Example FastAPI 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)

Use Cases

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

Need Enterprise Features?

KeyNeg Enterprise offers air-gapped deployment, custom taxonomies, and dedicated support.

Contact for Pricing