![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
文本分类
Young Panda
初来乍到,请多多指教
展开
-
pytorch 余弦相似度矩阵cos_similar,批量运算
import torchfrom torch import Tensordef cos_similar(p: Tensor, q: Tensor): sim_matrix = p.matmul(q.transpose(-2, -1)) a = torch.norm(p, p=2, dim=-1) b = torch.norm(q, p=2, dim=-1) sim_matrix /= a.unsqueeze(-1) sim_matrix /= b.unsqu.原创 2021-03-13 20:52:27 · 3464 阅读 · 0 评论 -
2021-01-12
pytorchpacked_rnnimport torchimport torch.nn as nnimport torch.nn.functional as Fimport mathclass Packed(nn.Module): def __init__(self, rnn): super().__init__() self.rnn = rnn @property def batch_first(self): .原创 2021-01-12 23:25:15 · 135 阅读 · 0 评论 -
ACL2020 pytorch复现 (TextING) Every Document Owns Its Structure- Inductive Text Classification
一、模型图二、构图方式滑动窗口,捕捉共现边三、消息传递聚合,通过GRU训练。四,读出原创 2020-08-06 21:10:16 · 2627 阅读 · 21 评论 -
torch训练模板
如题from text_semantic.model import TextBiLSTMfrom text_semantic.dataset import MyDatasetfrom text_semantic.config import TEMP_PATH, RECORD_PATHimport timeimport torchimport numpy as npfrom torch import nnfrom torch.utils.data import DataLoader.原创 2020-07-11 11:36:16 · 578 阅读 · 0 评论 -
pytoch常用
三角函数的位置编码(原始Transformer)def get_pos_embedding(seq_len, dim): import math vectors = [[.0 if i % 2 == 0 else 1. for i in range(dim)], [math.sin(1. / math.pow(10000., (i / dim))) if i % 2 == 0 else math.cos(1. / math.原创 2020-07-11 11:35:32 · 258 阅读 · 0 评论 -
NLP-文本分类实战-Text Level GNN-20newsgroup
Text Level Graph Neural Network for Text Classification(https://arxiv.org/pdf/1910.02356.pdf)一、文章概述1.1 模型图图1:单一文本的图形结构“他为您感到非常骄傲。” 为了便于显示,在此图中,我们为节点“非常”设置了p = 2(节点和边用红色表示),而其他节点设置了p = 1(蓝色表示)。 在实际情况下,会话期间的p值是唯一的。 图中的所有参数均来自全局共享表示矩阵,该矩阵显示在图的底部。1.2原创 2020-07-08 10:56:36 · 1263 阅读 · 1 评论 -
python版本-文本分类流程-英文文本预处理
英文文本预处理单词原型word_map = { "i'll": "i will", "it'll": "it will", "we'll": "we will", "he'll": "he will", "they'll": "they will", "i'd": "i would", "we'd": "we would", ...原创 2020-04-03 22:11:15 · 1205 阅读 · 0 评论 -
文本分类论文及pytorch版复现(五):TextLevelGNN
Text Level Graph Neural Network for Text Classification一、模型图示:定义:消息传递机制:分类器:损失函数:二、代码from torch import nn, tensorimport torch.nn.functional as Fimport numpy as npimport tor...原创 2020-03-30 23:52:45 · 1456 阅读 · 1 评论 -
文本分类论文及pytorch版复现(四):TextGCN
Graph Convolutional Networks for Text Classification一、模型图示:图的定义:二、代码import torchimport numpy as npimport torch.nn.functional as Ffrom torch import nn, tensorfrom textgcn.config i...原创 2020-03-30 23:47:19 · 4011 阅读 · 7 评论 -
基于词级别和字级别的中文文本预处理
一、基于词级别文本预处理词级别预处理过程:1、文本分词2、统计词频3、去除低频词和停用词4、选取适量的高频词形成词典5、用词典过滤并映射文本分词6、查看文本序列长度分布,确定补全长度7、文本序列补全具体代码:from collections import Counterimport jieba_fast as jiebaimport joblib...原创 2020-02-04 16:02:47 · 852 阅读 · 0 评论 -
文本分类论文及pytorch版复现(三):VDCNN
Very Deep Convolutional Networks for Text Classification1、模型2、代码import torchimport torch.nn.functional as Ffrom torch import nn# char-level# embedding_dim=16, SGD, mini-batch=128...原创 2019-12-21 16:54:14 · 596 阅读 · 0 评论 -
文本分类论文及pytorch版复现(二):HAN
Hierarchical Attention Networks for Document Classification一、模型二、代码import torch.nn.functional as Ffrom torch import nnclass SelfAttention(nn.Module): def __init__(self, input_size...原创 2019-12-21 12:07:10 · 2156 阅读 · 6 评论 -
文本分类论文及pytorch版复现(一):TextCNN
Convolutional Neural Networks for Sentence Classification1、模型2、代码import torch.nn.functional as Ffrom torch import nnclass TextCNN(nn.Module): def __init__(self): super(Text...原创 2019-12-21 12:02:24 · 1352 阅读 · 1 评论