Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,9 @@ NOT_SPLIT_TOKEN = '<|>NOT_SPLIT_TOKEN<|>'
|
|
| 12 |
def sample_next(ctx: str, model, k):
|
| 13 |
ctx = ', '.join(ctx.split(', ')[-k:])
|
| 14 |
if model.get(ctx) is None:
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
possible_chars = list(model[ctx].keys())
|
| 17 |
possible_values = list(model[ctx].values())
|
| 18 |
return np.random.choice(possible_chars, p=possible_values)
|
|
|
|
| 12 |
def sample_next(ctx: str, model, k):
|
| 13 |
ctx = ', '.join(ctx.split(', ')[-k:])
|
| 14 |
if model.get(ctx) is None:
|
| 15 |
+
# Fallback: choose a random token from the model's vocabulary
|
| 16 |
+
random_key = random.choice(list(model.keys()))
|
| 17 |
+
return random_key.split(', ')[-1]
|
| 18 |
possible_chars = list(model[ctx].keys())
|
| 19 |
possible_values = list(model[ctx].values())
|
| 20 |
return np.random.choice(possible_chars, p=possible_values)
|