Skip to content
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

implemented XOR splitting method of train,dev,test #58

Merged
merged 2 commits into from
Jan 29, 2019
Merged
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
24 changes: 18 additions & 6 deletions src/corporacreator/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,30 @@ def _post_process_valid_data(self):
)
self.valid = self.valid.sort_values(["user_sentence_count", "client_id"])
valid = self.valid.groupby("sentence").head(self.args.duplicate_sentence_count)

valid = valid.sort_values(["user_sentence_count", "client_id"], ascending=False)
valid = valid.drop(columns="user_sentence_count")
self.valid = self.valid.drop(columns="user_sentence_count")
# Determine train, dev, and test sizes
train_size, dev_size, test_size = self._calculate_data_set_sizes(len(valid))
# Split into train, dev, and test datasets
self.train = valid.iloc[0:train_size]
self.dev = valid.iloc[train_size : train_size + dev_size]
self.test = valid.iloc[
train_size + dev_size : train_size + dev_size + test_size
]
# TODO: Make sure users are in train, dev, xor test
continous_client_index, uniques = pd.factorize(valid["client_id"])
valid["continous_client_index"] = continous_client_index
train = pd.DataFrame(columns=valid.columns)
dev = pd.DataFrame(columns=valid.columns)
test = pd.DataFrame(columns=valid.columns)

for i in range(max(continous_client_index), -1, -1):
if len(test) + len(valid[valid["continous_client_index"] == i]) <= test_size:
test = pd.concat([test, valid[valid["continous_client_index"] == i]])
elif len(dev) + len(valid[valid["continous_client_index"] == i]) <= dev_size:
dev = pd.concat([dev, valid[valid["continous_client_index"] == i]])
else:
simnotes marked this conversation as resolved.
Show resolved Hide resolved
train = pd.concat([train, valid[valid["continous_client_index"] == i]])

self.train = train.drop(columns="continous_client_index")
self.dev = dev.drop(columns="continous_client_index")
self.test = test[:train_size].drop(columns="continous_client_index")

def _calculate_data_set_sizes(self, total_size):
# Find maximum size for the training data set in accord with sample theory
Expand Down