Editor
the base class for Knowledge Editing
BaseEditor
BaseEditor
is the class for factual and generation editing. Given the edit descriptor and the edit target, you can use different editing methods to change the behavior of the model.
from_hparams() -> BaseEditor
Static method, editor can be initialized through this function
Paramters
hparams(Hyperparams): hyperparameters for editing method
Return Type
editor(BaseEditor): The Editor class defined by
hparams
edit()-> List[Dict]
Main function: do fact editing according to the selected editing method
Paramters
prompts(Union[str, List[str]]): The prompt string of edit descriptor
target_new(Union[str, List[str]]): The prompt string of edit target
ground_truth(Optional[Union[str, List[str]]]): The original model output of the edit descriptor(you can set it
None
)rephrase_prompts(Optional[Union[str, List[str]]]): The rephrase prompt string, semantically similar to
prompts
, in order to test Generalizationlocality_inputs(Optional[Dict]): For each measurement dimension, you need to provide the corresponding prompt and its corresponding ground truth. Test Locality.
portability_inputs(Optional[Dict]): Similar to
locality_inputs
, in order to test Portabilitykeep_original_weight(bool): whether to edit sequentially
False
: edit sequentially(because the original weight is not maintained after each edit)True
: not edit sequentially
verbose(bool): whether to print intermediate output
Return Type
metrics(List[Dict]): the metric for model editing(see this link for more details)
edited_model(PreTrainedModel): model weights after editing
batch_edit()->List[Dict]
Main function: do fact editing according to the selected editing method
Paramters
prompts(Union[str, List[str]]): The prompt string of edit descriptor
target_new(Union[str, List[str]]): The prompt string of edit target
ground_truth(Optional[Union[str, List[str]]]): The original model output of the edit descriptor(you can set it
None
)rephrase_prompts(Optional[Union[str, List[str]]]): The rephrase prompt string, semantically similar to
prompts
, in order to test Generalizationlocality_inputs(Optional[Dict]): For each measurement dimension, you need to provide the corresponding prompt and its corresponding ground truth. Test Locality.
portability_inputs(Optional[Dict]): Similar to
locality_inputs
, in order to test Portabilitykeep_original_weight(bool): whether to edit sequentially
False
: edit sequentially(because the original weight is not maintained after each edit)True
: not edit sequentially
Return Type
metrics(List[Dict]): the metric for model editing(see this link for more details)
edited_model(PreTrainedModel): model weights after editing
Example
Last updated