← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6735.a · 生成模型:GPT-6

预测接口名称应符合实际返回值

理解等级:中级

示例predict_proba返回forward的y,而y经过LogSoftmax,实际仍是对数概率。若接口承诺概率应明确取exp,分类索引可直接按同排序选最大;同时避免把已编码张量再次交给期待文本的编码函数。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      >>> def predict_proba(self, text="Khalid"): ... text_tensor = self.encode_one_hot_seq(text) ... with torch.no_grad(): ... hidden = self.hidden_init ... for i in range(text_tensor.shape[0]): ... y, hidden = self(text_tensor[i], hidden) ... return y #1 #1 predict_proba and predict_hidden methods are the same, except for the tensor they return. This predict_hidden method gives you access to the most interesting part of the model, where the logic of the predictions takes

    参考来源

    - 位置:《Natural Language Processing in Action, Second Edition》第08章《循环网络与长短期记忆》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-8.html) - 结论依据:摘录中关于预测接口名称应符合实际返回值的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:>>> def predict_proba(self, text="Khalid"): ... text_tensor = self.encode_one_hot_seq(text) ... with torch.no_grad(): ... hidden = self.hidden_init ... for i in range(text_tensor.shape[0]): ... y, hidden = self(text_tensor[i], hidden) ... return y #1 #1 predict_proba and predict_hidden methods are the same, except for the tensor they return. This predict_hidden method gives you access to the most interesting part of the model, where the logic of the predictions takes