SCBert/SCBert.py
def __word_pooling (self, encoded_layers_b, layers, idx,  pooling_method, MAX_LEN = 256) :
            """
            Parameters
            ----------
            vectors : list of vectors representing each words including the BOS and EOS tag
            
            pooling_method : string
                average, max or concat.
                
            MAX_LEN : int, optional
                Corresponds to the max number of word to take into account during tokenizing. If a text is 350 words long and 
                MAX_LEN is 256, the text will be truncated after the 256th word, starting at the beginning of the sentence. 
                Default: The default is 256.

            Returns
            -------
            pooled_words : tensor 
                pooled tensors according to the method.

            """
            pooled_words = torch.tensor([])
            
            if pooling_method.lower() == "concat" :
                for layer in layers :   
                    pooled_words = torch.cat((pooled_words, encoded_layers_b[layer][idx]), dim=1)
                    
            if pooling_method.lower() == "average" :
                pooled_words = torch.tensor([[0. for i in range(self.hidden_length)] for j in range(MAX_LEN)])
                for layer in layers :
                    pooled_words = pooled_words.add(encoded_layers_b[layer][idx])
                pooled_words = pooled_words/(len(layers))
                
            elif pooling_method.lower() == "max" :
                pooled_words = torch.tensor([[-100. for i in range(self.hidden_length)] for j in range(MAX_LEN)])
                for layer in layers :   
                    pooled_words = torch.max(pooled_words, encoded_layers_b[layer][idx])
            
            return pooled_words

            Parameters
            ----------
            vectors : list of vectors representing each words including the BOS and EOS tag
            
            pooling_method : string
                average, max or concat.
                
            MAX_LEN : int, optional
                Corresponds to the max number of word to take into account during tokenizing. If a text is 350 words long and 
                MAX_LEN is 256, the text will be truncated after the 256th word, starting at the beginning of the sentence. 
                Default: The default is 256.

            Returns
            -------
            pooled_words : tensor 
                pooled tensors according to the method.

            
Parameters
vectors : list of vectors representing each words including the BOS and EOS tag

pooling_method : string
average, max or concat.

MAX_LEN : int, optional
Corresponds to the max number of word to take into account during tokenizing. If a text is 350 words long and
MAX_LEN is 256, the text will be truncated after the 256th word, starting at the beginning of the sentence.
Default: The default is 256.

Returns

pooled_words : tensor
pooled tensors according to the method.
Parameters vectors : list of vectors representing each words including the BOS and EOS tag pooling_method : string average max or concat . MAX_LEN : int optional Corresponds to the max number of word to take into account during tokenizing . If a text is 350 words long and MAX_LEN is 256 the text will be truncated after the 256th word starting at the beginning of the sentence . Default : The default is 256 . Returns pooled_words : tensor pooled tensors according to the method .
def __word_pooling (self, encoded_layers_b, layers, idx,  pooling_method, MAX_LEN = 256) :
            pooled_words = torch.tensor([])
            if pooling_method.lower() == "concat" :
                for layer in layers :   
                    pooled_words = torch.cat((pooled_words, encoded_layers_b[layer][idx]), dim=1)
            if pooling_method.lower() == "average" :
                pooled_words = torch.tensor([[0. for i in range(self.hidden_length)] for j in range(MAX_LEN)])
                for layer in layers :
                    pooled_words = pooled_words.add(encoded_layers_b[layer][idx])
                pooled_words = pooled_words/(len(layers))
            elif pooling_method.lower() == "max" :
                pooled_words = torch.tensor([[-100. for i in range(self.hidden_length)] for j in range(MAX_LEN)])
                for layer in layers :   
                    pooled_words = torch.max(pooled_words, encoded_layers_b[layer][idx])
            return pooled_words
def __word_pooling ( self , encoded_layers_b , layers , idx , pooling_method , MAX_LEN = 256 ) : pooled_words = torch . tensor ( [ ] ) if pooling_method . lower ( ) == "concat" : for layer in layers : pooled_words = torch . cat ( ( pooled_words , encoded_layers_b [ layer ] [ idx ] ) , dim = 1 ) if pooling_method . lower ( ) == "average" : pooled_words = torch . tensor ( [ [ 0. for i in range ( self . hidden_length ) ] for j in range ( MAX_LEN ) ] ) for layer in layers : pooled_words = pooled_words . add ( encoded_layers_b [ layer ] [ idx ] ) pooled_words = pooled_words / ( len ( layers ) ) elif pooling_method . lower ( ) == "max" : pooled_words = torch . tensor ( [ [ - 100. for i in range ( self . hidden_length ) ] for j in range ( MAX_LEN ) ] ) for layer in layers : pooled_words = torch . max ( pooled_words , encoded_layers_b [ layer ] [ idx ] ) return pooled_words
Parameters
vectors : list of vectors representing each words including the BOS and EOS tag
Parameters vectors : list of vectors representing each words including the BOS and EOS tag
"""
            Parameters
            ----------
            vectors : list of vectors representing each words including the BOS and EOS tag
            
            pooling_method : string
                average, max or concat.
                
            MAX_LEN : int, optional
                Corresponds to the max number of word to take into account during tokenizing. If a text is 350 words long and 
                MAX_LEN is 256, the text will be truncated after the 256th word, starting at the beginning of the sentence. 
                Default: The default is 256.

            Returns
            -------
            pooled_words : tensor 
                pooled tensors according to the method.

            """
self
encoded_layers_b
layers
idx
pooling_method
MAX_LEN