首页 > 解决方案 > 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 笔记本的链接是这个

标签: pythonnumpynlpnan

解决方案


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.


推荐阅读