tensorflow - 使用 Keras 嵌入层进行词嵌入的情感分析
问题描述
我需要对我的模型结果进行一些说明。
这是我的用例:
- 确定标准普尔 500 指数公司的评论是负面的还是正面的。我确实使用了一个爬取的数据集。(数据集被标记(0 - 正,1 - 负),标记和清理)。
以下是一些重要信息,以了解模型和我的方法:
# Constants
NB_WORDS = 44000 # Parameter indicating the number of words we'll put in the dictionary
VAL_SIZE = 1000 # Size of the validation set
NB_START_EPOCHS = 10 # Number of epochs we usually start to train with
EPOCH_ITER = list(range(0,11)) # For stepwise evaluating the accuracy metrics for 10 epochs
BATCH_SIZE = 512 # Size of the batches used in the mini-batch gradient descent
MAX_LEN = 267 # Maximum number of words in a sequence (review)
REV_DIM = 300 # Number of dimensions of the indeed review word embeddings --> most common Mikolow et al., 2013
# Modeling
emb_model = models.Sequential()
emb_model.add(layers.Embedding(NB_WORDS, REV_DIM, input_length=MAX_LEN))
# Embedding layer is first hidden layer
"""
Embedding Layer (
input_length = no. of words in vocabularly;
output_dim = dimensionality;
max_length = length of largest review
)
"""
emb_model.add(layers.Flatten())
# Flatten Layers are reshaping tensor to 1-D array
emb_model.add(layers.Dense(2, activation='softmax'))
# Is the regular deeply connected neural network layer. It is most common and
# frequently used layer. Dense layer does the below operation on the input and return the output.
# Operation := output = activation(dot(input, kernel) + bias)
# further see: https://www.tutorialspoint.com/keras/keras_dense_layer.htm#:~:text=Advertisements,input%20and%20return%20the%20output.
# Defines the output size in our case 2, hence positive or negative (0 or 1)
emb_model.summary()
我已经做了一些解释。但由于我是初学者,我真的需要更多信息/解释/提示,特别是关于如何以及为什么改进我的模型。
这是我的结果:
解决方案
推荐阅读
- javascript - readdirSync() 找不到任何文件
- blockchain - 从交易中更新 Hyperledger ACL
- java - 使用 Jsoup 登录
- c - C - 指向数组的指针:如何将一个指针的值(不是地址)复制到另一个指针?
- azure - IoT 中心事件摄取和数据存储
- angularjs - 将 Protractor e2e 测试设置为每晚运行的最简单方法是什么?
- python-3.x - 创建嵌套的python字典并内联赋值?
- rest - JIRA:使用 REST API 获取 Epic 和 Epic 级别下的所有问题的描述
- sql - 如何根据条件分离和求和 2 列
- dictionary - 在 highmap 上加载不同的底图