Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion complex_tokenization/examples/bne.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def train_bne_tokenizer(texts: list[str],

GraphSettings.ONLY_MINIMAL_MERGES = True
GraphSettings.MAX_MERGE_SIZE = n
GraphSettings.USE_SINGLETONS = False

graphs = tuple(words(text, connected=connected, units=units) for text in texts)

Expand Down
17 changes: 0 additions & 17 deletions complex_tokenization/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ def dot_escape(s: str) -> str:


class GraphVertex:
_instances = {} # Singleton pattern

def __new__(cls, *args, **kwargs):
if not GraphSettings.USE_SINGLETONS:
return super().__new__(cls)

key = (cls, args, tuple(sorted(kwargs.items())))
if key not in cls._instances:
cls._instances[key] = super().__new__(cls)
return cls._instances[key]

def __bytes__(self):
raise NotImplementedError

Expand All @@ -36,12 +25,6 @@ def __str__(self):
return token_replacement
return self_str

def __eq__(self, other):
return self is other

def __hash__(self):
return id(self)

def dot(self, level=0) -> Iterable[str]:
raise NotImplementedError

Expand Down
1 change: 0 additions & 1 deletion complex_tokenization/graphs/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class GraphSettings:
USE_SINGLETONS = False # speeds up computation but hurts visualization
MAX_MERGE_SIZE = 2
ONLY_MINIMAL_MERGES = True
10 changes: 0 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@
@pytest.fixture(autouse=True)
def reset_graph_settings():
original = {
"USE_SINGLETONS": GraphSettings.USE_SINGLETONS,
"MAX_MERGE_SIZE": GraphSettings.MAX_MERGE_SIZE,
"ONLY_MINIMAL_MERGES": GraphSettings.ONLY_MINIMAL_MERGES,
}
yield
GraphSettings.USE_SINGLETONS = original["USE_SINGLETONS"]
GraphSettings.MAX_MERGE_SIZE = original["MAX_MERGE_SIZE"]
GraphSettings.ONLY_MINIMAL_MERGES = original["ONLY_MINIMAL_MERGES"]


@pytest.fixture(autouse=True)
def clear_singleton_cache():
from complex_tokenization.graph import GraphVertex
GraphVertex._instances.clear()
yield
GraphVertex._instances.clear()
36 changes: 0 additions & 36 deletions tests/test_singletons.py

This file was deleted.

Loading