python - RuntimeWarning:在乘法中遇到无效值,RuntimeWarning:在日志中遇到除以零
问题描述
在训练词向量时,我在我的时代之间面临以下运行时问题。
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:12: RuntimeWarning: divide by zero encountered in log
if sys.path[0] == '':
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:12: RuntimeWarning: invalid value encountered in multiply
if sys.path[0] == '':
在检查时我发现不知何故所有嵌入矩阵值都变成了 NaN。我该如何解决这个问题?我从哪里得到 NaN?这是一个用 Python 和 NumPy 编写的简单训练模型,但我仍然收到此错误。我的 colab 笔记本的链接是这个
解决方案
I'm guessing this is occurring because you have a class in your word vector model that has a frequency of 0. And, as @CJR said, if you take the log of zero, you will get NaN.
I would recommend debugging this by first checking your class frequencies across your dataset, and seeing if anything looks out of the ordinary.
推荐阅读
- java - 接口序列化
- java - 如何从 Jenkins 启动 java 服务
- python - 有没有办法让 gensim LDA 自动选择最佳主题数量
- javascript - 将应用程序部署到 Heroku 后无法获取 API 数据(在本地完美运行)
- reactjs - 如何使用 React JS 在 Redirect 上执行函数
- php - 为什么无法识别用于重新登录的 Laravel League/ouath2 令牌
- javascript - 对数组对象内的数组元素执行操作
- php - 将对象数组转换为 Vue js 和 php 中的对象
- javascript - 画布在 60Hz 显示器上闪烁,在 144Hz 显示器上工作正常
- ansible - Openstack train aio 安装问题