Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Performance/caching issue: tokenizer fails to reset has_special flag after encountering special span, effectively disabling caching #13950

Copy link
Copy link
@jberg5

Description

@jberg5
Issue body actions

How to reproduce the behaviour

nlp = English()
doc = nlp("I can't believe you have done this")

"can't" is a tokenizer exception because of the funky contraction (yay english)

{ORTH: "ca", NORM: "can"},

Spans that contain these exceptions are marked as has_special
declared here:

cdef int has_special = 0

set here:
has_special[0] = 1

And has_special spans are not cached:

if has_special[0]:

The problem is that has_special, once set to a nonzero value, is never reset. And this means that once the tokenizer encounters a special case, every subsequent span is also marked as special, and none of them get cached, even if they should be.

This has some fairly significant tokenizer performance implications. It should be much faster than it is. I'll put some benchmarking in my PR.

Your Environment

Info about spaCy

  • spaCy version: 3.8.14
  • Platform: macOS-26.3.1-arm64-arm-64bit
  • Python version: 3.12.4
  • Pipelines: en_core_web_md (3.8.0), en_core_web_sm (3.8.0)
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.