Skip to content

Label data using BERTforABSA models (based on HuggingFace's transformers) and automatically get predictions on your data

License

Notifications You must be signed in to change notification settings

Redelyx/label-studio-BERT-for-ABSA

 
 

Repository files navigation

Label Studio for BERTforABSA

Code for my degree thesis (in italian) A dataset labeling support system for Aspect-Based Sentiment Analysis

Transfer learning for NLP models by annotating your textual data without any additional coding.

This package provides a ready-to-use container that links together:


labelstudio-bertforabsa

Quick Usage

Install Label Studio and other dependencies
pip install -r requirements.txt
Download Bert models

Place laptop and restaurant post-trained BERTs into pt_model/laptop_pt and pt_model/rest_pt, respectively. The post-trained Laptop weights can be download here and restaurant here.

See BERTforABSA to obtain the fine-tuned models from training. The two *.pt files (one for Aspect Extraction, one for Aspect Sentiment Classification), have to be renamed by the following standard: model_task_domain.pt where, model can be hsum, psum or at, task is ae or asc, domain can be rest or laptop. for example:

hsum_ae_laptop.pt
hsum_asc_laptop.pt
Create ML backend for ABSA
label-studio-ml init my-ml-backend-ae --script models/bert_absa.py
cp models/absa_data_utils.py my-ml-backend-ae/absa_data_utils.py
cp models/pick_bert.py my-ml-backend-ae/pick_bert.py
cp models/modelconfig.py my-ml-backend-ae/modelconfig.py
robocopy models/pt_model my-ml-backend-ae/pt_model /E
robocopy models/berts my-ml-backend-ae/berts /E

You can also do the two tasks separately:

Create ML backend for ABSA Aspect Extraction
label-studio-ml init my-ml-backend-ae --script models/bert_ae.py
cp models/absa_data_utils.py my-ml-backend-ae/absa_data_utils.py
cp models/pick_bert.py my-ml-backend-ae/pick_bert.py
cp models/run_config.py my-ml-backend-ae/run_config.py
cp models/modelconfig.py my-ml-backend-ae/modelconfig.py
robocopy models/pt_model my-ml-backend-ae/pt_model /E
robocopy models/berts my-ml-backend-ae/berts /E
Create ML backend for ABSA Aspect Sentiment Classification
label-studio-ml init my-ml-backend-asc --script models/bert_asc.py
cp models/absa_data_utils.py my-ml-backend-asc/absa_data_utils.py
cp models/pick_bert.py my-ml-backend-asc/pick_bert.py
cp models/run_config.py my-ml-backend-asc/run_config.py
cp models/modelconfig.py my-ml-backend-asc/modelconfig.py
robocopy models/pt_model my-ml-backend-asc/pt_model /E
robocopy models/berts my-ml-backend-asc/berts /E
Start ML backend at http://localhost:9090
label-studio-ml start my-ml-backend-name

If you want to do the two tasks separately you have to create two projects on Label Studio and two backends, one for AE, one for ASC.

Start Label Studio with ML backend connection
label-studio start my-project-name --init --ml-backend http://localhost:9090

The browser opens at http://localhost:8080. Upload your data on Import page and retrieve your predictions.
See my other repo BERTforABSA to train bert-based models.

Click here to read more about how to use Machine Learning backend and build Human-in-the-Loop pipelines with Label Studio

Other useful instructions

You can find explanations for these instructions here:

Set up your labeling interface

Get data into Label Studio

Set up your labeling interface on Label Studio

This is the code for the ABSA labeling interface:

<View>
  <Labels name="label" toName="text">
    <Label value="positive" background="#00ff33"/>
    <Label value="negative" background="#ff0000"/>
    <Label value="neutral" background="#FFC069"/>
  </Labels>
  <Text name="text" value="$ner"/>
</View>

This is the code for the AE labeling interface:

<View>
  <Labels name="label" toName="text">
    <Label value="B" background="#fd8326"/>
    <Label value="I" background="#fff570"/>
  </Labels>
  <Text name="text" value="$text"/>
</View>

This is the code for the ASC labeling interface:

<View>
  <Labels name="label" toName="text">
    <Label value="positive" background="green"/>
    <Label value="negative" background="#ff0d00"/>
    <Label value="neutral" background="#f79b55"/>
  </Labels>
  <Header value="Sentence"/>
  <Text name="text" value="$sentence"/>
  <Header value="Aspect"/>
  <Text name="text1" value="$term"/>
</View>

Import dataset

For ABSA you can import a *.txt file with one sentence per line.
For AE task you can import a *.txt file with one sentence per line.
For ASC task you can import a *.tsv file similiar to this:

sentence	term
The screen is nice, side view angles are pretty good	screen
Applications respond immediately (not like the tired MS applications).	Applications
i also love having the extra calculator number set up on the keyboard.	calculator number

About

Label data using BERTforABSA models (based on HuggingFace's transformers) and automatically get predictions on your data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.0%
  • Batchfile 1.0%