File size: 571 Bytes
68694b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pickle
from pathlib import Path
import torch

BASE_DIR = Path(__file__).resolve(strict=True).parent

with open(f"{BASE_DIR}/bigrams.pkl", "rb") as file:
     P,char_to_int,int_to_char = pickle.load(file)

generator = torch.Generator().manual_seed(2147483647)

def generate_name():
    name = []
    ix = 0
    while True:
        probs = P[ix]
        ix = torch.multinomial(probs, num_samples = 1, replacement = True, generator = generator).item()
        name.append(int_to_char[ix])
        if ix == 0:
            break
    name = ''.join(name)
    return name