Code Monkey home page Code Monkey logo

textmatch's Introduction

基于Pytorch的中文语义相似度匹配模型

基于Pytorch的中文语义相似度匹配模型

本项目将持续更新,对比目前业界主流文本匹配模型在中文的效果

运行环境: python3.7、pytorch1.2、transformers2.5.1

数据集采用LCQMC数据(将一个句对进行分类,判断两个句子的语义是否相同(二分类任务)),因数据存在侵权嫌疑,故不提供下载,需要者可向官方提出数据申请http://icrc.hitsz.edu.cn/info/1037/1146.htm ,并将数据解压到data文件夹即可。模型评测指标为:ACC,AUC以及预测总共耗时。

Embeding:
本项目输入都统一采用分字策略,故通过维基百科中文语料,训练了字向量作为Embeding嵌入。训练语料、向量模型以及词表,可通过百度网盘下载。
链接:https://pan.baidu.com/s/1qByw67GdFSj0Vt03GSF0qg
提取码:s830

模型文件:
本项目训练的模型文件(不一定最优,可通过超参继续调优),也可通过网盘下载。
链接:https://pan.baidu.com/s/1qByw67GdFSj0Vt03GSF0qg
提取码:s830

测试集结果对比:

模型 ACC AUC 耗时(s)(备注:环境1070TI)
ABCNN 0.8081 0.9059 4.6260
Albert 0.8522 0.9475 52.3823
Bert 0.8714 0.9544 61.2800
BIMPM 0.8359 0.9375 18.8210
DecomposableAttention 0.8068 0.9334 3.7170
DistilBert 0.8450 0.9403 31.1680
ESIM 0.8385 0.9311 2.7410
RE2 0.8391 0.9196 5.2200
Roberta 0.8726 0.9591 61.3130
SiaGRU 0.8281 0.9336 3.5500
XlNet 0.8694 0.9601 89.8090

部分模型,借鉴了
https://github.com/alibaba-edu/simple-effective-text-matching-pytorch
https://github.com/pengshuang/Text-Similarity
等项目。

textmatch's People

Contributors

zhaogaofeng611 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

textmatch's Issues

推理代码有BUG

test.py文件中,DataLoader(test_data, shuffle=True, batch_size=batch_size) shuffle应该设为False,这是一个很低级的BUG,卡了我一天,在最意想不到的地方有BUG

数据格式

您好,可以提供一个训练数据的格式案例吗,谢谢

embedding与vocab的对应

你好,这个词向量矩阵与vocab是否错位? embedding_matrix[idx + 1] = model[word]#词向量矩阵,然而vocab前两位是pad 和 unk. 而词向量第一个位置为的。

esim model may exist problem about embedding initailizing

在看esim模型时,lstm 的embedding 初始化参数使用预训练的,预训练word2vec的model存在69840token,vocab.txt存在69842token,补充了2个[PAD]和[UNK]这样token,在构建预训练imbedding参数矩阵时,embedding_matrix = np.zeros((len(model.index2word) + 1, model.vector_size)),这行代码是否需要改成embedding_matrix = np.zeros((len(model.index2word) + 2, model.vector_size)),这样[PAD]和[UNK]这样token分别对应第0行和1行,与word2idx = {word: index for index, word in enumerate(vocab)}这样相对应.

about train model issues!

Hi,I want to know how to define the train data (validation data) label?now i am define 1 means match ,and 0 means not match,but I train model ,there is a error occurs,I find maybe the label doesn't match to network output logits and probs .Thanks!

esim

请问训练的时候出现这个问题 Length of all samples has to be greater than 0, but found an element in 'lengths' that is <= 0,如何解决呀
image

下载回来模型和data 跑test 的时候报错

Traceback (most recent call last):
File ".\test.py", line 51, in
main("d:\test.csv", "models/best.pth.tar")
File ".\test.py", line 43, in main
model.load_state_dict(checkpoint["model"])
File "C:\Python\Python38\lib\site-packages\torch\nn\modules\module.py", line 1044, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for BertModelTest:
Missing key(s) in state_dict: "bert.bert.embeddings.position_ids".

如何解决?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.