예제 #1
0
def main():
    parser = argparse.ArgumentParser()

    # Required parameters
    parser.add_argument("--bert_model_dir",
                        default=config.bert_model_dir,
                        type=str,
                        help="Bert pre-trained model dir")
    args = parser.parse_args()

    nlp = pipeline(
        'fill-mask',
        model=args.bert_model_dir,
        tokenizer=args.bert_model_dir,
        device=0,  # gpu device id
    )
    i = nlp('hi lili, What is the name of the [MASK] ?')
    print(i)

    i = nlp('今天[MASK]情很好')
    print(i)

    i = nlp('少先队员[MASK]该为老人让座')
    print(i)

    i = nlp('[MASK]七学习是人工智能领遇最能体现智能的一个分知')
    print(i)

    i = nlp('机[MASK]学习是人工智能领遇最能体现智能的一个分知')
    print(i)
예제 #2
0
def main():
    parser = argparse.ArgumentParser()

    # Required parameters
    parser.add_argument("--bert_model_dir",
                        default=os.path.join(
                            pwd_path,
                            '../data/bert_models/chinese_finetuned_lm/'),
                        type=str,
                        help="Bert pre-trained model dir")
    args = parser.parse_args()

    nlp = pipeline('fill-mask',
                   model=args.bert_model_dir,
                   tokenizer=args.bert_model_dir)
    i = nlp('hi lili, What is the name of the [MASK] ?')
    print(i)

    i = nlp('今天[MASK]情很好')
    print(i)

    i = nlp('少先队员[MASK]该为老人让座')
    print(i)

    i = nlp('[MASK]七学习是人工智能领遇最能体现智能的一个分知')
    print(i)

    i = nlp('机[MASK]学习是人工智能领遇最能体现智能的一个分知')
    print(i)
예제 #3
0
    def __init__(self, d_model_dir=D_model_dir, g_model_dir=G_model_dir):
        super(ElectraCorrector, self).__init__()
        self.name = 'electra_corrector'
        t1 = time.time()
        self.g_model = pipeline("fill-mask",
                                model=g_model_dir,
                                tokenizer=g_model_dir)
        self.d_model = ElectraForPreTraining.from_pretrained(d_model_dir)

        if self.g_model:
            self.mask = self.g_model.tokenizer.mask_token
            logger.debug('Loaded electra model: %s, spend: %.3f s.' %
                         (g_model_dir, time.time() - t1))
예제 #4
0
 def __init__(self, bert_model_dir=config.bert_model_dir):
     super(BertCorrector, self).__init__()
     self.name = 'bert_corrector'
     t1 = time.time()
     self.model = pipeline(
         'fill-mask',
         model=bert_model_dir,
         tokenizer=bert_model_dir,
         device=0,  # gpu device id
     )
     if self.model:
         self.mask = self.model.tokenizer.mask_token
         logger.debug('Loaded bert model: %s, spend: %.3f s.' % (bert_model_dir, time.time() - t1))
예제 #5
0
def fill_mask_demo():
    nlp = pipeline(
        "fill-mask",
        model=G_model_dir,
        tokenizer=G_model_dir
    )
    print(nlp.tokenizer.mask_token)
    print(
        nlp(f"HuggingFace is creating a {nlp.tokenizer.mask_token} that the community uses to solve NLP tasks.")
    )

    i = nlp('hi, What is your [MASK] ?')
    print(i)

    i = nlp('今天[MASK]情很好')
    print(i)
예제 #6
0
 def __init__(self,
              bert_model_dir=os.path.join(
                  pwd_path, '../data/bert_models/chinese_finetuned_lm/')):
     super(BertCorrector, self).__init__()
     self.name = 'bert_corrector'
     t1 = time.time()
     self.model = pipeline(
         'fill-mask',
         model=bert_model_dir,
         tokenizer=bert_model_dir,
         device=0,  # gpu device id
     )
     if self.model:
         self.mask = self.model.tokenizer.mask_token
         logger.debug('Loaded bert model: %s, spend: %.3f s.' %
                      (bert_model_dir, time.time() - t1))