• Stars
    star
    345
  • Rank 122,014 (Top 3 %)
  • Language
    Python
  • Created over 5 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Multiple-Relations-Extraction-Only-Look-Once. Just look at the sentence once and extract the multiple pairs of entities and their corresponding relations. 端到端联合多关系抽取模型,可用于 http://lic2019.ccf.org.cn/kg 信息抽取。

Multiple-Relations-Extraction-Only-Look-Once

Multiple-Relations-Extraction-Only-Look-Once. Just look at the sentence once and extract the multiple pairs of entities and their corresponding relations. 只用看一次,抽取所有的实体及其对应的所有关系。

input "text": "《逐风行》是百度文学旗下纵横中文网签约作家清水秋风创作的一部东方玄幻小说,小说已于2014-04-28正式发布"

output

"spo_list": [{"predicate": "连载网站", "object_type": "网站", "subject_type": "网络小说", "object": "纵横中文网", "subject": "逐风行"}, {"predicate": "作者", "object_type": "人物", "subject_type": "图书作品", "object": "清水秋风", "subject": "逐风行"}]

Main principle

The entity extraction task is converted into a sequence annotation task, and the multi-relationship extraction task is converted into a multi-head selection task. The token will be sent to the model, and the model will predict the output label, predicate value, and predicate location. Using the bin/read_standard_format_data.py file, the original game data format can be converted into the data format required for the multi-head selection model, as follows:

把实体抽取任务转换成序列标注任务,把多关系抽取任务转换成多头选择任务。token会被送入模型,模型会预测输出label、predicate value 和 predicate location。使用bin/read_standard_format_data.py文件可以把原始比赛数据格式转换成多头选择模型所需数据格式,如下所示:

+-------+-------+------------+----------------------+--------------------+
| index | token |   label    |   predicate value    | predicate location |
+-------+-------+------------+----------------------+--------------------+
|   0   |   《  |     O      |        ['N']         |        [0]         |
|   1   |   逐  | B-图书作品  | ['连载网站', '作者']  |      [12, 21]      |
|   2   |   风  | I-图书作品  |        ['N']         |        [2]         |
|   3   |   行  | I-图书作品  |        ['N']         |        [3]         |
|   4   |   》  |     O      |        ['N']         |        [4]         |
|   5   |   是  |     O      |        ['N']         |        [5]         |
|   6   |   百  |     O      |        ['N']         |        [6]         |
|   7   |   度  |     O      |        ['N']         |        [7]         |
|   8   |   文  |     O      |        ['N']         |        [8]         |
|   9   |   学  |     O      |        ['N']         |        [9]         |
|   10  |   旗  |     O      |        ['N']         |        [10]        |
|   11  |   下  |     O      |        ['N']         |        [11]        |
|   12  |   纵  |   B-网站   |        ['N']         |        [12]        |
|   13  |   横  |   I-网站   |        ['N']         |        [13]        |
|   14  |   中  |   I-网站   |        ['N']         |        [14]        |
|   15  |   文  |   I-网站   |        ['N']         |        [15]        |
|   16  |   网  |   I-网站   |        ['N']         |        [16]        |
|   17  |   签  |     O      |        ['N']         |        [17]        |
|   18  |   约  |     O      |        ['N']         |        [18]        |
|   19  |   作  |     O      |        ['N']         |        [19]        |
|   20  |   家  |     O      |        ['N']         |        [20]        |
|   21  |   清  |   B-人物   |        ['N']         |        [21]        |
|   22  |   水  |   I-人物   |        ['N']         |        [22]        |
|   23  |   秋  |   I-人物   |        ['N']         |        [23]        |
|   24  |   风  |   I-人物   |        ['N']         |        [24]        |
|   25  |   创  |     O      |        ['N']         |        [25]        |
...
+-------+-------+------------+----------------------+--------------------+

See my blog for more details

Document description

name description
bert The feature extractor of the model, where BERT is used as the feature extractor for the model. It can be replaced with other feature extractors, such as BiLSTM and CNN.
bin/data_manager.py Prepare formatted data for the mode.
bin/integrated_model_output.py Organize the output of model prediction into standard data format.
bin/read_standard_format_data.py View formatted data.
bin/test_head_select_scores.py One method for solving the relationship extraction problem: the multi-head selection method.
experimental_loss_function run_multiple_relations_extraction_XXX.py, File under experiment.
raw_data
produce_submit_json_file.py Generate entity relationship triples and write them to JSON files.
run_multiple_relations_extraction.py The most basic model for model training and prediction.

Need Your Help!

Problem code location

run_multiple_relations_extraction.py 531~549 lines!

You can try different experiments (experimental_loss_function/run_multiple_relations_extraction_XXX.py) and share your results.

Use example

2019语言与智能技术竞赛

竞赛任务

给定schema约束集合及句子sent,其中schema定义了关系P以及其对应的主体S和客体O的类别,例如(S_TYPE:人物,P:妻子,O_TYPE:人物)、(S_TYPE:公司,P:创始人,O_TYPE:人物)等。 任务要求参评系统自动地对句子进行分析,输出句子中所有满足schema约束的SPO三元组知识Triples=[(S1, P1, O1), (S2, P2, O2)…]。 输入/输出: (1) 输入:schema约束集合及句子sent (2) 输出:句子sent中包含的符合给定schema约束的三元组知识Triples

例子 输入句子: "text": "《古世》是连载于云中书城的网络小说,作者是未弱"

输出三元组: "spo_list": [{"predicate": "作者", "object_type": "人物", "subject_type": "图书作品", "object": "未弱", "subject": "古世"}, {"predicate": "连载网站", "object_type": "网站", "subject_type": "网络小说", "object": "云中书城", "subject": "古世"}]}

数据简介

本次竞赛使用的SKE数据集是业界规模最大的基于schema的中文信息抽取数据集,其包含超过43万三元组数据、21万中文句子及50个已定义好的schema,表1中展示了SKE数据集中包含的50个schema及对应的例子。数据集中的句子来自百度百科和百度信息流文本。数据集划分为17万训练集,2万验证集和2万测试集。其中训练集和验证集用于训练,可供自由下载,测试集分为两个,测试集1供参赛者在平台上自主验证,测试集2在比赛结束前一周发布,不能在平台上自主验证,并将作为最终的评测排名。

Getting Started

Environment Requirements

  • python 3.6+
  • Tensorflow 1.12.0+

Step 1: Environmental preparation

  • Install Tensorflow
  • Dowload bert-base, chinese, unzip file and put it in pretrained_model floader.

Step 2: Download the training data, dev data and schema files

Please download the training data, development data and schema files from the competition website, then unzip files and put them in ./raw_data/ folder.

cd data
unzip train_data.json.zip 
unzip dev_data.json.zip
cd -

此处不再提供2019语言与智能技术竞赛_信息抽取原始数据下载,如有疑问可以联系我的邮箱 [email protected]

There is no longer a raw data download, if you have any questions, you can contact my mailbox [email protected]

Step3: Data preprocessing

python bin/data_manager.py

It is currently recommended to use the run_multiple_relations_extraction_MSE_loss.py file instead of the run_multiple_relations_extraction.py file for model and forecasting!

Step4: Model training

Run_multiple_relations_extraction_mask_loss.py is recommended.

python run_multiple_relations_extraction.py \
--task_name=SKE_2019 \
--do_train=true \
--do_eval=false \
--data_dir=bin/standard_format_data \
--vocab_file=pretrained_model/chinese_L-12_H-768_A-12/vocab.txt \
--bert_config_file=pretrained_model/chinese_L-12_H-768_A-12/bert_config.json \
--init_checkpoint=pretrained_model/chinese_L-12_H-768_A-12/bert_model.ckpt \
--max_seq_length=128 \
--train_batch_size=32 \
--learning_rate=2e-5 \
--num_train_epochs=3.0 \
--output_dir=./output_model/multiple_relations_model/epochs3/

Step5: Model prediction

python run_multiple_relations_extraction.py \
  --task_name=SKE_2019 \
  --do_predict=true \
  --data_dir=bin/standard_format_data \
  --vocab_file=pretrained_model/chinese_L-12_H-768_A-12/vocab.txt \
  --bert_config_file=pretrained_model/chinese_L-12_H-768_A-12/bert_config.json \
  --init_checkpoint=output_model/multiple_relations_model/epochs3/model.ckpt-2000 \
  --max_seq_length=128 \
  --output_dir=./infer_out/multiple_relations_model/epochs3/ckpt2000

Step6: Generating Entities and Relational Files

python produce_submit_json_file.py

You can use other strategies to generate the final entity relationship file for better results. I have written the template code for you (see produce_submit_json_file.py).

Paper realization

This code is an unofficial implementation of Extracting Multiple-Relations in One-Pass with Pre-Trained Transformers and Joint entity recognition and relation extraction as a multi-head selection problem.

More Repositories

1

DeepImage-an-Image-to-Image-technology

DeepNude's algorithm and general image generation theory and practice research, including pix2pix, CycleGAN, UGATIT, DCGAN, SinGAN, ALAE, mGANprior, StarGAN-v2 and VAE models (TensorFlow2 implementation). DeepNude的算法以及通用生成对抗网络(GAN,Generative Adversarial Network)图像生成的理论与实践研究。
Python
5,168
star
2

Entity-Relation-Extraction

Entity and Relation Extraction Based on TensorFlow and BERT. 基于TensorFlow和BERT的管道式实体及关系抽取,2019语言与智能技术竞赛信息抽取任务解决方案。Schema based Knowledge Extraction, SKE 2019
Python
1,214
star
3

Machine-Learning-Book

《机器学习宝典》包含:谷歌机器学习速成课程(招式)+机器学习术语表(口诀)+机器学习规则(心得)+机器学习中的常识性问题 (内功)。该资源适用于机器学习、深度学习研究人员和爱好者参考!
Jupyter Notebook
1,031
star
4

BERT_Paper_Chinese_Translation

BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding 论文的中文翻译 Chinese Translation!
677
star
5

BERT-for-Sequence-Labeling-and-Text-Classification

This is the template code to use BERT for sequence lableing and text classification, in order to facilitate BERT for more tasks. Currently, the template code has included conll-2003 named entity identification, Snips Slot Filling and Intent Prediction.
Python
465
star
6

Schema-based-Knowledge-Extraction

Code for http://lic2019.ccf.org.cn/kg 信息抽取。使用基于 BERT 的实体抽取和关系抽取的端到端的联合模型。
Python
283
star
7

Machine_Learning_bookshelf

机器学习深度学习相关书籍、课件、代码的仓库。 Machine learning is the warehouse of books, courseware and codes.
Jupyter Notebook
189
star
8

Multimodal-short-video-dataset-and-baseline-classification-model

500,000 multimodal short video data and baseline models. 50万条多模态短视频数据集和基线模型(TensorFlow2.0)。
Jupyter Notebook
125
star
9

Theoretical-Proof-of-Neural-Network-Model-and-Implementation-Based-on-Numpy

This resource implements a deep neural network through Numpy, and is equipped with easy-to-understand theoretical derivation, mainly for the in-depth understanding of neural networks. 神经网络模型的理论证明与基于Numpy的实现。
Python
77
star
10

Find-a-Machine-Learning-Job

找一份机器学习工作(算法工程师),需要提纲(算法能力)挈领(编程能力),充分准备。 本人学习和在找工作期间受到了很多前辈们的帮助,目前已经找到心仪的工作,撰写此文献给那些在求职路上有梦有汗水的人们!2020秋招算法,难度剧增!没有选择,只能迎难而上。
65
star
11

XLNet_Paper_Chinese_Translation

XLNet: Generalized Autoregressive Pretraining for Language Understanding 论文的中文翻译 Paper Chinese Translation!
50
star
12

Slot-Filling-and-Intention-Prediction-in-Paper-Translation

槽填充、意图预测(口语理解)论文整理和中文翻译。Slot filling and intent prediction paper collation and Chinese translation.
49
star
13

SMP2018

SMP2018中文人机对话技术评测(ECDT)
Jupyter Notebook
47
star
14

fan-ren-xiu-xian-zhuan

凡人修仙传(fanrenxiuxianzhuan)的资源汇总,谨献给“凡友”们。
Python
45
star
15

Image-Captioning

CNN-Encoder and RNN-Decoder (Bahdanau Attention) for image caption or image to text on MS-COCO dataset. 图片描述
Jupyter Notebook
35
star
16

ELMo

ELMo: Embeddings from Language Models. Using, visualizing and understanding EMLo by examples!
Jupyter Notebook
32
star
17

Text-generation-task-and-language-model-GPT2

solve text generation tasks by the language model GPT2, including papers, code, demo demos, and hands-on tutorials. 使用语言模型GPT2来解决文本生成任务的资源,包括论文、代码、展示demo和动手教程。
29
star
18

Transformer_implementation_and_application

The 300 lines of code (Tensorflow 2) completely replicates the Transformer model and is used in neural machine translation tasks and chat bots. 300行代码(Tensorflow 2)完整复现了Transformer模型,并且应用在神经机器翻译任务和聊天机器人上。
Jupyter Notebook
26
star
19

yuanxiaosc.github.io

个人博客;论文;机器学习;深度学习;Python学习;C++学习;
HTML
21
star
20

CPlusPlus-Programming-Language-Foundation

《CPlusPlus编程语言基础》又称为“C加加知识树”,用树状思维导图的形式展现C++从业人员必备的所有C++基础知识。
21
star
21

Keras_Attention_Seq2Seq

A sequence-to-sequence framework of Keras-based generative attention mechanisms that humans can read.一个人类可以阅读的基于Keras的代注意力机制的序列到序列的框架/模型,或许你不用写复杂的代码,直接使用吧。
Python
18
star
22

Deep_dynamic_contextualized_word_representation

TensorFlow code and pre-trained models for A Dynamic Word Representation Model Based on Deep Context. It combines the idea of BERT model and ELMo's deep context word representation.
Python
16
star
23

Path-Classification-Experiment

Introduction to Data Analysis: Path Classification Experiment. 本资源以选择最优路径为例详细介绍了如何解决一般的分类问题,包括原始数据的探索、模型的构建、模型调优和模型预测分析。包含前馈神经网络(Keras)、机器学习模型(sklearn)和绘制数据图表(matplotlib)的基础使用。
Jupyter Notebook
13
star
24

Deep-Convolutional-Generative-Adversarial-Network

Tensorflow 2. This repository demonstrates how to generate images of handwritten digits (MINIST) using a Deep Convolutional Generative Adversarial Network (DCGAN). 深度卷积生成对抗网络
Jupyter Notebook
9
star
25

NLPCC2019-Conference-Materials

NLPCC2019会议资料分享:论文投稿信息总结、NLP当前研究内容和趋势、学者演讲、海报、公司介绍和招聘信息。
7
star
26

Slot-Gated-Modeling-for-Joint-Slot-Filling-and-Intent-Prediction

Code parsing and paper parsing for "Slot-Gated Modeling for Joint Slot Filling and Intent Prediction"
Python
5
star
27

Image_to_Text

Taking the image description task on the MS-COCO data set as an example, the template code of Image_to_Text is shown.
Jupyter Notebook
5
star
28

Seq2Seq-English-French-Machine-Translation-Model

Seq2Seq English-French Machine Translation Model
Python
5
star
29

Hands-on-chat-robots

There are a variety of out-of-the-box chat bot codes here.
Jupyter Notebook
3
star