word embedding可视化:
import fileinput
import torch
from torch.utils.tensorboard import SummaryWriter
import tensorflow as tf
import tensorboard as tb
# 重新引入gfile
tf.io.gfile = tb.compat.tensorflow_stub.io.gfile
# 实例化一个写入对象
writer = SummaryWriter()
# 随机初始化一个100*5的矩阵,将其视作已经得到的词嵌入矩阵
embedded = torch.randn(100, 50)
meta = list(map(lambda x: x.strip(), fileinput.FileInput("./vocab100.csv", openhook=fileinput.hook_encoded(encoding='utf-8'))))
writer.add_embedding(embedded, metadata=meta)
writer.close()
vocab100.csv
链接: https://pan.baidu.com/s/1LOhOgR8bpAaMNa9EttdOEg 提取码: cvgm 复制这段内容后打开百度网盘手机App,操作更方便哦。
当前路径终端回车:
tensorboard --logdir runs --host 0.0.0.0
浏览器回车:
# 具体端口号依据自己
http://127.0.0.1:6006/
结果:
参考:
https://www.jianshu.com/p/1bd4ca7f815b
某马:
http://121.199.45.168/
pytorch中文:
https://www.bookstack.cn/read/PyTorch-1.2-zh/bcfaebf287a0e667.md