| from datasets import load_dataset | |
| import hashlib | |
| def main(): | |
| ds = load_dataset("GAIR/lima" ,split="train") | |
| ds_test = load_dataset("GAIR/lima" ,split="test") | |
| ds = ds.map(lambda x: { | |
| "length": len(x['conversations']) | |
| }) | |
| ds = ds.filter(lambda x: x['length'] == 2) | |
| ds = ds.map( | |
| lambda x: { | |
| "prompt_id": hashlib.sha256(x['conversations'][0].encode("utf-8")).hexdigest(), | |
| "prompt": x['conversations'][0], | |
| "messages": [ | |
| {"role": "user", "content": x['conversations'][0]}, | |
| {"role": "assistant", "content": x['conversations'][1]} | |
| ], | |
| "meta": {"source": "lima", "category": x['source']} | |
| }) | |
| ds_test = ds_test.map(lambda x: { | |
| "prompt_id": hashlib.sha256(x['conversations'][0].encode("utf-8")).hexdigest(), | |
| "prompt": x['conversations'][0], | |
| "messages": [ | |
| {"role": "user", "content": x['conversations'][0]}, | |
| ], | |
| "meta": {"source": "lima", "category": x['source']} | |
| }) | |
| ds.push_to_hub("HuggingFaceH4/lima", split = "train_ift") | |
| ds_test.push_to_hub("HuggingFaceH4/lima", split = "test_ift") | |
| if __name__ == "__main__": | |
| main() | |