glaserl / glassplitter Goto Github PK
View Code? Open in Web Editor NEWA sentence splitter and tokenizer.
License: Apache License 2.0
A sentence splitter and tokenizer.
License: Apache License 2.0
DEBUG:main:Analyzing pdf 0909.3986
Token indices sequence length is longer than the specified maximum sequence length for this model (673 > 512). Running this sequence through the model will result in indexing errors
Low priority, but maybe it's an easy fix:
In my tests, split sentences always(?) begin and end with an empty ''
token, that is associated with the previous span.
(The first sentence has no previous span, and there it attaches to the first span in the sentence)
Das betrifft anscheinend nur leere Tokens, die ich vermutlich sowieso, ignorieren kann.
Der folgende Test schlägt für "Different" fehl.
(Und für den leeren String davor auch, aber so sophisticated ist mein assert nicht.)
def test_glassplitter():
tokenizer = Tokenizer(lang="en", clean=True, doc_type="pdf")
example = ["I am a sentence with trailing space. ", "Different Box", " from the rest of the sentence.Hello there.", "StudNr something wrt TUD & KHG"]
example_input = [(text, {"some_data": "schwund is immer"}) for text in example]
for i, a in enumerate(tokenizer.split(example_input, trim=True)):
logger.debug("Group %s", i)
for j, (text, span) in enumerate(a):
logger.debug("%s-%s: %s '%s'", i, j, span, text)
assert text in example[span]
The TF-IDF Vectorizer expects a function/callable with the signature
str -> list[str]
I request a function (let's call it tokenize_flat or something) that expects a list/iterable of strings (instead of tuples) and returns a list/iterable of strings. (instead of a nested list of enumerated strings)
My kinda messy workaround for reference:
tokenizer = Tokenizer(lang="en", clean=True, doc_type="pdf")
def tokenize_only(tokenizer: Tokenizer, text_boxes):
"""Tokenize text-boxes."""
spans = ((item["text"], i) for i, item in enumerate(text_boxes))
sentence_list = tokenizer.split(spans, trim=True)
for sentence in sentence_list:
yield [a for a, i in sentence]
def tokenizer_wrapped(tokenizer: Tokenizer) -> Callable:
def tokenize(arg: str):
return list(reduce(operator.add, tokenize_only(tokenizer, arg)))
return tokenize
# print("Vectorizing %d documents..." % len(data))
tfidf_vectorizer = TfidfVectorizer(
max_df=0.5, # Percentage of docs
min_df=3, # Absolute number of docs to contain feature (word)
max_features=5000,
use_idf=True,
sublinear_tf=True,
preprocessor=lambda x: x, #HACK
tokenizer=tokenizer_wrapped(tokenizer),
# tokenizer=str.split,
token_pattern=None,
stop_words="english",
ngram_range=(1, 2),
)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.