rohith2812
commited on
Commit
•
b62814a
1
Parent(s):
5666b7c
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
The text file contains the collection of short movie reviews.
|
2 |
+
Each review is enclosed in parentheses and consists of a numerical rating followed by the review text.
|
3 |
+
The numerical rating is on a scale of 0 to 4, where higher numbers indicate a more positive review.
|
4 |
+
|
5 |
+
Here are some additional observations:
|
6 |
+
|
7 |
+
Format: The reviews follow a consistent format with the rating at the beginning, making it easy to identify the sentiment of each review.
|
8 |
+
Concise: The reviews are generally concise, focusing on key aspects of the movie.
|
9 |
+
Variety of Movies: The reviews cover a wide range of movies, from dramas and comedies to documentaries and action films.
|
10 |
+
Diverse Opinions: The ratings suggest a diversity of opinions on the movies.
|
11 |
+
|
12 |
+
The text file contains sentences that are hierarchically structured, likely using nested parentheses to represent some form of syntactic parsing.
|
13 |
+
To convert this into a format suitable for sentiment analysis, we need to extract the sentences in a plain text format and load them into a DataFrame.
|
14 |
+
|
15 |
+
Follow the below code for the above process
|
16 |
+
|
17 |
+
import pandas as pd
|
18 |
+
import re
|
19 |
+
|
20 |
+
labels = []
|
21 |
+
texts = []
|
22 |
+
|
23 |
+
with open("train.txt", "r") as file:
|
24 |
+
for line in file:
|
25 |
+
match = re.search(r'\((\d+) \((.*)\)\)', line)
|
26 |
+
if match:
|
27 |
+
labels.append(int(match.group(1)))
|
28 |
+
texts.append(match.group(2))
|
29 |
+
|
30 |
+
df = pd.DataFrame({"label": labels, "text": texts})
|
31 |
+
df.to_csv("output.csv", index=False)
|
32 |
+
|
33 |
+
|
34 |
+
import pandas as pd
|
35 |
+
import re
|
36 |
+
|
37 |
+
df = pd.read_csv("output.csv")
|
38 |
+
pattern = r'[().,;:"!?0-9]'
|
39 |
+
df['cleaned_text'] = df['text'].astype(str).apply(lambda x: re.sub(pattern, '', x))
|
40 |
+
df[['label', 'cleaned_text']].to_csv("cleaned_output.csv", index=False)
|
41 |
+
df = df.drop('text' , axis=1)
|
42 |
+
df.to_csv('sentence_train.csv' , index=False)
|