def shift_reduce(queue, w_s, w_l, w_r):
    heads = []
    stack = [util.Token(0, util.ROOT, util.ROOT, None)]
    while len(queue) > 0 or len(stack) > 1:
        feats = make_feature(stack, queue)
        action = get_action(feats, w_s, w_l, w_r, queue)
        do_action(action, stack, queue, heads)
    return heads
Ejemplo n.º 2
0
def shift_reduce(queue, w_s, w_l, w_r):
    heads = []
    stack = [util.Token(0, util.ROOT, util.ROOT, None)]
    while len(queue) > 0 or len(stack) > 1:
        feats = make_feature(stack, queue)
        action = get_action(feats, w_s, w_l, w_r, queue)
        do_action(action, stack, queue, heads)
    return heads
def get_action(feats, w_s, w_l, w_r, queue):
    feats = make_feature(stack, queue)
    score_s = get_score(feats, w_s)
    score_l = get_score(feats, w_l)
    score_r = get_score(feats, w_r)
    if score_s >= score_l and score_s >= score_r and len(queue) > 0:
        return util.SHIFT
    elif score_l >= score_s:
        return util.LEFT_REDUCE
    return util.RIGHT_REDUCE
Ejemplo n.º 4
0
def get_action(feats, w_s, w_l, w_r, queue):
    feats = make_feature(stack, queue)
    score_s = get_score(feats, w_s)
    score_l = get_score(feats, w_l)
    score_r = get_score(feats, w_r)
    if score_s >= score_l and score_s >= score_r and len(queue) > 0:
        return util.SHIFT
    elif score_l >= score_s:
        return util.LEFT_REDUCE
    return util.RIGHT_REDUCE
Ejemplo n.º 5
0
def shift_reduce_train(queue, w_s, w_l, w_r):
    heads = []
    stack = [util.Token(0, util.ROOT, util.ROOT, util.ROOT)]
    while len(queue) > 0 or len(stack) > 1:
        feats = make_feature(stack, queue)
        action = get_action(feats, w_s, w_l, w_s, queue)
        correct_action = get_correct_action()
        if action != correct_action:
            w_a = get_weight_of(action, w_s, w_l, w_r)
            w_ca = get_weight_of(correct_action, w_s, w_l, w_r)
            update_weight(feats, w_a, w_ca)
            do_action(action, stack, queue, heads)
Ejemplo n.º 6
0
    run_time = datetime.now().strftime("%Y%m%d_%H%M%S")

    # ... data params
    n_data_size = 4000
    n_seq = 50
    n_test = 100
    n_future = 5
    n_fwd = 5

    # ... ticker symbols in data set

    #    ticker = ['aapl', 'crm', 'dji', 'flir', 'nvda', 'sp500', 'vix']
    ticker = DOW_30

    df_feature = mf.make_feature(ticker, days=n_data_size, refresh=False)

    feature_columns = df_feature.columns.to_list()
    feature_columns.pop(0)
    n_feature = len(feature_columns)

    # ... model params
    batch_size = 64
    n_epochs = 4

    # ... plot switch
    save_plots = True

    df_summary = pd.DataFrame()

    for n_seq in [90]: