Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tokenize_document() with slow tokenizer #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/document/processing/test_tokenization.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,29 @@ def test_tokenize_document_partition(text_document, tokenizer):
(str(rel.head), rel.label, str(rel.tail)) for rel in tokenized_doc.relations
]
assert relation_tuples == [("('it',)", "per:founder", "('O',)")]


def test_tokenize_document_with_slow_tokenizer():
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased", use_fast=False)
text_document = TextBasedDocument(text="Alice has a cat. Bob has a dog.")

tokenized_docs = tokenize_document(
text_document, tokenizer=tokenizer, result_document_type=TokenBasedDocument
)
assert len(tokenized_docs) == 1


def test_tokenize_document_with_slow_tokenizer_and_windowing():
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased", use_fast=False)
text_document = TextBasedDocument(text="Alice has a cat. Bob has a dog.")

tokenized_docs = tokenize_document(
text_document,
tokenizer=tokenizer,
result_document_type=TokenBasedDocument,
max_length=5,
return_overflowing_tokens=True,
)
assert (
len(tokenized_docs) == 3
) # the input text gets tokenized into 12 tokens and max_length is 5
Loading