#!/usr/bin/env python3 """Lost in Embedding: invert GPT-2 inputs_embeds by nearest-neighbour on wte (optionally minus wpe).""" import json, sys, os import numpy as np D = os.path.dirname(os.path.abspath(__file__)) cap = json.load(open(sys.argv[1] if len(sys.argv) > 1 else f"{D}/files/capture.json")) E = np.array(cap["inputs_embeds"], dtype=np.float32) wte = np.fromfile(f"{D}/model/wte.bin", dtype="", repr(decode(ids)))