Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于train_retriever.py中的loss #49

Open
llllooong opened this issue Jul 20, 2023 · 2 comments
Open

关于train_retriever.py中的loss #49

llllooong opened this issue Jul 20, 2023 · 2 comments

Comments

@llllooong
Copy link

麻烦问一下train_retriever.py文件中第44行求loss的函数中,cross_entropy的训练target为什么是是torch.arange(0, len(l_pos)呀?
image

@Longin-Yu
Copy link
Collaborator

  1. 每一条训练数据包含一条强关联(作为 positive sample)与弱关联(作为 hard negative sample)。
  2. 训练过程中,若 batchsize 为 $n$,则同一个 batch 内将包含 $n$ 条 positive sample 和 $n$ 条 hard negative sample,对于每一条数据而言,只有它的 positive sample 是正例,其余 $2n - 1$ 条全都是负例。
  3. 将这 2n 条数据按 $(pos_1, \cdots, pos_n, neg_1, \cdots, neg_n)$ 的方式拼接起来后,第 $i$ 条数据的正样本 index 即为 $i$

@llllooong
Copy link
Author

那是不是得确保一个batch内,尽量少有相似问题?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants