查看: 2040| 回复: 5
跳转到指定楼层
上一主题 下一主题
收起左侧

求解释一下MLP

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
本帖最后由 gloriasuns 于 2019-10-2 12:44 编辑

Google有这样一个介绍:
https://developers.google.com/ma ... assification/step-4

里面有一部分介绍 Build n-gram model【Option A】:
We refer to models that process the tokens independently (not taking into account word order) as n-gram models. Simple multi-layer perceptrons (including logistic regression), gradient boosting machines and support vector machines models all fall under this category; they cannot leverage any information about text ordering.

We compared the performance of some of the n-gram models mentioned above and observed that multi-layer perceptrons (MLPs) typically perform better than other options. MLPs are simple to define and understand, provide good accuracy, and require relatively little computation.

The following code defines a two-layer MLP model in tf.keras, adding a couple of Dropout layers for regularization (to prevent overfitting to training samples).

接下来有一段code,我的问题是这个code怎么反映出来ngram的?我怎么知道这段code是unigram,bigram,trigram还是其他的gram。。。

  1. from tensorflow.python.keras import models
  2. from tensorflow.python.keras.layers import Dense
  3. from tensorflow.python.keras.layers import Dropout

  4. def mlp_model(layers, units, dropout_rate, input_shape, num_classes):
  5.     """Creates an instance of a multi-layer perceptron model.

  6.     # Arguments
  7.         layers: int, number of `Dense` layers in the model.
  8.         units: int, output dimension of the layers.
  9.         dropout_rate: float, percentage of input to drop at Dropout layers.
  10.         input_shape: tuple, shape of input to the model.
  11.         num_classes: int, number of output classes.

  12.     # Returns
  13.         An MLP model instance.
  14.     """
  15.     op_units, op_activation = _get_last_layer_units_and_activation(num_classes)
  16.     model = models.Sequential()
  17.     model.add(Dropout(rate=dropout_rate, input_shape=input_shape))

  18.     for _ in range(layers-1):
  19.         model.add(Dense(units=units, activation='relu'))
  20.         model.add(Dropout(rate=dropout_rate))

  21.     model.add(Dense(units=op_units, activation=op_activation))
  22.     return model
复制代码

谢谢


上一篇:求解释一下roc_auc_score()
下一篇:大家approach text classification的问题的时候会选什么模型?
推荐
xyz_abc 2019-10-2 15:24:03 | 只看该作者
全局:
mlp接收vector/matrix作为输入,所以你需要把text转成vector,可以用ngram,具体n是多少由自己定义,mlp接收转换成vector的data作为输入。
ngram里没有word embedding,只有每个gram vocab的count。比如unigram你就count vocab里的每个单词数量,bigram就count vocab里的 两词短语的数量。vocab也是自己定义的,根据你关注哪些gram

评分

参与人数 1大米 +10 收起 理由
admin + 10 参与讨论加分!

查看全部评分

回复

使用道具 举报

全局:
我猜是input_shape决定的,每次把n 个 word embedding 同时输入进去。

(在地里甚至可以讨论学术)

评分

参与人数 1大米 +6 收起 理由
admin + 6

查看全部评分

回复

使用道具 举报

🔗
pagpires 2019-10-3 04:18:35 | 只看该作者
全局:
这边说的不是NLP的ngram,而是ngram model,相对于文章底下的sequence model而言的(也所以跟unigram/bigram没有关系)。这词感觉是G自己发明的。。。它就是指这类model的input feature之间没有顺序关系:你的所有training data从(f0, f1, f2)变成(f2, f1, f0)的话,MLP的性能不变,相比之下sequence model的性能会变。
回复

使用道具 举报

🔗
 楼主| gloriasuns 2019-10-3 06:06:19 | 只看该作者
全局:
我找到答案了,大家感兴趣的可以去看看step 2,里面提到了具体的implementation

补充内容 (2019-10-3 08:48):
应该是step 3
回复

使用道具 举报

🔗
 楼主| gloriasuns 2019-10-3 06:09:51 | 只看该作者
全局:
pagpires 发表于 2019-10-3 04:18
这边说的不是NLP的ngram,而是ngram model,相对于文章底下的sequence model而言的(也所以跟unigram/bigra ...

谢谢,确实是跟顺序没关系。但是这个词就是nlp的n-gram,不是G家发明的,你也可以看看step 2:)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表