-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_labelling.py
69 lines (35 loc) · 949 Bytes
/
dynamic_labelling.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# coding: utf-8
# In[50]:
import pandas as pd
import numpy as np
import joblib
# In[34]:
print("Enter name of csv file to label")
print("NOTE: put file in csv_files directory")
file_name = input("")
file_location = f'/csv_files/{file_name}'
df_read = pd.read_csv(file_location)
# In[35]:
# In[36]:
df_pred = pd.DataFrame(columns=['title', 'label'])
# In[47]:
df1 = pd.DataFrame(columns=['title', 'label'])
# In[48]:
df1.append(['title'], "hello")
# In[55]:
pipeline = joblib.load('pipeline_final.sav')
# In[63]:
print("Labelling...")
for index, row in df_read.iterrows():
text = row['title']
text2 = [text]
pred = pipeline.predict(text2)
df1 = df1.append({'title': text, 'label': pred}, ignore_index=True)
# print(f'{text}: {pred}')
# In[64]:
df1
# In[66]:
file_save_location = f'/csv_files/{file_name}_labelled.csv'
df1.to_csv('/csv_files/example1_labelled.csv')
# In[ ]: