Instructions to use Asopo/cacifer_char_lstm_storyteller with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use Asopo/cacifer_char_lstm_storyteller with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://Asopo/cacifer_char_lstm_storyteller") - Notebooks
- Google Colab
- Kaggle
Cacifer Char LSTM Storyteller
A character-level LSTM trained on my Cacifer stories (monastery, Cacifer the cat, Romé, Dania, Deonardo, etc.).
It continues text one character at a time and produces Cacifer-style lines like:
“If the fore of the cobled the stell of her breath…”
- Framework: Keras / TensorFlow
- Context length: 60 characters
- Vocabulary: characters in
char_to_idx.json
Files
cacifer_char_lstm_storyteller.keras– Keras model filechar_to_idx.json– character → indexidx_to_char.json– index → character
Usage
import json, numpy as np
from tensorflow.keras.models import load_model
model = load_model("cacifer_char_lstm_storyteller.keras", compile=False)
char_to_idx = json.load(open("char_to_idx.json"))
idx_to_char = {int(k): v for k, v in json.load(open("idx_to_char.json")).items()}
seq_len = 60
def sample_char(probs, temperature=0.7):
probs = np.asarray(probs, dtype="float64")
if temperature != 1.0:
logits = np.log(probs + 1e-8) / temperature
probs = np.exp(logits)
probs /= probs.sum()
probs = np.clip(probs, 1e-12, 1.0)
probs /= probs.sum()
return np.random.choice(len(probs), p=probs)
def generate(seed, length=400, temperature=0.7):
x = seed[-seq_len:]
for _ in range(length):
x_idx = np.array([[char_to_idx.get(c, 0) for c in x]])
preds = model.predict(x_idx, verbose=0)[0]
x += idx_to_char[sample_char(preds, temperature)]
return x
seed = "I am Cacifer, a cat, listening to the bells and the breathing of the guests."
print(generate(seed, length=400, temperature=0.6))
- Downloads last month
- -