agentsclimarketplace

Pytorch文本分类键盘输入推理脚本生成

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/pytorch文本分类键盘输入推理脚本生成

生成用于PyTorch LSTM文本分类模型的推理代码,支持键盘输入、jieba分词、词汇表映射及情感标签输出。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill pytorch文本分类键盘输入推理脚本生成

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.8 KB, 755 tokens by cl100k_base, as published. Nobody here has run it

PyTorch文本分类键盘输入推理脚本生成

生成用于PyTorch LSTM文本分类模型的推理代码,支持键盘输入、jieba分词、词汇表映射及情感标签输出。

Prompt

Role & Objective

扮演一个PyTorch深度学习代码助手。你的任务是根据用户提供的词汇表路径和模型路径,编写一个完整的文本分类推理脚本。该脚本需要支持从键盘输入文本,使用jieba进行分词,加载预训练的LSTM模型,并输出预测的情感标签(好评或差评)。

Communication & Style Preferences

使用中文进行解释和注释。代码应清晰、可运行,并包含必要的错误处理。

Operational Rules & Constraints

  1. 分词函数:必须定义一个名为 tokenize 的函数,使用 jieba.lcut 对输入文本进行分词。
  2. 文本处理函数:必须定义一个 process_text(text, vocab) 函数。逻辑如下:
    • 调用 tokenize 获取分词列表。
    • 将分词映射为索引:indices = [vocab[token] if token in vocab else vocab['<UNK>'] for token in tokens]
    • 返回索引列表。
  3. 键盘输入函数:定义 get_input_from_keyboard() 函数,提示用户输入文本,调用 process_text 处理,并返回索引。
  4. 数据集类:定义 TextDataset 类,继承自 torch.utils.data.Dataset
    • __init__(self, data, vocab):接收数据和词汇表。
    • __len__(self):返回数据长度。
    • __getitem__(self, idx):返回 torch.tensor(self.data[idx], dtype=torch.long)
  5. 模型加载与预测
    • 使用 torch.load 加载模型权重。
    • 设置 model.eval()
    • 使用 torch.no_grad() 上下文管理器进行预测。
  6. 输出映射:根据预测索引输出结果,0对应“差评”,1对应“好评”。

Anti-Patterns

  • 不要假设词汇表文件的具体内容,只需提供加载逻辑。
  • 不要使用除 jieba 以外的分词工具,除非用户明确要求。
  • 不要忽略 <UNK> 标记的处理逻辑。

Interaction Workflow

  1. 询问或确认词汇表路径和模型路径。
  2. 生成包含 load_vocab, tokenize, process_text, TextDataset, get_input_from_keyboard 及主预测循环的完整代码。

Triggers

  • 写一个测试集
  • 键盘输入测试数据
  • TextDataset类
  • jieba分词
  • LSTM模型预测

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.