Giter Club home page Giter Club logo

deepke's Introduction

Documentation PyPI GitHub Documentation Open In Colab

English | 简体中文

A Deep Learning Based Knowledge Extraction Toolkit
for Knowledge Graph Construction

DeepKE is a knowledge extraction toolkit for knowledge graph construction supporting cnSchemalow-resource, document-level and multimodal scenarios for entity, relation and attribute extraction. We provide documents, online demo, paper, slides and poster for beginners.

If you encounter any issues during the installation of DeepKE and DeepKE-LLM, please check Tips or promptly submit an issue, and we will assist you with resolving the problem!

Table of Contents


What's New

  • April, 2024 We release a new bilingual (Chinese and English) schema-based information extraction model called OneKE based on Chinese-Alpaca-2-13B.
  • Feb, 2024 We release a large-scale (0.32B tokens) high-quality bilingual (Chinese and English) Information Extraction (IE) instruction dataset named IEPile, along with two models trained with IEPile, baichuan2-13b-iepile-lora and llama2-13b-iepile-lora.
  • Sep 2023 a bilingual Chinese English Information Extraction (IE) instruction dataset called InstructIE was released for the Instruction based Knowledge Graph Construction Task (Instruction based KGC), as detailed in here.
  • June, 2023 We update DeepKE-LLM to support knowledge extraction with KnowLM, ChatGLM, LLaMA-series, GPT-series etc.
  • Apr, 2023 We have added new models, including CP-NER(IJCAI'23), ASP(EMNLP'22), PRGC(ACL'21), PURE(NAACL'21), provided event extraction capabilities (Chinese and English), and offered compatibility with higher versions of Python packages (e.g., Transformers).
  • Feb, 2023 We have supported using LLM (GPT-3) with in-context learning (based on EasyInstruct) & data generation, added a NER model W2NER(AAAI'22).
Previous News

Prediction Demo

There is a demonstration of prediction. The GIF file is created by Terminalizer. Get the code.


Model Framework

  • DeepKE contains a unified framework for named entity recognition, relation extraction and attribute extraction, the three knowledge extraction functions.
  • Each task can be implemented in different scenarios. For example, we can achieve relation extraction in standard, low-resource (few-shot), document-level and multimodal settings.
  • Each application scenario comprises of three components: Data including Tokenizer, Preprocessor and Loader, Model including Module, Encoder and Forwarder, Core including Training, Evaluation and Prediction.

Quick Start

DeepKE-LLM

In the era of large models, DeepKE-LLM utilizes a completely new environment dependency.

conda create -n deepke-llm python=3.9
conda activate deepke-llm

cd example/llm
pip install -r requirements.txt

Please note that the requirements.txt file is located in the example/llm folder.

DeepKE

  • DeepKE supports pip install deepke.
    Take the fully supervised relation extraction for example.
  • DeepKE supports both manual and docker image environment configuration, you can choose the appropriate way to build.
  • Highly recommended to install deepke in a Linux environment.

🔧Manual Environment Configuration

Step1 Download the basic code

git clone --depth 1 https://github.com/zjunlp/DeepKE.git

Step2 Create a virtual environment using Anaconda and enter it.

conda create -n deepke python=3.8

conda activate deepke
  1. Install DeepKE with source code

    pip install -r requirements.txt
    
    python setup.py install
    
    python setup.py develop
  2. Install DeepKE with pip (NOT recommended!)

    pip install deepke

Step3 Enter the task directory

cd DeepKE/example/re/standard

Step4 Download the dataset, or follow the annotation instructions to obtain data

wget 120.27.214.45/Data/re/standard/data.tar.gz

tar -xzvf data.tar.gz

Many types of data formats are supported,and details are in each part.

Step5 Training (Parameters for training can be changed in the conf folder)

We support visual parameter tuning by using wandb.

python run.py

Step6 Prediction (Parameters for prediction can be changed in the conf folder)

Modify the path of the trained model in predict.yaml.The absolute path of the model needs to be used,such as xxx/checkpoints/2019-12-03_ 17-35-30/cnn_ epoch21.pth.

python predict.py
  • ❗NOTE: if you encounter any errors, please refer to the Tips or submit a GitHub issue.

🐳Building With Docker Images

Step1 Install the Docker client

Install Docker and start the Docker service.

Step2 Pull the docker image and run the container

docker pull zjunlp/deepke:latest
docker run -it zjunlp/deepke:latest /bin/bash

The remaining steps are the same as Step 3 and onwards in Manual Environment Configuration.

  • ❗NOTE: You can refer to the Tips to speed up installation

Requirements

DeepKE

python == 3.8

  • torch>=1.5,<=1.11
  • hydra-core==1.0.6
  • tensorboard==2.4.1
  • matplotlib==3.4.1
  • transformers==4.26.0
  • jieba==0.42.1
  • scikit-learn==0.24.1
  • seqeval==1.2.2
  • opt-einsum==3.3.0
  • wandb==0.12.7
  • ujson==5.6.0
  • huggingface_hub==0.11.0
  • tensorboardX==2.5.1
  • nltk==3.8
  • protobuf==3.20.1
  • numpy==1.21.0
  • ipdb==0.13.11
  • pytorch-crf==0.7.2
  • tqdm==4.66.1
  • openai==0.28.0
  • Jinja2==3.1.2
  • datasets==2.13.2
  • pyhocon==0.3.60

Introduction of Three Functions

1. Named Entity Recognition

  • Named entity recognition seeks to locate and classify named entities mentioned in unstructured text into pre-defined categories such as person names, organizations, locations, organizations, etc.

  • The data is stored in .txt files. Some instances as following (Users can label data based on the tools Doccano, MarkTool, or they can use the Weak Supervision with DeepKE to obtain data automatically):

    Sentence Person Location Organization
    本报北京9月4日讯记者杨涌报道:部分省区人民日报宣传发行工作座谈会9月3日在4日在京举行。 杨涌 北京 人民日报
    《红楼梦》由王扶林导演,周汝昌、王蒙、周岭等多位专家参与制作。 王扶林,周汝昌,王蒙,周岭
    秦始皇兵马俑位于陕西省西安市,是世界八大奇迹之一。 秦始皇 陕西省,西安市
  • Read the detailed process in specific README

    • STANDARD (Fully Supervised)

      We support LLM and provide the off-the-shelf model, DeepKE-cnSchema-NER, which will extract entities in cnSchema without training.

      Step1 Enter DeepKE/example/ner/standard. Download the dataset.

      wget 120.27.214.45/Data/ner/standard/data.tar.gz
      
      tar -xzvf data.tar.gz

      Step2 Training

      The dataset and parameters can be customized in the data folder and conf folder respectively.

      python run.py

      Step3 Prediction

      python predict.py
    • FEW-SHOT

      Step1 Enter DeepKE/example/ner/few-shot. Download the dataset.

      wget 120.27.214.45/Data/ner/few_shot/data.tar.gz
      
      tar -xzvf data.tar.gz

      Step2 Training in the low-resouce setting

      The directory where the model is loaded and saved and the configuration parameters can be cusomized in the conf folder.

      python run.py +train=few_shot

      Users can modify load_path in conf/train/few_shot.yaml to use existing loaded model.

      Step3 Add - predict to conf/config.yaml, modify loda_path as the model path and write_path as the path where the predicted results are saved in conf/predict.yaml, and then run python predict.py

      python predict.py
    • MULTIMODAL

      Step1 Enter DeepKE/example/ner/multimodal. Download the dataset.

      wget 120.27.214.45/Data/ner/multimodal/data.tar.gz
      
      tar -xzvf data.tar.gz

      We use RCNN detected objects and visual grounding objects from original images as visual local information, where RCNN via faster_rcnn and visual grounding via onestage_grounding.

      Step2 Training in the multimodal setting

      • The dataset and parameters can be customized in the data folder and conf folder respectively.
      • Start with the model trained last time: modify load_path in conf/train.yamlas the path where the model trained last time was saved. And the path saving logs generated in training can be customized by log_dir.
      python run.py

      Step3 Prediction

      python predict.py

2. Relation Extraction

  • Relationship extraction is the task of extracting semantic relations between entities from a unstructured text.

  • The data is stored in .csv files. Some instances as following (Users can label data based on the tools Doccano, MarkTool, or they can use the Weak Supervision with DeepKE to obtain data automatically):

    Sentence Relation Head Head_offset Tail Tail_offset
    《岳父也是爹》是王军执导的电视剧,由马恩然、范明主演。 导演 岳父也是爹 1 王军 8
    《九玄珠》是在纵横中文网连载的一部小说,作者是龙马。 连载网站 九玄珠 1 纵横中文网 7
    提起杭州的美景,西湖总是第一个映入脑海的词语。 所在城市 西湖 8 杭州 2
  • !NOTE: If there are multiple entity types for one relation, entity types can be prefixed with the relation as inputs.

  • Read the detailed process in specific README

    • STANDARD (Fully Supervised)

      We support LLM and provide the off-the-shelf model, DeepKE-cnSchema-RE, which will extract relations in cnSchema without training.

      Step1 Enter the DeepKE/example/re/standard folder. Download the dataset.

      wget 120.27.214.45/Data/re/standard/data.tar.gz
      
      tar -xzvf data.tar.gz

      Step2 Training

      The dataset and parameters can be customized in the data folder and conf folder respectively.

      python run.py

      Step3 Prediction

      python predict.py
    • FEW-SHOT

      Step1 Enter DeepKE/example/re/few-shot. Download the dataset.

      wget 120.27.214.45/Data/re/few_shot/data.tar.gz
      
      tar -xzvf data.tar.gz

      Step 2 Training

      • The dataset and parameters can be customized in the data folder and conf folder respectively.
      • Start with the model trained last time: modify train_from_saved_model in conf/train.yamlas the path where the model trained last time was saved. And the path saving logs generated in training can be customized by log_dir.
      python run.py

      Step3 Prediction

      python predict.py
    • DOCUMENT

      Step1 Enter DeepKE/example/re/document. Download the dataset.

      wget 120.27.214.45/Data/re/document/data.tar.gz
      
      tar -xzvf data.tar.gz

      Step2 Training

      • The dataset and parameters can be customized in the data folder and conf folder respectively.
      • Start with the model trained last time: modify train_from_saved_model in conf/train.yamlas the path where the model trained last time was saved. And the path saving logs generated in training can be customized by log_dir.
      python run.py

      Step3 Prediction

      python predict.py
    • MULTIMODAL

      Step1 Enter DeepKE/example/re/multimodal. Download the dataset.

      wget 120.27.214.45/Data/re/multimodal/data.tar.gz
      
      tar -xzvf data.tar.gz

      We use RCNN detected objects and visual grounding objects from original images as visual local information, where RCNN via faster_rcnn and visual grounding via onestage_grounding.

      Step2 Training

      • The dataset and parameters can be customized in the data folder and conf folder respectively.
      • Start with the model trained last time: modify load_path in conf/train.yamlas the path where the model trained last time was saved. And the path saving logs generated in training can be customized by log_dir.
      python run.py

      Step3 Prediction

      python predict.py

3. Attribute Extraction

  • Attribute extraction is to extract attributes for entities in a unstructed text.

  • The data is stored in .csv files. Some instances as following:

    Sentence Att Ent Ent_offset Val Val_offset
    张冬梅,女,汉族,1968年2月生,河南淇县人 民族 张冬梅 0 汉族 6
    诸葛亮,字孔明,三国时期杰出的军事家、文学家、发明家。 朝代 诸葛亮 0 三国时期 8
    2014年10月1日许鞍华执导的电影《黄金时代》上映 上映时间 黄金时代 19 2014年10月1日 0
  • Read the detailed process in specific README

    • STANDARD (Fully Supervised)

      Step1 Enter the DeepKE/example/ae/standard folder. Download the dataset.

      wget 120.27.214.45/Data/ae/standard/data.tar.gz
      
      tar -xzvf data.tar.gz

      Step2 Training

      The dataset and parameters can be customized in the data folder and conf folder respectively.

      python run.py

      Step3 Prediction

      python predict.py

4. Event Extraction

  • Event extraction is the task to extract event type, event trigger words, event arguments from a unstructed text.
  • The data is stored in .tsv files, some instances are as follows:
Sentence Event type Trigger Role Argument
据《欧洲时报》报道,当地时间27日,法国巴黎卢浮宫博物馆员工因不满工作条件恶化而罢工,导致该博物馆也因此闭门谢客一天。 组织行为-罢工 罢工 罢工人员 法国巴黎卢浮宫博物馆员工
时间 当地时间27日
所属组织 法国巴黎卢浮宫博物馆
**外运2019年上半年归母净利润增长17%:收购了少数股东股权 财经/交易-出售/收购 收购 出售方 少数股东
收购方 **外运
交易物 股权
美国亚特兰大航展13日发生一起表演机坠机事故,飞行员弹射出舱并安全着陆,事故没有造成人员伤亡。 灾害/意外-坠机 坠机 时间 13日
地点 美国亚特兰
  • Read the detailed process in specific README

    • STANDARD(Fully Supervised)

      Step1 Enter the DeepKE/example/ee/standard folder. Download the dataset.

      wget 120.27.214.45/Data/ee/DuEE.zip
      unzip DuEE.zip

      Step 2 Training

      The dataset and parameters can be customized in the data folder and conf folder respectively.

      python run.py

      Step 3 Prediction

      python predict.py

Tips

1.Using nearest mirror, THU in China, will speed up the installation of Anaconda; aliyun in China, will speed up pip install XXX.

2.When encountering ModuleNotFoundError: No module named 'past',run pip install future .

3.It's slow to install the pretrained language models online. Recommend download pretrained models before use and save them in the pretrained folder. Read README.md in every task directory to check the specific requirement for saving pretrained models.

4.The old version of DeepKE is in the deepke-v1.0 branch. Users can change the branch to use the old version. The old version has been totally transfered to the standard relation extraction (example/re/standard).

5.If you want to modify the source code, it's recommended to install DeepKE with source codes. If not, the modification will not work. See issue

6.More related low-resource knowledge extraction works can be found in Knowledge Extraction in Low-Resource Scenarios: Survey and Perspective.

7.Make sure the exact versions of requirements in requirements.txt.

To do

In next version, we plan to release a stronger LLM for KE.

Meanwhile, we will offer long-term maintenance to fix bugs, solve issues and meet new requests. So if you have any problems, please put issues to us.

Reading Materials

Data-Efficient Knowledge Graph Construction, 高效知识图谱构建 (Tutorial on CCKS 2022) [slides]

Efficient and Robust Knowledge Graph Construction (Tutorial on AACL-IJCNLP 2022) [slides]

PromptKG Family: a Gallery of Prompt Learning & KG-related Research Works, Toolkits, and Paper-list [Resources]

Knowledge Extraction in Low-Resource Scenarios: Survey and Perspective [Survey][Paper-list]

Related Toolkit

DoccanoMarkToolLabelStudio: Data Annotation Toolkits

LambdaKG: A library and benchmark for PLM-based KG embeddings

EasyInstruct: An easy-to-use framework to instruct Large Language Models

Reading Materials:

Data-Efficient Knowledge Graph Construction, 高效知识图谱构建 (Tutorial on CCKS 2022) [slides]

Efficient and Robust Knowledge Graph Construction (Tutorial on AACL-IJCNLP 2022) [slides]

PromptKG Family: a Gallery of Prompt Learning & KG-related Research Works, Toolkits, and Paper-list [Resources]

Knowledge Extraction in Low-Resource Scenarios: Survey and Perspective [Survey][Paper-list]

Related Toolkit:

DoccanoMarkToolLabelStudio: Data Annotation Toolkits

LambdaKG: A library and benchmark for PLM-based KG embeddings

EasyInstruct: An easy-to-use framework to instruct Large Language Models

Citation

Please cite our paper if you use DeepKE in your work

@inproceedings{EMNLP2022_Demo_DeepKE,
  author    = {Ningyu Zhang and
               Xin Xu and
               Liankuan Tao and
               Haiyang Yu and
               Hongbin Ye and
               Shuofei Qiao and
               Xin Xie and
               Xiang Chen and
               Zhoubo Li and
               Lei Li},
  editor    = {Wanxiang Che and
               Ekaterina Shutova},
  title     = {DeepKE: {A} Deep Learning Based Knowledge Extraction Toolkit for Knowledge Base Population},
  booktitle = {{EMNLP} (Demos)},
  pages     = {98--108},
  publisher = {Association for Computational Linguistics},
  year      = {2022},
  url       = {https://aclanthology.org/2022.emnlp-demos.10}
}

Contributors

Ningyu Zhang, Haofen Wang, Fei Huang, Feiyu Xiong, Liankuan Tao, Xin Xu, Honghao Gui, Zhenru Zhang, Chuanqi Tan, Qiang Chen, Xiaohan Wang, Zekun Xi, Xinrong Li, Haiyang Yu, Hongbin Ye, Shuofei Qiao, Peng Wang, Yuqi Zhu, Xin Xie, Xiang Chen, Zhoubo Li, Lei Li, Xiaozhuan Liang, Yunzhi Yao, Jing Chen, Yuqi Zhu, Shumin Deng, Wen Zhang, Guozhou Zheng, Huajun Chen

Community Contributors: thredreams, eltociear, Ziwen Xu, Rui Huang, Xiaolong Weng

Other Knowledge Extraction Open-Source Projects

deepke's People

Contributors

231sm avatar alexzhuan avatar beasteryong avatar eltociear avatar flow3rdown avatar gooodte avatar guihonghao avatar hrhrhrhr666 avatar huajunsir avatar hunxuewangzi avatar lesilez avatar litmirror123 avatar mikedean2367 avatar njcx-ai avatar oe-heart avatar pengzju avatar rolnand avatar shengyumao avatar timelordri avatar tlk1997 avatar tubg avatar wangxh-07 avatar xeekee avatar xxupiano avatar xzwyyd avatar yuwl798180 avatar zxlzr 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  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

deepke's Issues

关于预测

你好~如果是想通过输入句子,然后输出类似{实体A,实体B,关系}的话, 是否需要在相应的模型中加入predict的代码?然后通过model.load_state_dict(torch.load('./checkpoints/xx.pth')),然后再去用model.predict()来输出结果?

在windows上跑CNN模型出现以下错误

Traceback (most recent call last):
File "main.py", line 83, in
model_name = model.save(epoch=epoch)
File "C:\Users\asus\Desktop\deepke\deepke\model\BasicModule.py", line 33, in save
torch.save(self.state_dict(), name)
File "D:\Python3.6.4\lib\site-packages\torch\serialization.py", line 224, in save
return _with_file_like(f, "wb", lambda f: _save(obj, f, pickle_module, pickle_protocol))
File "D:\Python3.6.4\lib\site-packages\torch\serialization.py", line 147, in _with_file_like
f = open(f, mode)
OSError: [Errno 22] Invalid argument: 'checkpoints/CNN_epoch1_1107_19:31:57.pth'

问题麻烦解答(运行GCN和LM报错)

运行GCN报错
========== Start training ========== Traceback (most recent call last): File "main.py", line 81, in <module> train(epoch, device, train_dataloader, model, optimizer, criterion, config) File "/home/mere/deepke/deepke/trainer.py", line 16, in train y_pred = model(x) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 541, in __call__ result = self.forward(*input, **kwargs) File "/home/mere/deepke/deepke/model/GCN.py", line 32, in forward x = self.embedding(x) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 541, in __call__ result = self.forward(*input, **kwargs) File "/home/mere/deepke/deepke/model/Embedding.py", line 13, in forward words, head_pos, tail_pos = x ValueError: not enough values to unpack (expected 3, got 2)
1

运行LM报错
========== Start training ========== Traceback (most recent call last): File "main.py", line 81, in <module> train(epoch, device, train_dataloader, model, optimizer, criterion, config) File "/home/mere/deepke/deepke/trainer.py", line 16, in train y_pred = model(x) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 541, in __call__ result = self.forward(*input, **kwargs) File "/home/mere/deepke/deepke/model/LM.py", line 19, in forward out = self.fc(out) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 541, in __call__ result = self.forward(*input, **kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/linear.py", line 87, in forward return F.linear(input, self.weight, self.bias) File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 1370, in linear ret = torch.addmm(bias, input, weight.t()) RuntimeError: size mismatch, m1: [64 x 1024], m2: [768 x 10] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:197
2

胶囊网络碰到一些问题

你好,想请教一下一个问题:
当我用胶囊网络的时候,我发现损失在不断的下降,但是,精度却在不断的降低?这让我很疑惑。
========== Start training ==========
Train Epoch: 1 [640/4000 (16%)] Loss: 0.808406
Train Epoch: 1 [1280/4000 (32%)] Loss: 0.807249
Train Epoch: 1 [1920/4000 (48%)] Loss: 0.805759
Train Epoch: 1 [2560/4000 (63%)] Loss: 0.803572
Train Epoch: 1 [3200/4000 (79%)] Loss: 0.800597
Train Epoch: 1 [3840/4000 (95%)] Loss: 0.796495
Train Epoch: 1 [4000/4000 (100%)] Loss: 0.795066
macro metrics: [p: 0.4085, r:0.2570, f1:0.2254]
micro metrics: [p: 0.2570, r:0.2570, f1:0.2570]
Train Epoch: 2 [640/4000 (16%)] Loss: 0.789447
Train Epoch: 2 [1280/4000 (32%)] Loss: 0.782183
Train Epoch: 2 [1920/4000 (48%)] Loss: 0.773557
Train Epoch: 2 [2560/4000 (63%)] Loss: 0.762742
Train Epoch: 2 [3200/4000 (79%)] Loss: 0.750204
Train Epoch: 2 [3840/4000 (95%)] Loss: 0.735720
Train Epoch: 2 [4000/4000 (100%)] Loss: 0.731115
macro metrics: [p: 0.1102, r:0.1210, f1:0.0532]
micro metrics: [p: 0.1210, r:0.1210, f1:0.1210]
Train Epoch: 3 [640/4000 (16%)] Loss: 0.714159
Train Epoch: 3 [1280/4000 (32%)] Loss: 0.695173
Train Epoch: 3 [1920/4000 (48%)] Loss: 0.674588
Train Epoch: 3 [2560/4000 (63%)] Loss: 0.652236
Train Epoch: 3 [3200/4000 (79%)] Loss: 0.628999
Train Epoch: 3 [3840/4000 (95%)] Loss: 0.607024
Train Epoch: 3 [4000/4000 (100%)] Loss: 0.601029
macro metrics: [p: 0.0100, r:0.1000, f1:0.0182]
micro metrics: [p: 0.1000, r:0.1000, f1:0.1000]
Train Epoch: 4 [640/4000 (16%)] Loss: 0.581706
Train Epoch: 4 [1280/4000 (32%)] Loss: 0.566093
Train Epoch: 4 [1920/4000 (48%)] Loss: 0.553648
Train Epoch: 4 [2560/4000 (63%)] Loss: 0.543705
Train Epoch: 4 [3200/4000 (79%)] Loss: 0.536618
这是什么情况呢?

多显卡训练问题

您好,我在使用多个显卡训练的时候开始出现报错,但之前使用单显卡的时候没有报错。
我只在main.py中添加了语句model = nn.DataParallel(model),训练的模型是transformer。
报错信息如下:
Traceback (most recent call last):
File "main.py", line 144, in
main()
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/hydra/main.py", line 24, in decorated_main
strict=strict,
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/hydra/_internal/utils.py", line 174, in run_hydra
overrides=args.overrides,
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/hydra/_internal/hydra.py", line 86, in run
job_subdir_key=None,
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/hydra/plugins/common/utils.py", line 109, in run_job
ret.return_value = task_function(task_cfg)
File "main.py", line 93, in main
train_loss = train(epoch, model, train_dataloader, optimizer, criterion, device, writer, cfg)
File "/root/joi/deepke/trainer.py", line 21, in train
y_pred = model(x)
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 152, in forward
outputs = self.parallel_apply(replicas, inputs, kwargs)
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 162, in parallel_apply
return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)])
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/parallel/parallel_apply.py", line 83, in parallel_apply
raise output
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/parallel/parallel_apply.py", line 59, in worker
output = module(*input, **kwargs)
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/root/joi/deepke/models/Transformer.py", line 25, in forward
last_layer_hidden_state, all_hidden_states, all_attentions = self.transformer(inputs, key_padding_mask=mask)
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/root/joi/deepke/module/Transformer.py", line 134, in forward
layer_outputs = layer_module(hidden_states, key_padding_mask, attention_mask, head_mask[i])
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/root/joi/deepke/module/Transformer.py", line 97, in forward
attention_outputs = self.attention(hidden_states, key_padding_mask, attention_mask, head_mask)
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/root/joi/deepke/module/Transformer.py", line 55, in forward
attention_outputs = self.multihead_attention(x, x, x, key_padding_mask, attention_mask, head_mask)
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/root/joi/deepke/module/Attention.py", line 114, in forward
attention_out, attention_weight = self.attention(q, k, v, mask_out=mask_out, head_mask=head_mask)
File "/root/anaconda3/envs/NER/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/root/joi/deepke/module/Attention.py", line 38, in forward
attention_weight.masked_fill
(mask_out, -1e8)
RuntimeError: The expanded size of the tensor (270) must match the existing size (96) at non-singleton dimension 3. Target sizes: [1, 4, 270, 270]. Tensor sizes: [1, 1, 1, 96]

关于自己标注数据集

你好,请问demo内使用的数据集中各个字段详细的含义或者如何标注的能否简单告知吗,我想针对某一个领域自己标注数据集,但是不太理解demo使用的数据字段的含义,比如tail_offset,head_offset

bert

你好,麻烦更新GCN部分的问题哦,感谢

请问cnn代码中的mask的作用是?

mask

我想问一下在module中的cnn源码里面的mask是作为工程功能吗?因为我在读论文的时候并没有发现类似mask之类的操作

#param mask: [batch_size, max_len], 句长部分为0,padding部分为1。不影响卷积运算,max-pool一定不会pool到pad为0的位置

上面为mask在源码的注释,并不是看的很懂,只是理解为工程中的一个trick,可否帮忙解释一下?谢谢了

代码复现问题

您好!我在学习您的deepke源代码,并试图复现相关实验,但是在使用Bert的时候(model=lm),一直报无法找到预训练模型的错误,错误代码为:Model name '/deepke-master/deepke-master/pretrained' was not found in tokenizers model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese, bert-base-german-cased, bert-large-uncased-whole-word-masking, bert-large-cased-whole-word-masking, bert-large-uncased-whole-word-masking-finetuned-squad, bert-large-cased-whole-word-masking-finetuned-squad, bert-base-cased-finetuned-mrpc, bert-base-german-dbmdz-cased, bert-base-german-dbmdz-uncased, bert-base-finnish-cased-v1, bert-base-finnish-uncased-v1, bert-base-dutch-cased). We assumed '/deepke-master/deepke-master/pretrained' was a path, a model identifier, or url to a directory containing vocabulary files named ['vocab.txt'] but couldn't find such vocabulary files at this path or url.
但是我是严格按照readme中的要求,下载了完整的bert模型(pytorch版)并放置在pretrained文件夹内,不知是何错误?
还有一个小问题,源代码中在predict里运行后有“实体类型”输入这一选项,但给出的train data格式中并没有“实体类型”,是否意味着我可以在训练数据中自行添加“实体类型”的训练特征,而后的预测也可以因此提高精确度?
请批评指正!望不吝赐教!谢谢!
bug

dev branch下predict文件中的serializer

你好,我目前在尝试改写predict部分的代码,看到predict.py中引入了一个serializer库,pip安装之后无法导入,并且看到有一些比较个性化的参数,想问一下这个库是哪里来的?

Does this tool support NER?

Describe the question

A clear and concise description of what the question is.

Environment (please complete the following information):

  • OS: [e.g. mac / window]
  • Python Version [e.g. 3.6]

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

请问,要做一个接口的话,应该怎么传入数据到predict中呢?

Describe the question

A clear and concise description of what the question is.
您好,如果我想做一个接口用于测试的话,应该怎么应用呢?因为对hydra不熟,麻烦大神指点指点!

Environment (please complete the following information):

  • OS: [e.g. mac / window]
  • Python Version [e.g. 3.6]

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

如果待识别的是问句呢?

如果待抽取的句子是一个问句,比如"姚明的老婆是谁?",此时是否支持抽取出 实体 “姚明” ,还有 关系属性 “老婆”?

KeyError

您好,您项目中所给数据顺利跑通。但换成自己的数据时,疯狂报KeyError,每一个字段都曾报过,最后一个KeyError: 'index'实在是解决不了了。数据格式与您要求的一样。报错信息如下Traceback (most recent call last):
File "main.py", line 140, in
main()
File "/home/wgh/anaconda3/envs/pytorch/lib/python3.6/site-packages/hydra/main.py", line 24, in decorated_main
strict=strict,
File "/home/wgh/anaconda3/envs/pytorch/lib/python3.6/site-packages/hydra/_internal/utils.py", line 174, in run_hydra
overrides=args.overrides,
File "/home/wgh/anaconda3/envs/pytorch/lib/python3.6/site-packages/hydra/_internal/hydra.py", line 86, in run
job_subdir_key=None,
File "/home/wgh/anaconda3/envs/pytorch/lib/python3.6/site-packages/hydra/plugins/common/utils.py", line 109, in run_job
ret.return_value = task_function(task_cfg)
File "main.py", line 46, in main
preprocess(cfg)
File "/home/wgh/deepke/preprocess.py", line 116, in preprocess
rels = _handle_relation_data(relation_data)
File "/home/wgh/deepke/preprocess.py", line 90, in _handle_relation_data
relation_data = sorted(relation_data, key=lambda i: int(i['index']))
File "/home/wgh/deepke/preprocess.py", line 90, in
relation_data = sorted(relation_data, key=lambda i: int(i['index']))
KeyError: 'index'

没有负样本在做预测的时候怎么处理

比如说【张小明上高中的时候经常去浙江大学玩】这种先不考虑容易误分到【毕业学校】,只能设置argmax的阈值去处理吗。是因为没有负样本的语料吗,

数据标注

你好,想请问一下你们的训练数据是怎样生成的,是用软件标注的么,还是人工整理的,因为我想做其它领域的关系抽取研究。

Environment (please complete the following information):

  • OS: [e.g. mac / window]
  • Python Version [e.g. 3.6]

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

执行安装报错了

CNdeepdive$ sudo bash install.sh
DeepDive installer for Ubuntu
curl: (7) Failed to connect to raw.githubusercontent.com port 443: 连接超时

模型效果

你好,结果跑出来bert模型的结果比CNN还要差,请问正常吗

Bug in run main.py

Describe the bug

A clear and concise description of what the bug is.
When running the main.py in Colab, I met a error: can't import utils in "from hydra import utils". And I tried to comment the the code "from hydra import utils", the next error---"module 'hydra' has no attribute 'main'" in line 29, which is " @hydra.main(config_path='conf/config.yaml')"

Environment (please complete the following information):

  • OS: [e.g. mac / window]
  • Python Version [e.g. 3.6]

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

我想用自己的数据训练模板,出现错误了

你好,你知道这个是什么错误吗?
Traceback (most recent call last):
File "main.py", line 140, in
main()
File "/root/miniconda3/envs/openNRE/lib/python3.7/site-packages/hydra/main.py", line 24, in decorated_main
strict=strict,
File "/root/miniconda3/envs/openNRE/lib/python3.7/site-packages/hydra/_internal/utils.py", line 174, in run_hydra
overrides=args.overrides,
File "/root/miniconda3/envs/openNRE/lib/python3.7/site-packages/hydra/_internal/hydra.py", line 86, in run
job_subdir_key=None,
File "/root/miniconda3/envs/openNRE/lib/python3.7/site-packages/hydra/plugins/common/utils.py", line 109, in run_job
ret.return_value = task_function(task_cfg)
File "main.py", line 46, in main
preprocess(cfg)
File "/root/deepke/deepke/preprocess.py", line 131, in preprocess
_serialize_sentence(train_data, serial, cfg)
File "/root/deepke/deepke/preprocess.py", line 55, in _serialize_sentence
head_idx, tail_idx = d['tokens'].index('head'), d['tokens'].index('tail')
ValueError: 'tail' is not in list

直接运行显示错误

Describe the bug

直接运行显示错误

Environment (please complete the following information):

  • OS:windows
  • Python 3.7

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

if torch.cuda.CUDA_ENABLED and use_deterministic_cudnn:
  torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

错误信息

if torch.cuda.CUDA_ENABLED and use_deterministic_cudnn:
AttributeError: module 'torch.cuda' has no attribute 'CUDA_ENABLED'

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

BERT在大规模数据集上运行报错

你好,我重构了百度的数据集,重构后大概又30多w条。其中某些数据在其他模型预处理的时候会报错,但舍弃这些数据后最终跑通了,但是BERT模型遇到了如下问题,看上去应该是维度不太匹配,想请教一下问题可能会出在哪里,谢谢
>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2, IndexIsMajor = true]: block: [195,0,0], thread: [31,0,0] AssertionsrcIndex < srcSelectDimSize failed. Traceback (most recent call last): File "main.py", line 82, in <module> macro_f1, micro_f1 = validate(test_dataloader, model, device, config) File "/home/***/deepke/deepke/trainer.py", line 53, in validate x = [i.to(device) for i in x] File "/home/***/deepke/deepke/trainer.py", line 53, in <listcomp> x = [i.to(device) for i in x] RuntimeError: CUDA error: device-side assert triggered

KeyError问题

你好,在data中添加了自己的数据集,运行main.py报KeyError 是为什么呢?
是需要在哪个词典添加吗?

model choose

Describe the question

A clear and concise description of what the question is.
我想对比CNN\PCNN\GCN\Transform等模型在自己标注的数据上的准确性,请问代码应该在哪里修改一下代码,谢谢,请问此外模型是否可以输出不同关系的分类准确率、召回率,即导演、国籍、祖籍等类别。

Environment (please complete the following information):

  • OS: [e.g. mac / window]
  • Python Version [e.g. 3.6]

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

tutorial-notebooks lm模型小bug

Describe the bug

A clear and concise description of what the bug is.

output,pooler_output = self.lm (word)
image

Environment (please complete the following information):

  • OS: [ window]
  • Python Version [3.7]
  • torch 1.7.1

Additional context
讲道理会自动匹配元组,但是没有,只返回了字符串,如下
image

您好,请问bert模型为什么没有了,模型里面没找到bert

Describe the question

A clear and concise description of what the question is.

Environment (please complete the following information):

  • OS: [e.g. mac / window]
  • Python Version [e.g. 3.6]

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

请问GCN中如何得到句法依存树?

您好,在对模型进行训练时,我发现GCN的效果显著低于其他几个模型,查阅代码后在GCN.py中,并没有找到代码关于pyhanlp的相关调用,请问这里是如何通过句法分析构建出词语之间的邻接矩阵来进行关系抽取的呢?如果要添加pyhanlp来做的话,请问应该怎么操作?

你好,我在百度的数据集上运行,出现如下错误,能麻烦您帮我看一下吗

========= Start training ==========
Traceback (most recent call last):
File "main.py", line 83, in
train(epoch, device, train_dataloader, model, optimizer, criterion, config)
File "/home/mere/deepke/deepke/trainer.py", line 12, in train
for batch_idx, (*x, y) in enumerate(dataloader, 1):
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 346, in next
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
return self.collate_fn(data)
File "/home/mere/deepke/deepke/dataset.py", line 20, in collate_fn
batch.sort(key=lambda data: data['seq_len'], reverse=True)
File "/home/mere/deepke/deepke/dataset.py", line 20, in
batch.sort(key=lambda data: data['seq_len'], reverse=True)
KeyError: 'seq_len'

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.