Coder Social home page Coder Social logo

hanjx16 / bert-transformer-for-summarization Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fangpings/bert-transformer-for-summarization

0.0 1.0 0.0 108 KB

A BERT-Transformer network for abstractive text summarization

Jupyter Notebook 2.21% Python 97.60% Shell 0.18%

bert-transformer-for-summarization's Introduction

BERT-Transformer for Abstractive Text Summarization

It is a Pytorch implementation for abstractive text summarization model using BERT as encoder and transformer decoder as decoder. It tries to use bert encoder in generative tasks. The Pytorch Bert implementation is brought from pytorch-pretrained-BERT and Transformer implementaion from attention-is-all-you-need-pytorch. It has been tested on LCSTS Chinese dataset and achieved good results.

Preparation

Dataset

We use LCSTS dataset for Chinese task. If you also use this dataset, you can just download the original data into data/raw_data and run data.py. If you use other data set, you should process the dataset into following csv format. Every line stands for one entry in index, summarization, source order.

%index%\t%summarization%\t%source%\n

BERT pretrained model

You should download the BERT pretrained model yourself into pretrained_model/ directory. The organization should like this

pretrained_model/
├── bert_config.json
├── pytorch_model.bin
└── vocab.txt

See the pytorch-pretrained-BERT repo for details.

Usage

Training

For training, just run train.sh, there are 2 parameters that you have to specify.

--data_dir You have to designate your data directory and it must contains train.csv. If eval.csv is not in the same directory, not evaluation will be carried out during the training.

--bert_model Also, you must designate your bert pretrained model directory.

The rest are optional.

--GPU_index parameter allows you to choose which GPU to use.

--output_dir designate the directory where the model is saved into. If it is not designated, no model will be saved

There are also other optional parameters that you can change. You can refer to train.py. Detailed description for each parameter is on the top of the file.

Evaluation

For evaluation, just run predict.sh

It is mostly the same as train.sh, but you have to specify 5 required parameters.

--model_path The path to trained model for evaluation.

--config_path The path to configuration file. Default is inside the model_path.

--eval_path The path to evaluation data path.

--bert_model The path to bert pretrained model.

--result_path The path where you save your results.

Server

For online testing, run server.sh. The same as evaluation, you have to specify --model_path, --config_path and --bert_model. Besides, you can also specify which address to listen to by specifying --address (default is 0.0.0.0) and which port to set up your service by --port (default is 8080).

To use this feature, you should POST your JSON-formatted data to address:port/summarization. The data should contain 'text' key where you put the source text you want to summarize. An example may like this

curl -X POST -H "Content-type: application/json" -d '{"text":"美国商务部官方网站5月20日发布:给华为及其合作伙伴90天的临时许可。该发布称,这项安排是为了给相关部门和公司提供进行调整的时间。"}' localhost:8080/summarization

bert-transformer-for-summarization's People

Contributors

fangpings avatar

Watchers

James Cloos avatar

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.