Skip to main content

Grimbert

Speaker attribution in novels. Based on the older bert-quote-attribution project.

Documentation

from grimbert.model import SpeakerAttributionModel
from grimbert.predict import predict_speaker
from grimbert.datas import (
    SpeakerAttributionDataset,
    SpeakerAttributionDocument,
    SpeakerAttributionQuote,
    SpeakerAttributionMention
) 
from transformers import BertTokenizerFast


model = SpeakerAttributionModel.from_pretrained(
	"compnet-renard/spanbert-base-cased-literary-speaker-attribution"
)
tokenizer = BertTokenizerFast.from_pretrained(
	"compnet-renard/spanbert-base-cased-literary-speaker-attribution"
)

tokens = '" This is horrible " , John said to Max .'.split(" ")
quote_start = 0
quote_end = 4
john_mention_start = 6
john_mention_end = 7
max_mention_start = 9
max_mention_end = 10

dataset = SpeakerAttributionDataset(
    [
        SpeakerAttributionDocument(
            tokens,
            [SpeakerAttributionQuote(
                tokens[quote_start:quote_end], quote_start, quote_end, "John"
            )],
            [
                SpeakerAttributionMention(
                    tokens[john_mention_start:john_mention_end],
                    john_mention_start,
                    john_mention_end,
                    "John"
                ),
                SpeakerAttributionMention(
                    tokens[max_mention_start:max_mention_end],
                    max_mention_start,
                    max_mention_end,
                    "Max"
                ),
            ]
            
        )
    ],
    quote_ctx_len=512,
    speaker_repr_nb=4, 
    tokenizer=tokenizer
)

preds = predict_speaker(dataset, model, tokenizer, batch_size=4)

Metadata

Release files for grimbert 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grimbert 0.1.5
File Size Uploaded Provenance Actions
grimbert-0.1.5.tar.gz 22.8 kB Without provenance Details for grimbert-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for grimbert 0.1.5
File Interpreter ABI Platform Actions
grimbert-0.1.5-py3-none-any.whl Python 3 none any Details for grimbert-0.1.5-py3-none-any.whl

Total release size: 48.2 kB

Release files / grimbert-0.1.5.tar.gz

Download URL grimbert-0.1.5.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ba79d88dd242c3ecb456a7baac0fb97dc29b4338250194479f02e0a0a8440c08
BLAKE2b-256 checksum
How to use checksums
9805756f5c7b51e773294e949c1627d2ed287fcf24b0cec0662417d8a764f655
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.8

Release files / grimbert-0.1.5-py3-none-any.whl

Download URL grimbert-0.1.5-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00eca74c7e0376392d994a1e27519cfb71ed502bc4a34111ca3406f184fe0e1a
BLAKE2b-256 checksum
How to use checksums
90afd2670edb4b4d8c95d905515cb823bc36811879c30a58dbc247ac2c2f33b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.8

Security for grimbert 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page