File size: 2,465 Bytes
69b6486
7deacc7
 
 
69b6486
 
 
 
 
 
 
 
 
 
 
99081a3
69b6486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Model Card: BART-based Sentiment Classification Model
# LABEL_0 = NEGATIVE
# LABEL_1  = NEUTRAL
# LABEL_2 = POSITIVE 

# Model Details
Model Name: BART-based Sentiment Classification Model
Description: This model is trained using BART (Bidirectional and Auto-Regressive Transformers) for sentiment classification on the chat_dataset. It takes a message as input and predicts the sentiment category, which can be one of three labels: LABEL_0, LABEL_1, or LABEL_2.
Framework: PyTorch
Model Architecture: BARTForSequenceClassification (based on the BART model architecture)
Pretrained Model: Facebook's BART-base

# Intended Use
Primary Task: Sentiment Classification
Input: Textual message (string)
Output: Sentiment category label (LABEL_0(NEGATIVE), LABEL_1(NEUTRAL), or LABEL_2(POSITIVE))

# Training Data
Dataset: chat_dataset.csv
Data Preprocessing: The dataset is loaded from the CSV file. The messages are tokenized using the BART tokenizer, and the sentiment labels are encoded using a LabelEncoder. The dataset is split into training and testing sets.
Model Training: The model is trained using the training set with a batch size of 4 and AdamW optimizer. The training loop runs for 5 epochs, optimizing the cross-entropy loss between predicted and true labels.

# Evaluation
Evaluation Dataset: The model's performance can be evaluated using the provided testing set or any other suitable dataset with sentiment labels.
Expected Performance: The model is expected to achieve reasonable accuracy in sentiment classification based on the quality and representativeness of the training data.

# Usage Example
Load the model and tokenizer
model = BartForSequenceClassification.from_pretrained("path/to/model/directory")
tokenizer = BartTokenizer.from_pretrained("path/to/tokenizer/directory")

Perform sentiment classification on a sample sentence
input_text = "This is a great product!"
input_tokens = tokenizer.encode_plus(input_text, padding="max_length", truncation=True, max_length=max_length, return_tensors="pt")
input_ids = input_tokens["input_ids"].to(device)
attention_mask = input_tokens["attention_mask"].to(device)

with torch.no_grad():
    outputs = model(input_ids=input_ids, attention_mask=attention_mask)
    logits = outputs.logits
    predicted_label = torch.argmax(logits, dim=1).item()
    sentiment_category = le.inverse_transform([predicted_label])[0]

print(f"Input: {input_text}")
print(f"Predicted Sentiment: {sentiment_category}")