developerPushkal commited on
Commit
341e095
Β·
verified Β·
1 Parent(s): 22c4905

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +99 -0
README.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # DistilBERT Quantized Model for LinkedIn Post Sentiment Analysis
2
+
3
+ This repository hosts a quantized version of the DistilBERT model, fine-tuned for LinkedIn post sentiment analysis 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:** DistilBERT Base Uncased
8
+ - **Task:** LinkedIn Post Sentiment Analysis
9
+ - **Dataset:** Stanford Sentiment Treebank v2 (SST2)
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
+ ### Loading the Model
22
+
23
+ ```python
24
+ from transformers import DistilBertForSequenceClassification, DistilBertTokenizer
25
+ import torch
26
+
27
+ # Load quantized model
28
+ quantized_model_path = "/kaggle/working/distilbert_finetuned_fp16"
29
+ quantized_model = DistilBertForSequenceClassification.from_pretrained(quantized_model_path)
30
+ quantized_model.eval() # Set to evaluation mode
31
+ quantized_model.half() # Convert model to FP16
32
+
33
+ # Load tokenizer
34
+ tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased")
35
+
36
+ # Define a test sentence
37
+ test_sentence = "This update has received great engagement!"
38
+
39
+ # Tokenize input
40
+ inputs = tokenizer(test_sentence, return_tensors="pt", padding=True, truncation=True, max_length=128)
41
+
42
+ # Ensure input tensors are in correct dtype
43
+ inputs["input_ids"] = inputs["input_ids"].long() # Convert to long type
44
+ inputs["attention_mask"] = inputs["attention_mask"].long() # Convert to long type
45
+
46
+ # Make prediction
47
+ with torch.no_grad():
48
+ outputs = quantized_model(**inputs)
49
+
50
+ # Get predicted class
51
+ predicted_class = torch.argmax(outputs.logits, dim=1).item()
52
+ print(f"Predicted Class: {predicted_class}")
53
+
54
+ label_mapping = {0: "very_negative", 1: "negative", 2: "neutral", 3: "positive", 4: "very_positive"} # Example
55
+
56
+ predicted_label = label_mapping[predicted_class]
57
+ print(f"Predicted Label: {predicted_label}")
58
+ ```
59
+
60
+ ## Performance Metrics
61
+
62
+ - **Accuracy:** 0.82
63
+
64
+ ## Fine-Tuning Details
65
+
66
+ ### Dataset
67
+
68
+ The dataset is taken from Kaggle Stanford Sentiment Treebank v2 (SST2).
69
+
70
+ ### Training
71
+
72
+ - Number of epochs: 3
73
+ - Batch size: 8
74
+ - Evaluation strategy: epoch
75
+ - Learning rate: 2e-5
76
+
77
+ ### Quantization
78
+
79
+ Post-training quantization was applied using PyTorch's built-in quantization framework to reduce the model size and improve inference efficiency.
80
+
81
+ ## Repository Structure
82
+
83
+ ```
84
+ .
85
+ β”œβ”€β”€ model/ # Contains the quantized model files
86
+ β”œβ”€β”€ tokenizer_config/ # Tokenizer configuration and vocabulary files
87
+ β”œβ”€β”€ model.safensors/ # Fine Tuned Model
88
+ β”œβ”€β”€ README.md # Model documentation
89
+ ```
90
+
91
+ ## Limitations
92
+
93
+ - The model may not generalize well to domains outside the fine-tuning dataset.
94
+ - Quantization may result in minor accuracy degradation compared to full-precision models.
95
+
96
+ ## Contributing
97
+
98
+ Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
99
+