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.5.tar.gz (22.8 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.5-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: grimbert-0.1.5.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for grimbert-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ba79d88dd242c3ecb456a7baac0fb97dc29b4338250194479f02e0a0a8440c08
MD5 958cdf426a23f8a044cce2d5058f1cf2
BLAKE2b-256 9805756f5c7b51e773294e949c1627d2ed287fcf24b0cec0662417d8a764f655

See more details on using hashes here.

File details

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

File metadata

  • Download URL: grimbert-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for grimbert-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 00eca74c7e0376392d994a1e27519cfb71ed502bc4a34111ca3406f184fe0e1a
MD5 9310c6469c8ed7e320368a95a58b9d17
BLAKE2b-256 90afd2670edb4b4d8c95d905515cb823bc36811879c30a58dbc247ac2c2f33b5

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