Skip to main content

Hybrid rule + ML based tone analysis library

Project description

tonneanalyzer-ankit

A hybrid rule + machine-learning tone analysis library.

This library analyzes spoken or written text across multiple independent communicative tone axes using:

  • deterministic linguistic rules (precision)
  • lightweight ML classifiers (robustness)
  • explicit rule–model fusion
  • negation-aware suppression

The system is designed to be:

  • modular
  • interpretable
  • reproducible
  • production-safe

This is not a large language model.


Table of Contents

  • Installation
  • Python Version
  • Package Name vs Import Name
  • Project Structure
  • Core Concept
  • Supported Axes
  • Required Artifacts
  • Quick Start
  • Full Usage
  • Output Format
  • Negation Handling
  • Rule–Model Fusion
  • Design Constraints
  • What This Library Is / Is Not
  • Versioning
  • License

Installation

pip install tonneanalyzer-ankit
This installs the library code only.

⚠️ Trained model artifacts are not downloaded automatically.
You must provide them explicitly (see below).

Python Version
Python 3.8 or higher

Tested on Python 3.9

Package Name vs Import Name (IMPORTANT)
Purpose	Name
pip install name	tonneanalyzer-ankit
Python package	tone
Main class	tone.analyzer.ToneAnalyzer

This separation is intentional and standard in Python packaging.

Project Structure (after installation)
The installed package provides:

arduino
Copy code
tone/
├── __init__.py
├── analyzer.py        # public API
├── fusion/            # rule–model fusion logic
├── rules/             # deterministic linguistic rules
└── models/            # ML classifier definitions
You do not import from fusion, rules, or models directly.

Core Concept
Each tone axis is handled independently.

For a given axis:

A rule function produces a binary signal (0 or 1)

A trained ML model produces a probability

Both are combined using a weighted fusion rule

Negation is applied when linguistically valid

There is no shared label space and no shared classifier.

Supported Axes (v1)
Axis	Meaning
Persuasive	Attempts to influence or convince
Questioning	Interrogative intent
Formal	Formal vs informal language
Assertive	Forceful vs submissive tone
Authoritative	Commanding vs collaborative
Narrative	Story-like vs explanatory

Each axis returns a boolean decision.

Required Artifacts (MANDATORY)
You must provide trained model artifacts in Joblib format.

Required directory layout
Copy code
artifacts/
├── persuasive_model.joblib
├── questioning_model.joblib
├── formal_model.joblib
├── assertive_model.joblib
├── authoritative_model.joblib
└── narrative_model.joblib
These files are loaded at runtime.

The library does not train models automatically.

Quick Start
python
Copy code
from tone.analyzer import ToneAnalyzer

analyzer = ToneAnalyzer("path/to/artifacts")

result = analyzer.analyze(
    "I strongly recommend using this approach."
)

print(result)
Full Usage (Step by Step)
1. Import
python
Copy code
from tone.analyzer import ToneAnalyzer
2. Initialize Analyzer
python
Copy code
analyzer = ToneAnalyzer("path/to/artifacts")
The path must exist

All required .joblib files must be present

Missing files raise FileNotFoundError

3. Analyze Text
python
Copy code
output = analyzer.analyze(
    "I do not recommend this approach."
)
Output Format
The output is a Python dictionary:

python
Copy code
{
  'persuasive': False,
  'questioning': False,
  'formal': False,
  'assertive': False,
  'authoritative': False,
  'narrative': False
}
Each value is a boolean

True means the axis is detected

False means it is not detected

Negation Handling
Negation is applied selectively, only where linguistically valid.

Example:

graphql
Copy code
"I recommend this." persuasive = True

"I do not recommend this." persuasive = False
Negation is not applied to all axes blindly.

Sarcasm is not handled in v1.

Rule–Model Fusion
For each axis:

ini
Copy code
score = α * rule_signal + (1  α) * model_probability
decision = score  threshold
Where:

α is axis-specific

rules have higher priority than models

models smooth noisy or ambiguous cases

Fusion is deterministic.

Design Constraints (Intentional)
No deep learning models

No transformer dependencies

No shared embeddings across axes

No global confidence score

No auto-downloaded data

No hidden state

This is by design.

What This Library IS
A tone / intent analyzer

Deterministic and inspectable

Suitable for production pipelines

Lightweight and fast

Modular and extensible

What This Library Is NOT
❌ A large language model

❌ A sentiment analyzer

❌ A dialogue agent

❌ A text generator

❌ A black-box classifier

Versioning
0.1.x  documentation and stability

0.2.x  new axes or features

1.0.0  stable public API

PyPI versions are immutable.

License
MIT License.

Author
Ankit Ghosh

yaml
Copy code

---

### What to do next (exact steps)

1. Save this as `README.md`
2. Bump version in `pyproject.toml` (e.g. `0.1.1`)
3. Run:
   ```bash
   python -m build
   python -m twine upload dist/*

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

tonneanalyzer_ankit-0.1.3.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

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

tonneanalyzer_ankit-0.1.3-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file tonneanalyzer_ankit-0.1.3.tar.gz.

File metadata

  • Download URL: tonneanalyzer_ankit-0.1.3.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for tonneanalyzer_ankit-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e9553c01f42c22710a97b1eb47ec699a92d6f25116513a6e0aa835d6eeece892
MD5 26b03c626dcfb11a87e0d0e6844a1411
BLAKE2b-256 6ae865b441ae03248e3541a9d01852a73f7234e03298a3f13cba25d0bb505e2e

See more details on using hashes here.

File details

Details for the file tonneanalyzer_ankit-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for tonneanalyzer_ankit-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 97f5d09a490d61cd94bafe8730fb49d21e5605e87ab2df9cf84d680b039dd3e3
MD5 dca73fd2dd2194034685f5026e8def0c
BLAKE2b-256 b429275a5d64f92c02354a3d2f3ee96fa93bc277c56919278b595648b3b326e8

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