基于感知机的Yelp评论分类器训练与评估
1. 感知机分类器与损失函数
在使用特定的损失函数时,输出不应应用Sigmoid函数。因此,默认情况下,我们不应用Sigmoid函数。不过,如果分类器的用户需要概率值,则需要使用Sigmoid函数,并且将其作为一个选项保留。以下是一个用于对Yelp评论进行分类的感知机分类器的代码示例:
import torch.nn as nn
import torch.nn.functional as F
class ReviewClassifier(nn.Module):
""" a simple perceptron-based classifier """
def __init__(self, num_features):
"""
Args:
num_features (int): the size of the input feature vector
"""
super(ReviewClassifier, self).__init__()
self.fc1 = nn.Linear(in_features=num_features,
out_features=1)
def forward(self, x_in, apply_sigmoid=False):
"""The forward pass of the classifier
Args:
x_in (to
超级会员免费看
订阅专栏 解锁全文
1443

被折叠的 条评论
为什么被折叠?



