Skip to main content

A library to predict email signatures using an ONNX model.

Project description

Email Signature Detector

PyPI version License: MIT

Email Signature Detector is a Python library for accurately identifying and extracting email signatures from raw email text. It leverages a fine-tuned BERT model packaged in ONNX format for efficient, cross-platform inference.

This tool is designed to be simple to integrate, providing clear and actionable output that includes not only the signature text but also its precise location (character and token indices) within the email body.

Key Features

  • High Accuracy: Utilizes a state-of-the-art transformer model for robust signature detection.
  • Efficient and Portable: The model is converted to ONNX format, ensuring fast inference with minimal dependencies.
  • Detailed Output: Provides the start and end character indices of the signature, making it easy to slice and process email content.
  • Easy to Use: A straightforward API that requires only a few lines of code to integrate.
  • Bundled Model: The ONNX model and tokenizer are included with the package, so no extra downloads are needed.

Installation

You can install the library directly from PyPI:

pip install email-signature-detector

How to Use

Here is a simple example of how to use the ONNXSignaturePredictor to detect and extract an email signature.

from email_signature_detector import ONNXSignaturePredictor

# 1. Instantiate the predictor
# The model is bundled with the package, so no arguments are needed.
predictor = ONNXSignaturePredictor()

# 2. Define the email text
email_text = """Hi Team,

I hope this email finds you well.

I'm writing to follow up on our discussion from last week's meeting. I've attached the document with the updated project timeline. Please review it and provide your feedback by the end of the day.

Also, a quick reminder that the quarterly review is scheduled for this Friday.

Thanks for your cooperation.

Best regards,
John Doe
Senior Project Manager
"""

# 3. Get the prediction
result = predictor.predict(email_text)

# 4. Use the results
if result["has_signature"]:
    signature_data = result["signature"]
    start_char = signature_data.get("start_token")
    end_char = signature_data.get("end_token")

    print("--- Signature Found ---")
    if start_char is not None and end_char is not None:
        # Extract the body and signature using character indices
        email_body = email_text[:start_char].strip()
        signature = email_text[start_char:end_char]

        print(f"\nEmail Body:\n'{email_body}'")
        print(f"\nSignature:\n'{signature}'")
    else:
        # Fallback if character indices are not available
        print(f"Signature Text: '{signature_data['text']}'")
else:
    print("No signature was detected.")

Prediction Output

The predict method returns a dictionary with the following structure:

{
  "has_signature": true,
  "confidence": 0.98,
  "signature": {
    "text": "Best regards,\nJohn Doe\nSenior Project Manager",
    "start_token": 45,
    "end_token": 55,
  },
  "body": "Hi Team, ... Thanks for your cooperation."
}

API Reference

ONNXSignaturePredictor

The main class for making predictions.

__init__(self, model_path=None, tokenizer_path=None, confidence_threshold=0.5)

  • model_path (Optional[Path]): Path to a custom ONNX model file. Defaults to the bundled model.
  • tokenizer_path (Optional[Path]): Path to a custom tokenizer. Defaults to the bundled tokenizer.
  • confidence_threshold (float): The minimum average confidence for a span to be considered a signature.

predict(self, email_text: str) -> Dict

  • email_text (str): The raw email content to be processed.
  • Returns: A dictionary containing the prediction results.

predict_batch(self, email_texts: List[str], batch_size=32) -> List[Dict]

  • email_texts (List[str]): A list of email contents to be processed in a batch.
  • batch_size (int): The number of emails to process at once.
  • Returns: A list of prediction dictionaries.

For Developers

Publishing to PyPI

If you contribute to the project and need to publish a new version, follow these steps.

1. Install Build Tools

Make sure you have the latest versions of build and twine:

pip install --upgrade build twine

2. Build the Package

From the root of the project, run the build command:

python3 -m build

This command will create a dist directory containing the distribution files (.tar.gz and .whl).

3. Upload to PyPI

Use twine to upload the package to the official PyPI repository. You will need a PyPI account and an API token.

python3 -m twine upload dist/*

License

This project is licensed under the MIT License. See the LICENSE file for details.


This README was generated with assistance from an AI pair programmer.

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

email_signature_detector-0.1.3.tar.gz (650.6 kB view details)

Uploaded Source

Built Distribution

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

email_signature_detector-0.1.3-py3-none-any.whl (671.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: email_signature_detector-0.1.3.tar.gz
  • Upload date:
  • Size: 650.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for email_signature_detector-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b5d684b1d1b21f22bd9764a6cc1b1c82189127a65b3f962fd99de7e381718672
MD5 243e8e7316bca78e7cec08bd50a8e796
BLAKE2b-256 ba6c76e0ee87f4f3c395d75df12b7301caa2259e1eaca3e74f2eb9fc818b3680

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for email_signature_detector-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 961c9d636615b276099507eafb35242b293dac4a69d21d7004f9e0bbf8f7f4bf
MD5 99ca466b728aa6b09580f4b7c2199b33
BLAKE2b-256 abb30b0b220070e7b869dde147867dfed265660407b15609738fb4e7f2632a66

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