def create_and_check_albert_for_sequence_classification(
     self, config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
 ):
     config.num_labels = self.num_labels
     model = TFAlbertForSequenceClassification(config=config)
     inputs = {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     result = model(inputs)
     self.parent.assertListEqual(list(result["logits"].shape), [self.batch_size, self.num_labels])
Beispiel #2
0
def load_model_and_tokenizer():
    unzipped_saved_model_dir = get_unzipped_dir_path(MODEL_ZIP_PATH,
                                                     UNZIPPED_MODEL_PATH)

    print("Loading pretrained ALBERT classification model")
    start = time.time()

    config = AlbertConfig.from_pretrained(unzipped_saved_model_dir,
                                          num_labels=NUM_LABELS,
                                          max_length=DEFAULT_MAX_LEN)
    model = TFAlbertForSequenceClassification.from_pretrained(
        unzipped_saved_model_dir, config=config)
    tokenizer = AlbertTokenizer.from_pretrained(unzipped_saved_model_dir,
                                                do_lower_case=True)

    duration = time.time() - start
    print(f"Initializing model took {duration}")

    return model, tokenizer