mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 01:48:04 +03:00 
			
		
		
		
	Add span.tensor and token.tensor attributes
This commit is contained in:
		
							parent
							
								
									d3071ecdbc
								
							
						
					
					
						commit
						944a66c326
					
				| 
						 | 
				
			
			@ -471,6 +471,17 @@ cdef class Span:
 | 
			
		|||
            self._vector_norm = xp.sqrt(total) if total != 0. else 0.
 | 
			
		||||
        return self._vector_norm
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def tensor(self):
 | 
			
		||||
        """The span's slice of the doc's tensor.
 | 
			
		||||
        
 | 
			
		||||
        RETURNS (ndarray[ndim=2, dtype='float32']): A 2D numpy or cupy array
 | 
			
		||||
            representing the span's semantics.
 | 
			
		||||
        """
 | 
			
		||||
        if self.doc.tensor is None:
 | 
			
		||||
            return None
 | 
			
		||||
        return self.doc.tensor[self.start : self.end]
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def sentiment(self):
 | 
			
		||||
        """RETURNS (float): A scalar value indicating the positivity or
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -408,6 +408,12 @@ cdef class Token:
 | 
			
		|||
        total = (vector ** 2).sum()
 | 
			
		||||
        return xp.sqrt(total) if total != 0. else 0.
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def tensor(self):
 | 
			
		||||
        if self.doc.tensor is None:
 | 
			
		||||
            return None
 | 
			
		||||
        return self.doc.tensor[self.i]
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def n_lefts(self):
 | 
			
		||||
        """The number of leftward immediate children of the word, in the
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user