Skip to content

adds a sampler to reduce the dataset with even distribution, called p… #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: mmo010-documentation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions data/create_df_with_nlp_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,40 @@

from spacy.lang.nl.examples import sentences

nlp = spacy.load("../model/nl_core_news_sm")
print("spacy geladen", flush=True)

def process_text(text):
# Load the model from the relative path
return nlp(text)

rows_to_keep = range(0, 100)
vaderland = pd.read_csv("HetVaderland_1873.csv", index_col=0, delimiter=',', encoding='utf-8', quotechar='"', quoting=0, skiprows = lambda x: x not in rows_to_keep)
standaard = pd.read_csv("DeStandaard_1873.csv", index_col = 0, delimiter=',', encoding='utf-8', quotechar='"', quoting=0, skiprows = lambda x: x not in rows_to_keep)
tijd = pd.read_csv("DeTijd_1873.csv", index_col = 0, delimiter=',', encoding='utf-8', quotechar='"', quoting=0, skiprows = lambda x: x not in rows_to_keep)
vaderland = pd.read_csv("HetVaderland_1873.csv", index_col=0, delimiter=',', encoding='utf-8', quotechar='"', quoting=0)
print("vaderland ingelezen: " + str(len(vaderland)), flush=True)
standaard = pd.read_csv("DeStandaard_1873.csv", index_col = 0, delimiter=',', encoding='utf-8', quotechar='"', quoting=0)
print("standaard ingelezen: " + str(len(standaard)), flush=True)
tijd = pd.read_csv("DeTijd_1873.csv", index_col = 0, delimiter=',', encoding='utf-8', quotechar='"', quoting=0)
print("tijd ingelezen: " + str(len(tijd)), flush=True)

data = pd.concat([vaderland, standaard, tijd])
print("data geplakt", flush=True)

data["date"] = pd.to_datetime(data["date"])

data['month'] = data['date'].dt.strftime("%B")
data['day'] = data['date'].dt.strftime("%A")

data = data.sort_values(by='date')
print("data gesorteerd", flush=True)

data = data.dropna(subset=['content'])

# Specify the relative path to the model directory
model_path = "../model/nl_core_news_sm"

# Load the model from the relative path
nlp = spacy.load(model_path)
print("data gerefinet", flush=True)

data["doc"] = data["content"].apply(process_text)

# Serialize
with open('processed_docs.pkl', 'wb') as f:
pickle.dump(data, f)

print("klaar met dumpen", flush=True)
# # Deserialize
# with open('processed_docs.pkl', 'rb') as f:
# processed_docs = pickle.load(f)
10 changes: 10 additions & 0 deletions data/prune.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pandas as pd
import pickle


# Deserialize
data = pd.read_pickle('processed_docs.pkl')
reduced_data = data.sample(frac = 0.005)

with open('reduced_docs.pkl', 'wb') as f:
pickle.dump(reduced_data, f)
Binary file added data/reduced_docs.pkl
Binary file not shown.