Skip to content

Commit

Permalink
modified knowledge extraction models package and file names
Browse files Browse the repository at this point in the history
  • Loading branch information
changzong committed Apr 22, 2021
1 parent 95370ba commit e63ab4e
Show file tree
Hide file tree
Showing 24 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/kg_learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
platform = 'PyTorch'
executor = 'KGLearn'
model = 'TransR'
model = 'TransE'
print("根据配置,使用 {} 框架,{} 执行器训练 {} 模型。".format(platform, executor, model))
print("-----------------------------------------------")
# 模型训练
Expand Down
2 changes: 1 addition & 1 deletion examples/text_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'model_dir': './ner_model'
}
platform = 'Paddle'
executor = 'general'
executor = 'KELearn'
model = 'entity-extract'
print("根据配置,使用 {} 框架,{} 执行器训练 {} 模型。".format(platform, executor, model))
print("-----------------------------------------------")
Expand Down
2 changes: 1 addition & 1 deletion examples/text_industry_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'log_file_path': './industry_ner_model/run.log'
}
platform = 'TensorFlow'
executor = 'general'
executor = 'KELearn'
model = 'industry-entity-extract'
print("根据配置,使用 {} 框架,{} 执行器训练 {} 模型。".format(platform, executor, model))
print("-----------------------------------------------")
Expand Down
2 changes: 1 addition & 1 deletion examples/text_keyphrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}

platform = 'MLLib'
executor = 'general'
executor = 'KELearn'
model = 'keyphrase-rake-topic'
print("根据配置,使用 {} 框架,{} 执行器训练 {} 模型。".format(platform, executor, model))
print("-----------------------------------------------")
Expand Down
4 changes: 2 additions & 2 deletions openks/models/mllib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"""
init
"""
from .gen_learn import *
from .gen_modules import *
from .ke_learn import *
from .ke_modules import *
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import argparse
import json

from ..model import GeneralModel
from ..model import KELearnModel

@GeneralModel.register("general", "MLLib")
class GeneralMLLib(GeneralModel):
@KELearnModel.register("KELearn", "MLLib")
class KELearnMLLib(KELearnModel):
def __init__(self, name='mllib-default', dataset=None, model=None, args=None):
self.name = name
self.dataset = dataset
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion openks/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def run(self, *args):
return NotImplemented


class GeneralModel(OpenKSModel):
class KELearnModel(OpenKSModel):
''' Base class for knowledge graph building trainer, such as text and image information extraction '''
def __init__(self, name: str = 'model-name', dataset: MMD = None, args: List = None):
self.name = name
Expand Down
4 changes: 2 additions & 2 deletions openks/models/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
init
"""
from .kg_learn import *
from .gen_learn import *
from .ke_learn import *
from .kg_modules import *
from .gen_modules import *
from .ke_modules import *
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import paddle.fluid as fluid
import time
import ast
from ..model import GeneralModel
from ..model import KELearnModel


@GeneralModel.register("general", "Paddle")
class GeneralPaddle(GeneralModel):
@KELearnModel.register("KELearn", "Paddle")
class KELearnPaddle(KELearnModel):

def __init__(self, name='paddle-default', dataset=None, model=None, args=None):
self.name = name
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions openks/models/pytorch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
init
"""
from .kg_learn import *
from .gen_learn import *
from .ke_learn import *
from .kg_modules import *
from .gen_modules import *
from .ke_modules import *
from .kg_learn_dist import *
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import torch
import torch.nn as nn
from sklearn.model_selection import train_test_split
from ..model import GeneralModel
from ..model import KELearnModel

@GeneralModel.register("general", "PyTorch")
class GeneralTorch(GeneralModel):
@KELearnModel.register("KELearn", "PyTorch")
class KELearnTorch(KELearnModel):
def __init__(self, name='pytorch-default', dataset=None, model=None, args=None):
self.name = name
self.dataset = dataset
Expand Down
2 changes: 2 additions & 0 deletions openks/models/pytorch/kg_modules/TransE.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import torch.nn as nn
import numpy as np
from ...model import TorchModel
import pdb


@TorchModel.register("TransE", "PyTorch")
Expand All @@ -29,6 +30,7 @@ def _algorithm(self, triples):
heads = triples[:, 0]
relations = triples[:, 1]
tails = triples[:, 2]
pdb.set_trace()
score = self.entities_emb(heads) + self.relations_emb(relations) - self.entities_emb(tails)
score = score.norm(p=self.norm, dim=1)
return score
Expand Down
4 changes: 2 additions & 2 deletions openks/models/tensorflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"""
init
"""
from .gen_learn import *
from .ke_learn import *
# from .kg_learn import *
from .rec_learn import *

from .gen_modules import *
from .ke_modules import *
# from .kg_modules import *
from .rec_modules import *
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import numpy as np
import ast
import os
from ..model import GeneralModel
from ..model import KELearnModel
from .utils import extract_kvpairs_in_bio, cal_f1_score, cal_f1_score_org_pro, load_vocabulary
from .utils import DataProcessor_LSTM as DataProcessor
from .utils import DataProcessor_LSTM_for_sentences as DataProcessor_predict
from ..model import logger

@GeneralModel.register("general", "TensorFlow")
class GeneralTorch(GeneralModel):
@KELearnModel.register("KELearn", "TensorFlow")
class KELearnTorch(KELearnModel):
def __init__(self, name='tensorflow-default', dataset=None, model=None, args=None):
self.name = name
self.dataset = dataset
Expand Down

0 comments on commit e63ab4e

Please sign in to comment.