lixin4ever/BERT-E2E-ABSA

How to use the trained model

Opened this issue · 21 comments

Hi!

I was wondering if I can use the model, after training it, on new stuff to do the aspect extraction and also to find aspect sentiment polarity?

If yes how can I do it?

Thanks!

This feature is mentioned here, please check it out.

Thanks for the reply! In which format the dataset should be in order for the model to work fine?

Same to the given data files. For example, you can follow the format of rest16.train and randomly assign the tag for each input word (just to facilitate the input and these tags are not used during inference).

When I create something like that it says ValueError: not enough values to unpack (expected 2, got 1)
test.txt

Can you show me the log?

Hello sorry for the late reply,

here is my text document and also my log file:

test.txt

output.txt

my work.sh looks like this after I created a folder named test inside /data and in this test folder I put the test.txt file.

#!/usr/bin/env bash TASK_NAME="test" ABSA_HOME="./bert-linear-laptop14-finetune" CUDA_VISIBLE_DEVICES=0 python work.py --absa_home ${ABSA_HOME} \ --ckpt ${ABSA_HOME}/checkpoint-1400 \ --model_type bert \ --data_dir ./data/${TASK_NAME} \ --task_name ${TASK_NAME} \ --model_name_or_path bert-base-uncased \ --cache_dir ./cache \ --max_seq_length 128 \ --tagging_schema BIEOS

Same to the given data files. For example, you can follow the format of rest16.train and randomly assign the tag for each input word (just to facilitate the input and these tags are not used during inference).

Sorry for not saying this clearly. You should randomly assign a valid tag, which comes from the valid tag set {T-POS, T-NEG, T-NEU, O}, rather than 0 (in your case) to each word.

Thank you for the reply! I changed the tags and now I am getting AssertionError in work.py Line 152:

assert len(words) == len(pred_labels)

should I remove the stop words from the tagging part?

Well, you may need to print them out and see what happened.

I printed them out and when I print the words it actually prints the words I add after #### and pred_labels is just a list of 17 zeros which I couldn't link to something? The sentence has 10 words in total.

10 is not equal to 17 so that's why there is an AssertionError but I don't understand what is 17 in this case.

The length of words should be equal to the length of pred_labels. In your case, 10 is the length of words and 17 should be the length of sub-words. Normally, the sub-word sequence is longer than the original word sequence because sub-word is a more fine-grained semantic unit.

Is there anything wrong with your input?

Another way to check if the code is problematic is to apply it to the data files provided in this repo, e.g., laptop14/test.txt.

I checked with other data files and the problem seems to be this:

The code expects 800 reviews because at the Evaluation process it says 0/800 at the end and when I only type for example 10 reviews the AssertionError occurs at 10/800.

Normally when I use laptop14/test.txt everything runs smooth but when I delete some reviews from test.txt I encounter an error again. So that might be the problem. Maybe the code expects a certain amount of reviews to go through.

output2.txt

I don't think the error come from the input data.

Have you ever checked the values of "idx" and "total words"?

yes for example when I add 10 reviews to test.txt "idx" only goes up to 9 then there is this IndexError and total words is always the length of the review.

When I type in this text file myself, even if I write in the same review in "test.txt", I get AssertionError this is really interesting what might cause this?

OK, I will check this issue, please stay tuned.

Hello, I train a model on laptop14 and do the inference on test20/test.txt (the running scripts fast_run.py and work.sh are also updated accordingly). Everything works normally.

Here is the output log: output.log.

I have no idea about your issues. I suggest you re-clone this repo, upgrade transformers to 4.1.1, and see what will happen.

When I add a sentence myself to the test20/test.txt it doesn't recognize it and just applies the model on 20 sentences. When I delete a sentence I get an error.
This might be an absurd question but is there a special way to add or delete a sentence from test20/test.txt ?

This is NOT an absurd question. PLEASE read the code carefully.

The program will cache the feature file for the first time you perform inference. If you want to change the content of test20/test.txt, you should delete the cached feature file (at ./data/test20/) as well, otherwise, the previous features will be loaded as the model input in the following runs.

This was the problem the whole time.... Thanks for all the help!!!!!!!!!!!!

Is there a way to disable this tagging part of the input text file? Is there a way to modify the code so that the input data doesnt require the part after '####' ? (For the interference part)