-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel_sentiments.py
More file actions
28 lines (22 loc) · 1.13 KB
/
label_sentiments.py
File metadata and controls
28 lines (22 loc) · 1.13 KB
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
import pandas as pd # For loading/saving CSV
# Step 1: Load the data
# Replace 'IMDB Dataset.csv' and 'review' with your actual file and column names
df = pd.read_csv('IMDB Dataset.csv') # Example file name
texts = df['review'][:20] # Use first 20 rows for testing
# Step 2: Prepare labels list
labels = []
print("Sentiment Annotation Tool")
print("Instructions: Label each text as 'positive', 'neutral', or 'negative'.")
for i, text in enumerate(texts):
print(f"\nText {i+1}: {text[:100]}...") # Show first 100 characters
label = input("Enter label (positive/neutral/negative): ").lower().strip()
while label not in ['positive', 'neutral', 'negative']:
print("Invalid label. Try again.")
label = input("Enter label (positive/neutral/negative): ").lower().strip()
labels.append(label)
# Step 3: Add labels to DataFrame and save
df_labeled = df.copy()
df_labeled['sentiment_label'] = [''] * len(df_labeled)
df_labeled.loc[:len(labels)-1, 'sentiment_label'] = labels
df_labeled.to_csv('labeled_data.csv', index=False)
print("\nLabeled data saved to 'labeled_data.csv'! Ready for sentiment analysis or machine learning.")