Skip to content

Fix KTO doc #1517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/source/LLM/自定义与拓展.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ system,instruction,input,output

语言模型 (KTO)
```jsonl
{"query": "11111", "response": "22222", "label": True}
{"query": "aaaaa", "response": "bbbbb", "label": False}
{"system": "123", "query": "AAAAA", "response": "BBBBB", "label": True, "history": [["AAAAA", "BBBBB"], ["CCCCC", "DDDDD"]]}
{"query": "11111", "response": "22222", "label": true}
{"query": "aaaaa", "response": "bbbbb", "label": false}
{"system": "123", "query": "AAAAA", "response": "BBBBB", "label": true, "history": [["AAAAA", "BBBBB"], ["CCCCC", "DDDDD"]]}
```
注意`label`需要是bool类型, 不能是字符串

其中`system`和`history`为可选项


Expand Down
8 changes: 5 additions & 3 deletions docs/source_en/LLM/Customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ Language model (DPO/ORPO/SimPO/CPO)

Language model (KTO)
```jsonl
{"query": "11111", "response": "22222", "label": True}
{"query": "aaaaa", "response": "bbbbb", "label": False}
{"system": "123", "query": "AAAAA", "response": "BBBBB", "label": True, "history": [["AAAAA", "BBBBB"], ["CCCCC", "DDDDD"]]}
{"query": "11111", "response": "22222", "label": true}
{"query": "aaaaa", "response": "bbbbb", "label": false}
{"system": "123", "query": "AAAAA", "response": "BBBBB", "label": true, "history": [["AAAAA", "BBBBB"], ["CCCCC", "DDDDD"]]}
```
Note: `label` needs to be of type bool, not str.

(Where system and history are optional.)


Expand Down
5 changes: 0 additions & 5 deletions swift/trainers/kto_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ def encode_batch(batch: Dict[str, List[Any]], template: Template):
template._concat_context_list(template.prompt, res_context_list, compute_loss_idx, query=query, round0=len(history))
res_context_list, compute_loss_idx = template._simplify_context_list(res_context_list, compute_loss_idx)
prompt = ''.join(res_context_list)
if isinstance(batch['label'], str) and batch['label'].lower() == 'true':
batch['label'] = True

if isinstance(batch['label'], str) and batch['label'].lower() == 'false':
batch['label'] = False

return {'prompt': prompt, 'completion': batch['response'], 'label': batch['label']}

Expand Down
Loading