【问题标题】:deserializing object for spacy [python]反序列化 spacy 的对象 [python]
【发布时间】: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


    【解决方案1】:

    在文档页面上花了很多时间后,我意识到当我加载 EntityRuler 对象时,我必须将它添加到 NLP 管道中。 所以加载后我添加了:

    nlp.add_pipe(ruler)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 2021-10-01
      • 2018-01-09
      • 1970-01-01
      • 2021-12-08
      • 2013-09-24
      • 2016-10-12
      相关资源
      最近更新 更多