Ejemplo n.º 1
0
    args = parser.parse_args()
    args.cuda_device = [0]  # [0, 1, 2, 3]
    args.label_num = 2
    args.threshold = 0.5
    model_name = model_names[args.model]
    torch.backends.cudnn.enabled = False

    logger.debug('------------------------')
    logger.debug('------------------------')
    logger.debug('-------Parameters-------')
    logger.debug('{}: {}'.format('model', model_name))
    logger.debug(args)

    # load data
    # TODO: file path
    reader = EventDataReader()
    train_dataset = ensure_list(reader.read('./dataset/1_{}/{}/train.data'.format(args.file_dir, args.event_type)))
    eval_dataset = ensure_list(reader.read('./dataset/1_{}/{}/eval.data'.format(args.file_dir, args.event_type)))
    with open('./dataset/1_{}/{}/test.data'.format(args.file_dir, args.event_type), 'r', encoding='utf-8') as f:
        test_dataset = json.loads(f.read())

    # reader = EventDataReader()
    # train_dataset = ensure_list(reader.read(os.path.join('.', 'dataset', 'example', 'train.data')))
    # eval_dataset = ensure_list(reader.read(os.path.join('.', 'dataset', 'example', 'train.data')))
    # with open(os.path.join('.', 'dataset', 'example', 'train.data'), 'r', encoding='utf-8') as f:
    #     test_dataset = json.loads(f.read())

    # get vocabulary and embedding
    vocab = Vocabulary.from_instances(train_dataset + eval_dataset,
                                      min_count={"trigger_0": 0,
                                                 "trigger_agent_0": 0,
Ejemplo n.º 2
0
    # init parameters
    parser = argparse.ArgumentParser()
    args = parser.parse_args()
    args.embedding_size = 300
    args.learning_rate = 1e-4
    args.batch_size = 1
    args.epochs = 10
    args.patience = 1
    args.cuda_device = -1
    args.hidden_size = 8
    args.hop_num = 6
    args.label_num = 2
    args.threshold = 0.5

    # load data
    reader = EventDataReader()
    train_dataset = ensure_list(
        reader.read(os.path.join('..', 'dataset', 'example', 'train.data')))
    eval_dataset = ensure_list(
        reader.read(os.path.join('..', 'dataset', 'example', 'train.data')))
    test_dataset = ensure_list(
        reader.read(os.path.join('..', 'dataset', 'example', 'train.data')))

    # get vocabulary and embedding
    vocab = Vocabulary.from_instances(train_dataset + eval_dataset,
                                      min_count={
                                          "trigger_0": 0,
                                          "trigger_agent_0": 0,
                                          "agent_attri_0": 0,
                                          "trigger_object_0": 0,
                                          "object_attri_0": 0,
Ejemplo n.º 3
0
event_type = [-1]

args.embedding_size = 300
args.learning_rate = 1e-3
args.cuda_device = [0]
args.hidden_size = 32
args.hop_num = 3
args.label_num = 2
args.threshold = 0.5

# 读取文件

for et in event_type:

    reader = EventDataReader()
    train_dataset = ensure_list(
        reader.read(os.path.join('.', 'dataset', '1_4', str(et),
                                 'train.data')))
    eval_dataset = ensure_list(
        reader.read(os.path.join('.', 'dataset', '1_4', str(et), 'eval.data')))
    with open(os.path.join('.', 'dataset', '1_4', str(et), 'test.data'),
              'r',
              encoding='utf-8') as f:
        test_dataset = json.loads(f.read())
    print('load done')

    vocab = Vocabulary.from_instances(train_dataset + eval_dataset,
                                      min_count={
                                          "trigger_0": 0,
                                          "trigger_agent_0": 0,