【发布时间】:2020-07-03 15:37:35
【问题描述】:
这是代码,想法是我想构建一个多语言情感分类器,但这里的问题是: (tensorflow 2.0.1), (tf-hub 0.7.0)
import tensorflow as tf
import tensorflow_hub as hub
ml_module = hub.load('https://tfhub.dev/google/universal-sentence-encoder-multilingual/3')
module = hub.KerasLayer(ml_module , dtype=tf.string, trainable=False, name='bert_embedding')
input_text = tf.keras.Input((), dtype=tf.string, name='input_text')
embedding = module(input_text)
conv1 = tf.keras.layers.Conv1D(32, 2, padding='valid', activation='relu', strides=1)(embedding)
dense1 = tf.keras.layers.Dense(512, activation="relu")(conv1)
layer1 = tf.keras.layers.Dense(9, name='sentiment')(dense1)
model = tf.keras.models.Model(inputs=input_text, outputs=layer1)
ValueError: Input 0 of layer conv1d_3 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 512]
也许我可以尝试使用 keras lambda 函数来调整嵌入输出的大小,但我没有找到让它工作的方法
你们有什么想法吗?
谢谢
【问题讨论】:
标签: tensorflow keras deep-learning tensorflow2.0 tensorflow-hub