Skip to content

PhraseMatcher persistance issue #5493

Discussion options

You must be logged in to vote

Hi, after unpickling the PhraseMatcher, I think the missing step is to initialize your new nlp pipeline with the same vocab like this:

import pickle
import spacy
from spacy.matcher import PhraseMatcher

nlp = spacy.blank("en")
pm = PhraseMatcher(nlp.vocab)
pm.add("A", [nlp("a"), nlp("the")])
b = pickle.dumps(pm)

pm2 = pickle.loads(b)
nlp2 = spacy.blank("en", vocab=pm2.vocab) # vocab from reloaded PhraseMatcher

print(pm2(nlp("the dog is not a cat")))
# [(14862748245026736845, 0, 1), (14862748245026736845, 4, 5)]

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ines
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat / matcher Feature: Token, phrase and dependency matcher
2 participants
Converted from issue

This discussion was converted from issue #5493 on December 11, 2020 00:18.