phngahn commited on
Commit
9efa4d6
·
verified ·
1 Parent(s): fbed7e0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +158 -6
README.md CHANGED
@@ -1,10 +1,162 @@
1
  ---
2
- base_model:
3
- - vinai/phobert-base
4
- language:
5
- - vi
6
  pipeline_tag: text-classification
7
  tags:
8
- - aspect-based-sentiment-analysis
9
- - sentiment-analysis
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ---
 
1
  ---
2
+ base_model: vinai/phobert-base
3
+ language: vi
 
 
4
  pipeline_tag: text-classification
5
  tags:
6
+ - aspect-based-sentiment-analysis
7
+ - sentiment-analysis
8
+ - vietnamese-nlp
9
+ - phobert
10
+ license: mit
11
+ ---
12
+
13
+ # PhoBERT Aspect-Based Sentiment Analysis
14
+
15
+ Mô hình phân tích cảm xúc theo khía cạnh (Aspect-Based Sentiment Analysis - ABSA) cho tiếng Việt, được xây dựng dựa trên PhoBERT. Mô hình dự đoán cực tính cảm xúc (**tiêu cực / trung lập / tích cực**) cho **4 khía cạnh** đồng thời trong một lần forward pass:
16
+
17
+ - **food** (món ăn)
18
+ - **price** (giá cả)
19
+ - **space** (không gian)
20
+ - **service** (phục vụ)
21
+
22
+ Mô hình được thiết kế đặc biệt cho phân tích đánh giá nhà hàng và ẩm thực tiếng Việt.
23
+
24
+ ## Model Overview
25
+
26
+ - **Base model:** [vinai/phobert-base](https://huggingface.co/vinai/phobert-base)
27
+ - **Architecture:** PhoBERT encoder với 4 classification heads độc lập
28
+ - **Task:** Aspect-Based Sentiment Analysis (ABSA)
29
+ - **Number of aspects:** 4
30
+ - **Number of sentiment classes:** 3 (negative, neutral, positive)
31
+
32
+ ## Output Format
33
+
34
+ Mô hình trả về tensor với shape: `(batch_size, 4, 3)`
35
+
36
+ Trong đó:
37
+ - `4` tương ứng với số lượng khía cạnh
38
+ - `3` tương ứng với số lớp cảm xúc cho mỗi khía cạnh
39
+
40
+ **Thứ tự các khía cạnh trong output tensor:**
41
+ ```python
42
+ ["food", "price", "space", "service"]
43
+ ```
44
+
45
+ **Sentiment Labels:**
46
+
47
+ | ID | Label | Mô tả |
48
+ |----|----------|-------------|
49
+ | 0 | negative | Tiêu cực |
50
+ | 1 | neutral | Trung lập |
51
+ | 2 | positive | Tích cực |
52
+
53
+ ## Installation
54
+
55
+ ```bash
56
+ pip install torch transformers
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ > ⚠️ **Important:** Mô hình này sử dụng custom architecture, do đó bạn phải enable `trust_remote_code=True` khi load.
62
+
63
+ ### Load Model and Tokenizer
64
+
65
+ ```python
66
+ import torch
67
+ from transformers import AutoTokenizer, AutoModel
68
+
69
+ tokenizer = AutoTokenizer.from_pretrained(
70
+ "phngahn/phobert-aspect-based-sentiment"
71
+ )
72
+
73
+ model = AutoModel.from_pretrained(
74
+ "phngahn/phobert-aspect-based-sentiment",
75
+ trust_remote_code=True
76
+ )
77
+ ```
78
+
79
+ ### Inference
80
+
81
+ ```python
82
+ text = "Món ăn ngon nhưng phục vụ chậm và giá hơi cao"
83
+
84
+ inputs = tokenizer(text, return_tensors="pt")
85
+
86
+ with torch.no_grad():
87
+ logits = model(**inputs)
88
+
89
+ print(logits.shape) # torch.Size([1, 4, 3])
90
+ ```
91
+
92
+ ### Decode Predictions
93
+
94
+ ```python
95
+ aspect_names = ["food", "price", "space", "service"]
96
+ sentiment_labels = ["negative", "neutral", "positive"]
97
+
98
+ def predict(text):
99
+ inputs = tokenizer(text, return_tensors="pt")
100
+
101
+ with torch.no_grad():
102
+ logits = model(**inputs)[0]
103
+
104
+ preds = logits.argmax(dim=1)
105
+
106
+ return {
107
+ aspect: sentiment_labels[p.item()]
108
+ for aspect, p in zip(aspect_names, preds)
109
+ }
110
+
111
+ # Example
112
+ result = predict("Món ăn ngon nhưng giá cao, phục vụ chậm")
113
+ print(result)
114
+ ```
115
+
116
+ **Output:**
117
+ ```python
118
+ {
119
+ "food": "positive",
120
+ "price": "negative",
121
+ "space": "neutral",
122
+ "service": "negative"
123
+ }
124
+ ```
125
+
126
+ ## Model Details
127
+
128
+ - Mô hình dựa trên kiến trúc PhoBERT/RoBERTa và bỏ qua `token_type_ids`
129
+ - Tương thích với `AutoModel` và `Trainer` của Hugging Face
130
+ - Mô hình không được wrap sẵn thành Hugging Face pipeline
131
+
132
+ ## Intended Use
133
+
134
+ ✅ Phân tích đánh giá nhà hàng tiếng Việt
135
+ ✅ Phân tích cảm xúc theo khía cạnh
136
+ ✅ Nghiên cứu học thuật và dự án sinh viên
137
+
138
+ ## Limitations
139
+
140
+ ⚠️ Chỉ được huấn luyện trên dữ liệu nhà hàng/ẩm thực
141
+ ⚠️ Hiệu suất có thể giảm trên các domain khác
142
+ ⚠️ Mô hình luôn dự đoán cả 4 khía cạnh (giả định tất cả khía cạnh đều xuất hiện)
143
+
144
+ ## Citation
145
+
146
+ Nếu bạn sử dụng mô hình này trong công trình học thuật, vui lòng trích dẫn PhoBERT:
147
+
148
+ ```bibtex
149
+ @article{phobert,
150
+ title = {{PhoBERT: Pre-trained language models for Vietnamese}},
151
+ author = {Dat Quoc Nguyen and Anh Tuan Nguyen},
152
+ journal = {Findings of EMNLP},
153
+ year = {2020}
154
+ }
155
+
156
+ ```
157
+
158
+ ## License
159
+
160
+ Mô hình này tuân theo license của base model [vinai/phobert-base](https://huggingface.co/vinai/phobert-base).
161
+
162
  ---