mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 09:57:26 +03:00 
			
		
		
		
	* Add continue_for argument to parser 'partial' function, which is now renamed to get_state
This commit is contained in:
		
							parent
							
								
									0653288fa5
								
							
						
					
					
						commit
						18331dca89
					
				| 
						 | 
					@ -88,14 +88,30 @@ cdef class Parser:
 | 
				
			||||||
            self.parse(stcls, eg.c)
 | 
					            self.parse(stcls, eg.c)
 | 
				
			||||||
        tokens.set_parse(stcls._sent)
 | 
					        tokens.set_parse(stcls._sent)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def partial(self, Doc tokens, initial_actions):
 | 
					    def get_state(self, Doc tokens, initial_actions, continue_for=0):
 | 
				
			||||||
        cdef StateClass stcls = StateClass.init(tokens.data, tokens.length)
 | 
					        cdef StateClass stcls = StateClass.init(tokens.data, tokens.length)
 | 
				
			||||||
        self.moves.initialize_state(stcls)
 | 
					        self.moves.initialize_state(stcls)
 | 
				
			||||||
        cdef object action_name
 | 
					        cdef object action_name
 | 
				
			||||||
        cdef Transition action
 | 
					        cdef Transition action
 | 
				
			||||||
 | 
					        cdef Example eg
 | 
				
			||||||
        for action_name in initial_actions:
 | 
					        for action_name in initial_actions:
 | 
				
			||||||
 | 
					            try:
 | 
				
			||||||
                action = self.moves.lookup_transition(action_name)
 | 
					                action = self.moves.lookup_transition(action_name)
 | 
				
			||||||
 | 
					            except IndexError:
 | 
				
			||||||
 | 
					                break
 | 
				
			||||||
            action.do(stcls, action.label)
 | 
					            action.do(stcls, action.label)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            eg = Example(self.model.n_classes, CONTEXT_SIZE,
 | 
				
			||||||
 | 
					                         self.model.n_feats, self.model.n_feats)
 | 
				
			||||||
 | 
					            while not stcls.is_final() and continue_for != 0:
 | 
				
			||||||
 | 
					                memset(eg.c.scores, 0, eg.c.nr_class * sizeof(weight_t))
 | 
				
			||||||
 | 
					                self.moves.set_valid(eg.c.is_valid, stcls)
 | 
				
			||||||
 | 
					                fill_context(eg.c.atoms, stcls)
 | 
				
			||||||
 | 
					                self.model.set_scores(eg.c.scores, eg.c.atoms)
 | 
				
			||||||
 | 
					                eg.guess = arg_max_if_true(eg.c.scores, eg.c.is_valid, self.model.n_classes)
 | 
				
			||||||
 | 
					                self.moves.c[eg.guess].do(stcls, self.moves.c[eg.c.guess].label)
 | 
				
			||||||
 | 
					        if stcls.is_final():
 | 
				
			||||||
 | 
					            self.moves.finalize_state(stcls)
 | 
				
			||||||
        tokens.set_parse(stcls._sent)
 | 
					        tokens.set_parse(stcls._sent)
 | 
				
			||||||
        return stcls
 | 
					        return stcls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user