程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在 Keras 中使用 textVectorization 和 Embedding 层创建子模型抛出:'str' object has no attribute 'base_dtype' in Keras大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决在 Keras 中使用 textVectorization 和 Embedding 层创建子模型抛出:'str' object has no attribute 'base_dtype' in Keras?

开发过程中遇到在 Keras 中使用 textVectorization 和 Embedding 层创建子模型抛出:'str' object has no attribute 'base_dtype' in Keras的问题如何解决?下面主要结合日常开发的经验,给出你关于在 Keras 中使用 textVectorization 和 Embedding 层创建子模型抛出:'str' object has no attribute 'base_dtype' in Keras的解决方法建议,希望对你解决在 Keras 中使用 textVectorization 和 Embedding 层创建子模型抛出:'str' object has no attribute 'base_dtype' in Keras有所启发或帮助;

我正在使用文本和数字数据制作多输入 Tensorflow NLP 模型。为了创建这个,我计划制作两个子模型,一个用于文本,另一个用于数字数据,然后将它们的输出连接到我的主模型中。对于文本子模型,我一直在遵循 Keras 的文本矢量化和嵌入指南(https://www.tensorflow.org/tutorials/text/word_embeddings#configure_the_dataset_for_perfoRMANce 和 https://www.tensorflow.org/api_docs/python/tf/keras/layers/experimental/preprocessing/TextVectorization),并使用 TF-IDF 加权,为所有二元组建立索引。这是 TextVectorization 层的代码:

# Instantiate TextVectorization with "tf-IDf" output_mode
# (multi-hot with TF-IDF weighTing) and ngrams=2 (index all bigrams)
text_vectorizer = preprocessing.TextVectorization(output_mode="tf-IDf",ngrams=2)
# Index the bigrams and learn the TF-IDF weights via `adapt()`
text_vectorizer.adapt(df['tweet_punct'].dropna().to_numpy())
print('Size of vocabulary:',len(text_vectorizer.get_vocabulary()))
vocab_size = len(text_vectorizer.get_vocabulary())

当我尝试将矢量化层连接到嵌入层时出现错误。这是我一直在使用的以下脚本:

embedding_layer = Embedding(vocab_size,100)(text_vectorizer)
LSTM_layer_1 = LSTM(128)(embedding_layer)

根据我能找到的与此问题相关的唯一其他问题:'str' object has no attribute 'base_dtype' error TensorFlow model 层相互添加的方式应该是正确的,但是运行它在第一行给了我 AttributeError: 'str' object has no attribute 'base_dtype'我如何连接两层有问题吗?我是 Tensorflow 的新手,从未尝试过以这种方式制作模型,所以我对这里发生的事情有点迷茫。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的在 Keras 中使用 textVectorization 和 Embedding 层创建子模型抛出:'str' object has no attribute 'base_dtype' in Keras全部内容,希望文章能够帮你解决在 Keras 中使用 textVectorization 和 Embedding 层创建子模型抛出:'str' object has no attribute 'base_dtype' in Keras所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。