【发布时间】:2019-12-22 01:52:54
【问题描述】:
我正在尝试从序列化对象加载 EntityRuler。加载对象的过程不会失败或任何事情,但我确信它不会这样做。我仔细检查了 try 和 except 语句,它仍然没有设置新的统治者。我不确定它是否与 EntityRuler 有关。
这就是我的序列化方式:
def save_loc_rules(stations):
print('Adding rules')
for station in stations:
ruler.add_patterns([{"label": "GPE", "pattern": station.lower()}])
nlp.add_pipe(ruler)
rules = ruler.to_bytes()
with open("location_rules.pickle", "wb") as f:
pickle.dump((rules), f)
print('Rules added')
这是反序列化的方式:
def load_loc_rules(ruler):
#ruler = EntityRuler(nlp)
print('Loading location rules')
with open("location_rules.pickle", "rb") as f:
rules = pickle.load(f)
print('Loading locations failed')
#print('Location rules loaded')
ruler = ruler.from_bytes(rules)
【问题讨论】:
标签: python serialization deserialization spacy