小编Shu*_*ngh的帖子

langchain 的色度 `vectordb.similarity_search_with_score()` 和 `vectordb.similarity_search_with_relevancy_scores()` 返回相同的输出

我一直在使用 langchain 的色度矢量数据库。它有两种使用分数运行相似性搜索的方法。

  1. vectordb.similarity_search_with_score()
  2. vectordb.similarity_search_with_relevance_scores()

根据文档,第一个应该返回 的余弦距离float在此输入图像描述

越小越好。

第二个应该返回从 0 到 1 的分数,0 表示不相似,1 表示相似。 在此输入图像描述

但是当我尝试相同的方法时,它给出了完全相同的结果和相同的分数,这超出了上限 1,第二个函数不应该出现这种情况。

这里发生了什么?

nlp langchain

8
推荐指数
2
解决办法
2万
查看次数

类型错误:需要任何非张量类型,而是得到一个张量

我正在关注“使用 TensorFlow 2.0 为聊天机器人训练变压器模型”的帖子。尽管代码在 colab 中运行良好,但我在本地机器上遇到了错误。下面是代码片段。

def encoder_layer(units, d_model, num_heads, dropout, name="encoder_layer"):
  inputs = tf.keras.Input(shape=(None, d_model), name="inputs")
  padding_mask = tf.keras.Input(shape=(1, 1, None), name="padding_mask")

  attention = MultiHeadAttention(
      d_model, num_heads, name="attention")({
          'query': inputs,
          'key': inputs,
          'value': inputs,
          'mask': padding_mask
      })
  attention = tf.keras.layers.Dropout(rate=dropout)(attention)
  attention = tf.keras.layers.LayerNormalization(
      epsilon=1e-6)(inputs + attention)

  outputs = tf.keras.layers.Dense(units=units, activation='relu')(attention)
  outputs = tf.keras.layers.Dense(units=d_model)(outputs)
  outputs = tf.keras.layers.Dropout(rate=dropout)(outputs)
  outputs = tf.keras.layers.LayerNormalization(
      epsilon=1e-6)(attention + outputs)

  return tf.keras.Model(
      inputs=[inputs, padding_mask], outputs=outputs, name=name)
Run Code Online (Sandbox Code Playgroud)

我用下面的函数调用调用了上面的函数;

sample_encoder_layer = encoder_layer(
    units=512,
    d_model=128,
    num_heads=4, …
Run Code Online (Sandbox Code Playgroud)

transformer-model chatbot deep-learning keras tensorflow

5
推荐指数
2
解决办法
4826
查看次数