> For the complete documentation index, see [llms.txt](https://zjunlp.gitbook.io/easyedit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zjunlp.gitbook.io/easyedit/easyeditor/models/kn.md).

# KN

<figure><img src="/files/EcqCwn69Af8qESAfovGC" alt=""><figcaption><p>Knowledge Neurons in Pretrained Transformers</p></figcaption></figure>

### apply\_kn\_to\_model-> *PreTrainedModel*

> Main function: Given the request, it applies mend to your model. Return the changed weights of the model.

```python
def apply_kn_to_model(
    model,
    tok: AutoTokenizer,
    request: List[Dict],
    hparams: KNHyperParams,
    copy=False,
    return_orig_weights=False,
    keep_original_weight=True,
    **kwargs
)
```

* **Paramters**
  * model(<mark style="color:purple;">PreTrainedModel</mark>): model to be edited
  * tok(<mark style="color:purple;">PreTrainedTokenizer</mark>): tokenizer for inputs
  * requests(<mark style="color:purple;">List\[Dict]</mark>): The edit descriptors and targets.
  * hparams(<mark style="color:purple;">Hyperparams</mark>): hyperparameters for editing method
  * copy(<mark style="color:purple;">bool</mark>): whether to copy original model
  * return\_orig\_weights(<mark style="color:purple;">bool</mark>): whether to return the weights of original model
  * keep\_original\_weight(<mark style="color:purple;">bool</mark>): whether to edit sequentially
    * `False`: edit sequentially(because the original weight is not maintained after each edit)
    * `True`: not edit sequentially
* **Return Type**
  * edited\_model(<mark style="color:purple;">PreTrainedModel</mark>): model weights after editing

### Example

```python
editor = BaseEditor.from_hparams(hparams)
prompts = ['What university did Watts Humphrey attend?',
    'Which family does Ramalinaceae belong to',
    'What role does Denny Herzig play in football?'
]
target_new = ['University of Michigan',
    'Lamiinae',
    'winger'
]
metrics, edited_model, _ = editor.edit(
    prompts=prompts,
    target_new=target_new,
    keep_original_weight=True
)
```

###


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zjunlp.gitbook.io/easyedit/easyeditor/models/kn.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
