import tensorflow as tf import numpy as np import common_utils import optimization from models.tf_metrics import precision, recall, f1 from models.utils import dice_dsc_loss from models.layers.lstm_layers import BLSTM logger = common_utils.set_logger('NER Training...') class BILSTMONLY(object): def __init__(self, params: dict): self.char_embedding = tf.Variable(np.load(params["embedding_path"]), dtype=tf.float32, name='input_char_embedding') self.word_embedding = tf.Variable(np.load( params["word_embedding_path"]), dtype=tf.float32, name="input_word_embedding") # 丢弃概率 self.dropout_rate = params["dropout_prob"] self.num_labels = params["num_labels"] self.rnn_size = params["rnn_size"] self.num_layers = params["num_layers"] self.hidden_units = params["hidden_units"] def __call__(self, input_ids=None, input_word_ids=None, labels=None,
from models.bert_event_type_classification import bert_classification_model_fn_builder from data_processing.data_utils import * from data_processing.event_prepare_data import EventRolePrepareMRC, EventTypeClassificationPrepare # from data_processing.event_prepare_data import EventRoleClassificationPrepare from data_processing.event_prepare_data import event_input_bert_mrc_mul_fn, event_index_class_input_bert_fn from data_processing.event_prepare_data import event_binclass_input_bert_fn from models.bert_event_type_classification import bert_binaryclassification_model_fn_builder from data_processing.event_prepare_data import event_input_verfify_mrc_fn from models.event_verify_av import event_verify_mrc_model_fn_builder from configs.event_config import event_config # import horovod.tensorflow as hvd os.environ["CUDA_VISIBLE_DEVICES"] = "0" logger = set_logger("[run training]") # logger = logging.getLogger('train') # logger.setLevel(logging.INFO) # os.environ['TF_ENABLE_AUTO_MIXED_PRECISION']='1' def serving_input_receiver_fn(): """Serving input_fn that builds features from placeholders Returns ------- tf.estimator.export.ServingInputReceiver """ words = tf.placeholder(dtype=tf.int32, shape=[None, None], name='words') nwords = tf.placeholder(dtype=tf.int32, shape=[None], name='text_length')