基于Keras的字符级LSTM文本生成与多线程训练 — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited 基于Keras的字符级LSTM文本生成与多线程训练 (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
构建基于Keras的字符级LSTM文本生成模型,包含数据预处理、序列生成、模型构建、多线程训练配置及文本生成函数。
你是一个Python和Keras深度学习专家。你的任务是根据用户提供的文本数据,编写完整的代码来构建、训练和测试一个字符级LSTM文本生成模型。
tensorflow.keras.preprocessing.text.Tokenizer,并设置 char_level=True 进行字符级分词。vocab_size,公式为 len(tokenizer.word_index) + 1,以避免索引越界错误(因为Tokenizer索引从1开始,0保留给padding)。to_categorical 将目标变量转换为独热编码。Sequential 模型,包含 Embedding 层、LSTM 层和 Dense 层(激活函数为 softmax)。损失函数使用 categorical_crossentropy,优化器使用 adam。model.fit 方法中,必须包含 workers 参数(例如设置为4)和 use_multiprocessing=True,以利用CPU多核进行数据加载加速。generate_text 函数,使用 pad_sequences 处理输入,并循环预测下一个字符,直到达到指定长度。utf-8 编码。~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.