如何使用BERT进行排序,并在Finetuining期间使用Pairwise损失函数?

eh57zj3b  于 4个月前  发布在  其他
关注(0)|答案(6)|浏览(72)

Hi I want to use BERT for pairwise loss function. I know how to use it using pointwise loss using the run_classiifer where I can pass query as text_a and passage as a text_b.
But for pairwise loss, I have a triplet like [query, positive_passage, negative_passage]. So I want BERT to give me like this pos_score = modeling.BertModel(query, positive_passage) and neg_score= modeling.BertModel(query, negative_passage). Then apply Dense layer on the Difference of pos_score and neg_score and SoftMax like in run_classifier.
Note that I want the same modeling.BertModel for both positive and negative passage not two sepearte modeling.BertModel. In another word, positive passage and negative passage share the same BERT layer. Please let me know how to do it.
You can take a look at this Keras code to get the idea of what I am talking about https://github.com/airalcorn2/RankNet/blob/master/ranknet.py

相关问题