Update app.py
Browse files
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 |
-
|
| 33 |
-
|
| 34 |
-
encode = lambda s: [
|
| 35 |
-
decode = lambda 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):
|