示例#1
0
def main():
    args = parse_args()
    OpenKSModel.list_modules()
    model: ExpertRecModel = OpenKSModel.get_module("PyTorch", "HGTExpertRec")(
        "openks/data/nsf_dblp_kg/nsfkg/", args)
    model.preprocess_data()
    model.load_data_and_model()
    logger.info('Training HGT with #param: %d' % model.get_n_params())
    model.train_expert()
    model.evaluate()
示例#2
0
# Copyright (c) 2022 OpenKS Authors, SCIR, HIT.
# All Rights Reserved.

from openks.models import OpenKSModel
import argparse
# 列出已加载模型
OpenKSModel.list_modules()

parser = argparse.ArgumentParser(
    description=
    'Implement of SISO, SIMO, MISO, MIMO for Conditional Statement Extraction')

# Model parameters.
parser.add_argument('--train',
                    type=str,
                    default='data/stmts-train.tsv',
                    help='location of the labeled training set')
parser.add_argument('--eval',
                    type=str,
                    default='data/stmts-eval.tsv',
                    help='location of the evaluation set')
parser.add_argument('--model_name',
                    type=str,
                    default='MIMO_BERT_LSTM',
                    help='the model to be trained')
parser.add_argument('--language_model',
                    type=str,
                    default='resources/model.pt',
                    help='language model checkpoint to use')
parser.add_argument('--wordembed',
                    type=str,
示例#3
0
# 载入参数配置与数据集载入
loader_config.source_type = SourceType.LOCAL_FILE
loader_config.file_type = FileType.OPENKS
# loader_config.source_type = SourceType.NEO4J
# graph_db = Graph(host='127.0.0.1', http_port=7474, user='******', password='******')
# loader_config.graph_db = graph_db
loader_config.source_uris = 'openks/data/company-kg'
# loader_config.source_uris = 'openks/data/medical-kg'
loader_config.data_name = 'my-data-set'
# 图谱数据结构载入
graph_loader = GraphLoader(loader_config)
graph = graph_loader.graph
graph.info_display()
''' 图谱表示学习模型训练 '''
# 列出已加载模型
OpenKSModel.list_modules()
# 算法模型选择配置
args = {
	'gpu': False, 
	'learning_rate': 0.001, 
	'epoch': 10, 
	'batch_size': 1000, 
	'optimizer': 'adam', 
	'hidden_size': 50, 
	'margin': 4.0, 
	'model_dir': './', 
	'eval_freq': 10
}
platform = 'Paddle'
executor = 'KGLearn'
model = 'TransR'
示例#4
0
# Copyright (c) 2021 OpenKS Authors, DCD Research Lab, Zhejiang University. 
# All Rights Reserved.

import argparse
from openks.models.pytorch import semeval_constant as constant
from openks.loaders import loader_config, SourceType, FileType, Loader
from openks.models import OpenKSModel

''' 载入数据 '''
# TODO
dataset = None

''' 文本信息抽取模型训练 '''
# 列出已加载模型
OpenKSModel.list_modules()
# 算法模型选择配置
parser = argparse.ArgumentParser(description='RE args.')
parser.add_argument("--model", default=None, type=str, required=True)
parser.add_argument("--output_dir", default=None, type=str, required=True,
                    help="The output directory where the model predictions and checkpoints will be written.")
parser.add_argument("--eval_per_epoch", default=10, type=int,
                    help="How many times it evaluates on dev set per epoch")
parser.add_argument("--max_seq_length", default=128, type=int,
                    help="The maximum total input sequence length after WordPiece tokenization. \n"
                            "Sequences longer than this will be truncated, and sequences shorter \n"
                            "than this will be padded.")
parser.add_argument("--negative_label", default="no_relation", type=str)
parser.add_argument('--fp16', action='store_true',
                    help="Whether to use 16-bit float precision instead of 32-bit")
parser.add_argument("--do_train", action='store_true', help="Whether to run training.")
parser.add_argument("--train_file", default=None, type=str, help="The path of the training data.")
示例#5
0
from openks.loaders import loader_config, SourceType, FileType, Loader
from openks.models import OpenKSModel

''' 文本载入与MMD数据结构生成 '''
# 载入参数配置与数据集载入
loader_config.source_type = SourceType.LOCAL_FILE
loader_config.file_type = FileType.OPENKS
loader_config.source_uris = 'openks/data/patent-text'
loader_config.data_name = 'my-data-set'
loader = Loader(loader_config)
dataset = loader.dataset
dataset.info_display()

''' 文本信息抽取模型训练 '''
# 列出已加载模型
OpenKSModel.list_modules()
# 算法模型选择配置
args = {
    'extractor': 'topic-rake', 
    'finetuned': '/path/to/finetuned/word_embedding',
    'stopword': '/path/to/domain/stopwords.txt',
    'stopword_open': '/path/to/common/stopwords.txt', 
    'params': {
        'MIN_SCORE_TOTAL': 0.2,
        'MIN_WORD_LEN': 3,
        'SUFFIX_REMOVE': True,
        'STOPWORD_SINGLE_CHECK': True,
        'OPEN_STOPWORD': True,
        'WORD_SEPARATOR': True
    },
    'result_dir': loader_config.source_uris, 
示例#6
0
from openks.models import OpenKSModel

platform = 'Paddle'
executor = 'HypernymExtract'
model = 'HypernymExtract'
print("根据配置,使用 {} 框架,{} 执行器训练 {} 模型。".format(platform, executor, model))
print("-----------------------------------------------")
# 模型训练
entity = '苹果'
executor = OpenKSModel.get_module(platform, executor)
hypernym_extract = executor()
res = hypernym_extract.entity2hyper_lst(entity)
print(res)

print("-----------------------------------------------")
val_data = demand_data(val_texts, val_abs, val_label)

#%%
'''TRAINING MODEL'''

print('--'*10)
print('TRAINING MODEL...')
print('--'*10)

# from openks.models.pytorch.attn_inter import AttInter
from torch_geometric.data import Data
from openks.models import OpenKSModel

platform = 'PyTorch'
model_name = 'AttInter'
AttInter = OpenKSModel.get_module(platform, model_name)


import argparse
def parse_args(args=None):
	parser = argparse.ArgumentParser(
		description='Training and Testing Command Predictions Models',
	)
	parser.add_argument('--batch_size', default=1, type=int)
	parser.add_argument('--feat_dim', default=768, type=int)
	parser.add_argument('--conv_emb_dim', default=300, type=int)
	parser.add_argument('--pred_hid_dim', default=84, type=int)
	parser.add_argument('--graph_pooling', default="mean", type=str)
	parser.add_argument('--gnn_type', default="gin", type=str)
	parser.add_argument('--conv_drop_ratio', default=0.0, type=float)
	parser.add_argument('--JK', type=str, default="last",
loader_config.source_type = SourceType.LOCAL_FILE
loader_config.file_type = FileType.OPENKS
# loader_config.source_type = SourceType.NEO4J
# graph_db = Graph(host='127.0.0.1', http_port=7474, user='******', password='******')
# loader_config.graph_db = graph_db
loader_config.source_uris = 'openks/data/company-kg'
# loader_config.source_uris = 'openks/data/FB15k-237'
# loader_config.source_uris = 'openks/data/medical-kg'
loader_config.data_name = 'my-data-set'
# 图谱数据结构载入
graph_loader = GraphLoader(loader_config)
graph = graph_loader.graph
graph.info_display()
''' 图谱表示学习模型训练 '''
# 列出已加载模型
OpenKSModel.list_modules()
# 算法模型选择配置
args = {
    'gpu': True,
    'learning_rate': 0.001,
    'epoch': 500,
    'batch_size': 1024,
    'optimizer': 'adam',
    'hidden_size': 500,
    'margin': 4.0,
    'model_dir': './',
    'eval_freq': 20,
    'gamma': 12.0,
    'epsilon': 2.0
}
platform = 'PyTorch'