linguicator_predictor/models/en/distilgpt2.py
def predict(self, sequence, max_length = 150):
        """
        Predicts the next words from a sequence within a maximum length.

        :param sequence: initial sequence
        :type  sequence: str

        :param max_length: prediction maximum length
        :type  max_length: int

        :returns: predicted sequence
        :rtype: str
        """

        # tokenize input sequence as pytorch tensor
        tokenized = self.__tokenizer.encode(sequence, return_tensors = 'pt')

        # predict next tokens
        predicted = self.__model.generate(
            tokenized,
            pad_token_id = self.__tokenizer.eos_token_id,
            min_length = MINUMUM_LENGTH,
            max_length = max_length,
            do_sample = True,
            repetition_penalty = float('inf'),
            top_k = 50,
            top_p = 0.95
        )

        # return decoded generated sequence
        return self.__tokenizer.decode(predicted.tolist()[0])

        Predicts the next words from a sequence within a maximum length.

        :param sequence: initial sequence
        :type  sequence: str

        :param max_length: prediction maximum length
        :type  max_length: int

        :returns: predicted sequence
        :rtype: str
        
Predicts the next words from a sequence within a maximum length.
Predicts the next words from a sequence within a maximum length .
def predict(self, sequence, max_length = 150):
        tokenized = self.__tokenizer.encode(sequence, return_tensors = 'pt')
        predicted = self.__model.generate(
            tokenized,
            pad_token_id = self.__tokenizer.eos_token_id,
            min_length = MINUMUM_LENGTH,
            max_length = max_length,
            do_sample = True,
            repetition_penalty = float('inf'),
            top_k = 50,
            top_p = 0.95
        )
        return self.__tokenizer.decode(predicted.tolist()[0])
def predict ( self , sequence , max_length = 150 ) : tokenized = self . __tokenizer . encode ( sequence , return_tensors = 'pt' ) predicted = self . __model . generate ( tokenized , pad_token_id = self . __tokenizer . eos_token_id , min_length = MINUMUM_LENGTH , max_length = max_length , do_sample = True , repetition_penalty = float ( 'inf' ) , top_k = 50 , top_p = 0.95 ) return self . __tokenizer . decode ( predicted . tolist ( ) [ 0 ] )
Predicts the next words from a sequence within a maximum length.
Predicts the next words from a sequence within a maximum length .
"""
        Predicts the next words from a sequence within a maximum length.

        :param sequence: initial sequence
        :type  sequence: str

        :param max_length: prediction maximum length
        :type  max_length: int

        :returns: predicted sequence
        :rtype: str
        """ # tokenize input sequence as pytorch tensor # predict next tokens # return decoded generated sequence
None
str
self
sequence
None
max_length
prediction maximum length
prediction maximum length