lm_polygraph.generation_metrics.alignscore_utils module

class lm_polygraph.generation_metrics.alignscore_utils.AlignScorer(model: str, batch_size: int, device: int, ckpt_path: str, evaluation_mode='nli_sp', verbose=True)[source]

Bases: object

score(contexts: List[str], claims: List[str]) List[float][source]
class lm_polygraph.generation_metrics.alignscore_utils.BERTAlignModel(model='roberta-large', using_pretrained=True, *args, **kwargs)[source]

Bases: Module

configure_optimizers()[source]

Prepare optimizer and schedule (linear warmup and decay)

electra_forward(batch)[source]
forward(batch)[source]

Define 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.

mse_loss(input, target, ignored_index=-100.0, reduction='mean')[source]
training_step(train_batch, batch_idx)[source]
training_step_end(step_output)[source]
validation_epoch_end(outputs)[source]
validation_step(val_batch, batch_idx)[source]
validation_step_end(step_output)[source]
class lm_polygraph.generation_metrics.alignscore_utils.ElectraDiscriminatorPredictions(config)[source]

Bases: Module

Prediction module for the discriminator, made up of two dense layers.

forward(discriminator_hidden_states)[source]

Define 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 lm_polygraph.generation_metrics.alignscore_utils.Inferencer(ckpt_path='https://huggingface.co/yzha/AlignScore/resolve/main/AlignScore-large.ckpt', model='bert-base-uncased', batch_size=32, device='cuda', verbose=True)[source]

Bases: object

batch_tokenize(premise, hypo)[source]

input premise and hypos are lists

chunks(lst, n)[source]

Yield successive n-sized chunks from lst.

inference(premise, hypo)[source]

inference a list of premise and hypo

Standard aggregation

inference_example_batch(premise: list, hypo: list)[source]

inference a example, premise: list hypo: list using self.inference to batch the process

SummaC Style aggregation

inference_per_example(premise: str, hypo: str)[source]

inference a example, premise: string hypo: string using self.inference to batch the process

inference_reg(premise, hypo)[source]

inference a list of premise and hypo

Standard aggregation

nlg_eval(premise, hypo)[source]
smart_doc(premise: list, hypo: list)[source]

inference a example, premise: list hypo: list using self.inference to batch the process

SMART Style aggregation

smart_l(premise, hypo)[source]
smart_n(premise, hypo)[source]
class lm_polygraph.generation_metrics.alignscore_utils.ModelOutput(loss: torch.FloatTensor | None = None, all_loss: list | None = None, loss_nums: list | None = None, prediction_logits: torch.FloatTensor = None, seq_relationship_logits: torch.FloatTensor = None, tri_label_logits: torch.FloatTensor = None, reg_label_logits: torch.FloatTensor = None, hidden_states: Tuple[torch.FloatTensor] | None = None, attentions: Tuple[torch.FloatTensor] | None = None)[source]

Bases: object

all_loss: list | None = None
attentions: Tuple[FloatTensor] | None = None
hidden_states: Tuple[FloatTensor] | None = None
loss: FloatTensor | None = None
loss_nums: list | None = None
prediction_logits: FloatTensor = None
reg_label_logits: FloatTensor = None
seq_relationship_logits: FloatTensor = None
tri_label_logits: FloatTensor = None