"""
pretrained_bert_model = nemo_nlp.huggingface.BERT(
    pretrained_model_name=args.pretrained_bert_model, factory=nf)
tokenizer = BertTokenizer.from_pretrained(args.pretrained_bert_model)
hidden_size = pretrained_bert_model.local_parameters["hidden_size"]

data_desc = JointIntentSlotDataDesc(args.data_dir, args.do_lower_case,
                                    args.dataset_name)

query = args.query
if args.do_lower_case:
    query = query.lower()

data_layer = nemo_nlp.BertJointIntentSlotInferDataLayer(
    queries=[query],
    tokenizer=tokenizer,
    max_seq_length=args.max_seq_length,
    batch_size=1)

# Create sentence classification loss on top
classifier = nemo_nlp.JointIntentSlotClassifier(
    hidden_size=hidden_size,
    num_intents=data_desc.num_intents,
    num_slots=data_desc.num_slots,
    dropout=args.fc_dropout)

ids, type_ids, input_mask, loss_mask, subtokens_mask = data_layer()

hidden_states = pretrained_bert_model(input_ids=ids,
                                      token_type_ids=type_ids,
                                      attention_mask=input_mask)
示例#2
0
tokenizer = BertTokenizer.from_pretrained(args.pretrained_bert_model)
hidden_size = pretrained_bert_model.local_parameters["hidden_size"]

data_desc = JointIntentSlotDataDesc(
    args.dataset_name, args.data_dir, args.do_lower_case)

query = args.query
if args.do_lower_case:
    query = query.lower()


dataset = nemo_nlp.BertJointIntentSlotInferDataset(
    queries=[query],
    tokenizer=tokenizer,
    max_seq_length=args.max_seq_length)
data_layer = nemo_nlp.BertJointIntentSlotInferDataLayer(dataset,
                                                        batch_size=1)


# Create sentence classification loss on top
classifier = nemo_nlp.JointIntentSlotClassifier(
    hidden_size=hidden_size,
    num_intents=data_desc.num_intents,
    num_slots=data_desc.num_slots,
    dropout=args.fc_dropout)

ids, type_ids, input_mask, slot_mask = data_layer()


hidden_states = pretrained_bert_model(input_ids=ids,
                                      token_type_ids=type_ids,
                                      attention_mask=input_mask)