Update README.md
Browse files
README.md
CHANGED
@@ -5,4 +5,55 @@ language:
|
|
5 |
base_model:
|
6 |
- google-bert/bert-base-uncased
|
7 |
library_name: transformers
|
8 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
base_model:
|
6 |
- google-bert/bert-base-uncased
|
7 |
library_name: transformers
|
8 |
+
---
|
9 |
+
|
10 |
+
This model requires custom code as it uses GridTaggingScheme to predict the labels on the input. For the convenience,
|
11 |
+
the custom code and model architecture has been included with the model.
|
12 |
+
|
13 |
+
## Example Code for inferencing
|
14 |
+
|
15 |
+
### STEP 1 (Installing huggingface libs)
|
16 |
+
|
17 |
+
```bash
|
18 |
+
pip install --upgrade huggingface_hub
|
19 |
+
```
|
20 |
+
|
21 |
+
### STEP 2 (Download the custom code and model to predict opinion target, opinion span and sentiment polarity)
|
22 |
+
```python
|
23 |
+
|
24 |
+
from huggingface_hub import hf_hub_download
|
25 |
+
import sys
|
26 |
+
# Download the custom model code
|
27 |
+
bert_gts_pretrained = hf_hub_download(repo_id="gauneg/bert-gts-absa-triple", filename="bert_gts_pretrained.py")
|
28 |
+
post = hf_hub_download(repo_id="gauneg/bert-gts-absa-triple", filename="post.py")
|
29 |
+
|
30 |
+
sys.path.append(bert_gts_pretrained)
|
31 |
+
sys.path.append(post)
|
32 |
+
|
33 |
+
from bert_gts_model import GTSBertBaseABSATriple
|
34 |
+
from token_decode_module import DecodeAndEvaluate
|
35 |
+
from bert_gts_pretrained import GTSBertBaseABSATriple
|
36 |
+
from post import DecodeAndEvaluate
|
37 |
+
|
38 |
+
|
39 |
+
from transformers import AutoTokenizer
|
40 |
+
|
41 |
+
model_id = 'gauneg/bert-gts-absa-triple'
|
42 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
43 |
+
model = GTSBertBaseABSATriple.from_pretrained(model_id)
|
44 |
+
dec_and_infer = DecodeAndEvaluate(tokenizer)
|
45 |
+
test_sentence0 = """I charge it at night and skip taking the cord with me because of the good battery life ."""
|
46 |
+
test_sentence = "The Dell Inspiron 14 Plus is the most well-rounded laptop with great display and battery life that money can buy."
|
47 |
+
|
48 |
+
|
49 |
+
# prediction
|
50 |
+
print(dec_and_infer.decode_predict_string_one(test_sentence, model))
|
51 |
+
|
52 |
+
```
|
53 |
+
Expected output
|
54 |
+
|
55 |
+
```bash
|
56 |
+
[['display', 'well - rounded', 'positive'],
|
57 |
+
['display', 'great', 'positive'],
|
58 |
+
['battery life', 'great', 'positive']]
|
59 |
+
```
|