gauneg commited on
Commit
63d1a3d
·
verified ·
1 Parent(s): 32da917

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +81 -81
README.md CHANGED
@@ -1,82 +1,82 @@
1
- ---
2
- license: apache-2.0
3
- ---
4
-
5
- ## Dataset Domain: Restaurant Reviews
6
-
7
- ## Overview
8
- This work is based on [Grid Tagging Scheme for Aspect-oriented Fine-grained Opinion Extraction](https://aclanthology.org/2020.findings-emnlp.234/).The code from
9
- their [github repository](https://github.com/NJUNLP/GTS) was also utilized along with their dataset.
10
-
11
- This model requires custom code as it uses GridTaggingScheme to predict the labels on the input. For the convenience,
12
- the custom code and model architecture has been included with the model.
13
-
14
- ## Example Code for inferencing
15
-
16
- ### STEP 1 (Installing huggingface lib)
17
-
18
- ```bash
19
- pip install --upgrade huggingface_hub
20
- ```
21
-
22
- ### STEP 2 (Download the custom code and model to predict opinion target, opinion span and sentiment polarity)
23
- ```python
24
-
25
- from huggingface_hub import hf_hub_download
26
- import sys
27
- # Download the custom model code
28
- bert_gts_pretrained = hf_hub_download(repo_id='gauneg/bert-gts-absa-triple-restaurant', filename="bert_opinion.py")
29
- post = hf_hub_download(repo_id='gauneg/bert-gts-absa-triple-restaurant', filename="post.py")
30
-
31
- sys.path.append(bert_gts_pretrained.rsplit("/", 1)[0])
32
- sys.path.append(post.rsplit("/", 1)[0])
33
-
34
-
35
- from bert_opinion import BertGTSOpinionTriple
36
- from post import DecodeAndEvaluate
37
-
38
-
39
- from transformers import AutoTokenizer
40
-
41
-
42
- model_id = 'gauneg/bert-gts-absa-triple-restaurant'
43
- tokenizer = AutoTokenizer.from_pretrained(model_id)
44
- model = BertGTSOpinionTriple.from_pretrained(model_id)
45
- dec_and_infer = DecodeAndEvaluate(tokenizer)
46
- test_sentence0 = """The food was good but the ambience was bad"""
47
-
48
-
49
-
50
- # prediction
51
- print(dec_and_infer.decode_predict_string_one(test_sentence, model, max_len=128))
52
-
53
- ```
54
- Expected output
55
-
56
- ```bash
57
- [['display', 'great', 'positive'], ['battery life', 'great', 'positive']]
58
- ```
59
-
60
- # DETAILS
61
- The model has been trained to use Grid Tagging Scheme (GTS) to predict `Opinion Target`, `Opinion Span` and `Sentiment Polarity`. For the purpose of training this model the domain specific datasets (laptop and restaurant reviews) were combined. The grid tagging example is shown
62
- in the following diagram:
63
-
64
- <figure>
65
- <img src="./gts_pic.png" alt="gts-image" style="width:45%">
66
- <figcaption>Fig 1. Grid tagging Scheme from <a href="https://aclanthology.org/2020.findings-emnlp.234/">(Wu et al., Findings 2020)</a> </figcaption>
67
- </figure>
68
-
69
- In the above sentence there are two absa triples. Each triple is expressed in the following order:
70
-
71
- [<span style="color:red">Aspect Term/Opinion Target</span>, <span style="color:#7393B3">opinion span</span>, <span style="color:purple">sentiment polarity</span>]
72
-
73
- The model and sample code as shown in the snippet with extract opinion triplets as: [
74
- [<span style="color:red">hot dogs</span>, <span style="color:#7393B3">top notch</span>, <span style="color:purple">positive</span>],
75
- [<span style="color:red">coffee</span>, <span style="color:#7393B3">avergae</span>, <span style="color:purple">neutral</span>]
76
- ]
77
-
78
- Definitions <a href="https://aclanthology.org/2020.findings-emnlp.234/">(Wu et al., Findings 2020)</a>:
79
-
80
- 1. <span style="color:red">Aspect Term/Opinion Target</span>: Aspect term, also known as opinion target, is the word or phrase in a sentence representing feature or entity of products or services.
81
- 2. <span style="color:#7393B3">Opinion Term </span>: Opinion Term refers to the term in a sentence used to express attitudes or opinions explicitly.
82
  3. <span style="color:purple">Sentiment Polarity</span>: This is the sentiment expressed.
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ ## Dataset Domain: Restaurant Reviews
6
+
7
+ ## Overview
8
+ This work is based on [Grid Tagging Scheme for Aspect-oriented Fine-grained Opinion Extraction](https://aclanthology.org/2020.findings-emnlp.234/).The code from
9
+ their [github repository](https://github.com/NJUNLP/GTS) was also utilized along with their dataset.
10
+
11
+ This model requires custom code as it uses GridTaggingScheme to predict the labels on the input. For the convenience,
12
+ the custom code and model architecture has been included with the model.
13
+
14
+ ## Example Code for inferencing
15
+
16
+ ### STEP 1 (Installing huggingface lib)
17
+
18
+ ```bash
19
+ pip install --upgrade huggingface_hub
20
+ ```
21
+
22
+ ### STEP 2 (Download the custom code and model to predict opinion target, opinion span and sentiment polarity)
23
+ ```python
24
+
25
+ from huggingface_hub import hf_hub_download
26
+ import sys
27
+ # Download the custom model code
28
+ bert_gts_pretrained = hf_hub_download(repo_id='gauneg/bert-gts-absa-triple-restaurant', filename="bert_opinion.py")
29
+ post = hf_hub_download(repo_id='gauneg/bert-gts-absa-triple-restaurant', filename="post.py")
30
+
31
+ sys.path.append(bert_gts_pretrained.rsplit("/", 1)[0])
32
+ sys.path.append(post.rsplit("/", 1)[0])
33
+
34
+
35
+ from bert_opinion import BertGTSOpinionTriple
36
+ from post import DecodeAndEvaluate
37
+
38
+
39
+ from transformers import AutoTokenizer
40
+
41
+
42
+ model_id = 'gauneg/bert-gts-absa-triple-restaurant'
43
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
44
+ model = BertGTSOpinionTriple.from_pretrained(model_id)
45
+ dec_and_infer = DecodeAndEvaluate(tokenizer)
46
+ test_sentence0 = """The food was good but the ambience was bad"""
47
+
48
+
49
+
50
+ # prediction
51
+ print(dec_and_infer.decode_predict_string_one(test_sentence, model, max_len=128))
52
+
53
+ ```
54
+ Expected output
55
+
56
+ ```bash
57
+ [['food', 'good', 'positive'], ['ambience', 'bad', 'negative']]
58
+ ```
59
+
60
+ # DETAILS
61
+ The model has been trained to use Grid Tagging Scheme (GTS) to predict `Opinion Target`, `Opinion Span` and `Sentiment Polarity`. For the purpose of training this model the domain specific datasets (laptop and restaurant reviews) were combined. The grid tagging example is shown
62
+ in the following diagram:
63
+
64
+ <figure>
65
+ <img src="./gts_pic.png" alt="gts-image" style="width:45%">
66
+ <figcaption>Fig 1. Grid tagging Scheme from <a href="https://aclanthology.org/2020.findings-emnlp.234/">(Wu et al., Findings 2020)</a> </figcaption>
67
+ </figure>
68
+
69
+ In the above sentence there are two absa triples. Each triple is expressed in the following order:
70
+
71
+ [<span style="color:red">Aspect Term/Opinion Target</span>, <span style="color:#7393B3">opinion span</span>, <span style="color:purple">sentiment polarity</span>]
72
+
73
+ The model and sample code as shown in the snippet with extract opinion triplets as: [
74
+ [<span style="color:red">hot dogs</span>, <span style="color:#7393B3">top notch</span>, <span style="color:purple">positive</span>],
75
+ [<span style="color:red">coffee</span>, <span style="color:#7393B3">avergae</span>, <span style="color:purple">neutral</span>]
76
+ ]
77
+
78
+ Definitions <a href="https://aclanthology.org/2020.findings-emnlp.234/">(Wu et al., Findings 2020)</a>:
79
+
80
+ 1. <span style="color:red">Aspect Term/Opinion Target</span>: Aspect term, also known as opinion target, is the word or phrase in a sentence representing feature or entity of products or services.
81
+ 2. <span style="color:#7393B3">Opinion Term </span>: Opinion Term refers to the term in a sentence used to express attitudes or opinions explicitly.
82
  3. <span style="color:purple">Sentiment Polarity</span>: This is the sentiment expressed.