コード例 #1
0
def get_factor_expressions(fws,
                           bws,
                           tfemb,
                           tfdict,
                           valid_fes,
                           sentence,
                           spaths_x=None,
                           cpaths_x=None):
    pw_z = parameter(w_z)
    pb_z = parameter(b_z)
    pw_f = parameter(w_f)
    pb_f = parameter(b_f)

    factexprs = {}
    sentlen = len(fws)

    sortedtfd = sorted(tfdict.keys())
    targetspan = (sortedtfd[0], sortedtfd[-1])

    for j in xrange(sentlen):
        istart = 0
        if USE_SPAN_CLIP and j > ALLOWED_SPANLEN:
            istart = max(0, j - ALLOWED_SPANLEN)
        for i in xrange(istart, j + 1):

            spanlen = scalarInput(j - i + 1)
            logspanlen = scalarInput(math.log(j - i + 1))
            spanwidth = sp_x[SpanWidth.howlongisspan(i, j)]
            spanpos = ap_x[ArgPosition.whereisarg((i, j), targetspan)]

            fbemb_ij_basic = concatenate([
                fws[i][j], bws[i][j], tfemb, spanlen, logspanlen, spanwidth,
                spanpos
            ])
            if USE_DEPS:
                outs = oh_s[OutHeads.getnumouts(i, j, sentence.outheads)]
                shp = spaths_x[sentence.shortest_paths[(i, j, targetspan[0])]]
                fbemb_ij = concatenate([fbemb_ij_basic, outs, shp])
            elif USE_CONSTITS:
                isconstit = scalarInput((i, j) in sentence.constitspans)
                lca = ct_x[sentence.lca[(i, j)][1]]
                phrp = cpaths_x[sentence.cpaths[(i, j, targetspan[0])]]
                fbemb_ij = concatenate([fbemb_ij_basic, isconstit, lca, phrp])
            else:
                fbemb_ij = fbemb_ij_basic

            for y in valid_fes:
                fctr = Factor(i, j, y)
                if USE_HIER and y in feparents:
                    fefixed = esum([fe_x[y]] +
                                   [fe_x[par] for par in feparents[y]])
                else:
                    fefixed = fe_x[y]
                fbemb_ijy = concatenate([fefixed, fbemb_ij])
                factexprs[fctr] = pw_f * rectify(pw_z * fbemb_ijy +
                                                 pb_z) + pb_f
    return factexprs
コード例 #2
0
FRMDIM = configuration["frame_dim"]
FEDIM = configuration["fe_dim"]
INPDIM = TOKDIM + POSDIM + 1

PATHLSTMDIM = configuration["path_lstm_dim"]
PATHDIM = configuration["path_dim"]

if USE_CONSTITS:
    PHRASEDIM = configuration["phrase_dim"]

LSTMINPDIM = configuration["lstm_input_dim"]
LSTMDIM = configuration["lstm_dim"]
LSTMDEPTH = configuration["lstm_depth"]
HIDDENDIM = configuration["hidden_dim"]

ARGPOSDIM = ArgPosition.size()
SPANDIM = SpanWidth.size()

ALL_FEATS_DIM = 2 * LSTMDIM \
                + LUDIM \
                + LUPOSDIM \
                + FRMDIM \
                + LSTMINPDIM \
                + LSTMDIM \
                + FEDIM \
                + ARGPOSDIM \
                + SPANDIM \
                + 2  # spanlen and log spanlen features and is a constitspan

if USE_DEPS:
    DEPHEADDIM = LSTMINPDIM + POSDIM