mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-01 00:17:44 +03:00 
			
		
		
		
	Update beam-parser to allow parser to maintain nogil
This commit is contained in:
		
							parent
							
								
									3d4e389d23
								
							
						
					
					
						commit
						c61c501406
					
				|  | @ -78,11 +78,13 @@ cdef class BeamParser(Parser): | ||||||
|         self.beam_density = kwargs.get('beam_density', BEAM_DENSITY) |         self.beam_density = kwargs.get('beam_density', BEAM_DENSITY) | ||||||
|         Parser.__init__(self, *args, **kwargs) |         Parser.__init__(self, *args, **kwargs) | ||||||
| 
 | 
 | ||||||
|     cdef int parseC(self, TokenC* tokens, int length, int nr_feat, int nr_class) with gil: |     cdef int parseC(self, TokenC* tokens, int length, int nr_feat) nogil: | ||||||
|         self._parseC(tokens, length, nr_feat, nr_class) |         with gil: | ||||||
|  |             self._parseC(tokens, length, nr_feat, self.moves.n_moves) | ||||||
| 
 | 
 | ||||||
|     cdef int _parseC(self, TokenC* tokens, int length, int nr_feat, int nr_class) except -1: |     cdef int _parseC(self, TokenC* tokens, int length, int nr_feat, int nr_class) except -1: | ||||||
|         cdef Beam beam = Beam(self.moves.n_moves, self.beam_width, min_density=self.beam_density) |         cdef Beam beam = Beam(self.moves.n_moves, self.beam_width, min_density=self.beam_density) | ||||||
|  |         # TODO: How do we handle new labels here? This increases nr_class | ||||||
|         beam.initialize(self.moves.init_beam_state, length, tokens) |         beam.initialize(self.moves.init_beam_state, length, tokens) | ||||||
|         beam.check_done(_check_final_state, NULL) |         beam.check_done(_check_final_state, NULL) | ||||||
|         if beam.is_done: |         if beam.is_done: | ||||||
|  | @ -190,7 +192,7 @@ cdef class BeamParser(Parser): | ||||||
|         if follow_gold: |         if follow_gold: | ||||||
|             beam.advance(_transition_state, NULL, <void*>self.moves.c) |             beam.advance(_transition_state, NULL, <void*>self.moves.c) | ||||||
|         else: |         else: | ||||||
|             beam.advance(_transition_state, NULL, <void*>self.moves.c) |             beam.advance(_transition_state, _hash_state, <void*>self.moves.c) | ||||||
|         beam.check_done(_check_final_state, NULL) |         beam.check_done(_check_final_state, NULL) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -254,11 +256,13 @@ def is_gold(StateClass state, GoldParse gold, StringStore strings): | ||||||
|     predicted = set() |     predicted = set() | ||||||
|     truth = set() |     truth = set() | ||||||
|     for i in range(gold.length): |     for i in range(gold.length): | ||||||
|  |         if gold.cand_to_gold[i] is None: | ||||||
|  |             continue | ||||||
|         if state.safe_get(i).dep: |         if state.safe_get(i).dep: | ||||||
|             predicted.add((i, state.H(i), strings[state.safe_get(i).dep])) |             predicted.add((i, state.H(i), strings[state.safe_get(i).dep])) | ||||||
|         else: |         else: | ||||||
|             predicted.add((i, state.H(i), 'ROOT')) |             predicted.add((i, state.H(i), 'ROOT')) | ||||||
|         id_, word, tag, head, dep, ner = gold.orig_annot[i] |         id_, word, tag, head, dep, ner = gold.orig_annot[gold.cand_to_gold[i]] | ||||||
|         truth.add((id_, head, dep)) |         truth.add((id_, head, dep)) | ||||||
|     return truth == predicted |     return truth == predicted | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user