注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
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。。。
- from tensorflow.python.keras import models
- from tensorflow.python.keras.layers import Dense
- from tensorflow.python.keras.layers import Dropout
- def mlp_model(layers, units, dropout_rate, input_shape, num_classes):
- """Creates an instance of a multi-layer perceptron model.
- # Arguments
- layers: int, number of `Dense` layers in the model.
- units: int, output dimension of the layers.
- dropout_rate: float, percentage of input to drop at Dropout layers.
- input_shape: tuple, shape of input to the model.
- num_classes: int, number of output classes.
- # Returns
- An MLP model instance.
- """
- op_units, op_activation = _get_last_layer_units_and_activation(num_classes)
- model = models.Sequential()
- model.add(Dropout(rate=dropout_rate, input_shape=input_shape))
- for _ in range(layers-1):
- model.add(Dense(units=units, activation='relu'))
- model.add(Dropout(rate=dropout_rate))
- model.add(Dense(units=op_units, activation=op_activation))
- return model
复制代码
谢谢
|