-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfineGrainAnalysis.py
More file actions
34 lines (29 loc) · 1.08 KB
/
Copy pathfineGrainAnalysis.py
File metadata and controls
34 lines (29 loc) · 1.08 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
29
30
31
32
33
34
# Load data
import pytreebank
import sys
import os
out_path = os.path.join(sys.path[0], 'sst_{}.txt')
dataset = pytreebank.load_sst('./raw_data')
# Store train, dev and test in separate files
for category in ['train', 'test', 'dev']:
with open(out_path.format(category), 'w') as outfile:
for item in dataset[category]:
outfile.write("__label__{}\t{}\n".format(
item.to_labeled_lines()[0][0] + 1,
item.to_labeled_lines()[0][1]
))
# Print the length of the training set
print(len(dataset['train']))
import pandas as pd
# Read train data
df = pd.read_csv('sst_train.txt', sep='\t', header=None, names=['truth', 'text'])
df['truth'] = df['truth'].str.replace('__label__', '')
df['truth'] = df['truth'].astype(int).astype('category')
df.head()
import matplotlib.pyplot as plt
ax = df['truth'].value_counts(sort=False).plot(kind='barh')
ax.set_xlabel("Number of Samples in training Set")
ax.set_ylabel("Label")
df['len'] = df['text'].str.len() # Store string length of each sample
df = df.sort_values(['len'], ascending=True)
df.head(20)