NikG100 commited on
Commit
66d6eba
·
verified ·
1 Parent(s): aee90cf

Upload 8 files

Browse files
Files changed (8) hide show
  1. README.md +126 -0
  2. config.json +37 -0
  3. merges.txt +0 -0
  4. model.safetensors +3 -0
  5. special_tokens_map.json +15 -0
  6. tokenizer.json +0 -0
  7. tokenizer_config.json +58 -0
  8. vocab.json +0 -0
README.md ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # RoBERTa-Base Quantized Model for Sentiment Analysis
2
+
3
+ This repository hosts a quantized version of the RoBERTa model, fine-tuned for sentiment-analysis-classification tasks. The model has been optimized for efficient deployment while maintaining high accuracy, making it suitable for resource-constrained environments.
4
+
5
+ ## Model Details
6
+
7
+ - **Model Architecture:** RoBERTa Base
8
+ - **Task:** Sentiment Analysis
9
+ - **Dataset:** Custom Twitter Dataset (`twitter_training.csv`)
10
+ - **Quantization:** Float16
11
+ - **Fine-tuning Framework:** Hugging Face Transformers
12
+
13
+ ## Usage
14
+
15
+ ### Installation
16
+
17
+ ```sh
18
+ pip install transformers torch
19
+ ```
20
+
21
+
22
+ ### Loading the Model
23
+
24
+ ```python
25
+
26
+ from transformers import RobertaTokenizerFast, RobertaForSequenceClassification, Trainer, TrainingArguments
27
+ import torch
28
+
29
+
30
+
31
+ # Load tokenizer
32
+
33
+ tokenizer = RobertaTokenizerFast.from_pretrained("roberta-base")
34
+
35
+ # Define a test sentence
36
+
37
+ test_sentence = "The food was absolutely delicious and the service was amazing!"
38
+
39
+ # Tokenize input
40
+
41
+ inputs = tokenizer(test_sentence, return_tensors="pt", padding=True, truncation=True, max_length=128)
42
+
43
+ # Ensure input tensors are in correct dtype
44
+
45
+ inputs["input_ids"] = inputs["input_ids"].long() # Convert to long type
46
+
47
+ inputs["attention_mask"] = inputs["attention_mask"].long() # Convert to long type
48
+
49
+ # Move inputs to the model's device
50
+
51
+ inputs = {key: value.to(device) for key, value in inputs.items()}
52
+
53
+ # Make prediction
54
+
55
+ with torch.no_grad():
56
+
57
+ outputs = quantized_model(**inputs)
58
+
59
+ # Get predicted class
60
+
61
+ predicted_class = torch.argmax(outputs.logits, dim=1).item()
62
+
63
+ print(f"Predicted Class: {predicted_class}")
64
+
65
+
66
+ label_mapping = {0: "very_negative", 1: "nagative", 2: "neutral", 3: "Positive", 4: "very_positive"}
67
+
68
+ #Example
69
+
70
+ predicted_label = label_mapping[predicted_class]
71
+
72
+ print(f"Predicted Label: {predicted_label}")
73
+
74
+ ```
75
+
76
+ ## Performance Metrics
77
+
78
+ - **Accuracy:** 0.82
79
+
80
+ ## Fine-Tuning Details
81
+
82
+ ### Dataset
83
+
84
+ The dataset is taken from Kaggle .
85
+
86
+ ### Training
87
+
88
+ - Number of epochs: 3
89
+
90
+ - Batch size: 8
91
+
92
+ - Evaluation strategy: epoch
93
+
94
+ - Learning rate: 2e-5
95
+
96
+ ### Quantization
97
+
98
+ Post-training quantization was applied using PyTorch's built-in quantization framework to reduce the model size and improve inference efficiency.
99
+
100
+ ## Repository Structure
101
+
102
+ ```
103
+
104
+ .
105
+
106
+ ├── model/ # Contains the quantized model files
107
+
108
+ ├── tokenizer_config/ # Tokenizer configuration and vocabulary files
109
+
110
+ ├── model.safensors/ # Fine Tuned Model
111
+
112
+ ├── README.md # Model documentation
113
+
114
+ ```
115
+
116
+ ## Limitations
117
+
118
+ - The model may not generalize well to domains outside the fine-tuning dataset.
119
+
120
+ - Quantization may result in minor accuracy degradation compared to full-precision models.
121
+
122
+ ## Contributing
123
+
124
+ Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
125
+
126
+
config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RobertaForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "classifier_dropout": null,
8
+ "eos_token_id": 2,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "id2label": {
13
+ "0": "LABEL_0",
14
+ "1": "LABEL_1",
15
+ "2": "LABEL_2"
16
+ },
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "label2id": {
20
+ "LABEL_0": 0,
21
+ "LABEL_1": 1,
22
+ "LABEL_2": 2
23
+ },
24
+ "layer_norm_eps": 1e-05,
25
+ "max_position_embeddings": 514,
26
+ "model_type": "roberta",
27
+ "num_attention_heads": 12,
28
+ "num_hidden_layers": 12,
29
+ "pad_token_id": 1,
30
+ "position_embedding_type": "absolute",
31
+ "problem_type": "single_label_classification",
32
+ "torch_dtype": "float16",
33
+ "transformers_version": "4.51.1",
34
+ "type_vocab_size": 1,
35
+ "use_cache": true,
36
+ "vocab_size": 50265
37
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f04bd6d7a794f774ac3341c4994b77a1287acd11fa9105ca4586a35a1c1f1bba
3
+ size 249319966
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<s>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<pad>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "</s>",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<unk>",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "50264": {
37
+ "content": "<mask>",
38
+ "lstrip": true,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ }
44
+ },
45
+ "bos_token": "<s>",
46
+ "clean_up_tokenization_spaces": false,
47
+ "cls_token": "<s>",
48
+ "eos_token": "</s>",
49
+ "errors": "replace",
50
+ "extra_special_tokens": {},
51
+ "mask_token": "<mask>",
52
+ "model_max_length": 512,
53
+ "pad_token": "<pad>",
54
+ "sep_token": "</s>",
55
+ "tokenizer_class": "RobertaTokenizer",
56
+ "trim_offsets": true,
57
+ "unk_token": "<unk>"
58
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff