GithubHelp home page GithubHelp logo

bert-sentiment-analysis's Introduction

Bert-Sentiment-Analysis

Sentiment analysis using pretrained Bert model

Dependencies

python3.6
torch==1.3.1
torchtext==0.5.0
transformers==2.8.0

Prepare Data

Prepare test.json and train.json in the data directory. Each file contain lines of json strings with following fields.

{
  "text": [string, the sentence],
  "label": [integer, true sentiment label],
  "id": [integer, sentence id]
}

Training

Run the following command.

$ cd code
$ python train.py \
    --data_path [data path] \
    --epochs 40 \
    --epochs_per_val 5 \
    --save_id [id] \
    --device_id [device id] \
    --bidirectional

Here are some more options.

optional arguments:
  -h, --help            show this help message and exit
  --data_path DATA_PATH
                        data path, contains `train.json` and `test.json`
  --epochs EPOCHS       training epochs
  --epochs_per_val EPOCHS_PER_VAL
                        epochs per evaluation
  --batch_size BATCH_SIZE
                        batch size of data
  --device_id DEVICE_ID
                        gpu index
  --save_id SAVE_ID     model save id
  --h_dim H_DIM         hidden dimension of GRU
  --n_cls N_CLS         number of classes
  --n_layers N_LAYERS   number of layers
  --bidirectional       whether to use bidirectional GRU
  --dropout DROPOUT     dropout rate

Testing

Run the following command.

$ cd code
$ python eval.py --data_path [data path] --save_id [id] --device_id [device id]

bert-sentiment-analysis's People

Contributors

higgsboson-x avatar

Watchers

 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.