All Projects → zjunlp → Deepke

zjunlp / Deepke

Licence: apache-2.0
基于深度学习的开源中文关系抽取框架

Projects that are alternatives of or similar to Deepke

D2l Torch
《动手学深度学习》 PyTorch 版本
Stars: ✭ 105 (-80%)
Mutual labels:  chinese, jupyter-notebook
Doc Han Att
Hierarchical Attention Networks for Chinese Sentiment Classification
Stars: ✭ 206 (-60.76%)
Mutual labels:  chinese, jupyter-notebook
Pytorch multi head selection re
BERT + reproduce "Joint entity recognition and relation extraction as a multi-head selection problem" for Chinese and English IE
Stars: ✭ 105 (-80%)
Mutual labels:  chinese, relation-extraction
Agriculture knowledgegraph
农业知识图谱(AgriKG):农业领域的信息检索,命名实体识别,关系抽取,智能问答,辅助决策
Stars: ✭ 2,957 (+463.24%)
Mutual labels:  knowledge-graph, relation-extraction
Casrel
A Novel Cascade Binary Tagging Framework for Relational Triple Extraction. Accepted by ACL 2020.
Stars: ✭ 329 (-37.33%)
Mutual labels:  knowledge-graph, relation-extraction
Lightnlp
基于Pytorch和torchtext的自然语言处理深度学习框架。
Stars: ✭ 739 (+40.76%)
Mutual labels:  chinese, relation-extraction
Icychesszero
中国象棋alpha zero程序
Stars: ✭ 206 (-60.76%)
Mutual labels:  chinese, jupyter-notebook
Multihopkg
Multi-hop knowledge graph reasoning learned via policy gradient with reward shaping and action dropout
Stars: ✭ 202 (-61.52%)
Mutual labels:  knowledge-graph, jupyter-notebook
knowledge-graph-nlp-in-action
从模型训练到部署,实战知识图谱(Knowledge Graph)&自然语言处理(NLP)。涉及 Tensorflow, Bert+Bi-LSTM+CRF,Neo4j等 涵盖 Named Entity Recognition,Text Classify,Information Extraction,Relation Extraction 等任务。
Stars: ✭ 58 (-88.95%)
Mutual labels:  knowledge-graph, relation-extraction
KGPool
[ACL 2021] KGPool: Dynamic Knowledge Graph Context Selection for Relation Extraction
Stars: ✭ 33 (-93.71%)
Mutual labels:  knowledge-graph, relation-extraction
Drkg
A knowledge graph and a set of tools for drug repurposing
Stars: ✭ 231 (-56%)
Mutual labels:  knowledge-graph, jupyter-notebook
Chinesenre
中文实体关系抽取,pytorch,bilstm+attention
Stars: ✭ 463 (-11.81%)
Mutual labels:  chinese, relation-extraction
Bert Attributeextraction
USING BERT FOR Attribute Extraction in KnowledgeGraph. fine-tuning and feature extraction. 使用基于bert的微调和特征提取方法来进行知识图谱百度百科人物词条属性抽取。
Stars: ✭ 224 (-57.33%)
Mutual labels:  knowledge-graph, relation-extraction
Zhopenie
Chinese Open Information Extraction (Tree-based Triple Relation Extraction Module)
Stars: ✭ 98 (-81.33%)
Mutual labels:  chinese, relation-extraction
Knowledge Graph Analysis Programming Exercises
Exercises for the Analysis of Knowledge Graphs
Stars: ✭ 208 (-60.38%)
Mutual labels:  knowledge-graph, jupyter-notebook
Cluedatasetsearch
搜索所有中文NLP数据集,附常用英文NLP数据集
Stars: ✭ 2,112 (+302.29%)
Mutual labels:  chinese, knowledge-graph
Tensorflow Nlp
NLP and Text Generation Experiments in TensorFlow 2.x / 1.x
Stars: ✭ 1,487 (+183.24%)
Mutual labels:  knowledge-graph, jupyter-notebook
Pytextrank
Python implementation of TextRank for phrase extraction and summarization of text documents
Stars: ✭ 1,675 (+219.05%)
Mutual labels:  knowledge-graph, jupyter-notebook
Shukongdashi
使用知识图谱,自然语言处理,卷积神经网络等技术,基于python语言,设计了一个数控领域故障诊断专家系统
Stars: ✭ 109 (-79.24%)
Mutual labels:  knowledge-graph, relation-extraction
Deep Learning Resources
由淺入深的深度學習資源 Collection of deep learning materials for everyone
Stars: ✭ 422 (-19.62%)
Mutual labels:  chinese, jupyter-notebook

DeepKE

DeepKE 是基于 Pytorch 的深度学习中文关系抽取处理套件。

Contributors

Organization: 浙江大学知识引擎实验室

Mentor: 陈华钧,张宁豫


@huajunsir @zxlzr @231sm @ruoxuwang @yezqNLP @yuwl798180 @seventk

环境依赖:

python >= 3.6

  • torch >= 1.2
  • hydra-core >= 0.11
  • tensorboard >= 2.0
  • matplotlib >= 3.1
  • transformers >= 2.0
  • jieba >= 0.39
  • pyhanlp >= 0.1.57(中文句法分析使用,但是在多句时效果也不好。。求推荐有比较好的中文句法分析)

主要目录

├── conf                      # 配置文件夹
│  ├── config.yaml            # 配置文件主入口
│  ├── preprocess.yaml        # 数据预处理配置
│  ├── train.yaml             # 训练过程参数配置
│  ├── hydra                  # log 日志输出目录配置
│  ├── embedding.yaml         # embeding 层配置
│  ├── model                  # 模型配置文件夹
│  │  ├── cnn.yaml            # cnn 模型参数配置
│  │  ├── rnn.yaml            # rnn 模型参数配置
│  │  ├── capsule.yaml        # capsule 模型参数配置
│  │  ├── transformer.yaml    # transformer 模型参数配置
│  │  ├── gcn.yaml            # gcn 模型参数配置
│  │  ├── lm.yaml             # lm 模型参数配置
├── pretrained                # 使用如 bert 等语言预训练模型时存放的参数
│  ├── vocab.txt              # BERT 模型词表
│  ├── config.json            # BERT 模型结构的配置文件
│  ├── pytorch_model.bin      # 预训练模型参数
├── data                      # 数据目录
│  ├── origin                 # 训练使用的原始数据集
│  │  ├── train.csv           # 训练数据集
│  │  ├── valid.csv           # 验证数据集
│  │  ├── test.csv            # 测试数据集
│  │  ├── relation.csv        # 关系种类
│  ├── out                    # 预处理数据后的存放目录
├── module                    # 可复用模块
│  ├── Embedding.py           # embedding 层
│  ├── CNN.py                 # cnn
│  ├── RNN.py                 # rnn
│  ├── Attention.py           # attention
│  ├── Transformer.py         # transformer
│  ├── Capsule.py             # capsule
│  ├── GCN.py                 # gcn
├── models                    # 模型目录
│  ├── BasicModule.py         # 模型基本配置
│  ├── PCNN.py                # PCNN / CNN 模型
│  ├── BiLSTM.py              # BiLSTM 模型
│  ├── Transformer.py         # Transformer 模型
│  ├── LM.py                  # Language Model 模型
│  ├── Capsule.py             # Capsule 模型
│  ├── GCN.py                 # GCN 模型
├── test                      # pytest 测试目录
├── tutorial-notebooks        # simple jupyter notebook tutorial
├── utils                     # 常用工具函数目录
├── metrics.py                # 评测指标文件
├── serializer.py             # 预处理数据过程序列化字符串文件
├── preprocess.py             # 训练前预处理数据文件
├── vocab.py                  # token 词表构建函数文件
├── dataset.py                # 训练过程中批处理数据文件
├── trainer.py                # 训练验证迭代函数文件
├── main.py                   # 主入口文件(训练)
├── predict.py                # 测试入口文件(测试)            
├── README.md                 # read me 文件

快速开始

数据为 csv 文件,样式范例为:

sentence relation head head_offset tail tail_offset
《岳父也是爹》是王军执导的电视剧,由马恩然、范明主演。 导演 岳父也是爹 1 王军 8
《九玄珠》是在纵横中文网连载的一部小说,作者是龙马。 连载网站 九玄珠 1 纵横中文网 7
提起杭州的美景,西湖总是第一个映入脑海的词语。 所在城市 西湖 8 杭州 2
  • 安装依赖: pip install -r requirements.txt

  • 存放数据:在 data/origin 文件夹下存放训练数据。训练文件主要有三个文件。更多数据建议使用百度数据库中Knowledge Extraction

    • train.csv:存放训练数据集

    • valid.csv:存放验证数据集

    • test.csv:存放测试数据集

    • relation.csv:存放关系种类

  • 开始训练:python main.py

  • 每次训练的日志保存在 logs 文件夹内,模型结果保存在 checkpoints 文件夹内。

具体介绍

wiki

备注(常见问题)

  1. 使用 Anaconda 时,建议添加国内镜像,下载速度更快。如清华镜像

  2. 使用 pip 时,建议使用国内镜像,下载速度更快,如阿里云镜像。

  3. 安装后提示 ModuleNotFoundError: No module named 'past',输入命令 pip install future 即可解决。

  4. 使用 python main.py --help 可以查看所有可配置参数,并定制修改参数结果。参数为 bool 值的,可以用 1,0 代替 True, False

    • python main.py epoch=100 batch_size=128 use_gpu=False
  5. 使用 python main.py xxx=xx,xx -m 可以多任务处理程序。

    • python main.py model=cnn,rnn,lm chinese_split=0,1 -m 可以生成 3*2=6 个子任务。
  6. 中文英文在数据预处理上有很多不同之处,serializer.py 用来专门序列化句子为 tokens。中文分词使用的是 jieba 分词。

    • 英文序列化要求:大小写、特殊标点字符处理、特殊英文字符是否分词、是否做 word-piece 处理等。

    • 中文序列化要求:是否分词、遇到英文字母是否大小写处理、是否将英文单词拆分按照单独字母处理等。

  7. PCNN 预处理时,需要按照 head tail 的位置,将句子分为三段,做 piece wise max pooling。如果句子本身无法分为三段,就无法用统一的预处理方式处理句子。

    • 比如句子为:杭州西湖,不管怎么分隔都不能分隔为三段。

    • 原文分隔三段的方式为:[...head, ..., tail....],当然也可以分隔为:[..., head...tail, ....],或者 [...head, ...tail, ....] 或者 [..., head..., tail...] 等。具体效果没多少区别。

  8. PCNN 为什么不比 CNN 好,甚至更差??

    • 本人在跑百度的数据集,也发现 PCNN 效果并没有想象中的比 CNN 有提升,甚至大多时候都不如 CNN 那种直接 max pooling的结果。百度的 ARNOR 结果也是 PCNN 并不一定比 CNN 好。
  9. 使用语言预训练模型时,在线安装下载模型比较慢,更建议提前下载好,存放到 pretrained 文件夹内。具体存放文件要求见文件夹内的 readme.md

  10. 数据量较小时,直接使用如12层的 BERT,效果并不理想。此时可采取一些处理方式改善效果:

    • 数据量较小时层数调低些,如设置为2、3层。

    • 按照 BERT 训练方式,对新任务语料按照语言模型方式预训练。

  11. 在单句上使用 GCN 时,需要先做句法分析,构建出词语之间的邻接矩阵(句法树相邻的边值设为1,不相邻为0)。

    • 目前使用的是 pyhanlp 工具构建语法树。这个工具需要按照 java 包,具体使用见 pyhanlp 的介绍。 pyhanlp 在多句时效果也不理想,很多时候把整个单句当作一个节点。
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].