Loading the Model

embeddings = None with open("./text/output.json", "r", encoding="utf-8") as file: embeddings = json.loads(file.read()) map = {} for item in embeddings: map[tuple(item['embedding'])] = item network = nn.Sequential( nn.Linear(20, 20), nn.Tanh(), nn.Linear(20,len(embeddings)), nn.Sigmoid() ) # 2. Load the saved weights into the structure network.load_state_dict(torch.load("./text/model.txt"))

Generating Text

word = random.sample(embeddings, 1)[0] print(word) def next(list): float_list = list.data.tolist() indices = range(len(float_list)) random_index = random.choices(indices, weights=float_list, k=1)[0] return embeddings[random_index] for i in range(10): output = network(torch.tensor(word['embedding'])) word = next(output) print(word['token']) pass

Full Desktop