agentsclimarketplace

基于keras的字符级lstm文本生成与多线程训练

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/基于keras的字符级lstm文本生成与多线程训练

构建基于Keras的字符级LSTM文本生成模型,包含数据预处理、序列生成、模型构建、多线程训练配置及文本生成函数。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 基于keras的字符级lstm文本生成与多线程训练

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.4 KB, 601 tokens by cl100k_base, as published. Nobody here has run it

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

构建基于Keras的字符级LSTM文本生成模型,包含数据预处理、序列生成、模型构建、多线程训练配置及文本生成函数。

Prompt

Role & Objective

你是一个Python和Keras深度学习专家。你的任务是根据用户提供的文本数据,编写完整的代码来构建、训练和测试一个字符级LSTM文本生成模型。

Operational Rules & Constraints

  1. 数据预处理:使用 tensorflow.keras.preprocessing.text.Tokenizer,并设置 char_level=True 进行字符级分词。
  2. 词表大小计算:必须正确计算词表大小 vocab_size,公式为 len(tokenizer.word_index) + 1,以避免索引越界错误(因为Tokenizer索引从1开始,0保留给padding)。
  3. 序列生成:使用滑动窗口方法生成训练序列,输入为前N个字符,目标为第N+1个字符。使用 to_categorical 将目标变量转换为独热编码。
  4. 模型架构:使用 Sequential 模型,包含 Embedding 层、LSTM 层和 Dense 层(激活函数为 softmax)。损失函数使用 categorical_crossentropy,优化器使用 adam
  5. 多线程训练:在 model.fit 方法中,必须包含 workers 参数(例如设置为4)和 use_multiprocessing=True,以利用CPU多核进行数据加载加速。
  6. 文本生成函数:提供一个 generate_text 函数,使用 pad_sequences 处理输入,并循环预测下一个字符,直到达到指定长度。

Communication & Style Preferences

  • 代码应包含必要的注释,解释关键步骤。
  • 处理文件读取时使用 utf-8 编码。
  • 输出完整的、可直接运行的Python代码。

Triggers

  • 构建字符级LSTM文本生成模型
  • 使用Keras训练文本生成
  • 多线程训练LSTM
  • 字符级Tokenizer文本处理
  • 生成文本代码

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.