jiant/models.py
def build_task_specific_modules(task, model, d_sent, d_emb, vocab, embedder, args):
    """ Build task-specific components for a task and add them to model.
        These include decoders, linear layers for linear models.
     """
    #XXX We need to get the input size right for the final classification layers
    if args.special_task:
        if task.subspace == 'syn':
            #d_sent = args.k_syn
            if not 'adv' in task.name:
                d_sent = args.k_syn + args.k_shared
            else:
                d_sent = args.k_syn
        if task.subspace == 'sem':
            #d_sent = args.k_sem
            if not 'adv' in task.name:
                d_sent = args.k_sem + args.k_shared
            else:
                d_sent = args.k_sem
    #XXX

    task_params = model._get_task_params(task.name)
    if isinstance(task, SingleClassificationTask): # CoLA, for example
        module = build_single_sentence_module(
            task=task, d_inp=d_sent, use_bert=model.use_bert, params=task_params
        )
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, (PairClassificationTask, PairRegressionTask, PairOrdinalRegressionTask)): # MNLI, for example
        module = build_pair_sentence_module(task, d_sent, model=model, params=task_params)
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, LanguageModelingParsingTask):
        # The LM Parsing task does not support embeddings that use skip_embs.
        hid2voc = build_lm(task, d_sent, args)
        setattr(model, "%s_hid2voc" % task.name, hid2voc)
        setattr(model, "%s_mdl" % task.name, hid2voc)
    elif isinstance(task, LanguageModelingTask):
        d_sent = args.d_hid + (args.skip_embs * d_emb)
        hid2voc = build_lm(task, d_sent, args)
        setattr(model, "%s_hid2voc" % task.name, hid2voc)
    elif isinstance(task, SpanClassificationTask):
        module = build_span_classifier(task, d_sent, task_params)
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, TaggingTask):
        hid2tag = build_tagger(task, d_sent, task.num_tags)
        setattr(model, "%s_mdl" % task.name, hid2tag)
    elif isinstance(task, MultipleChoiceTask):
        module = build_multiple_choice_module(
            task, d_sent, use_bert=model.use_bert, params=task_params
        )
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, EdgeProbingTask):
        module = EdgeClassifierModule(task, d_sent, task_params)
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, SequenceGenerationTask):
        decoder, hid2voc = build_decoder(task, d_sent, vocab, embedder, args)
        setattr(model, "%s_decoder" % task.name, decoder)
        setattr(model, "%s_hid2voc" % task.name, hid2voc)
    elif isinstance(task, (MultiRCTask, ReCoRDTask)):
        module = build_qa_module(task, d_sent, model.use_bert, task_params)
        setattr(model, "%s_mdl" % task.name, module)
    else:
        raise ValueError("Module not found for %s" % task.name)
 Build task-specific components for a task and add them to model.
        These include decoders, linear layers for linear models.
     
Build task-specific components for a task and add them to model.
These include decoders, linear layers for linear models.
Build task - specific components for a task and add them to model . These include decoders linear layers for linear models .
def build_task_specific_modules(task, model, d_sent, d_emb, vocab, embedder, args):
    if args.special_task:
        if task.subspace == 'syn':
            if not 'adv' in task.name:
                d_sent = args.k_syn + args.k_shared
            else:
                d_sent = args.k_syn
        if task.subspace == 'sem':
            if not 'adv' in task.name:
                d_sent = args.k_sem + args.k_shared
            else:
                d_sent = args.k_sem
    task_params = model._get_task_params(task.name)
    if isinstance(task, SingleClassificationTask): 
        module = build_single_sentence_module(
            task=task, d_inp=d_sent, use_bert=model.use_bert, params=task_params
        )
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, (PairClassificationTask, PairRegressionTask, PairOrdinalRegressionTask)): 
        module = build_pair_sentence_module(task, d_sent, model=model, params=task_params)
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, LanguageModelingParsingTask):
        hid2voc = build_lm(task, d_sent, args)
        setattr(model, "%s_hid2voc" % task.name, hid2voc)
        setattr(model, "%s_mdl" % task.name, hid2voc)
    elif isinstance(task, LanguageModelingTask):
        d_sent = args.d_hid + (args.skip_embs * d_emb)
        hid2voc = build_lm(task, d_sent, args)
        setattr(model, "%s_hid2voc" % task.name, hid2voc)
    elif isinstance(task, SpanClassificationTask):
        module = build_span_classifier(task, d_sent, task_params)
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, TaggingTask):
        hid2tag = build_tagger(task, d_sent, task.num_tags)
        setattr(model, "%s_mdl" % task.name, hid2tag)
    elif isinstance(task, MultipleChoiceTask):
        module = build_multiple_choice_module(
            task, d_sent, use_bert=model.use_bert, params=task_params
        )
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, EdgeProbingTask):
        module = EdgeClassifierModule(task, d_sent, task_params)
        setattr(model, "%s_mdl" % task.name, module)
    elif isinstance(task, SequenceGenerationTask):
        decoder, hid2voc = build_decoder(task, d_sent, vocab, embedder, args)
        setattr(model, "%s_decoder" % task.name, decoder)
        setattr(model, "%s_hid2voc" % task.name, hid2voc)
    elif isinstance(task, (MultiRCTask, ReCoRDTask)):
        module = build_qa_module(task, d_sent, model.use_bert, task_params)
        setattr(model, "%s_mdl" % task.name, module)
    else:
        raise ValueError("Module not found for %s" % task.name)
def build_task_specific_modules ( task , model , d_sent , d_emb , vocab , embedder , args ) : if args . special_task : if task . subspace == 'syn' : if not 'adv' in task . name : d_sent = args . k_syn + args . k_shared else : d_sent = args . k_syn if task . subspace == 'sem' : if not 'adv' in task . name : d_sent = args . k_sem + args . k_shared else : d_sent = args . k_sem task_params = model . _get_task_params ( task . name ) if isinstance ( task , SingleClassificationTask ) : module = build_single_sentence_module ( task = task , d_inp = d_sent , use_bert = model . use_bert , params = task_params ) setattr ( model , "%s_mdl" % task . name , module ) elif isinstance ( task , ( PairClassificationTask , PairRegressionTask , PairOrdinalRegressionTask ) ) : module = build_pair_sentence_module ( task , d_sent , model = model , params = task_params ) setattr ( model , "%s_mdl" % task . name , module ) elif isinstance ( task , LanguageModelingParsingTask ) : hid2voc = build_lm ( task , d_sent , args ) setattr ( model , "%s_hid2voc" % task . name , hid2voc ) setattr ( model , "%s_mdl" % task . name , hid2voc ) elif isinstance ( task , LanguageModelingTask ) : d_sent = args . d_hid + ( args . skip_embs * d_emb ) hid2voc = build_lm ( task , d_sent , args ) setattr ( model , "%s_hid2voc" % task . name , hid2voc ) elif isinstance ( task , SpanClassificationTask ) : module = build_span_classifier ( task , d_sent , task_params ) setattr ( model , "%s_mdl" % task . name , module ) elif isinstance ( task , TaggingTask ) : hid2tag = build_tagger ( task , d_sent , task . num_tags ) setattr ( model , "%s_mdl" % task . name , hid2tag ) elif isinstance ( task , MultipleChoiceTask ) : module = build_multiple_choice_module ( task , d_sent , use_bert = model . use_bert , params = task_params ) setattr ( model , "%s_mdl" % task . name , module ) elif isinstance ( task , EdgeProbingTask ) : module = EdgeClassifierModule ( task , d_sent , task_params ) setattr ( model , "%s_mdl" % task . name , module ) elif isinstance ( task , SequenceGenerationTask ) : decoder , hid2voc = build_decoder ( task , d_sent , vocab , embedder , args ) setattr ( model , "%s_decoder" % task . name , decoder ) setattr ( model , "%s_hid2voc" % task . name , hid2voc ) elif isinstance ( task , ( MultiRCTask , ReCoRDTask ) ) : module = build_qa_module ( task , d_sent , model . use_bert , task_params ) setattr ( model , "%s_mdl" % task . name , module ) else : raise ValueError ( "Module not found for %s" % task . name )
Build task-specific components for a task and add them to model.
Build task - specific components for a task and add them to model .
""" Build task-specific components for a task and add them to model.
        These include decoders, linear layers for linear models.
     """ #XXX We need to get the input size right for the final classification layers #d_sent = args.k_syn #d_sent = args.k_sem #XXX # CoLA, for example # MNLI, for example # The LM Parsing task does not support embeddings that use skip_embs.
task
model
d_sent
d_emb
vocab
embedder
args