Lit Models

deepke.relation_extraction.few_shot.lit_models.base module

class deepke.relation_extraction.few_shot.lit_models.base.Config[source]

Bases: dict

class deepke.relation_extraction.few_shot.lit_models.base.BaseLitModel(model, device, args)[source]

Bases: torch.nn.modules.module.Module

Generic PyTorch-Lightning class that must be initialized with a PyTorch module.

static add_to_argparse(parser)[source]
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_step(batch, batch_idx)[source]
validation_step(batch, batch_idx)[source]
test_step(batch, batch_idx)[source]
configure_optimizers()[source]
property num_training_steps: int

Total training steps inferred from datamodule and devices.

training: bool

deepke.relation_extraction.few_shot.lit_models.transformer module

deepke.relation_extraction.few_shot.lit_models.transformer.mask_hook(grad_input, st, ed)[source]
deepke.relation_extraction.few_shot.lit_models.transformer.multilabel_categorical_crossentropy(y_pred, y_true)[source]
class deepke.relation_extraction.few_shot.lit_models.transformer.BertLitModel(model, device, args, tokenizer)[source]

Bases: deepke.relation_extraction.few_shot.lit_models.base.BaseLitModel

use AutoModelForMaskedLM, and select the output by another layer in the lit model

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_step(batch, batch_idx)[source]
validation_step(batch, batch_idx)[source]
validation_epoch_end(outputs)[source]
test_step(batch, batch_idx)[source]
test_epoch_end(outputs)[source]
static add_to_argparse(parser)[source]
pvp(logits, input_ids)[source]
ke_loss(logits, labels, so)[source]
configure_optimizers()[source]
training: bool

deepke.relation_extraction.few_shot.lit_models.util module

deepke.relation_extraction.few_shot.lit_models.util.dialog_f1_eval(logits, labels)[source]
deepke.relation_extraction.few_shot.lit_models.util.f1_eval(logits, labels)[source]
deepke.relation_extraction.few_shot.lit_models.util.compute_f1(logits, labels)[source]
deepke.relation_extraction.few_shot.lit_models.util.acc(logits, labels)[source]
deepke.relation_extraction.few_shot.lit_models.util.f1_score(output, label, rel_num=42, na_num=13)[source]