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.2.0.tar.gz (369.9 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.2.0-py3-none-any.whl (383.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tonneanalyzer_ankit-0.2.0.tar.gz
  • Upload date:
  • Size: 369.9 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.2.0.tar.gz
Algorithm Hash digest
SHA256 e2fca7beb94b026ae72184b5940ec6120976e4fd48e61cfe184dfa85873d4f7f
MD5 0f7de12f09fc0e4b12d16f68b166f3bc
BLAKE2b-256 f4b8f6835ddb9a8452b0a17dd8c3e3a079fb14281d1052103b6c80764aed254f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tonneanalyzer_ankit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07bcb3f2cfda3554337b51df32512b85ef8565461f324138aae1ce25510ee6c2
MD5 7e50a8241430abc253ba8020f082654d
BLAKE2b-256 95bed509ec45a20e6f5356afbb76258fa755146f55f2fa0e64dce6db49a6f92b

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