mattyhew commited on
Commit
7a4f90a
·
verified ·
1 Parent(s): 822b8df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -29,10 +29,11 @@ with open("data.txt", "r", encoding="utf-8") as f:
29
  chars = sorted(list(set(dataset)))
30
  vocab_size = len(chars)
31
 
32
- stoi = {ch: i for i, ch in enumerate(chars)} # string to index mapping
33
- itos = {i: ch for i, ch in enumerate(chars)} # index to string mapping
34
- encode = lambda s: [stoi[c] for c in s]
35
- decode = lambda l: "".join([itos[i] for i in l])
 
36
  data = torch.tensor(encode(dataset), dtype=torch.long)
37
 
38
  class Head(nn.Module):
 
29
  chars = sorted(list(set(dataset)))
30
  vocab_size = len(chars)
31
 
32
+ string_to_int = { ch:i for i,ch in enumerate(chars) }
33
+ int_to_string = { i:ch for i,ch in enumerate(chars) }
34
+ encode = lambda s: [string_to_int[c] for c in s]
35
+ decode = lambda l: ''.join([int_to_string[i] for i in l])
36
+
37
  data = torch.tensor(encode(dataset), dtype=torch.long)
38
 
39
  class Head(nn.Module):