Instructions to use Asopo/cacifer-lstm-6word with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use Asopo/cacifer-lstm-6word 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-lstm-6word") - Notebooks
- Google Colab
- Kaggle
Cacifer 6‑Word LSTM
A word‑level LSTM trained on the first book of Cacifer, using 6‑word context to predict the 7th word.
It tends to produce coherent Cacifer‑style sentences like “in the monastery at night we turn the healer…”.
- Framework: Keras / TensorFlow
- Context length: 6 words
- Vocabulary: as in
word_index.json
Files
cacifer_lstm_6word.keras– Keras model fileword_index.json– word → id mappingindex_word.json– id → word mapping
Usage
import json, numpy as np
from tensorflow.keras.models import load_model
model = load_model("cacifer_lstm_6word.keras", compile=False)
word_index = json.load(open("word_index.json"))
index_word = {int(k): v for k, v in json.load(open("index_word.json")).items()}
vocab_size = len(word_index) + 1
def sample_with_temperature(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, num_words=40, temperature=0.7):
from tensorflow.keras.preprocessing.text import Tokenizer
tok = Tokenizer()
tok.word_index = word_index
words = seed.lower().split()
if len(words) < 6:
raise ValueError("Seed text must have at least 6 words.")
words = words[-6:]
for _ in range(num_words):
context = ' '.join(words[-6:])
seq = tok.texts_to_sequences([context])[0]
if len(seq) != 6:
break
x = np.array([seq])
preds = model.predict(x, verbose=0)[0]
next_id = sample_with_temperature(preds, temperature)
next_word = index_word.get(next_id)
if not next_word:
break
words.append(next_word)
return ' '.join(words)
print(generate("i am cacifer a cat watching", num_words=40, temperature=0.7))
- Downloads last month
- -