Skip to main content

No project description provided

Project description

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)

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

grimbert-0.1.3.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

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

grimbert-0.1.3-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: grimbert-0.1.3.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.10 Linux/6.11.10-200.fc40.x86_64

File hashes

Hashes for grimbert-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8991a5dc62ca0655351940cedd05ac842b6d1f390eb5a49f588a4310463bde82
MD5 5d59bd44009eb873acde84d46bf5bbe2
BLAKE2b-256 b34ebd820fefa3d1f16d4ae10af60e4a12d4407c603191be50b56dcef38d593a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: grimbert-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.10 Linux/6.11.10-200.fc40.x86_64

File hashes

Hashes for grimbert-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bb291a906a1de1e361f9abed31b3a35c6ce7f1c54fd835fb1c98295fa6c665d9
MD5 03b1af3f1d29c2a30c9f3964b64aaa77
BLAKE2b-256 72e8329631af47bc95899a6951d546c4106fca62e62c34a69b15676051cc0aca

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