mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-11 04:08:09 +03:00
Restore support for prior data format -- specifically, the labels field of the config.
This commit is contained in:
parent
c36e8676aa
commit
59038f7efa
|
@ -287,10 +287,6 @@ cdef class ArcEager(TransitionSystem):
|
|||
RIGHT: {},
|
||||
LEFT: {},
|
||||
BREAK: {'ROOT': True}})
|
||||
for label in kwargs.get('labels', []):
|
||||
if label.upper() != 'ROOT':
|
||||
actions[LEFT][label] = True
|
||||
actions[RIGHT][label] = True
|
||||
for label in kwargs.get('left_labels', []):
|
||||
if label.upper() != 'ROOT':
|
||||
actions[LEFT][label] = True
|
||||
|
|
|
@ -78,6 +78,9 @@ cdef class Parser:
|
|||
def load(cls, path, Vocab vocab, TransitionSystem=None, require=False):
|
||||
with (path / 'config.json').open() as file_:
|
||||
cfg = json.load(file_)
|
||||
# TODO: remove this shim when we don't have to support older data
|
||||
if 'labels' in cfg:
|
||||
cfg['actions'] = cfg.pop('labels')
|
||||
self = cls(vocab, TransitionSystem=TransitionSystem, model=None, **cfg)
|
||||
if (path / 'model').exists():
|
||||
self.model.load(str(path / 'model'))
|
||||
|
@ -188,8 +191,8 @@ cdef class Parser:
|
|||
free(eg.is_valid)
|
||||
return 0
|
||||
|
||||
def update(self, Doc tokens, raw_gold):
|
||||
cdef GoldParse gold = self.preprocess_gold(raw_gold)
|
||||
def update(self, Doc tokens, GoldParse gold):
|
||||
self.moves.preprocess_gold(gold)
|
||||
cdef StateClass stcls = StateClass.init(tokens.c, tokens.length)
|
||||
self.moves.initialize_state(stcls.c)
|
||||
cdef Pool mem = Pool()
|
||||
|
@ -226,15 +229,6 @@ cdef class Parser:
|
|||
for action in self.moves.action_types:
|
||||
self.moves.add_action(action, label)
|
||||
|
||||
def preprocess_gold(self, raw_gold):
|
||||
cdef GoldParse gold
|
||||
if isinstance(raw_gold, GoldParse):
|
||||
gold = raw_gold
|
||||
self.moves.preprocess_gold(raw_gold)
|
||||
return gold
|
||||
else:
|
||||
raise ValueError("Parser.preprocess_gold requires GoldParse-type input.")
|
||||
|
||||
|
||||
cdef class StepwiseState:
|
||||
cdef readonly StateClass stcls
|
||||
|
|
Loading…
Reference in New Issue
Block a user