Khoa commited on
Commit
3c901d7
·
verified ·
1 Parent(s): 7561298

Upload Vietnamese sentiment analysis model

Browse files
README.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: vi
3
+ license: mit
4
+ tags:
5
+ - vietnamese
6
+ - sentiment-analysis
7
+ - phobert
8
+ - text-classification
9
+ datasets:
10
+ - custom
11
+ metrics:
12
+ - f1
13
+ ---
14
+
15
+ # Vietnamese Sentiment Analysis Model
16
+
17
+ This model is fine-tuned from [vinai/phobert-base](https://huggingface.co/vinai/phobert-base) for Vietnamese sentiment analysis with entity context.
18
+
19
+ ## Model description
20
+
21
+ The model classifies text sentiment into three categories:
22
+ - NEGATIVE (0)
23
+ - NEUTRAL (1)
24
+ - POSITIVE (2)
25
+
26
+ It is specifically designed to analyze sentiment toward a specific entity mentioned in the text.
27
+
28
+ ## Intended uses & limitations
29
+
30
+ The model is intended to be used for Vietnamese sentiment analysis, specifically when analyzing sentiment toward a named entity.
31
+
32
+ ### How to use
33
+
34
+ ```python
35
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
36
+ import torch
37
+
38
+ # Load model and tokenizer
39
+ tokenizer = AutoTokenizer.from_pretrained("Khoa/vietnamese-sentiment-analysis-with-entity")
40
+ model = AutoModelForSequenceClassification.from_pretrained("Khoa/vietnamese-sentiment-analysis-with-entity")
41
+
42
+ # Function to predict sentiment
43
+ def predict_sentiment(text, entity, model, tokenizer):
44
+ combined_text = f"Đối với {entity}, {text}"
45
+ inputs = tokenizer(combined_text, return_tensors="pt", truncation=True, padding=True)
46
+
47
+ with torch.no_grad():
48
+ outputs = model(**inputs)
49
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
50
+ predicted_class = torch.argmax(predictions, dim=-1).item()
51
+
52
+ sentiment_labels = {0: "NEGATIVE", 1: "NEUTRAL", 2: "POSITIVE"}
53
+ return sentiment_labels[predicted_class], predictions[0].tolist()
54
+
55
+ # Example usage
56
+ text = "Món ăn rất ngon nhưng giá hơi đắt"
57
+ entity = "Nhà hàng ABC"
58
+ sentiment, confidence = predict_sentiment(text, entity, model, tokenizer)
59
+ print(f"Sentiment: {sentiment}")
60
+ ```
61
+
62
+ ## Training procedure
63
+
64
+ The model was fine-tuned on a custom Vietnamese dataset with entity-specific sentiment annotations.
65
+
66
+
67
+ This model was fine-tuned on a custom Vietnamese sentiment analysis dataset.
68
+ It achieves the following metrics on the test set:
69
+ - Accuracy: 0.0000
70
+ - F1 Score: 0.0000
71
+ - Precision: 0.0000
72
+ - Recall: 0.0000
73
+
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<mask>": 64000
3
+ }
bpe.codes ADDED
The diff for this file is too large to render. See raw diff
 
config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "vinai/phobert-base",
3
+ "architectures": [
4
+ "RobertaForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "eos_token_id": 2,
10
+ "gradient_checkpointing": false,
11
+ "hidden_act": "gelu",
12
+ "hidden_dropout_prob": 0.1,
13
+ "hidden_size": 768,
14
+ "id2label": {
15
+ "0": "LABEL_0",
16
+ "1": "LABEL_1",
17
+ "2": "LABEL_2"
18
+ },
19
+ "initializer_range": 0.02,
20
+ "intermediate_size": 3072,
21
+ "label2id": {
22
+ "LABEL_0": 0,
23
+ "LABEL_1": 1,
24
+ "LABEL_2": 2
25
+ },
26
+ "layer_norm_eps": 1e-05,
27
+ "max_position_embeddings": 258,
28
+ "model_type": "roberta",
29
+ "num_attention_heads": 12,
30
+ "num_hidden_layers": 12,
31
+ "pad_token_id": 1,
32
+ "position_embedding_type": "absolute",
33
+ "problem_type": "single_label_classification",
34
+ "tokenizer_class": "PhobertTokenizer",
35
+ "torch_dtype": "float32",
36
+ "transformers_version": "4.48.3",
37
+ "type_vocab_size": 1,
38
+ "use_cache": true,
39
+ "vocab_size": 64001
40
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:abbe45d0304b45cfc244c963ad7cc5850f2003dcbf7f31f4287284964c29fa45
3
+ size 540026460
special_tokens_map.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": "<mask>",
6
+ "pad_token": "<pad>",
7
+ "sep_token": "</s>",
8
+ "unk_token": "<unk>"
9
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "64000": {
36
+ "content": "<mask>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "<s>",
45
+ "clean_up_tokenization_spaces": false,
46
+ "cls_token": "<s>",
47
+ "eos_token": "</s>",
48
+ "extra_special_tokens": {},
49
+ "mask_token": "<mask>",
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "pad_token": "<pad>",
52
+ "sep_token": "</s>",
53
+ "tokenizer_class": "PhobertTokenizer",
54
+ "unk_token": "<unk>"
55
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff