0

我正在尝试通过双向 LSTM 传递 SBERT 嵌入。

s1 = ["Jack while talking over the cell phone entered the prison cell to extract blood cell samples of Jill and made an entry in the excel cell about the blood sample collection."]
s2 = ["extract blood cell samples of Jill and entered into an excel cell."]

embd1=embdmodel.encode(s1)
embd2=embdmodel.encode(s2) 

embd1=embd1.reshape(1,768,-1)
embd2=embd2.reshape(1,768,-1)

bilstm=Bidirectional(LSTM(activation='tanh', dropout=0.2, units=64, return_sequences=True))

print(type(t1),t1)
<class 'tensorflow.python.framework.ops.EagerTensor'> tf.Tensor(
[[[-2.5327273e-03 -2.7493148e-03 -1.3621929e-05 ... -9.6573209e-04
   -1.2917898e-03  1.0269388e-03]
  [ 6.0339028e-04  2.5809051e-05  7.7639311e-04 ...  1.0584032e-02
    6.5508196e-03  8.1811240e-03]
  [ 3.1445127e-03  2.9004358e-03  5.7615573e-04 ...  1.0758486e-02
    6.7473711e-03  6.8732686e-03]
  ...
  [-1.1306561e-04 -1.9196013e-03  2.7845167e-03 ...  5.2405000e-03
    3.6371003e-03  5.1377462e-03]
  [ 1.5569818e-03  1.8675721e-04  2.4465215e-03 ...  6.1087771e-03
    4.3185032e-03  5.0926427e-03]
  [ 2.5213691e-03  1.8961598e-03  1.5776788e-03 ...  4.0370375e-03
    2.8996556e-03  3.0477550e-03]]], shape=(1, 768, 128), dtype=float32)
<class 'tensorflow.python.framework.ops.EagerTensor'> tf.Tensor(
[[[-4.11060115e-04 -4.40460019e-04 -2.19363710e-06 ...  5.11768740e-03
    3.00049176e-03  6.81342976e-03]
  [ 3.05557298e-03  3.10453586e-03  1.39100142e-04 ...  1.29150162e-02
    8.59439280e-03  1.12189101e-02]
  [ 4.84283781e-03  5.67589840e-03 -7.39651150e-04 ...  1.07553005e-02
    6.93271169e-03  8.06750450e-03]
  ...
  [-1.49270741e-03 -3.98713863e-03  3.72989709e-03 ...  6.13715174e-03
    4.23531514e-03  6.30550832e-03]
  [ 2.08535348e-03 -7.44284916e-05  3.65654076e-03 ...  9.50277317e-03
    6.88536465e-03  7.85568263e-03]
  [ 3.07793613e-03  1.92491792e-03  2.46308488e-03 ...  4.67062648e-03
    3.37219983e-03  3.53964046e-03]]], shape=(1, 768, 128), dtype=float32)

sim = util.pytorch_cos_sim(t1, t2)

这给出了一个错误:

() 中的 TypeError Traceback (最近一次调用最后一次) ----> 1 sim = util.pytorch_cos_sim(t1, t2) 2 帧 /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ ops.py in len (self) 1094 """返回张量中第一个维度的长度。""" 1095 如果不是 self.shape.ndims: -> 1096 raise TypeError("Scalar tensor has no len()") 1097 # pylint: disable=protected-access 1098 try: TypeError: Scalar tensor has nolen()

4

0 回答 0