【问题标题】:Similar text categorization problems (word vectors, sentence vectors)相似文本分类问题(词向量、句子向量)
【发布时间】:2021-02-20 15:18:17
【问题描述】:

目的:有许多语句需要组织和聚类(相似的关键字组织在一起)。

我的技术知识:最近三周学习了 Python 和 Tensorflow 相关的内容。学习了一些基础知识。

  1. 先读取csv文件
keywords = pd.read_csv("copy.csv")
cover_words = []
for row in keywords.Keyword:
    cover_words.append(row)
  1. 分词器和序列
# Tokenizer
tokenizer = Tokenizer(num_words = 10000, oov_token='<OOV>')
tokenizer.fit_on_texts(cover_words)
word_index = tokenizer.word_index
# Sequences
Sequences = tokenizer.texts_to_sequences(cover_words)
sentences_padded = pad_sequences(Sequences, padding='post', truncating='post')
  1. 词嵌入
embedding_layer = layers.Embedding(20000, 4)
tf_data = tf.convert_to_tensor(sentences_padded, tf.float32, name='t')
result = embedding_layer(tf_data)

我的下一个想法是使用循环将句子的词向量相加以获得“句子向量”。然后用循环求向量的余弦相似度,相似度越接近,越接近。

但是现在我有一个问题,因为句子长度不一样,所以我用sentences_padded = pad_sequences(Sequences, padding='post', truncating='post') 让所有的句子长度一样。那么如果我需要将句子的词向量相加得到句子向量,是不是放入了太多无效向量呢?

我也不知道如何摆脱这个无效的向量。另外我不知道上述是否正确,或者是否有更简单的方法。

【问题讨论】:

    标签: python pandas tensorflow word-embedding


    【解决方案1】:

    使用嵌入的平均值而不是求和。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-26
      • 1970-01-01
      • 2016-08-12
      • 2020-12-12
      • 2019-08-01
      • 2018-10-17
      • 2020-08-22
      • 1970-01-01
      相关资源
      最近更新 更多