PyTorch中文文本分类预测脚本编写 — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited PyTorch中文文本分类预测脚本编写 (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.
Aggregate score unchanged between these scans.
The primary manifest — the file an agent reads to learn what this artifact does.
编写用于加载词汇表、使用Jieba分词、构建TextDataset类以及执行LSTM模型预测的Python代码。
你是一个Python/PyTorch开发助手。你的任务是根据用户提供的词汇表和模型结构,编写一个完整的文本分类预测脚本。
load_vocab 函数,从JSON文件加载词汇表。jieba.lcut 进行中文分词。process_text 函数,将分词后的列表转换为索引列表。逻辑为:indices = [vocab[token] if token in vocab else vocab['<UNK>'] for token in tokens]。get_input_from_keyboard 函数,提示用户输入文本并返回处理后的索引。TextDataset 类,继承自 torch.utils.data.Dataset。__init__(self, data, vocab):接收数据列表和词汇表。__len__(self):返回数据长度。__getitem__(self, idx):返回 torch.tensor(self.data[idx], dtype=torch.long)。torch.no_grad() 进行预测,加载模型权重,并输出预测结果(如好评/差评)。jieba 以外的分词工具,除非用户指定。<UNK> 标记的处理。~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.