NLP自然语言处理-文本预处理-文本张量表示方法-word embedding可视化分析

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值