Bert-as-service: 中文bert

Created on 23 Nov 2018  ·  8Comments  ·  Source: hanxiao/bert-as-service

在中文bert中,bert获得的是一句话的向量,还是一个词的向量,我在测试的时候,无论输入什么词或话,用余弦相似度计算,得出来的相似度都是在0.8以上,希望您能回复。

Most helpful comment

I quote from https://github.com/google-research/bert/issues/164#issuecomment-441324222

And even if they are decent representations when fed into a DNN trained for a downstream task, it doesn't mean that they will be meaningful in terms of cosine distance. (Since cosine distance is a linear space where all dimensions are weighted equally).

Suggestion from my side, if you want to use cosine distance anyway, then please focus on the rank not the absolute value. Namely, do not use:

cosine(A, B) > 0.9 then A and B are similar

please consider the following instead:

if cosine(A, B) > cosine(A, C) then A is more similar to B than C.

All 8 comments

我也遇到这个问题。
a=bc.encode(['你好。', '我听一下。'])
print(np.dot(a[0], a[1]) / (np.linalg.norm(a[0]) * np.linalg.norm(a[1]) + 1e-9))
结果相似度是0.9+(pool策略是PoolingStrategy.REDUCE_MEAN,默认参数)

bertclient.encode()的时候输入的是一句话,还是一句话分词以后以一个list形式输入。

遇到一样的问题,余弦相似度全部在0.8以上

I quote from https://github.com/google-research/bert/issues/164#issuecomment-441324222

And even if they are decent representations when fed into a DNN trained for a downstream task, it doesn't mean that they will be meaningful in terms of cosine distance. (Since cosine distance is a linear space where all dimensions are weighted equally).

Suggestion from my side, if you want to use cosine distance anyway, then please focus on the rank not the absolute value. Namely, do not use:

cosine(A, B) > 0.9 then A and B are similar

please consider the following instead:

if cosine(A, B) > cosine(A, C) then A is more similar to B than C.

THX

there is a bug in my pooling strategies: REDUCE_MEAN, REDUCE_MAX and REDUCE_MEAN_MAX. I fixed it in the latest master, please do git pull to check out the latest master. If you redo your experiment, result could be different.

in principle, this bug affects the most when ‘max_seq_len’ is much longer than the actual sequence length.

那个 ,怎么启动bert服务呢 ,windows不太会操作

@hanxiao 你修复后,现在还能使用绝对的余弦相识度来计算两个句子的相似性吗? 还是说仍然只能用相对的相似性?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xpact picture xpact  ·  5Comments

astariul picture astariul  ·  7Comments

babai3693 picture babai3693  ·  3Comments

kirdin picture kirdin  ·  3Comments

zhant09 picture zhant09  ·  3Comments