pytorch-day03
Text data Modeling Example
- IMDB数据集的目标是预测评论的情感标签
数据预处理
- 这里似乎只用了一个简单的构建词表,然后hard code每一个词?没有用到任何word-embedding。我很好奇这真的有用吗
- 这里我们定义了一个类用来处理数据
1
2
3
4
5
6
7
8
9
10
11class ImdbDataset(Dataset):
def __init__(self,df):
self.df = df
def __len__(self):
return len(self.df)
def __getitem__(self,index):
text = self.df["text"].iloc[index]
label = torch.tensor([self.df["label"].iloc[index]]).float()
tokens = torch.tensor(text_pipeline(text)).int()
return tokens,label - 使用这种模板是一种不错的选择,可以构建适用于每个不同task的dataloader
Define the model
使用的疑似是一维的因果卷积?是一个简单的1D 卷积- 1D conv用于特征提取而因果卷积用于时序建模
训练代码同前,不是我喜欢的直接不学
All articles on this blog are licensed under CC BY-NC-SA 3.0 CN unless otherwise stated.