Giter Site home page Giter Site logo

glassplitter's People

Contributors

glaserl avatar

Watchers

 avatar

glassplitter's Issues

Warn and/or trim overly long sentences

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

Split Sentences begin with an empty token, which is associated to the wrong span.

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.

tokenizer.split() occasionally returns the wrong span

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]

Add splitter interface for use with sklearn

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),
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.