我使用下面的代码将自定义添加Lookups
到自定义Lanuage
类:
def create_lookups():
lookups = Lookups()
lookups.add_table("lemma_lookup", LOOKUP)
lookups.add_table("lemma_rules", json_to_dict('lemma_rules.json'))
lookups.add_table("lemma_index", json_to_dict('lemma_index.json'))
lookups.add_table("lemma_exc", json_to_dict('lemma_exc.json'))
return lookups
def json_to_dict(filename):
location = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
with open(os.path.join(location, filename)) as f_in:
return json.load(f_in)
@CustomeLanguage.factory(
"lemmatizer",
assigns=["token.lemma"],
default_config={"model": None, "mode": "lookup", "overwrite": False},
default_score_weights={"lemma_acc": 1.0},
)
def make_lemmatizer(
nlp: Language, model: Optional[Model], name: str, mode: str, overwrite: bool
):
lemmatizer = Lemmatizer(nlp.vocab, model, name, mode=mode, overwrite=overwrite)
lemmatizer.lookups = create_lookups()
return lemmatizer
但是当我实例CustomLanguage
化nlp.vocab.lookups
. 有什么问题,我该如何解决?