Document

deepke.relation_extraction.document.evaluation module

deepke.relation_extraction.document.evaluation.to_official(args, preds, features)[source]
deepke.relation_extraction.document.evaluation.gen_train_facts(data_file_name, truth_dir)[source]
deepke.relation_extraction.document.evaluation.official_evaluate(tmp, path)[source]

Adapted from the official evaluation code

deepke.relation_extraction.document.losses module

deepke.relation_extraction.document.losses.multilabel_categorical_crossentropy(y_true, y_pred)[source]

多标签分类的交叉熵 说明:y_true和y_pred的shape一致,y_true的元素非0即1,

1表示对应的类为目标类,0表示对应的类为非目标类。

警告:请保证y_pred的值域是全体实数,换言之一般情况下y_pred

不用加激活函数,尤其是不能加sigmoid或者softmax!预测 阶段则输出y_pred大于0的类。如有疑问,请仔细阅读并理解 本文。

class deepke.relation_extraction.document.losses.ATLoss[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.

get_label(logits, num_labels=- 1)[source]
training: bool

deepke.relation_extraction.document.model module

class deepke.relation_extraction.document.model.DocREModel(config, args, model, emb_size=768, block_size=64, num_labels=- 1)[source]

Bases: torch.nn.modules.module.Module

encode(input_ids, attention_mask, entity_pos)[source]
get_hrt(sequence_output, attention, entity_pos, hts)[source]
get_mask(ents, bs, ne, run_device)[source]
get_ht(rel_enco, hts)[source]
get_channel_map(sequence_output, entity_as)[source]
forward(input_ids=None, attention_mask=None, labels=None, entity_pos=None, hts=None, instance_mask=None)[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.

training: bool

deepke.relation_extraction.document.module module

class deepke.relation_extraction.document.module.AttentionUNet(input_channels, class_number, **kwargs)[source]

Bases: torch.nn.modules.module.Module

UNet, down sampling & up sampling for global reasoning

forward(attention_channels)[source]

Given multi-channel attention map, return the logits of every one mapping into 3-class :param attention_channels: :return:

training: bool
class deepke.relation_extraction.document.module.DoubleConv(in_ch, out_ch)[source]

Bases: torch.nn.modules.module.Module

(conv => [BN] => ReLU) * 2

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.

training: bool
class deepke.relation_extraction.document.module.InConv(in_ch, out_ch)[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.

training: bool
class deepke.relation_extraction.document.module.DownLayer(in_ch, out_ch)[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.

training: bool
class deepke.relation_extraction.document.module.UpLayer(in_ch, out_ch, bilinear=True)[source]

Bases: torch.nn.modules.module.Module

forward(x1, x2)[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.

training: bool
class deepke.relation_extraction.document.module.OutConv(in_ch, out_ch)[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.

training: bool

deepke.relation_extraction.document.prepro module

deepke.relation_extraction.document.prepro.process_long_input(model, input_ids, attention_mask, start_tokens, end_tokens)[source]
deepke.relation_extraction.document.prepro.chunks(l, n)[source]
class deepke.relation_extraction.document.prepro.ReadDataset(args, dataset: str, tokenizer, max_seq_Length: int = 1024, transformers: str = 'bert')[source]

Bases: object

read(file_in: str)[source]
deepke.relation_extraction.document.prepro.read_docred(args, transfermers, file_in, save_file, tokenizer, max_seq_length=1024)[source]

deepke.relation_extraction.document.utils module

deepke.relation_extraction.document.utils.set_seed(args)[source]
deepke.relation_extraction.document.utils.collate_fn_sample(batch)[source]
deepke.relation_extraction.document.utils.collate_fn(batch)[source]