Skip to main content

The Python library containing the implementation of the authorship verification method 'LambdaG', including a kneser-ney language model implementation.

Project description

LambdaG - Grammar as a behavioral biometric: Using cognitively motivated grammar models for authorship verification

This is the official repository for the paper "Grammar as a behavioral biometric: Using cognitively motivated grammar models for authorship verification". The paper proposes an authorship verification (AV) method - called LambdaG - which seeks to answer the question of whether two given documents are written by the same author, or not. In contrast to existing AV methods which often suffer from high complexity, low explainability and especially from a lack of clear scientific justification, LambdaG represents a simpler method based on modeling the grammar of an author following Cognitive Linguistics principles.

Given two documents, 𝒟𝒜 and 𝒟𝒰 as well as some reference documents $𝔻_{\text{ref}}$, the ratio of the likelihoods of 𝒟𝒰 given 𝒜's grammar versus the grammar of a reference population’s grammar is calculated. Based on this ratio a final prediction of whether 𝒜=𝒰 holds is made.

Usage

Python implementation

To use LambdaG with Python install the LambdaG package from PyPI:

pip install lambdag

or alternatively directly from this repository:

pip install git+https://github.com/AndreaNini/LambdaG

Afterwards you can use LambdaG as follows, for example:

from sklearn.metrics import accuracy_score, roc_auc_score
from lambdag.corpus import load_corpus
from lambdag import LambdaGMethod

# load train and test corpus
train_problems, train_labels, train_author_texts = load_corpus("corpus/path/train")
test_problems, test_labels, test_author_texts = load_corpus("corpus/path/test")

# instantiate method object
method = LambdaGMethod(basis="tokens", order=8)

# train method
method.fit(train_problems, train_author_texts, train_labels)

# evaluate on test corpus
test_probas = method.predict_proba(test_problems, test_author_texts)

print(f"Accuracy: {accuracy_score(test_labels, test_probas[:,1]>=0.5):.3f}")

For further examples see examples.

Please keep in mind that, for best results, LambdaG should be used on texts that have been preprocessed with POSNoise (paper, original implementation).

R implementation

An alternative implementation in R is provided in the idiolect package.

Data

We will publish the data used in our paper soon.

Citation

If you use our code in your work, please consider citing:

@misc{nini2025grammarbehavioralbiometricusing,
    title={Grammar as a Behavioral Biometric: Using Cognitively Motivated Grammar Models for Authorship Verification}, 
    author={Andrea Nini and Oren Halvani and Lukas Graner and Valerio Gherardi and Shunichi Ishihara},
    year={2025},
    eprint={2403.08462},
    archivePrefix={arXiv},
    primaryClass={cs.CL},
    url={https://arxiv.org/abs/2403.08462}, 
}

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

lambdag-0.1.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

lambdag-0.1.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file lambdag-0.1.1.tar.gz.

File metadata

  • Download URL: lambdag-0.1.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lambdag-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b451a461c9da39375aeb84bd3372a3c08ac963aaf352acb7dc915a3eeffe8a5e
MD5 f4ab846976ee9524264c226124263331
BLAKE2b-256 1907b3bf58e409a094668aa0f7c3341581c579ac0c6225fc23ccf99817e667b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for lambdag-0.1.1.tar.gz:

Publisher: python-publish.yml on andreanini/lambdag

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lambdag-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lambdag-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lambdag-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d54b2b6ed8848413c3428d2274b23eaae1929a0b3b21f13d49c540a1d5d0fcc
MD5 124211170eada45dc4cc350cdb5adf70
BLAKE2b-256 99af7edfc444e5e40ee1c1887c5d0fe79e0a81799c1b26da3ae85e5929563bff

See more details on using hashes here.

Provenance

The following attestation bundles were made for lambdag-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on andreanini/lambdag

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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