Git Product home page Git Product logo

pcnn's Introduction

PCNN

Piecewise Convolution Neural Network is one kind of architecture for Relation Extraction task in NLP.
Applying one traditional single layer Convolution on sentence embeddings can capture n-gram features. After max pooling, only the strongest feature returns, which is insufficient for Relation Extraction tasks.
The PCNN architecture divide one sentence into three parts according to entities positions. This modification improve the capability of Relation Extraction.
The original architecture of PCNN is designed as follows.
origin PCNN This project re-implement the paper, Distant Supervision for Relation Extraction via Piecewise Convolutional Neural Networks, in Tensorflow.
Since it is still unsupported to split tensors into variable lengths in Tensorflow. The architecture is modified slightly as follows.
PCNN

Getting Started

Prerequisites

  • Python3(build with 3.6)

Installing

Required

Install python package in virtual environment

pip install -r requirements

Optional

To shuffle dataset, shuf is needed. And it is already installed on Linux.
Usage

shuf -o ./path/to/shuf_data ./path/to/origin_data

On OS X, gshuf is alternative.

brew install coreutils
gshuf -o ./path/to/shuf_data ./path/to/origin_data

You can configure ./model/config.py to set parameters.

Download Dataset

make download

Run

Run this project.

make run

Tensorboard

Using tensorboard

tensorboard --logdir="./graph" --port 6006

Open browser in http://localhost:6006/

License

This project is licensed under the Apache License - see the LICENSE.txt file for details

Cite

@inproceedings{Zeng2015DistantSF,
  title={Distant Supervision for Relation Extraction via Piecewise Convolutional Neural Networks},
  author={Daojian Zeng and Kang Liu and Yubo Chen and Jun Zhao},
  booktitle={EMNLP},
  year={2015}
}

pcnn's People

Contributors

pencoa 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pcnn's Issues

Lost dataset

When I run make download in the project. It can not download the dataset,I try to find the data in the net, but it shows that the data is drop. How can I find the data?

During training, GPU usage is very low.

Hi , I noticed that during the training process, GPU usage is very low, around 10%. We are using 1080 Ti.

How should we improve the situation? I believe that higher GPU usage should means faster training process.

我发现一个错误,希望你确认一下

def iter(self):
niter = 0
with open(self.filename) as f:
for line in f:
niter += 1
if self.max_iter is not None and niter > self.max_iter:
break
word_idx, pos1, pos2 = [], [], []
line = re.sub('###END###', '', line)
line = line.strip()
content = line.split()
ent1 = content[2]
ent2 = content[3]
relation = content[4]
if self.processing_relation is not None:
relation = self.processing_relation(relation)
sentence = line[5:] # 这里,我认为应该是 sentence = content[5]

About Data set

Hi, I was reviewing the data set and the number of sentences between the train.txt file of origin_data is different to the file that is in processed_data. I would like to know what processing was done to the data.
Another question, is this the original data set published by Riedel in 2010?
Thanks in advance
Best regards

Have wrong when I run evaluate.py

When I run evaluate.py, it has wrong about "AttributeError: 'Config' object has no attribute 'processing_tag'." Could you please tell me how can I solve it?
Thank you!

The detail is shown below

python evaluate.py /usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88 return f(*args, **kwds) /usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88 return f(*args, **kwds) Initializing tf session 2018-09-26 15:53:01.238774: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA 2018-09-26 15:53:02.296384: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 0 with properties: name: Tesla P40 major: 6 minor: 1 memoryClockRate(GHz): 1.531 pciBusID: 0000:3b:00.0 totalMemory: 22.38GiB freeMemory: 22.21GiB 2018-09-26 15:53:02.296457: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1484] Adding visible gpu devices: 0 2018-09-26 15:53:02.623675: I tensorflow/core/common_runtime/gpu/gpu_device.cc:965] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-09-26 15:53:02.623747: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0 2018-09-26 15:53:02.623760: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] 0: N 2018-09-26 15:53:02.624118: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1097] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 21549 MB memory) -> physical GPU (device: 0, name: Tesla P40, pci bus id: 0000:3b:00.0, compute capability: 6.1) Variable: pos1/_pos1_embeddings:0 Shape: (500, 5) Variable: pos2/_pos2_embeddings:0 Shape: (500, 5) Variable: conv/conv/kernel:0 Shape: (3, 60, 1, 230) Variable: conv/conv/bias:0 Shape: (230,) Variable: proj/W1:0 Shape: (690, 53) Variable: proj/b:0 Shape: (53,) Reloading the model in ./results/test/model.weights/early_best.ckpt... INFO:tensorflow:Restoring parameters from ./results/test/model.weights/early_best.ckpt Restoring parameters from ./results/test/model.weights/early_best.ckpt Traceback (most recent call last): File "evaluate.py", line 69, in <module> main() File "evaluate.py", line 61, in main config.processing_tag, config.max_iter) AttributeError: 'Config' object has no attribute 'processing_tag'

Hi! I want to know how to solve this problem

--- Logging error ---
Traceback (most recent call last):
File "/home/xyx/anaconda3/lib/python3.6/logging/init.py", line 992, in emit
msg = self.format(record)
File "/home/xyx/anaconda3/lib/python3.6/logging/init.py", line 838, in format
return fmt.format(record)
File "/home/xyx/anaconda3/lib/python3.6/logging/init.py", line 575, in format
record.message = record.getMessage()
File "/home/xyx/anaconda3/lib/python3.6/logging/init.py", line 338, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
File "/home/xyx/PCNN/train.py", line 26, in
main()
File "/home/xyx/PCNN/train.py", line 12, in main
model.build()
File "/home/xyx/PCNN/model/pcnn_model.py", line 312, in build
self.log_trainable()
File "/home/xyx/PCNN/model/pcnn_model.py", line 297, in log_trainable
self.logger.info("Shape: ", v.shape)
Message: 'Shape: '
Arguments: ((53,),)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.]
Epoch 1 out of 15

about the code and the paper

hi,firstly thxs for you resource~

  1. what i wonder is i can't find where is the part of the raw paper mentioned "Multi-instance Learning", is it that you still use the aver of the bag loss to train the model?
    2.in the resource ,you first slice the vector into pieces because the tensorflow doesn't support slice tensor,could i first embedding and the use mask to slice the tensor?

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.