Tools¶
deepke.relation_extraction.standard.tools.dataset module¶
deepke.relation_extraction.standard.tools.loss module¶
- class deepke.relation_extraction.standard.tools.loss.LabelSmoothSoftmaxCEV1(lb_smooth=0.1, reduction='mean', ignore_index=- 100)[source]¶
Bases:
torch.nn.modules.module.Module
- forward(logits, label)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- deepke.relation_extraction.standard.tools.loss.taylor_softmax_v1(x, dim=1, n=4, use_log=False)[source]¶
- class deepke.relation_extraction.standard.tools.loss.LogTaylorSoftmaxV1(dim=1, n=2)[source]¶
Bases:
torch.nn.modules.module.Module
- forward(x)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class deepke.relation_extraction.standard.tools.loss.TaylorCrossEntropyLossV1(n=2, ignore_index=- 1, reduction='mean')[source]¶
Bases:
torch.nn.modules.module.Module
- forward(logits, labels)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class deepke.relation_extraction.standard.tools.loss.FocalLoss(gamma=0, alpha=None, size_average=True)[source]¶
Bases:
torch.nn.modules.module.Module
- forward(input, target)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
deepke.relation_extraction.standard.tools.metrics module¶
- class deepke.relation_extraction.standard.tools.metrics.Metric[source]¶
Bases:
object
- abstract reset()[source]¶
Resets the metric to to it’s initial state. This is called at the start of each epoch.
deepke.relation_extraction.standard.tools.preprocess module¶
deepke.relation_extraction.standard.tools.serializer module¶
- class deepke.relation_extraction.standard.tools.serializer.Serializer(never_split: Optional[List] = None, do_lower_case=True, do_chinese_split=False)[source]¶
Bases:
object
deepke.relation_extraction.standard.tools.trainer module¶
- deepke.relation_extraction.standard.tools.trainer.train(epoch, model, dataloader, optimizer, criterion, device, writer, cfg)[source]¶
- training the model.
- Args:
epoch (int): number of training steps. model (class): model of training. dataloader (dict): dict of dataset iterator. Keys are tasknames, values are corresponding dataloaders. optimizer (Callable): optimizer of training. criterion (Callable): loss criterion of training. device (torch.device): device of training. writer (class): output to tensorboard. cfg: configutation of training.
- Return:
losses[-1] : the loss of training
- deepke.relation_extraction.standard.tools.trainer.validate(epoch, model, dataloader, criterion, device, cfg)[source]¶
- validating the model.
- Args:
epoch (int): number of validating steps. model (class): model of validating. dataloader (dict): dict of dataset iterator. Keys are tasknames, values are corresponding dataloaders. criterion (Callable): loss criterion of validating. device (torch.device): device of validating. cfg: configutation of validating.
- Return:
f1 : f1 score loss : the loss of validating
deepke.relation_extraction.standard.tools.vocab module¶
- class deepke.relation_extraction.standard.tools.vocab.Vocab(name: str = 'basic', init_tokens: Sequence = {'bos_token': '[BOS]', 'cls_token': '[CLS]', 'eos_token': '[EOS]', 'head_token': 'HEAD', 'mask_token': '[MASK]', 'pad_token': '[PAD]', 'sep_token': '[SEP]', 'tail_token': 'TAIL', 'unk_token': '[UNK]'})[source]¶
Bases:
object
构建词汇表,增加词汇,删除低频词汇