The registry (powered by catalogue) allows you to swap out the logic used to generate keys, split keys, or extract phrases. You can define custom functions, register them, and then pass them to Sense2Vec or Sense2VecComponent via the overrides dictionary.
Available Registry Names:
registry.make_key: Generates a string key from a word and sense (e.g., word|sense).registry.split_key: Splits a string key back into a (word, sense) tuple.registry.make_spacy_key: Generates a (word, sense) tuple from a spaCy Token or Span.registry.get_phrases: Returns a list of Span objects (e.g., noun phrases) for sense2vec.registry.merge_phrases: Merges sense2vec phrases into single tokens in a Doc.
Example Customization:
from sense2vec import registry
@registry.make_key.register("custom")
def custom_make_key(word, sense):
return f"{word}###{sense}"
@registry.split_key.register("custom")
def custom_split_key(key):
word, sense = key.split("###")
return word, sense
# Use the custom functions via overrides
overrides = {"make_key": "custom", "split_key": "custom"}
s2v = Sense2Vec(overrides=overrides)
from sense2vec import registry
@registry.make_key.register("custom")
def custom_make_key(word, sense):
return f"{word}###{sense}"
@registry.split_key.register("custom")
def custom_split_key(key):
word, sense = key.split("###")
return word, sense
overrides = {"make_key": "custom", "split_key": "custom"}
s2v = Sense2Vec(overrides=overrides)