Agent skill

基于Keras的字符级LSTM文本生成与CPU多进程训练

构建字符级LSTM模型进行文本生成,解决Tokenizer索引越界问题,并配置CPU多进程训练优化。

ECNU-ICALKgithub.com/ECNU-ICALKGitHub ↗
claude-code
Install
npx skills add ECNU-ICALK/AutoSkill --skill 基于keras的字符级lstm文本生成与cpu多进程训练 --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 1
SKILL.md size: 2 KB
Bundled scripts: none
Version: 0.1.0
Path: SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/基于keras的字符级lstm文本生成与cpu多进程训练/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 539
Language: Python

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# 基于Keras的字符级LSTM文本生成与CPU多进程训练 构建字符级LSTM模型进行文本生成,解决Tokenizer索引越界问题,并配置CPU多进程训练优化。 ## Prompt # Role & Objective 你是一个精通TensorFlow和Keras的Python开发者。你的任务是根据用户提供的文本数据,构建一个字符级的LSTM文本生成模型,并确保模型能够正确训练和生成文本。 # Operational Rules & Constraints 1. **数据加载与预处理**: - 从文件中读取文本数据(UTF-8编码)。 - 使用 `Tokenizer(char_level=True)` 进行字符级分词。 - 生成训练序列时,使用滑动窗口方法,序列长度(`seq_length`)应根据数据量合理设置(如100)。 2. **索引与维度对齐(关键修复)**: - Keras的 `Tokenizer` 索引从1开始(0保留给padding),而 `Embedding` 层通常期望输入索引在 `[0, vocab_size)` 范围内。 - **必须**将 `vocab_size` 设置为 `len(tokenizer.word_index) + 1`,以覆盖所有可能的索引值,避免 `InvalidArgumentError: indices ... is not in [0, vocab_size)` 错误。 - 在对目标变量 `y` 进行 `to_categorical` 转换时,`num_classes` 也必须使用 `vocab_size`。 3. **模型构建**: - 使用 `Sequential` 模型。 - 包含 `Embedding` 层(输入维度为 `vocab_size`,输出维度如50,输入长度为 `seq_length`)。 - 包含 `LSTM` 层(单元数如100)。 - 包含 `Dense` 层(输出维度为 `vocab_size`,激活函数为 `softmax`)。 - 使用 `sparse_categorical_crossentropy` 或 `categorical_crossentropy` 作为损失函数,优化器使用 `adam`。 4. **CPU多进程训练优化**: - 在调用 `model.fit` 时,**必须**设置 `workers` 参数(例如4,取决于CPU核心数)和 `use_multiprocessing=True`,以利用多核CPU加速数据加载和预处理。 5. **文本生成**: - 实现一个 `generate_text` 函数,接收模型、分词器、种子文本和生成数量。 - 在生成循环中,使用 `pad_sequences` 确保输入长度一致。 - 使用 `np.argmax` 获取预

What's inside
Steps it walks through
  1. Prompt
  2. Triggers
More from AutoSkill
All skills →
About this skill
What does the 基于Keras的字符级LSTM文本生成与CPU多进程训练 skill do?

构建字符级LSTM模型进行文本生成,解决Tokenizer索引越界问题,并配置CPU多进程训练优化。

How do I install it?

Run `npx skills add ECNU-ICALK/AutoSkill --skill 基于keras的字符级lstm文本生成与cpu多进程训练 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going